Exemplo n.º 1
0
        public void Can_collect_proof_with_branch()
        {
            TxReceipt   receipt1 = Build.A.Receipt.WithAllFieldsFilled.TestObject;
            TxReceipt   receipt2 = Build.A.Receipt.WithAllFieldsFilled.TestObject;
            ReceiptTrie trie     = new ReceiptTrie(1, MainnetSpecProvider.Instance, new[] { receipt1, receipt2 }, true);

            byte[][] proof = trie.BuildProof(0);
            Assert.AreEqual(2, proof.Length);

            trie.UpdateRootHash();
            VerifyProof(proof, trie.RootHash);
        }
Exemplo n.º 2
0
        => _receiptsMigration.Run(blockNumber + 1);     // add 1 to make go from inclusive (better for API) to exclusive (better for internal)

        public void InsertReceipts(BlockParameter blockParameter, TxReceipt[] txReceipts)
        {
            SearchResult <Block> searchResult = _blockTree.SearchForBlock(blockParameter);

            if (searchResult.IsError)
            {
                throw new InvalidDataException(searchResult.Error);
            }

            Block       block       = searchResult.Object;
            ReceiptTrie receiptTrie = new ReceiptTrie(block.Number, _specProvider, txReceipts);

            receiptTrie.UpdateRootHash();
            if (block.ReceiptsRoot != receiptTrie.RootHash)
            {
                throw new InvalidDataException("Receipts root mismatch");
            }

            _receiptStorage.Insert(block, txReceipts);
        }
Exemplo n.º 3
0
        public BlockBuilder WithTransactions(int txCount, ISpecProvider specProvider)
        {
            Transaction[] txs = new Transaction[txCount];
            for (int i = 0; i < txCount; i++)
            {
                txs[i] = new Transaction();
            }

            TxReceipt[] receipts = new TxReceipt[txCount];
            for (int i = 0; i < txCount; i++)
            {
                receipts[i] = Build.A.Receipt.TestObject;
            }

            var         number      = TestObjectInternal.Number;
            ReceiptTrie receiptTrie = new ReceiptTrie(number, specProvider, receipts);

            receiptTrie.UpdateRootHash();

            BlockBuilder result = WithTransactions(txs);

            TestObjectInternal.Header.ReceiptsRoot = receiptTrie.RootHash;
            return(result);
        }