public static Block GenerateGenesisBlock(KeyPair keyPair) { var outEntry = new OutEntry() { RecipientHash = BlockchainUtil.ToAddress(keyPair.PublicKey), Value = 10 }; var genesisBlock = new Block() { Id = 0, Hash = genesisHash, PreviousHash = null, Timestamp = DateTime.Now, Transaction = new Transaction() { Id = 0, Signature = EccService.Sign(genesisHash, keyPair.PrivateKey, keyPair.PublicKey), Timestamp = DateTime.Now, InEntries = null, OutEntries = new List <OutEntry>() { outEntry } } }; return(genesisBlock); }
protected void LinkButtonUploadMiningUser_Click(object sender, EventArgs e) { var selectedUser = DropDownList1.SelectedValue; var user = DataManager.UploadUser(selectedUser); //TextArea1.Value = JsonConvert.SerializeObject(user, Formatting.Indented); var receiver = new UdpClient(9999); IPEndPoint remoteIp = null; try { var data = receiver.Receive(ref remoteIp); var transaction = MessagePackSerializer.Deserialize <Transaction>(data); var additionalOutEntry = new OutEntry() { RecipientHash = user.KeyPair.PublicKey, Value = 10 }; transaction.OutEntries.Add(additionalOutEntry); var block = Mining.ComputeBlock(transaction); var chain = new KeyValuePair <string, Block>( HexConvert.FromBytes(DataManager.UploadBlockchainDictionary().Last().Value.Hash), block); DataManager.UpdateBlockchain(chain); Session["last chain"] = chain; Thread.Sleep(500); var senderUdpClient = new UdpClient(); var message = MessagePackSerializer.Serialize(chain); senderUdpClient.Send( message, message.Length, "127.0.0.1", remoteIp.Port); senderUdpClient.Close(); } finally { var json = JsonConvert.SerializeObject( (KeyValuePair <string, Block>)Session["last chain"], Formatting.Indented); receiver.Close(); TextArea1.Value = json; //Label1.Text = json; //Label1.Text = json.ToJonHtml(); } }