/** * Transactions can have an associated lock time, specified either as a block height or in seconds since the * UNIX epoch. A transaction is not allowed to be confirmed by miners until the lock time is reached, and * since Bitcoin 0.8+ a transaction that did not end its lock period (non final) is considered to be non * standard and won't be relayed or included in the memory pool either. */ public void setLockTime(long lockTime) { unCache(); boolean seqNumSet = false; for (TransactionInput input : inputs) { if (input.getSequenceNumber() != TransactionInput.NO_SEQUENCE) { seqNumSet = true; break; } } if (lockTime != 0 && (!seqNumSet || inputs.isEmpty())) { // At least one input must have a non-default sequence number for lock times to have any effect. // For instance one of them can be set to zero to make this feature work. log.warn("You are setting the lock time on a transaction but none of the inputs have non-default sequence numbers. This will not do what you expect!"); } this.lockTime = lockTime; }
/** * Transactions can have an associated lock time, specified either as a block height or in seconds since the * UNIX epoch. A transaction is not allowed to be confirmed by miners until the lock time is reached, and * since Bitcoin 0.8+ a transaction that did not end its lock period (non final) is considered to be non * standard and won't be relayed or included in the memory pool either. */ public void setLockTime(long lockTime) { unCache(); boolean seqNumSet = false; for (TransactionInput input : inputs) { if (input.getSequenceNumber() != TransactionInput.NO_SEQUENCE) { seqNumSet = true; break; } } if (lockTime != 0 && (!seqNumSet || inputs.isEmpty())) { // At least one input must have a non-default sequence number for lock times to have any effect. // For instance one of them can be set to zero to make this feature work. log.warn("You are setting the lock time on a transaction but none of the inputs have non-default sequence numbers. This will not do what you expect!"); } this.lockTime = lockTime; }
/** * Transactions can have an associated lock time, specified either as a block height or in seconds since the * UNIX epoch. A transaction is not allowed to be confirmed by miners until the lock time is reached, and * since Bitcoin 0.8+ a transaction that did not end its lock period (non final) is considered to be non * standard and won't be relayed or included in the memory pool either. */ public void setLockTime(long lockTime) { unCache(); boolean seqNumSet = false; for (TransactionInput input : inputs) { if (input.getSequenceNumber() != TransactionInput.NO_SEQUENCE) { seqNumSet = true; break; } } if (lockTime != 0 && (!seqNumSet || inputs.isEmpty())) { // At least one input must have a non-default sequence number for lock times to have any effect. // For instance one of them can be set to zero to make this feature work. log.warn("You are setting the lock time on a transaction but none " + "of the inputs have non-default sequence numbers. " + "This will not do what you expect!"); } this.lockTime = lockTime; }
/** * Transactions can have an associated lock time, specified either as a block height or in seconds since the * UNIX epoch. A transaction is not allowed to be confirmed by miners until the lock time is reached, and * since Bitcoin 0.8+ a transaction that did not end its lock period (non final) is considered to be non * standard and won't be relayed or included in the memory pool either. */ public void setLockTime(long lockTime) { unCache(); boolean seqNumSet = false; for (TransactionInput input : inputs) { if (input.getSequenceNumber() != TransactionInput.NO_SEQUENCE) { seqNumSet = true; break; } } if (lockTime != 0 && (!seqNumSet || inputs.isEmpty())) { // At least one input must have a non-default sequence number for lock times to have any effect. // For instance one of them can be set to zero to make this feature work. log.warn("You are setting the lock time on a transaction but none of the inputs have non-default sequence numbers. This will not do what you expect!"); } this.lockTime = lockTime; }
boolean addSig(final TransactionInput vin) { for(DarkSendEntryVin s : sev) { if(s.vin.getOutpoint().equals(vin.getOutpoint()) && s.vin.getSequenceNumber() == vin.getSequenceNumber()){ if(s.isSigSet){return false;} s.vin.setScriptSig(vin.getScriptSig()); //TODO: ???? s.vin.prevPubKey = vin.prevPubKey; s.isSigSet = true; return true; } } return false; }
/** * Check transaction lock time. * * @param transaction the transaction * @param locktime the locktime * @return true, if successful */ public static boolean checkTransactionLockTime (Transaction transaction, int locktime) { if (Math.abs(transaction.getLockTime() - locktime) > 5 * 60) { System.out.println("Locktime not correct. Should be: " + locktime + " Is: " + transaction.getLockTime() + " Diff: " + Math.abs(transaction .getLockTime() - locktime)); return false; } if (locktime == 0) { return true; } for (TransactionInput input : transaction.getInputs()) { if (input.getSequenceNumber() == 0) { return true; } } System.out.println("No Sequence Number is 0.."); return false; }
private static boolean checkSequence(long nSequence, Transaction txContainingThis, int index) { long txToSequence = txContainingThis.getInput(index).getSequenceNumber();
ByteArrayOutputStream bosSequence = new UnsafeByteArrayOutputStream(256); for (int i = 0; i < this.inputs.size(); ++i) { uint32ToByteStreamLE(this.inputs.get(i).getSequenceNumber(), bosSequence); bos.write(connectedScript); uint64ToByteStreamLE(BigInteger.valueOf(prevValue.getValue()), bos); uint32ToByteStreamLE(inputs.get(inputIndex).getSequenceNumber(), bos); bos.write(hashOutputs); uint32ToByteStreamLE(this.lockTime, bos);
ByteArrayOutputStream bosSequence = new UnsafeByteArrayOutputStream(256); for (int i = 0; i < this.inputs.size(); ++i) { uint32ToByteStreamLE(this.inputs.get(i).getSequenceNumber(), bosSequence); bos.write(connectedScript); uint64ToByteStreamLE(BigInteger.valueOf(prevValue.getValue()), bos); uint32ToByteStreamLE(inputs.get(inputIndex).getSequenceNumber(), bos); bos.write(hashOutputs); uint32ToByteStreamLE(this.lockTime, bos);
ByteArrayOutputStream bosSequence = new UnsafeByteArrayOutputStream(256); for (int i = 0; i < this.inputs.size(); ++i) { uint32ToByteStreamLE(this.inputs.get(i).getSequenceNumber(), bosSequence); bos.write(connectedScript); uint64ToByteStreamLE(BigInteger.valueOf(prevValue.getValue()), bos); uint32ToByteStreamLE(inputs.get(inputIndex).getSequenceNumber(), bos); bos.write(hashOutputs); uint32ToByteStreamLE(this.lockTime, bos);
.newBuilder() .addAllAddressN(addressN) .setSequence((int) input.getSequenceNumber()) .setScriptSig(ByteString.copyFrom(input.getScriptSig().getProgram())) .setScriptType(inputScriptType)
throw new VerificationException("Refund transaction does not have exactly one input"); if (refundTx.getInput(0).getSequenceNumber() == TransactionInput.NO_SEQUENCE) throw new VerificationException("Refund transaction's input's sequence number disables lock time"); if (refundTx.getLockTime() < minExpireTime)
throw new VerificationException("Refund transaction does not have exactly one input"); if (refundTx.getInput(0).getSequenceNumber() == TransactionInput.NO_SEQUENCE) throw new VerificationException("Refund transaction's input's sequence number disables lock time"); if (refundTx.getLockTime() < minExpireTime)
.newBuilder() .addAllAddressN(addressN) .setSequence((int) input.getSequenceNumber()) .setScriptSig(ByteString.copyFrom(input.getScriptSig().getProgram())) .setScriptType(inputScriptType)
throw new VerificationException("Refund transaction does not have exactly one input"); if (refundTx.getInput(0).getSequenceNumber() == TransactionInput.NO_SEQUENCE) throw new VerificationException("Refund transaction's input's sequence number disables lock time"); if (refundTx.getLockTime() < minExpireTime)
throw new VerificationException("Refund transaction does not have exactly one input"); if (refundTx.getInput(0).getSequenceNumber() == TransactionInput.NO_SEQUENCE) throw new VerificationException("Refund transaction's input's sequence number disables lock time"); if (refundTx.getLockTime() < minExpireTime)
@Test public void testSequenceNumber() throws Exception { Wallet wallet = new Wallet(PARAMS); Transaction tx1 = createFakeTx(PARAMS, Coin.COIN, wallet.currentReceiveAddress()); tx1.getInput(0).setSequenceNumber(TransactionInput.NO_SEQUENCE); wallet.receivePending(tx1, null); Transaction tx2 = createFakeTx(PARAMS, Coin.COIN, wallet.currentReceiveAddress()); tx2.getInput(0).setSequenceNumber(TransactionInput.NO_SEQUENCE - 1); wallet.receivePending(tx2, null); Wallet walletCopy = roundTrip(wallet); Transaction tx1copy = checkNotNull(walletCopy.getTransaction(tx1.getHash())); assertEquals(TransactionInput.NO_SEQUENCE, tx1copy.getInput(0).getSequenceNumber()); Transaction tx2copy = checkNotNull(walletCopy.getTransaction(tx2.getHash())); assertEquals(TransactionInput.NO_SEQUENCE - 1, tx2copy.getInput(0).getSequenceNumber()); }
assertTrue(transaction.isCached()); transaction.getInputs().get(0).setSequenceNumber(transaction.getInputs().get(0).getSequenceNumber());
.setTransactionOutPointIndex((int) input.getOutpoint().getIndex()); if (input.hasSequence()) inputBuilder.setSequence((int) input.getSequenceNumber()); if (input.getValue() != null) inputBuilder.setValue(input.getValue().value);
/** * 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())); } }