本文整理了Java中org.bitcoinj.core.Block.getNonce()
方法的一些代码示例,展示了Block.getNonce()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.getNonce()
方法的具体详情如下:
包路径:org.bitcoinj.core.Block
类名称:Block
方法名:getNonce
[英]Returns the nonce, an arbitrary value that exists only to make the hash of the block header fall below the difficulty target.
[中]返回nonce,这是一个任意值,它的存在只是为了使块头的哈希值低于难度目标。
代码示例来源:origin: fr.acinq/bitcoinj-core
/**
* <p>Finds a value of nonce that makes the blocks hash lower than the difficulty target. This is called mining, but
* solve() is far too slow to do real mining with. It exists only for unit testing purposes.
*
* <p>This can loop forever if a solution cannot be found solely by incrementing nonce. It doesn't change
* extraNonce.</p>
*/
public void solve() {
while (true) {
try {
// Is our proof of work valid yet?
if (checkProofOfWork(false))
return;
// No, so increment the nonce and try again.
setNonce(getNonce() + 1);
} catch (VerificationException e) {
throw new RuntimeException(e); // Cannot happen.
}
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* <p>Finds a value of nonce that makes the blocks hash lower than the difficulty target. This is called mining, but
* solve() is far too slow to do real mining with. It exists only for unit testing purposes.
*
* <p>This can loop forever if a solution cannot be found solely by incrementing nonce. It doesn't change
* extraNonce.</p>
*/
public void solve() {
while (true) {
try {
// Is our proof of work valid yet?
if (checkProofOfWork(false))
return;
// No, so increment the nonce and try again.
setNonce(getNonce() + 1);
} catch (VerificationException e) {
throw new RuntimeException(e); // Cannot happen.
}
}
}
代码示例来源:origin: greenaddress/GreenBits
/**
* <p>Finds a value of nonce that makes the blocks hash lower than the difficulty target. This is called mining, but
* solve() is far too slow to do real mining with. It exists only for unit testing purposes.
*
* <p>This can loop forever if a solution cannot be found solely by incrementing nonce. It doesn't change
* extraNonce.</p>
*/
public void solve() {
while (true) {
try {
// Is our proof of work valid yet?
if (checkProofOfWork(false))
return;
// No, so increment the nonce and try again.
setNonce(getNonce() + 1);
} catch (VerificationException e) {
throw new RuntimeException(e); // Cannot happen.
}
}
}
代码示例来源:origin: HashEngineering/dashj
/**
* <p>Finds a value of nonce that makes the blocks hash lower than the difficulty target. This is called mining, but
* solve() is far too slow to do real mining with. It exists only for unit testing purposes.
*
* <p>This can loop forever if a solution cannot be found solely by incrementing nonce. It doesn't change
* extraNonce.</p>
*/
public void solve() {
while (true) {
try {
// Is our proof of work valid yet?
if (checkProofOfWork(false))
return;
// No, so increment the nonce and try again.
setNonce(getNonce() + 1);
} catch (VerificationException e) {
throw new RuntimeException(e); // Cannot happen.
}
}
}
代码示例来源:origin: greenaddress/GreenBits
assertEquals("00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048",
zeroBlock.getHashAsString());
assertEquals(2573394689L, zeroBlock.getNonce());
assertEquals("000000004ebadb55ee9096c9a2f8880e09da59c0d68b1c228da88e48844a1485",
thirdBlock.getHashAsString());
assertEquals(2850094635L, thirdBlock.getNonce());
代码示例来源:origin: greenaddress/GreenBits
@Test
public void testProofOfWork() throws Exception {
// This params accepts any difficulty target.
NetworkParameters params = UnitTestParams.get();
Block block = params.getDefaultSerializer().makeBlock(blockBytes);
block.setNonce(12346);
try {
block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class));
fail();
} catch (VerificationException e) {
// Expected.
}
// Blocks contain their own difficulty target. The BlockChain verification mechanism is what stops real blocks
// from containing artificially weak difficulties.
block.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET);
// Now it should pass.
block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class));
// Break the nonce again at the lower difficulty level so we can try solving for it.
block.setNonce(1);
try {
block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class));
fail();
} catch (VerificationException e) {
// Expected to fail as the nonce is no longer correct.
}
// Should find an acceptable nonce.
block.solve();
block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class));
assertEquals(block.getNonce(), 2);
}
代码示例来源:origin: greenaddress/GreenBits
assertEquals(BLOCK_NONCE, block169482.getNonce());
代码示例来源:origin: greenaddress/GreenBits
@Test
public void testBasicChaining() throws Exception {
// Check that we can plug a few blocks together and the futures work.
ListenableFuture<StoredBlock> future = testNetChain.getHeightFuture(2);
// Block 1 from the testnet.
Block b1 = getBlock1();
assertTrue(testNetChain.add(b1));
assertFalse(future.isDone());
// Block 2 from the testnet.
Block b2 = getBlock2();
// Let's try adding an invalid block.
long n = b2.getNonce();
try {
b2.setNonce(12345);
testNetChain.add(b2);
fail();
} catch (VerificationException e) {
b2.setNonce(n);
}
// Now it works because we reset the nonce.
assertTrue(testNetChain.add(b2));
assertTrue(future.isDone());
assertEquals(2, future.get().getHeight());
}
代码示例来源:origin: greenaddress/GreenBits
break;
b47.block.setNonce(b47.block.getNonce() + 1);
内容来源于网络,如有侵权,请联系作者删除!