本文整理了Java中org.bitcoinj.core.Transaction.setLockTime()
方法的一些代码示例,展示了Transaction.setLockTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.setLockTime()
方法的具体详情如下:
包路径:org.bitcoinj.core.Transaction
类名称:Transaction
方法名:setLockTime
[英]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.
[中]事务可以有一个关联的锁定时间,可以指定为块高度,也可以指定自UNIX纪元以来的秒数。在达到锁定时间之前,矿工不允许确认交易,而且由于比特币0.8+未结束锁定期(非最终)的交易被视为非标准交易,也不会被中继或包含在内存池中。
代码示例来源:origin: matsjj/thundernetwork
/**
* Sets the transaction lock time.
*
* @param transaction the transaction
* @param locktime the locktime
* @return the transaction
*/
public static Transaction setTransactionLockTime (Transaction transaction, int locktime) {
transaction.setLockTime(locktime);
for (TransactionInput input : transaction.getInputs()) {
input.setSequenceNumber(0);
}
return transaction;
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void testEstimatedLockTime_WhenParameterSignifiesBlockHeight() {
int TEST_LOCK_TIME = 20;
Date now = Calendar.getInstance().getTime();
BlockChain mockBlockChain = createMock(BlockChain.class);
EasyMock.expect(mockBlockChain.estimateBlockTime(TEST_LOCK_TIME)).andReturn(now);
Transaction tx = FakeTxBuilder.createFakeTx(PARAMS);
tx.setLockTime(TEST_LOCK_TIME); // less than five hundred million
replay(mockBlockChain);
assertEquals(tx.estimateLockTime(mockBlockChain), now);
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void testToStringWhenLockTimeIsSpecifiedInBlockHeight() {
Transaction tx = FakeTxBuilder.createFakeTx(PARAMS);
TransactionInput input = tx.getInput(0);
input.setSequenceNumber(42);
int TEST_LOCK_TIME = 20;
tx.setLockTime(TEST_LOCK_TIME);
Calendar cal = Calendar.getInstance();
cal.set(2085, 10, 4, 17, 53, 21);
cal.set(Calendar.MILLISECOND, 0);
BlockChain mockBlockChain = createMock(BlockChain.class);
EasyMock.expect(mockBlockChain.estimateBlockTime(TEST_LOCK_TIME)).andReturn(cal.getTime());
replay(mockBlockChain);
String str = tx.toString(mockBlockChain);
assertEquals(str.contains("block " + TEST_LOCK_TIME), true);
assertEquals(str.contains("estimated to be reached at"), true);
}
代码示例来源:origin: greenaddress/GreenBits
assertTrue(transaction.isCached());
transaction.setLockTime(1);
代码示例来源:origin: greenaddress/GreenBits
@Test
public void nonFinalDependency() {
// Final tx has a dependency that is non-final.
Transaction tx1 = new Transaction(PARAMS);
tx1.addInput(PARAMS.getGenesisBlock().getTransactions().get(0).getOutput(0)).setSequenceNumber(1);
TransactionOutput output = tx1.addOutput(COIN, key1);
tx1.setLockTime(TIMESTAMP + 86400);
Transaction tx2 = new Transaction(PARAMS);
tx2.addInput(output);
tx2.addOutput(COIN, new ECKey());
DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx2, ImmutableList.of(tx1));
assertEquals(RiskAnalysis.Result.NON_FINAL, analysis.analyze());
assertEquals(tx1, analysis.getNonFinal());
}
代码示例来源:origin: fr.acinq/bitcoinj-core
refundTx.setLockTime(expiryTime);
if (Context.get().isEnsureMinRequiredFee()) {
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
refundTx.setLockTime(expiryTime);
if (Context.get().isEnsureMinRequiredFee()) {
代码示例来源:origin: greenaddress/GreenBits
refundTx.setLockTime(expiryTime);
if (Context.get().isEnsureMinRequiredFee()) {
代码示例来源:origin: HashEngineering/dashj
refundTx.setLockTime(expiryTime);
if (Context.get().isEnsureMinRequiredFee()) {
代码示例来源:origin: greenaddress/GreenBits
@Test
public void nonFinal() throws Exception {
// Verify that just having a lock time in the future is not enough to be considered risky (it's still final).
Transaction tx = new Transaction(PARAMS);
TransactionInput input = tx.addInput(PARAMS.getGenesisBlock().getTransactions().get(0).getOutput(0));
tx.addOutput(COIN, key1);
tx.setLockTime(TIMESTAMP + 86400);
DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
assertEquals(RiskAnalysis.Result.OK, analysis.analyze());
assertNull(analysis.getNonFinal());
// Set a sequence number on the input to make it genuinely non-final. Verify it's risky.
input.setSequenceNumber(TransactionInput.NO_SEQUENCE - 1);
analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
assertEquals(RiskAnalysis.Result.NON_FINAL, analysis.analyze());
assertEquals(tx, analysis.getNonFinal());
// If the lock time is the current block, it's about to become final and we consider it non-risky.
tx.setLockTime(1000);
analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
assertEquals(RiskAnalysis.Result.OK, analysis.analyze());
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void testCLTVPaymentChannelTransactionRefund() {
BigInteger time = BigInteger.valueOf(20);
ECKey from = new ECKey(), to = new ECKey(), incorrect = new ECKey();
Script outputScript = ScriptBuilder.createCLTVPaymentChannelOutput(time, from, to);
Transaction tx = new Transaction(PARAMS);
tx.addInput(new TransactionInput(PARAMS, tx, new byte[] {}));
tx.getInput(0).setSequenceNumber(0);
tx.setLockTime(time.add(BigInteger.ONE).longValue());
TransactionSignature fromSig =
tx.calculateSignature(0, from, outputScript, Transaction.SigHash.SINGLE, false);
TransactionSignature incorrectSig =
tx.calculateSignature(0, incorrect, outputScript, Transaction.SigHash.SINGLE, false);
Script scriptSig =
ScriptBuilder.createCLTVPaymentChannelRefund(fromSig);
Script invalidScriptSig =
ScriptBuilder.createCLTVPaymentChannelRefund(incorrectSig);
try {
scriptSig.correctlySpends(tx, 0, outputScript, Script.ALL_VERIFY_FLAGS);
} catch (ScriptException e) {
e.printStackTrace();
fail("Refund failed to correctly spend the payment channel");
}
try {
invalidScriptSig.correctlySpends(tx, 0, outputScript, Script.ALL_VERIFY_FLAGS);
fail("Invalid sig passed");
} catch (ScriptException e) { }
}
代码示例来源:origin: greenaddress/GreenBits
refundTx.setLockTime(expiryTime);
if (Context.get().isEnsureMinRequiredFee()) {
代码示例来源:origin: fr.acinq/bitcoinj-core
refundTx.setLockTime(expiryTime);
if (Context.get().isEnsureMinRequiredFee()) {
代码示例来源:origin: HashEngineering/dashj
refundTx.setLockTime(expiryTime);
if (Context.get().isEnsureMinRequiredFee()) {
代码示例来源:origin: greenaddress/GreenBits
@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());
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
refundTx.setLockTime(expiryTime);
if (Context.get().isEnsureMinRequiredFee()) {
代码示例来源:origin: HashEngineering/dashj
tx.setLockTime(0xffffffffL & txProto.getLockTime());
代码示例来源:origin: greenaddress/GreenBits
tx.addInput(new TransactionInput(PARAMS, tx, new byte[] {}));
tx.getInput(0).setSequenceNumber(0);
tx.setLockTime(time.subtract(BigInteger.ONE).longValue());
TransactionSignature fromSig =
tx.calculateSignature(0, from, outputScript, Transaction.SigHash.SINGLE, false);
代码示例来源:origin: greenaddress/GreenBits
t2.setLockTime(999999);
代码示例来源:origin: greenaddress/GreenBits
t2.setLockTime(999999);
inbound(writeTarget, t2);
Threading.waitForUserCode();
内容来源于网络,如有侵权,请联系作者删除!