Esempio n. 1
0
        public TxTrie(Transaction[] txs, bool allowProofs = false)
            : base(allowProofs ? (IDb) new MemDb() : NullDb.Instance, EmptyTreeHash, false, false)
        {
            _allowProofs = allowProofs;
            if (txs.Length == 0)
            {
                return;
            }

            for (int i = 0; i < txs.Length; i++)
            {
                Rlp transactionRlp = _txDecoder.Encode(txs[i]);
                Set(Rlp.Encode(i).Bytes, transactionRlp.Bytes);
            }

            UpdateRootHash();
        }
Esempio n. 2
0
        public static Keccak CalculateTxRoot(this Block block)
        {
            if (block.Transactions.Length == 0)
            {
                return(PatriciaTree.EmptyTreeHash);
            }

            PatriciaTree txTree = new PatriciaTree();

            for (int i = 0; i < block.Transactions.Length; i++)
            {
                Rlp transactionRlp = _txDecoder.Encode(block.Transactions[i]);
                txTree.Set(Rlp.Encode(i).Bytes, transactionRlp.Bytes);
            }

            txTree.UpdateRootHash();
            return(txTree.RootHash);
        }
Esempio n. 3
0
        public TxTrie(Transaction[] txs, bool allowProofs = false)
            : base(allowProofs ? (IDb) new MemDb() : NullDb.Instance, EmptyTreeHash, false, false)
        {
            _allowProofs = allowProofs;
            if (txs.Length == 0)
            {
                return;
            }

            // 3% allocations (2GB) on a Goerli 3M blocks fast sync due to calling transaction encoder hee
            // avoiding it would require pooling byte arrays and passing them as Spans to temporary trees
            // a temporary trie would be a trie that exists to create a state root only and then be disposed of
            for (int i = 0; i < txs.Length; i++)
            {
                Rlp transactionRlp = _txDecoder.Encode(txs[i]);
                Set(Rlp.Encode(i).Bytes, transactionRlp.Bytes);
            }

            // additional 3% 2GB is used here for trie nodes creation and root calculation
            UpdateRootHash();
        }
Esempio n. 4
0
        static async Task Main(string[] args)
        {
            Rlp.RegisterDecoders(typeof(DepositDecoder).Assembly);
            Rlp.RegisterDecoders(typeof(DepositDetailsDecoder).Assembly);

            string              dbPath      = args[0];
            ConsoleAsyncLogger  asyncLogger = new ConsoleAsyncLogger(LogLevel.Info);
            OneLoggerLogManager logManager  = new OneLoggerLogManager(asyncLogger);

            var deposits = await LoadDeposits(logManager, dbPath);

            IKeyStore         keyStore = BuildKeyStore(logManager);
            DevKeyStoreWallet wallet   = new DevKeyStoreWallet(keyStore, logManager, false);

            foreach (var depositGroup in deposits.Items.GroupBy(d => d.Consumer))
            {
                Console.WriteLine($"Deposits by {depositGroup.Key}");
                foreach (DepositDetails depositDetails in depositGroup)
                {
                    DateTimeOffset dto = DateTimeOffset.FromUnixTimeSeconds(depositDetails.Deposit.ExpiryTime);
                    Console.WriteLine($"  [REFUNDABLE] Deposit by {depositDetails.Consumer} for {depositDetails.DataAsset.Name} {depositDetails.Deposit.Units} expired on {dto.Date:f}");
                }

                Transaction[] refundTxs = GenerateTxsForRefunds(depositGroup, wallet);
                foreach (Transaction transaction in refundTxs)
                {
                    Console.WriteLine();
                    Console.WriteLine("***************************************");
                    TransactionDecoder decoder = new TransactionDecoder();
                    Rlp txRlp = decoder.Encode(transaction);
                    Console.WriteLine(txRlp.Bytes.ToHexString());
                    Console.WriteLine("***************************************");
                }
            }

            Console.ReadLine();
        }