@Override public void setSource(TransactionConfidence.Source source) { tx.getConfidence().setSource(source); }
@Override public void setSource(TransactionConfidence.Source source) { tx.getConfidence().setSource(source); }
/** * Parse transactions from the block. * * @param transactionsOffset Offset of the transactions within the block. * Useful for non-Bitcoin chains where the block header may not be a fixed * size. */ protected void parseTransactions(final int transactionsOffset) throws ProtocolException { cursor = transactionsOffset; optimalEncodingMessageSize = HEADER_SIZE; if (payload.length == cursor) { // This message is just a header, it has no transactions. transactionBytesValid = false; return; } int numTransactions = (int) readVarInt(); optimalEncodingMessageSize += VarInt.sizeOf(numTransactions); transactions = new ArrayList<Transaction>(numTransactions); for (int i = 0; i < numTransactions; i++) { Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH); // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows. tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK); transactions.add(tx); cursor += tx.getMessageSize(); optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize(); } transactionBytesValid = serializer.isParseRetainMode(); }
/** * Parse transactions from the block. * * @param transactionsOffset Offset of the transactions within the block. * Useful for non-Bitcoin chains where the block header may not be a fixed * size. */ protected void parseTransactions(final int transactionsOffset) throws ProtocolException { cursor = transactionsOffset; optimalEncodingMessageSize = HEADER_SIZE; if (payload.length == cursor) { // This message is just a header, it has no transactions. transactionBytesValid = false; return; } int numTransactions = (int) readVarInt(); optimalEncodingMessageSize += VarInt.sizeOf(numTransactions); transactions = new ArrayList<>(numTransactions); for (int i = 0; i < numTransactions; i++) { Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH); // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows. tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK); transactions.add(tx); cursor += tx.getMessageSize(); optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize(); } transactionBytesValid = serializer.isParseRetainMode(); }
/** * Parse transactions from the block. * * @param transactionsOffset Offset of the transactions within the block. * Useful for non-Bitcoin chains where the block header may not be a fixed * size. */ protected void parseTransactions(final int transactionsOffset) throws ProtocolException { cursor = transactionsOffset; optimalEncodingMessageSize = HEADER_SIZE; if (payload.length == cursor) { // This message is just a header, it has no transactions. transactionBytesValid = false; return; } int numTransactions = (int) readVarInt(); optimalEncodingMessageSize += VarInt.sizeOf(numTransactions); transactions = new ArrayList<>(numTransactions); for (int i = 0; i < numTransactions; i++) { Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH); // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows. tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK); transactions.add(tx); cursor += tx.getMessageSize(); optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize(); } transactionBytesValid = serializer.isParseRetainMode(); }
/** * Parse transactions from the block. * * @param transactionsOffset Offset of the transactions within the block. * Useful for non-Bitcoin chains where the block header may not be a fixed * size. */ protected void parseTransactions(final int transactionsOffset) throws ProtocolException { cursor = transactionsOffset; optimalEncodingMessageSize = HEADER_SIZE; if (payload.length == cursor) { // This message is just a header, it has no transactions. transactionBytesValid = false; return; } int numTransactions = (int) readVarInt(); optimalEncodingMessageSize += VarInt.sizeOf(numTransactions); transactions = new ArrayList<Transaction>(numTransactions); for (int i = 0; i < numTransactions; i++) { Transaction tx = new Transaction(params, payload, cursor, this, serializer, UNKNOWN_LENGTH); // Label the transaction as coming from the P2P network, so code that cares where we first saw it knows. tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK); transactions.add(tx); cursor += tx.getMessageSize(); optimalEncodingMessageSize += tx.getOptimalEncodingMessageSize(); } transactionBytesValid = serializer.isParseRetainMode(); }
TransactionOutPoint transactionOutPoint = new TransactionOutPoint(this.networkParameters, inputUtxo.getIndex(), inputUtxo.getHash()); transaction.addSignedInput(transactionOutPoint, inputUtxo.getScript(), this.key, Transaction.SigHash.ALL, true); transaction.getConfidence().setSource(TransactionConfidence.Source.SELF); transaction.setPurpose(Transaction.Purpose.USER_PAYMENT); dltTransaction.setSignedTransaction(DatatypeConverter.printHexBinary(transaction.bitcoinSerialize()));
for (ClientState.StoredClientPaymentChannel storedState : states.getChannelsList()) { Transaction refundTransaction = params.getDefaultSerializer().makeTransaction(storedState.getRefundTransaction().toByteArray()); refundTransaction.getConfidence().setSource(TransactionConfidence.Source.SELF); ECKey myKey = (storedState.getMyKey().isEmpty()) ? containingWallet.findKeyFromPubKey(storedState.getMyPublicKey().toByteArray()) :
for (ClientState.StoredClientPaymentChannel storedState : states.getChannelsList()) { Transaction refundTransaction = params.getDefaultSerializer().makeTransaction(storedState.getRefundTransaction().toByteArray()); refundTransaction.getConfidence().setSource(TransactionConfidence.Source.SELF); ECKey myKey = (storedState.getMyKey().isEmpty()) ? containingWallet.findKeyFromPubKey(storedState.getMyPublicKey().toByteArray()) :
for (ClientState.StoredClientPaymentChannel storedState : states.getChannelsList()) { Transaction refundTransaction = params.getDefaultSerializer().makeTransaction(storedState.getRefundTransaction().toByteArray()); refundTransaction.getConfidence().setSource(TransactionConfidence.Source.SELF); ECKey myKey = (storedState.getMyKey().isEmpty()) ? containingWallet.findKeyFromPubKey(storedState.getMyPublicKey().toByteArray()) :
for (ClientState.StoredClientPaymentChannel storedState : states.getChannelsList()) { Transaction refundTransaction = params.getDefaultSerializer().makeTransaction(storedState.getRefundTransaction().toByteArray()); refundTransaction.getConfidence().setSource(TransactionConfidence.Source.SELF); ECKey myKey = (storedState.getMyKey().isEmpty()) ? containingWallet.findKeyFromPubKey(storedState.getMyPublicKey().toByteArray()) :
/** Emulates receiving a valid block */ public static BlockPair createFakeBlock(BlockStore blockStore, StoredBlock previousStoredBlock, long version, long timeSeconds, int height, Transaction... transactions) { try { Block previousBlock = previousStoredBlock.getHeader(); Address to = new ECKey().toAddress(previousBlock.getParams()); Block b = previousBlock.createNextBlock(to, version, timeSeconds, height); // Coinbase tx was already added. for (Transaction tx : transactions) { tx.getConfidence().setSource(TransactionConfidence.Source.NETWORK); b.addTransaction(tx); } b.solve(); BlockPair pair = new BlockPair(); pair.block = b; pair.storedBlock = previousStoredBlock.build(b); blockStore.put(pair.storedBlock); blockStore.setChainHead(pair.storedBlock); return pair; } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } catch (BlockStoreException e) { throw new RuntimeException(e); // Cannot happen. } }
@Test public void selfCreatedAreNotRisky() { Transaction tx = new Transaction(PARAMS); tx.addInput(PARAMS.getGenesisBlock().getTransactions().get(0).getOutput(0)).setSequenceNumber(1); tx.addOutput(COIN, key1); tx.setLockTime(TIMESTAMP + 86400); { // Is risky ... DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS); assertEquals(RiskAnalysis.Result.NON_FINAL, analysis.analyze()); } tx.getConfidence().setSource(TransactionConfidence.Source.SELF); { // Is no longer risky. DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS); assertEquals(RiskAnalysis.Result.OK, analysis.analyze()); } }
refundTx.getInput(0).setScriptSig(ScriptBuilder.createCLTVPaymentChannelP2SHRefund(refundSignature, redeemScript)); refundTx.getConfidence().setSource(TransactionConfidence.Source.SELF); log.info("initiated channel with contract {}", contract.getHashAsString()); stateMachine.transition(State.SAVE_STATE_IN_WALLET);
@Test public void selectable() throws Exception { Transaction t; t = new Transaction(PARAMS); t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.PENDING); assertFalse(DefaultCoinSelector.isSelectable(t)); t.getConfidence().setSource(TransactionConfidence.Source.SELF); assertFalse(DefaultCoinSelector.isSelectable(t)); t.getConfidence().markBroadcastBy(new PeerAddress(PARAMS, InetAddress.getByName("1.2.3.4"))); assertFalse(DefaultCoinSelector.isSelectable(t)); t.getConfidence().markBroadcastBy(new PeerAddress(PARAMS, InetAddress.getByName("5.6.7.8"))); assertTrue(DefaultCoinSelector.isSelectable(t)); t = new Transaction(PARAMS); t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING); assertTrue(DefaultCoinSelector.isSelectable(t)); t = new Transaction(RegTestParams.get()); t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.PENDING); t.getConfidence().setSource(TransactionConfidence.Source.SELF); assertTrue(DefaultCoinSelector.isSelectable(t)); }
@Test public void lateProgressCallback() throws Exception { // Check that if we register a progress callback on a broadcast after the broadcast has started, it's invoked // immediately with the latest state. This avoids API users writing accidentally racy code when they use // a convenience method like peerGroup.broadcastTransaction. InboundMessageQueuer[] channels = { connectPeer(1), connectPeer(2), connectPeer(3), connectPeer(4) }; Transaction tx = FakeTxBuilder.createFakeTx(PARAMS, CENT, address); tx.getConfidence().setSource(TransactionConfidence.Source.SELF); TransactionBroadcast broadcast = peerGroup.broadcastTransaction(tx); inbound(channels[1], InventoryMessage.with(tx)); pingAndWait(channels[1]); final AtomicDouble p = new AtomicDouble(); broadcast.setProgressCallback(new TransactionBroadcast.ProgressCallback() { @Override public void onBroadcastProgress(double progress) { p.set(progress); } }, Threading.SAME_THREAD); assertEquals(1.0, p.get(), 0.01); }
t1.getConfidence().markBroadcastBy(new PeerAddress(PARAMS, InetAddress.getByName("1.2.3.4"))); t1.getConfidence().markBroadcastBy(new PeerAddress(PARAMS, InetAddress.getByName("5.6.7.8"))); t1.getConfidence().setSource(TransactionConfidence.Source.NETWORK); myWallet.receivePending(t1, null); Wallet wallet1 = roundTrip(myWallet);
InboundMessageQueuer[] channels = { connectPeer(1), connectPeer(2), connectPeer(3), connectPeer(4) }; Transaction tx = new Transaction(PARAMS); tx.getConfidence().setSource(TransactionConfidence.Source.SELF); TransactionBroadcast broadcast = new TransactionBroadcast(peerGroup, tx); final AtomicDouble lastProgress = new AtomicDouble();
tx.getConfidence().setSource(Source.SELF); account1.addNewTransactionIfNeeded(tx);
tx.getConfidence().setSource(Source.SELF); account1.addNewTransactionIfNeeded(tx);