本文整理汇总了C#中Block.VerifyHeader方法的典型用法代码示例。如果您正苦于以下问题:C# Block.VerifyHeader方法的具体用法?C# Block.VerifyHeader怎么用?C# Block.VerifyHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Block
的用法示例。
在下文中一共展示了Block.VerifyHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBlock1
private static Block GetBlock1()
{
var b1 = new Block(_testNet);
b1.MerkleRoot = new Sha256Hash(Hex.Decode("0e8e58ecdacaa7b3c6304a35ae4ffff964816d2b80b62b58558866ce4e648c10"));
b1.Nonce = 236038445;
b1.TimeSeconds = 1296734340;
b1.PrevBlockHash = new Sha256Hash(Hex.Decode("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"));
Assert.AreEqual("000000033cc282bc1fa9dcae7a533263fd7fe66490f550d80076433340831604", b1.HashAsString);
b1.VerifyHeader();
return b1;
}
示例2: GetBlock2
// Some blocks from the test net.
private static Block GetBlock2()
{
var b2 = new Block(_testNet);
b2.MerkleRoot = new Sha256Hash(Hex.Decode("addc858a17e21e68350f968ccd384d6439b64aafa6c193c8b9dd66320470838b"));
b2.Nonce = 2642058077;
b2.TimeSeconds = 1296734343;
b2.PrevBlockHash = new Sha256Hash(Hex.Decode("000000033cc282bc1fa9dcae7a533263fd7fe66490f550d80076433340831604"));
Assert.AreEqual("000000037b21cac5d30fc6fda2581cf7b2612908aed2abbcc429c45b0557a15f", b2.HashAsString);
b2.VerifyHeader();
return b2;
}
示例3: Load
/// <exception cref="IOException"/>
/// <exception cref="BlockStoreException"/>
private void Load(FileInfo file)
{
_log.InfoFormat("Reading block store from {0}", file);
using (var input = file.OpenRead())
{
// Read a version byte.
var version = input.Read();
if (version == -1)
{
// No such file or the file was empty.
throw new FileNotFoundException(file.Name + " does not exist or is empty");
}
if (version != 1)
{
throw new BlockStoreException("Bad version number: " + version);
}
// Chain head pointer is the first thing in the file.
var chainHeadHash = new byte[32];
if (input.Read(chainHeadHash) < chainHeadHash.Length)
throw new BlockStoreException("Truncated block store: cannot read chain head hash");
_chainHead = new Sha256Hash(chainHeadHash);
_log.InfoFormat("Read chain head from disk: {0}", _chainHead);
var now = Environment.TickCount;
// Rest of file is raw block headers.
var headerBytes = new byte[Block.HeaderSize];
try
{
while (true)
{
// Read a block from disk.
if (input.Read(headerBytes) < 80)
{
// End of file.
break;
}
// Parse it.
var b = new Block(_params, headerBytes);
// Look up the previous block it connects to.
var prev = Get(b.PrevBlockHash);
StoredBlock s;
if (prev == null)
{
// First block in the stored chain has to be treated specially.
if (b.Equals(_params.GenesisBlock))
{
s = new StoredBlock(_params.GenesisBlock.CloneAsHeader(), _params.GenesisBlock.GetWork(), 0);
}
else
{
throw new BlockStoreException("Could not connect " + b.Hash + " to " + b.PrevBlockHash);
}
}
else
{
// Don't try to verify the genesis block to avoid upsetting the unit tests.
b.VerifyHeader();
// Calculate its height and total chain work.
s = prev.Build(b);
}
// Save in memory.
_blockMap[b.Hash] = s;
}
}
catch (ProtocolException e)
{
// Corrupted file.
throw new BlockStoreException(e);
}
catch (VerificationException e)
{
// Should not be able to happen unless the file contains bad blocks.
throw new BlockStoreException(e);
}
var elapsed = Environment.TickCount - now;
_log.InfoFormat("Block chain read complete in {0}ms", elapsed);
}
}