當前位置: 首頁>>代碼示例>>C#>>正文


C# Block.RebuildMerkleRoot方法代碼示例

本文整理匯總了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(), "創世區塊頭簽名上下文");
 }
開發者ID:EppoFq,項目名稱:AntShares,代碼行數:25,代碼來源:DeveloperToolsForm.cs

示例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;
 }
開發者ID:cole2295,項目名稱:AntShares,代碼行數:66,代碼來源:MainService.cs


注:本文中的Block.RebuildMerkleRoot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。