/// <summary> /// Serializes the receipt into an RLP item for encoding. /// </summary> /// <returns>Returns a serialized RLP receipt.</returns> public RLPItem Serialize() { // We create a new RLP list that constitute this receipt. RLPList rlpReceipt = new RLPList(); // Add our state root, gas used rlpReceipt.Items.Add(StateRoot); rlpReceipt.Items.Add(RLP.FromInteger(GasUsed, EVMDefinitions.WORD_SIZE, true)); // Generate a new bloom filter, and add that. GenerateBloomFilter(); rlpReceipt.Items.Add(RLP.FromInteger(Bloom, EVMDefinitions.BLOOM_FILTER_SIZE)); // Add our RLP encoded logs. RLPList rlpLogs = new RLPList(); foreach (Log log in Logs) { rlpLogs.Items.Add(log.Serialize()); } rlpReceipt.Items.Add(rlpLogs); // Return our rlp receipt item. return(rlpReceipt); }
/// <summary> /// Serializes the block header into an RLP item for encoding. /// </summary> /// <returns>Returns a serialized RLP block header.</returns> private RLPItem Serialize(byte[] extraData, byte[] mixHash, byte[] nonce) { // We create a new RLP list that constitute this header. RLPList rlpBlockHeader = new RLPList(); rlpBlockHeader.Items.Add(PreviousHash); rlpBlockHeader.Items.Add(UnclesHash); rlpBlockHeader.Items.Add(RLP.FromInteger(Coinbase, Address.ADDRESS_SIZE)); rlpBlockHeader.Items.Add(StateRootHash); rlpBlockHeader.Items.Add(TransactionsRootHash); rlpBlockHeader.Items.Add(ReceiptsRootHash); rlpBlockHeader.Items.Add(RLP.FromInteger(Bloom, EVMDefinitions.BLOOM_FILTER_SIZE)); rlpBlockHeader.Items.Add(RLP.FromInteger(Difficulty, EVMDefinitions.WORD_SIZE, true)); rlpBlockHeader.Items.Add(RLP.FromInteger(BlockNumber, EVMDefinitions.WORD_SIZE, true)); rlpBlockHeader.Items.Add(RLP.FromInteger(GasLimit, EVMDefinitions.WORD_SIZE, true)); rlpBlockHeader.Items.Add(RLP.FromInteger(GasUsed, EVMDefinitions.WORD_SIZE, true)); rlpBlockHeader.Items.Add(RLP.FromInteger(Timestamp, EVMDefinitions.WORD_SIZE, true)); if (extraData != null) { rlpBlockHeader.Items.Add(extraData); } if (mixHash != null) { rlpBlockHeader.Items.Add(mixHash); } if (nonce != null) { rlpBlockHeader.Items.Add(nonce); } // Return our rlp header item. return(rlpBlockHeader); }
public static Address MakeContractAddress(Address sender, BigInteger nonce) { // Create an RLP list with the address and nonce RLPList list = new RLPList(RLP.FromInteger(sender, ADDRESS_SIZE), RLP.FromInteger(nonce)); var hash = KeccakHash.ComputeHash(RLP.Encode(list)).Slice(EVMDefinitions.WORD_SIZE - ADDRESS_SIZE); return(new Address(hash)); }
/// <summary> /// Serializes the account into an RLP item for encoding. /// </summary> /// <returns>Returns a serialized RLP account.</returns> public RLPItem Serialize() { // We create a new RLP list that constitute this account. RLPList rlpAccount = new RLPList(); // Add our nonce, balance, storage and code hash. rlpAccount.Items.Add(RLP.FromInteger(Nonce, EVMDefinitions.WORD_SIZE, true)); rlpAccount.Items.Add(RLP.FromInteger(Balance, EVMDefinitions.WORD_SIZE, true)); rlpAccount.Items.Add(StorageRoot); rlpAccount.Items.Add(CodeHash); // Return our rlp log item. return(rlpAccount); }
public override byte[] Serialize() { // Verify our underlying properties VerifyProperties(); // Create an RLP item to contain all of our data RLPList rlpList = new RLPList(); rlpList.Items.Add(EphemeralPublicKey); rlpList.Items.Add(Nonce); rlpList.Items.Add(RLP.FromInteger(Version, 32, true)); // Serialize our RLP data return(RLP.Encode(rlpList)); }
/// <summary> /// Serializes the transaction into an RLP item for encoding. /// </summary> /// <returns>Returns a serialized RLP transaction.</returns> public static RLPItem Serialize(byte?v, BigInteger?r, BigInteger?s, BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit, Address?to, BigInteger value, byte[] data) { // We create a new RLP list that constitute this transaction. RLPList rlpTransaction = new RLPList(); // Add our values rlpTransaction.Items.Add(RLP.FromInteger(nonce, 32, true)); rlpTransaction.Items.Add(RLP.FromInteger(gasPrice, 32, true)); rlpTransaction.Items.Add(RLP.FromInteger(gasLimit, 32, true)); if (to != null) { rlpTransaction.Items.Add(new RLPByteArray(to.Value.GetBytes())); } else { rlpTransaction.Items.Add(new RLPByteArray(Array.Empty <byte>())); } rlpTransaction.Items.Add(RLP.FromInteger(value, 32, true)); rlpTransaction.Items.Add(data); if (v != null) { rlpTransaction.Items.Add(v); } if (r != null) { rlpTransaction.Items.Add(RLP.FromInteger(r.Value, 32, true)); } if (s != null) { rlpTransaction.Items.Add(RLP.FromInteger(s.Value, 32, true)); } // Return our rlp log item. return(rlpTransaction); }
/// <summary> /// Serializes the log into an RLP item for encoding. /// </summary> /// <returns>Returns a serialized RLP log.</returns> public RLPItem Serialize() { // We create a new RLP list that constitute this log. RLPList rlpLog = new RLPList(); // Add our address rlpLog.Items.Add(RLP.FromInteger(Address, Address.ADDRESS_SIZE)); // Add our topics, a list of 32-bit integers. RLPList rlpTopicsList = new RLPList(); foreach (BigInteger topic in Topics) { rlpTopicsList.Items.Add(RLP.FromInteger(topic, EVMDefinitions.WORD_SIZE)); } rlpLog.Items.Add(rlpTopicsList); // Add our data rlpLog.Items.Add(Data); // Return our rlp log item. return(rlpLog); }