本文整理匯總了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;
}