本文整理汇总了C#中Block.Verify方法的典型用法代码示例。如果您正苦于以下问题:C# Block.Verify方法的具体用法?C# Block.Verify怎么用?C# Block.Verify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Block
的用法示例。
在下文中一共展示了Block.Verify方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBadTransactions
public void TestBadTransactions()
{
var block = new Block(_params, _blockBytes);
// Re-arrange so the coinbase transaction is not first.
var tx1 = block.Transactions[0];
var tx2 = block.Transactions[1];
block.Transactions[0] = tx2;
block.Transactions[1] = tx1;
try
{
block.Verify();
Assert.Fail();
}
catch (VerificationException)
{
// We should get here.
}
}
示例2: AddBlock
protected internal override bool AddBlock(Block block)
{
lock (block_cache)
{
if (!block_cache.ContainsKey(block.Hash))
{
block_cache.Add(block.Hash, block);
}
}
lock (header_chain)
{
if (!header_chain.Nodes.ContainsKey(block.PrevBlock)) return false;
if (!header_chain.Nodes.ContainsKey(block.Hash))
{
if (VerifyBlocks && !block.Verify()) return false;
header_chain.Add(block.Hash, block.Header, block.PrevBlock);
OnAddHeader(block);
}
}
return true;
}
示例3: GetBlock2
// Some blocks from the test net.
private static Block GetBlock2()
{
var b2 = new Block(_testNet);
b2.MerkleRoot = Hex.Decode("addc858a17e21e68350f968ccd384d6439b64aafa6c193c8b9dd66320470838b");
b2.Nonce = 2642058077;
b2.Time = 1296734343;
b2.PrevBlockHash = Hex.Decode("000000033cc282bc1fa9dcae7a533263fd7fe66490f550d80076433340831604");
Assert.AreEqual("000000037b21cac5d30fc6fda2581cf7b2612908aed2abbcc429c45b0557a15f", b2.HashAsString);
b2.Verify();
return b2;
}
示例4: GetBlock1
private static Block GetBlock1()
{
var b1 = new Block(_testNet);
b1.MerkleRoot = Hex.Decode("0e8e58ecdacaa7b3c6304a35ae4ffff964816d2b80b62b58558866ce4e648c10");
b1.Nonce = 236038445;
b1.Time = 1296734340;
b1.PrevBlockHash = Hex.Decode("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008");
Assert.AreEqual("000000033cc282bc1fa9dcae7a533263fd7fe66490f550d80076433340831604", b1.HashAsString);
b1.Verify();
return b1;
}
示例5: TestBlockVerification
public void TestBlockVerification()
{
var block = new Block(_params, _blockBytes);
block.Verify();
Assert.AreEqual("00000000a6e5eb79dcec11897af55e90cd571a4335383a3ccfbc12ec81085935", block.HashAsString);
}
示例6: TestProofOfWork
public void TestProofOfWork()
{
// This params accepts any difficulty target.
var networkParams = NetworkParameters.UnitTests();
var block = new Block(networkParams, _blockBytes);
block.Nonce = 12346;
try
{
block.Verify();
Assert.Fail();
}
catch (VerificationException)
{
// Expected.
}
// Blocks contain their own difficulty target. The BlockChain verification mechanism is what stops real blocks
// from containing artificially weak difficulties.
block.DifficultyTarget = Block.EasiestDifficultyTarget;
// Now it should pass.
block.Verify();
// Break the nonce again at the lower difficulty level so we can try solving for it.
block.Nonce = 1;
try
{
block.Verify();
Assert.Fail();
}
catch (VerificationException)
{
// Expected to fail as the nonce is no longer correct.
}
// Should find an acceptable nonce.
block.Solve();
block.Verify();
Assert.AreEqual(block.Nonce, 2U);
}