本文整理汇总了C#中Block.RebuildMerkleRoot方法的典型用法代码示例。如果您正苦于以下问题:C# Block.RebuildMerkleRoot方法的具体用法?C# Block.RebuildMerkleRoot怎么用?C# Block.RebuildMerkleRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Block
的用法示例。
在下文中一共展示了Block.RebuildMerkleRoot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button2_Click
private void button2_Click(object sender, EventArgs e)
{
Block block = new Block
{
PrevBlock = UInt256.Zero,
Timestamp = DateTime.Now.ToTimestamp(),
Height = 0,
Nonce = 2083236893, //向比特币致敬
NextMiner = Contract.CreateMultiSigContract(Blockchain.GetMinSignatureCount(Blockchain.StandbyMiners.Length), Blockchain.StandbyMiners).ScriptHash,
Transactions = new Transaction[]
{
new GenerationTransaction
{
Nonce = 0,
Inputs = new TransactionInput[0],
Outputs = new TransactionOutput[0],
Scripts = { }
},
textBox3.Text.HexToBytes().AsSerializable<RegisterTransaction>()
}
};
block.RebuildMerkleRoot();
SignatureContext context = new SignatureContext(block.Header);
InformationBox.Show(context.ToString(), "创世区块头签名上下文");
}
示例2: StartMine
private async void StartMine(CancellationToken token)
{
while (wallet == null && !token.IsCancellationRequested)
{
await Task.Delay(100);
}
while (!token.IsCancellationRequested)
{
ECPoint[] miners = Blockchain.Default.GetMiners();
bool is_miner = false;
foreach (Account account in wallet.GetAccounts())
{
if (miners.Contains(account.PublicKey))
{
is_miner = true;
break;
}
}
if (!is_miner)
{
try
{
await Task.Delay(Blockchain.TimePerBlock, token);
}
catch (TaskCanceledException) { }
continue;
}
Block header = Blockchain.Default.GetHeader(Blockchain.Default.CurrentBlockHash);
if (header == null) continue;
TimeSpan timespan = header.Timestamp.ToDateTime() + Blockchain.TimePerBlock - DateTime.Now;
if (timespan > TimeSpan.Zero)
{
try
{
await Task.Delay(timespan, token);
}
catch (TaskCanceledException) { }
if (token.IsCancellationRequested) break;
}
byte[] nonce_data = new byte[sizeof(ulong)];
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
{
rng.GetBytes(nonce_data);
}
ulong nonce = BitConverter.ToUInt64(nonce_data, 0);
List<Transaction> transactions = Blockchain.Default.GetMemoryPool().ToList();
transactions.Insert(0, CreateGenerationTransaction(transactions, header.Height + 1, nonce));
Block block = new Block
{
PrevBlock = header.Hash,
Timestamp = DateTime.Now.ToTimestamp(),
Height = header.Height + 1,
Nonce = nonce,
NextMiner = Blockchain.GetMinerAddress(Blockchain.Default.GetMiners(transactions).ToArray()),
Transactions = transactions.ToArray()
};
block.RebuildMerkleRoot();
wallet.Sign(block, miners);
await localnode.RelayAsync(block);
while (Blockchain.Default.CurrentBlockHash != block.Hash && !token.IsCancellationRequested)
{
await Task.Delay(100, token);
}
}
stopped = true;
}