@Override public void serialize(Transaction value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); // See RawTransactionInfo POJO for a more complete JSON representation of a Transaction that is used by JSON-RPC jgen.writeNumberField("confirmations", value.getConfidence().getDepthInBlocks()); jgen.writeNumberField("version", value.getVersion()); jgen.writeStringField("hash", value.getHashAsString()); jgen.writeEndObject(); } }
if (tx.getVersion() > 1 || tx.getVersion() < 1) { log.warn("TX considered non-standard due to unknown version number {}", tx.getVersion()); return RuleViolation.VERSION;
if (tx.getVersion() > 1 || tx.getVersion() < 1) { log.warn("TX considered non-standard due to unknown version number {}", tx.getVersion()); return RuleViolation.VERSION;
if (tx.getVersion() > 2 || tx.getVersion() < 1) { log.warn("TX considered non-standard due to unknown version number {}", tx.getVersion()); return RuleViolation.VERSION;
if (tx.getVersion() > 2 || tx.getVersion() < 1) { log.warn("TX considered non-standard due to unknown version number {}", tx.getVersion()); return RuleViolation.VERSION;
if (txContainingThis.getVersion() < 2) return false;
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { Utils.uint32ToByteStreamLE(height, stream); stream.write(chainHead.getBytes()); stream.write(new VarInt(hits.length).encode()); stream.write(hits); stream.write(new VarInt(outputs.size()).encode()); for (int i = 0; i < outputs.size(); i++) { TransactionOutput output = outputs.get(i); Transaction tx = output.getParentTransaction(); Utils.uint32ToByteStreamLE(tx != null ? tx.getVersion() : 0L, stream); // Version Utils.uint32ToByteStreamLE(heights[i], stream); // Height output.bitcoinSerializeToStream(stream); } }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { Utils.uint32ToByteStreamLE(height, stream); stream.write(chainHead.getBytes()); stream.write(new VarInt(hits.length).encode()); stream.write(hits); stream.write(new VarInt(outputs.size()).encode()); for (int i = 0; i < outputs.size(); i++) { TransactionOutput output = outputs.get(i); Transaction tx = output.getParentTransaction(); Utils.uint32ToByteStreamLE(tx != null ? tx.getVersion() : 0L, stream); // Version Utils.uint32ToByteStreamLE(heights[i], stream); // Height output.bitcoinSerializeToStream(stream); } }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { Utils.uint32ToByteStreamLE(height, stream); stream.write(chainHead.getBytes()); stream.write(new VarInt(hits.length).encode()); stream.write(hits); stream.write(new VarInt(outputs.size()).encode()); for (int i = 0; i < outputs.size(); i++) { TransactionOutput output = outputs.get(i); Transaction tx = output.getParentTransaction(); Utils.uint32ToByteStreamLE(tx != null ? tx.getVersion() : 0L, stream); // Version Utils.uint32ToByteStreamLE(heights[i], stream); // Height output.bitcoinSerializeToStream(stream); } }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { Utils.uint32ToByteStreamLE(height, stream); stream.write(chainHead.getBytes()); stream.write(new VarInt(hits.length).encode()); stream.write(hits); stream.write(new VarInt(outputs.size()).encode()); for (int i = 0; i < outputs.size(); i++) { TransactionOutput output = outputs.get(i); Transaction tx = output.getParentTransaction(); Utils.uint32ToByteStreamLE(tx != null ? tx.getVersion() : 0L, stream); // Version Utils.uint32ToByteStreamLE(heights[i], stream); // Height output.bitcoinSerializeToStream(stream); } }
/** * @param requestedTx The requested tx * * @return A KeepKey transaction type containing an overall description of the current transaction */ public static KeepKeyType.TransactionType buildTxMetaResponse(Optional<Transaction> requestedTx) { int inputCount = requestedTx.get().getInputs().size(); // TxOutputBinType and TxOutputType counts are the same so ignore hash flag int outputCount = requestedTx.get().getOutputs().size(); // Provide details about the requested transaction return KeepKeyType.TransactionType .newBuilder() .setVersion((int) requestedTx.get().getVersion()) .setLockTime((int) requestedTx.get().getLockTime()) .setInputsCnt(inputCount) .setOutputsCnt(outputCount) .build(); }
/** * @param requestedTx The requested tx * * @return A Trezor transaction type containing an overall description of the current transaction */ public static TrezorType.TransactionType buildTxMetaResponse(Optional<Transaction> requestedTx) { int inputCount = requestedTx.get().getInputs().size(); // TxOutputBinType and TxOutputType counts are the same so ignore hash flag int outputCount = requestedTx.get().getOutputs().size(); // Provide details about the requested transaction return TrezorType.TransactionType .newBuilder() .setVersion((int) requestedTx.get().getVersion()) .setLockTime((int) requestedTx.get().getLockTime()) .setInputsCnt(inputCount) .setOutputsCnt(outputCount) .build(); }
private void signMultisigInput(Transaction tx, Transaction.SigHash hashType, boolean anyoneCanPay) { //TransactionSignature signature = tx.calculateSignature(0, serverKey, getContractScript(), hashType, anyoneCanPay, true); TransactionSignature signature = tx.getVersion() >= Transaction.FORKID_VERSION ? tx.calculateWitnessSignature(0, serverKey, getContractScript(), tx.getInput(0).getConnectedOutput().getValue(), Transaction.SigHash.NONE, true): tx.calculateSignature(0, serverKey, getContractScript(), hashType, true); byte[] mySig = signature.encodeToBitcoin(); Script scriptSig = ScriptBuilder.createMultiSigInputScriptBytes(ImmutableList.of(bestValueSignature, mySig)); tx.getInput(0).setScriptSig(scriptSig); }
@Test public void roundtripVersionTwoTransaction() throws Exception { Transaction tx = new Transaction(PARAMS, Utils.HEX.decode( "0200000001d7902864af9310420c6e606b814c8f89f7902d40c130594e85df2e757a7cc301070000006b483045022100ca1757afa1af85c2bb014382d9ce411e1628d2b3d478df9d5d3e9e93cb25dcdd02206c5d272b31a23baf64e82793ee5c816e2bbef251e733a638b630ff2331fc83ba0121026ac2316508287761befbd0f7495ea794b396dbc5b556bf276639f56c0bd08911feffffff0274730700000000001976a91456da2d038a098c42390c77ef163e1cc23aedf24088ac91062300000000001976a9148ebf3467b9a8d7ae7b290da719e61142793392c188ac22e00600")); assertEquals(tx.getVersion(), 2); assertEquals(tx.getHashAsString(), "0321b1413ed9048199815bd6bc2650cab1a9e8d543f109a42c769b1f18df4174"); myWallet.addWalletTransaction(new WalletTransaction(Pool.UNSPENT, tx)); Wallet wallet1 = roundTrip(myWallet); Transaction tx2 = wallet1.getTransaction(tx.getHash()); assertEquals(checkNotNull(tx2).getVersion(), 2); }
TransactionSignature sig = refundTx.getVersion() >= Transaction.FORKID_VERSION ? refundTx.calculateWitnessSignature(0, serverKey, multisigPubKey, refundTx.getInput(0).getConnectedOutput().getValue(), Transaction.SigHash.NONE, true): refundTx.calculateSignature(0, serverKey, multisigPubKey, Transaction.SigHash.NONE, true);
throw new RuntimeException(e); // Cannot happen: we built this ourselves. TransactionSignature ourSignature = refundTx.getVersion() >= Transaction.FORKID_VERSION ? refundTx.calculateWitnessSignature(0, myKey.maybeDecrypt(userKey), multisigScript, refundTx.getInput(0).getConnectedOutput().getValue(), Transaction.SigHash.ALL, false) :
private void signP2SHInput(Transaction tx, Transaction.SigHash hashType, boolean anyoneCanPay) { TransactionSignature signature = tx.getVersion() >= Transaction.FORKID_VERSION ? tx.calculateWitnessSignature(0, serverKey, createP2SHRedeemScript(), tx.getInput(0).getConnectedOutput().getValue(), hashType, anyoneCanPay): tx.calculateSignature(0, serverKey, createP2SHRedeemScript(), hashType, anyoneCanPay); byte[] mySig = signature.encodeToBitcoin(); Script scriptSig = ScriptBuilder.createCLTVPaymentChannelP2SHInput(bestValueSignature, mySig, createP2SHRedeemScript()); tx.getInput(0).setScriptSig(scriptSig); }
else mode = Transaction.SigHash.SINGLE; TransactionSignature sig = tx.getVersion() >= Transaction.FORKID_VERSION ? tx.calculateWitnessSignature(0, myKey.maybeDecrypt(userKey), getSignedScript(), tx.getInput(0).getConnectedOutput().getValue(), mode, true) : tx.calculateSignature(0, myKey.maybeDecrypt(userKey), getSignedScript(), mode, true);
TransactionSignature refundSignature = refundTx.getVersion() >= Transaction.FORKID_VERSION ? refundTx.calculateWitnessSignature(0, myKey.maybeDecrypt(userKey), getSignedScript(), refundTx.getInput(0).getConnectedOutput().getValue(), Transaction.SigHash.ALL, false) :
/** * Construct from a bitcoinj transaction * @param transaction A bitcoinj confirmed or unconfirmed transaction */ public RawTransactionInfo(Transaction transaction) { this.hex = TransactionHexSerializer.bytesToHexString(transaction.bitcoinSerialize()); this.txid = transaction.getHash(); this.version = transaction.getVersion(); this.locktime = transaction.getLockTime(); this.blockhash = null; // For now this.confirmations = transaction.getConfidence().getDepthInBlocks(); this.time = 0; // TODO: block header time of block including transaction this.blocktime = this.time; // same as time (see API doc) vin = new VinList(); for (TransactionInput input : transaction.getInputs()) { vin.add(new Vin(txid, input.getOutpoint().getIndex(), input.getScriptSig().toString(), input.getSequenceNumber())); } vout = new VoutList(); for (TransactionOutput output : transaction.getOutputs()) { vout.add(new Vout(output.getValue(), output.getIndex(), output.getScriptPubKey().toString())); } }