本文整理汇总了Java中org.bitcoinj.core.VerificationException类的典型用法代码示例。如果您正苦于以下问题:Java VerificationException类的具体用法?Java VerificationException怎么用?Java VerificationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VerificationException类属于org.bitcoinj.core包,在下文中一共展示了VerificationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveFromBlock
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
@Override
public void receiveFromBlock(Transaction tx, StoredBlock block, AbstractBlockChain.NewBlockType blockType, int relativityOffset) throws VerificationException {
//Log.d("TransactionIsInBlock",block.toString());
synchronized (transactions) {
countTransactions++;
transactions.add(tx);
if (transactions.size() >= 30) {
transactions.remove(10);
}
}
if(System.currentTimeMillis()-lastTimestamp>1000) {
refreshUI();
lastTimestamp = System.currentTimeMillis();
}
}
示例2: decodeFromBitcoin
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
/**
* Returns a decoded signature.
*
* @param requireCanonicalEncoding if the encoding of the signature must
* be canonical.
* @param requireCanonicalSValue if the S-value must be canonical (below half
* the order of the curve).
* @throws RuntimeException if the signature is invalid or unparseable in some way.
*/
public static TransactionSignature decodeFromBitcoin(byte[] bytes,
boolean requireCanonicalEncoding,
boolean requireCanonicalSValue) throws VerificationException {
// Bitcoin encoding is DER signature + sighash byte.
if (requireCanonicalEncoding && !isEncodingCanonical(bytes))
throw new VerificationException("Signature encoding is not canonical.");
ECKey.ECDSASignature sig;
try {
sig = ECKey.ECDSASignature.decodeFromDER(bytes);
} catch (IllegalArgumentException e) {
throw new VerificationException("Could not decode DER", e);
}
if (requireCanonicalSValue && !sig.isCanonical())
throw new VerificationException("S-value is not canonical.");
// In Bitcoin, any value of the final byte is valid, but not necessarily canonical. See javadocs for
// isEncodingCanonical to learn more about this. So we must store the exact byte found.
return new TransactionSignature(sig.r, sig.s, bytes[bytes.length - 1]);
}
示例3: notifyTransactionIsInBlock
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
/**
* Called by the {@link BlockChain} when we receive a new filtered block that contains a transactions previously
* received by a call to {@link #receivePending}.<p>
*
* This is necessary for the internal book-keeping Wallet does. When a transaction is received that sends us
* coins it is added to a pool so we can use it later to create spends. When a transaction is received that
* consumes outputs they are marked as spent so they won't be used in future.<p>
*
* A transaction that spends our own coins can be received either because a spend we created was accepted by the
* network and thus made it into a block, or because our keys are being shared between multiple instances and
* some other node spent the coins instead. We still have to know about that to avoid accidentally trying to
* double spend.<p>
*
* A transaction may be received multiple times if is included into blocks in parallel chains. The blockType
* parameter describes whether the containing block is on the main/best chain or whether it's on a presently
* inactive side chain. We must still record these transactions and the blocks they appear in because a future
* block might change which chain is best causing a reorganize. A re-org can totally change our balance!
*/
@Override
public boolean notifyTransactionIsInBlock(Sha256Hash txHash, StoredBlock block,
BlockChain.NewBlockType blockType,
int relativityOffset) throws VerificationException {
lock.lock();
try {
Transaction tx = transactions.get(txHash);
if (tx == null) {
tx = riskDropped.get(txHash);
if (tx != null) {
// If this happens our risk analysis is probably wrong and should be improved.
log.info("Risk analysis dropped tx {} but was included in block anyway", tx.getHash());
} else {
// False positive that was broadcast to us and ignored by us because it was irrelevant to our keys.
return false;
}
}
receive(tx, block, blockType, relativityOffset);
return true;
} finally {
lock.unlock();
}
}
示例4: createNewStore
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
private void createNewStore(NetworkParameters params) throws BlockStoreException {
try {
// Set up the genesis block. When we start out fresh, it is by
// definition the top of the chain.
StoredBlock storedGenesisHeader = new StoredBlock(params.getGenesisBlock().cloneAsHeader(),
params.getGenesisBlock().getWork(), 0);
// The coinbase in the genesis block is not spendable. This is
// because of how the reference client inits
// its database - the genesis transaction isn't actually in the db
// so its spent flags can never be updated.
List<Transaction> genesisTransactions = Lists.newLinkedList();
StoredUndoableBlock storedGenesis = new StoredUndoableBlock(params.getGenesisBlock().getHash(),
genesisTransactions);
beginDatabaseBatchWrite();
put(storedGenesisHeader, storedGenesis);
setChainHead(storedGenesisHeader);
setVerifiedChainHead(storedGenesisHeader);
batchPut(getKey(KeyType.CREATED), bytes("done"));
commitDatabaseBatchWrite();
} catch (VerificationException e) {
throw new RuntimeException(e); // Cannot happen.
}
}
示例5: initStateFromBitcoinUri
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
private void initStateFromBitcoinUri(final Uri bitcoinUri) {
final String input = bitcoinUri.toString();
new StringInputParser(input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
updateStateFrom(paymentIntent);
}
@Override
protected void handlePrivateKey(final VersionedChecksummedBytes key) {
throw new UnsupportedOperationException();
}
@Override
protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
throw new UnsupportedOperationException();
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
dialog(activity, activityDismissListener, 0, messageResId, messageArgs);
}
}.parse();
}
示例6: handleTx
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
private boolean handleTx(final Transaction tx) {
log.info("tx " + tx.getHashAsString() + " arrived via blueooth");
try {
if (wallet.isTransactionRelevant(tx)) {
wallet.receivePending(tx, null);
handler.post(new Runnable() {
@Override
public void run() {
application.broadcastTransaction(tx);
}
});
} else {
log.info("tx " + tx.getHashAsString() + " irrelevant");
}
return true;
} catch (final VerificationException x) {
log.info("cannot verify tx " + tx.getHashAsString() + " received via bluetooth", x);
}
return false;
}
示例7: getSignature
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
/**
* Takes in a transaction and a private key and returns a signature (if possible)
* as a Bytestring object.
*/
public Bytestring getSignature(org.bitcoinj.core.Transaction signTx, ECKey privKey) {
org.bitcoinj.core.Transaction copyTx = signTx;
for (int i = 0; i < copyTx.getInputs().size(); i++) {
TransactionInput input = copyTx.getInput(i);
TransactionOutput connectedOutput = input.getConnectedOutput();
Sha256Hash hash = copyTx.hashForSignature(i, connectedOutput.getScriptPubKey(), org.bitcoinj.core.Transaction.SigHash.ALL, false);
ECKey.ECDSASignature ecSig = privKey.sign(hash);
TransactionSignature txSig = new TransactionSignature(ecSig, org.bitcoinj.core.Transaction.SigHash.ALL, false);
byte[] originalScript = input.getScriptBytes().clone();
Script inputScript = ScriptBuilder.createInputScript(txSig, ECKey.fromPublicOnly(privKey.getPubKey()));
input.setScriptSig(inputScript);
try {
input.verify(connectedOutput);
return new Bytestring(inputScript.getProgram());
} catch (VerificationException e) {
input.setScriptSig(this.bytestringToInputScript(new Bytestring(originalScript)));
}
}
return null;
}
示例8: verifyHeightTrustworthy
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
protected void verifyHeightTrustworthy(int height) throws IllegalArgumentException, VerificationException {
if (height < 1) {
throw new IllegalArgumentException("Nonpositive block height; not trustworthy!");
}
int headHeight = chain.getChainHead().getHeight();
int confirmations = headHeight - height + 1;
// TODO: optionally use transaction chains (with signature checks) to verify transactions without 12 confirmations
// TODO: the above needs to be optional, because some applications (e.g. cert transparency) require confirmations
if (confirmations < 12) {
throw new VerificationException("Block does not yet have 12 confirmations; not trustworthy!");
}
// TODO: check for off-by-one errors on this line
if (confirmations >= 36000) {
throw new VerificationException("Block has expired; not trustworthy!");
}
}
示例9: notifyNewBestBlock
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
@Override
public void notifyNewBestBlock (StoredBlock block) throws VerificationException {
// TODO: use BIP 113 timestamps
if ( (new Date().getTime() / 1000 ) - block.getHeader().getTimeSeconds() > 366 * 24 * 60 * 60) {
log.debug("NameDB skipping block at height " + block.getHeight() + " due to timestamp " + block.getHeader().getTimeSeconds());
return;
}
log.debug("NameDB started processing new best block at height " + block.getHeight());
try {
putBlockChain(getSafeBlock(block));
}
catch (Exception e) {
log.error("NameDB Exception while processing new best block", e);
throw new VerificationException(e);
}
log.debug("NameDB finished processing new best block at height " + block.getHeight());
}
示例10: reorganize
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
@Override
public void reorganize(StoredBlock splitPoint, List<StoredBlock> oldBlocks, List<StoredBlock> newBlocks) throws VerificationException {
// TODO: use BIP 113 timestamps
if ( (new Date().getTime() / 1000 ) - newBlocks.get(0).getHeader().getTimeSeconds() > 366 * 24 * 60 * 60) {
return;
}
setChainHead(splitPoint.getHeight() - 12);
try {
putBlockChain(getSafeBlock(newBlocks.get(0)));
}
catch (Exception e) {
log.error("Exception during NameDB reorganize", e);
throw new VerificationException(e);
}
log.warn("Finished NameDB reorganize, height " + newBlocks.get(0).getHeight());
}
示例11: notifyNewBestBlock
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
@Override
public void notifyNewBestBlock(StoredBlock block) throws VerificationException {
WalletObservable walletObservable = ewApplication.getWalletObservable();
//Log.d(TAG, "notifyNewBestBlock " + block.getHeight());
EWWalletService ewWalletService = ewApplication.getEwWalletService();
if(ewWalletService!=null) {
Wallet wallet = ewWalletService.getWallet();
if(wallet.getPendingTransactions().size()==0 && walletObservable.isPending() ) { //TODO check if it's right!!!
walletObservable.setState(WalletObservable.State.SYNCED);
walletObservable.notifyObservers();
}
//if(walletObservable.isPending())
ewWalletService.refreshNextsAndAlias();
//Log.i(TAG, "" + walletObservable );
}
}
示例12: notifyNewBestBlock
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
@Override
public void notifyNewBestBlock(StoredBlock block) throws VerificationException {
try {
bcg.updateTable();
BlockchainGUI.hideBtnMoreInfo();
} catch (BlockStoreException e) {
System.err.println(e.getMessage());
}
}
示例13: checkDifficultyTransitions
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
@Override
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
final BlockStore blockStore) throws VerificationException, BlockStoreException {
if (!isDifficultyTransitionPoint(storedPrev.getHeight()) && nextBlock.getTime().after(testnetDiffDate)) {
Block prev = storedPrev.getHeader();
// After 15th February 2012 the rules on the testnet change to avoid people running up the difficulty
// and then leaving, making it too hard to mine a block. On non-difficulty transition points, easy
// blocks are allowed if there has been a span of 20 minutes without one.
final long timeDelta = nextBlock.getTimeSeconds() - prev.getTimeSeconds();
// There is an integer underflow bug in bitcoin-qt that means mindiff blocks are accepted when time
// goes backwards.
if (timeDelta >= 0 && timeDelta <= NetworkParameters.TARGET_SPACING * 2) {
// Walk backwards until we find a block that doesn't have the easiest proof of work, then check
// that difficulty is equal to that one.
StoredBlock cursor = storedPrev;
while (!cursor.getHeader().equals(getGenesisBlock()) &&
cursor.getHeight() % getInterval() != 0 &&
cursor.getHeader().getDifficultyTargetAsInteger().equals(getMaxTarget()))
cursor = cursor.getPrev(blockStore);
BigInteger cursorTarget = cursor.getHeader().getDifficultyTargetAsInteger();
BigInteger newTarget = nextBlock.getDifficultyTargetAsInteger();
if (!cursorTarget.equals(newTarget))
throw new VerificationException("Testnet block transition that is not allowed: " +
Long.toHexString(cursor.getHeader().getDifficultyTarget()) + " vs " +
Long.toHexString(nextBlock.getDifficultyTarget()));
}
} else {
super.checkDifficultyTransitions(storedPrev, nextBlock, blockStore);
}
}
示例14: onActivityResultResumed
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
private void onActivityResultResumed(final int requestCode, final int resultCode, final Intent intent) {
if (requestCode == REQUEST_CODE_SCAN) {
if (resultCode == Activity.RESULT_OK) {
final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
new StringInputParser(input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
setState(null);
updateStateFrom(paymentIntent);
}
@Override
protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
cannotClassify(input);
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
dialog(activity, null, R.string.button_scan, messageResId, messageArgs);
}
}.parse();
}
} else if (requestCode == REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST) {
if (paymentIntent.isBluetoothPaymentRequestUrl())
requestPaymentRequest();
} else if (requestCode == REQUEST_CODE_ENABLE_BLUETOOTH_FOR_DIRECT_PAYMENT) {
if (paymentIntent.isBluetoothPaymentUrl())
directPaymentEnableView.setChecked(resultCode == Activity.RESULT_OK);
}
}
示例15: onActivityResult
import org.bitcoinj.core.VerificationException; //导入依赖的package包/类
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
if (requestCode == REQUEST_CODE_SCAN && resultCode == Activity.RESULT_OK) {
final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
new StringInputParser(input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
SendCoinsActivity.start(WalletActivity.this, paymentIntent);
}
@Override
protected void handlePrivateKey(final VersionedChecksummedBytes key) {
if (Constants.ENABLE_SWEEP_WALLET)
SweepWalletActivity.start(WalletActivity.this, key);
else
super.handlePrivateKey(key);
}
@Override
protected void handleDirectTransaction(final Transaction tx) throws VerificationException {
application.processDirectTransaction(tx);
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
dialog(WalletActivity.this, null, R.string.button_scan, messageResId, messageArgs);
}
}.parse();
}
}