private Hash ComputeRootWithTransactionStatusMerklePath(Hash txId, MerklePath path) { var txResultStatusRawBytes = EncodingHelper.EncodeUtf8(TransactionResultStatus.Mined.ToString()); var hash = HashHelper.ComputeFrom(ByteArrayHelper.ConcatArrays(txId.ToByteArray(), txResultStatusRawBytes)); return(path.ComputeRootWithLeafNode(hash)); }
private Hash ComputeRootWithTransactionStatusMerklePath(Hash txId, MerklePath path) { var txResultStatusRawBytes = EncodingHelper.GetBytesFromUtf8String(TransactionResultStatus.Mined.ToString()); var hash = Hash.FromRawBytes(txId.ToByteArray().Concat(txResultStatusRawBytes).ToArray()); return(path.ComputeRootWithLeafNode(hash)); }
public void MerklePathExtensions_ComputeRootWithLeafNode_Test() { // left node { var merkleLeftNode = new MerklePathNode { Hash = HashHelper.ComputeFrom("node1"), IsLeftChildNode = true }; var nodePath = new MerklePath { MerklePathNodes = { merkleLeftNode } }; var hash = HashHelper.ComputeFrom("new"); var calculateHash = nodePath.ComputeRootWithLeafNode(hash); var targetHash = HashHelper.ConcatAndCompute(merkleLeftNode.Hash, hash); calculateHash.ShouldBe(targetHash); } // right node { var merkleLeftNode = new MerklePathNode { Hash = HashHelper.ComputeFrom("node1"), IsLeftChildNode = false }; var nodePath = new MerklePath { MerklePathNodes = { merkleLeftNode } }; var hash = HashHelper.ComputeFrom("new"); var calculateHash = nodePath.ComputeRootWithLeafNode(hash); var targetHash = HashHelper.ConcatAndCompute(hash, merkleLeftNode.Hash); calculateHash.ShouldBe(targetHash); } }
private Hash ComputeRootWithMerklePathAndLeaf(Hash leaf, MerklePath path) { return(path.ComputeRootWithLeafNode(leaf)); }
public void TestMerklePathFromEth() { var expectedRoot = Hash.LoadFromByteArray( ByteArrayHelper.HexStringToByteArray( "0x90ae927b3312b71e5ea7c8644a9d6f4e6107bf6c0e06df094c94be16d8023c52")); { var hex = "0x324144584c63794b4d47477252653961474337584d584543763863787a33546f73317a36504a4853667958677553615662350000000000000000000000000000000000000000000000001111d67bb1bb0000"; var expectedHash = Hash.LoadFromByteArray( ByteArrayHelper.HexStringToByteArray( "0xa80afe5c85c3e9b09e8c74070d5d8d4de60780968d78e7b031e939e7335b6916")); var actualHash = HashHelper.ComputeFrom(ByteArrayHelper.HexStringToByteArray(hex)); Assert.Equal(expectedHash, actualHash); var merklePath = new MerklePath { MerklePathNodes = { new MerklePathNode { IsLeftChildNode = true, Hash = Hash.LoadFromByteArray( ByteArrayHelper.HexStringToByteArray( "0x739c9a33d81d44b3c6b511c326337c12d9f557fdc3c9476ab33f5d064785a47e")) }, new MerklePathNode { IsLeftChildNode = true, Hash = Hash.LoadFromByteArray( ByteArrayHelper.HexStringToByteArray( "0x8487ce95823a23aac06a040828761818b2d491fb6603c5d3284b3c9c73764c87")) }, new MerklePathNode { IsLeftChildNode = true, Hash = Hash.LoadFromByteArray( ByteArrayHelper.HexStringToByteArray( "0x7c8e76b0b80181c5154d138078d15aafd3e980858b8eb9076a3cae3fcdec76be")) } } }; var actualRoot = merklePath.ComputeRootWithLeafNode(actualHash); Assert.Equal(expectedRoot, actualRoot); } { var hex = "0x536b4d476a766941417339626e59767636634b636166626866367462524751474b393357674b765a6f436f5335616d4d4b00000000000000000000000000000000000000000000000302379bf2ca2e0000"; var expectedHash = Hash.LoadFromByteArray( ByteArrayHelper.HexStringToByteArray( "0xdbd4b01cea12038a3b0c3ce4900c64635b96a1ee2331625fbe473d6c1e816548")); var actualHash = HashHelper.ComputeFrom(ByteArrayHelper.HexStringToByteArray(hex)); Assert.Equal(expectedHash, actualHash); var merklePath = new MerklePath { MerklePathNodes = { new MerklePathNode { IsLeftChildNode = false, Hash = Hash.LoadFromByteArray( ByteArrayHelper.HexStringToByteArray( "0x12e2fc90c9b2c6887bf9633bf4872db4bb8cfe18619b0900dad49286abb81248")) }, new MerklePathNode { IsLeftChildNode = false, Hash = Hash.LoadFromByteArray( ByteArrayHelper.HexStringToByteArray( "0x56ac8fe5cfe48c5ddf5d40f9a8ed5e504929935b677376cae35b8c326a97d34b")) }, new MerklePathNode { IsLeftChildNode = true, Hash = Hash.LoadFromByteArray( ByteArrayHelper.HexStringToByteArray( "0x7c8e76b0b80181c5154d138078d15aafd3e980858b8eb9076a3cae3fcdec76be")) } } }; var actualRoot = merklePath.ComputeRootWithLeafNode(actualHash); Assert.Equal(expectedRoot, actualRoot); } }