Exemple #1
0
        public ResultWrapper <byte[]> eth_getStorageAt(Address address, UInt256 positionIndex, BlockParameter blockParameter = null)
        {
            SearchResult <BlockHeader> searchResult = _blockFinder.SearchForHeader(blockParameter);

            if (searchResult.IsError)
            {
                return(ResultWrapper <byte[]> .Fail(searchResult));
            }

            BlockHeader header  = searchResult.Object;
            Account     account = _stateReader.GetAccount(header.StateRoot, address);

            if (account == null)
            {
                return(ResultWrapper <byte[]> .Success(Array.Empty <byte>()));
            }

            var storage = _stateReader.GetStorage(account.StorageRoot, positionIndex);

            return(ResultWrapper <byte[]> .Success(storage.PadLeft(32)));
        }
Exemple #2
0
        public Task <ResultWrapper <UInt256?> > eth_getBalance(Address address, BlockParameter?blockParameter = null)
        {
            SearchResult <BlockHeader> searchResult = _blockFinder.SearchForHeader(blockParameter);

            if (searchResult.IsError)
            {
                return(Task.FromResult(ResultWrapper <UInt256?> .Fail(searchResult)));
            }

            BlockHeader header = searchResult.Object;

            if (!HasStateForBlock(header))
            {
                return(Task.FromResult(ResultWrapper <UInt256?> .Fail($"No state available for block {header.Hash}",
                                                                      ErrorCodes.ResourceUnavailable)));
            }

            Account account = _stateReader.GetAccount(header.StateRoot, address);

            return(Task.FromResult(ResultWrapper <UInt256?> .Success(account?.Balance ?? UInt256.Zero)));
        }
        public ResultWrapper <byte[]> eth_getStorageAt(Address address, UInt256 positionIndex, BlockParameter blockParameter = null)
        {
            SearchResult <BlockHeader> searchResult = _blockchainBridge.SearchForHeader(blockParameter);

            if (searchResult.IsError)
            {
                return(ResultWrapper <byte[]> .Fail(searchResult));
            }

            BlockHeader header  = searchResult.Object;
            Account     account = _blockchainBridge.GetAccount(address, header.StateRoot);

            if (account == null)
            {
                return(ResultWrapper <byte[]> .Success(Bytes.Empty));
            }

            var storage = _blockchainBridge.GetStorage(address, positionIndex, header.StateRoot);

            return(ResultWrapper <byte[]> .Success(storage.PadLeft(32)));
        }
Exemple #4
0
        public Task <ResultWrapper <UInt256?> > eth_getTransactionCount(Address address, BlockParameter blockParameter)
        {
            SearchResult <BlockHeader> searchResult = _blockFinder.SearchForHeader(blockParameter);

            if (searchResult.IsError)
            {
                return(Task.FromResult(ResultWrapper <UInt256?> .Fail(searchResult)));
            }

            BlockHeader header = searchResult.Object;

            if (!HasStateForBlock(_blockchainBridge, header))
            {
                return(Task.FromResult(ResultWrapper <UInt256?> .Fail($"No state available for block {header.Hash}",
                                                                      ErrorCodes.ResourceUnavailable)));
            }

            Account account = _stateReader.GetAccount(header.StateRoot, address);
            UInt256 nonce   = account?.Nonce ?? 0;

            return(Task.FromResult(ResultWrapper <UInt256?> .Success(nonce)));
        }
Exemple #5
0
        public ResultWrapper <string> eth_call(TransactionForRpc transactionCall, BlockParameter blockParameter = null)
        {
            SearchResult <BlockHeader> searchResult = _blockFinder.SearchForHeader(blockParameter);

            if (searchResult.IsError)
            {
                return(ResultWrapper <string> .Fail(searchResult));
            }

            BlockHeader header = searchResult.Object;

            if (!HasStateForBlock(header))
            {
                return(ResultWrapper <string> .Fail($"No state available for block {header.Hash}", ErrorCodes.ResourceUnavailable));
            }

            FixCallTx(transactionCall, header);

            Transaction tx = transactionCall.ToTransaction();

            BlockchainBridge.CallOutput result = _blockchainBridge.Call(header, tx);

            return(result.Error != null ? ResultWrapper <string> .Fail("VM execution error.", ErrorCodes.ExecutionError, result.Error) : ResultWrapper <string> .Success(result.OutputData.ToHexString(true)));
        }
Exemple #6
0
        private ResultWrapper <UInt256?> EstimateGas(TransactionForRpc transactionCall, BlockHeader head)
        {
            FixCallTx(transactionCall, head);

            var tokenTimeout = TimeSpan.FromMilliseconds(_rpcConfig.TracerTimeout);
            CancellationToken cancellationToken = new CancellationTokenSource(tokenTimeout).Token;

            BlockchainBridge.CallOutput result = _blockchainBridge.EstimateGas(head, transactionCall.ToTransaction(), cancellationToken);

            if (result.Error == null)
            {
                return(ResultWrapper <UInt256?> .Success((UInt256)result.GasSpent));
            }

            return(ResultWrapper <UInt256?> .Fail(result.Error));
        }
Exemple #7
0
        private ResultWrapper <UInt256?> EstimateGas(TransactionForRpc transactionCall, BlockHeader head)
        {
            FixCallTx(transactionCall, head);

            using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(_cancellationTokenTimeout);
            CancellationToken cancellationToken = cancellationTokenSource.Token;

            BlockchainBridge.CallOutput result = _blockchainBridge.EstimateGas(head, transactionCall.ToTransaction(), cancellationToken);

            if (result.Error == null)
            {
                return(ResultWrapper <UInt256?> .Success((UInt256)result.GasSpent));
            }

            return(ResultWrapper <UInt256?> .Fail(result.Error));
        }
Exemple #8
0
        private ResultWrapper <UInt256?> EstimateGas(TransactionForRpc transactionCall, BlockHeader head)
        {
            // 2021-03-04 08:54:18.6489|DEBUG|101|Responded to ID 40, eth_estimateGas({
            //     "from": "0x2b5ad5c4795c026514f8317c7a215e218dccd6cf",
            //     "to": "0xa28afda14be5789564ae5fa03665c4180e3c680b",
            //     "data": "0x25936984"
            // })

            // 2021-03-04 08:54:18.6533|DEBUG|13|Responded to ID 41, eth_sendTransaction({
            //     "gas": "0x1f815f1",
            //     "from": "0x2b5ad5c4795c026514f8317c7a215e218dccd6cf",
            //     "to": "0xa28afda14be5789564ae5fa03665c4180e3c680b",
            //     "data": "0x25936984",
            //     "gasPrice": "0x4a817c800"
            // })

            FixCallTx(transactionCall);

            // using CancellationTokenSource cancellationTokenSource = new(_cancellationTokenTimeout);
            CancellationToken cancellationToken = CancellationToken.None;

            BlockchainBridge.CallOutput result =
                _blockchainBridge.EstimateGas(head, transactionCall.ToTransaction(), cancellationToken);

            if (result.Error == null)
            {
                return(ResultWrapper <UInt256?> .Success((UInt256)result.GasSpent));
            }

            return(ResultWrapper <UInt256?> .Fail(result.Error, result.InputError?ErrorCodes.InvalidInput : ErrorCodes.InternalError));
        }
Exemple #9
0
 public Block WithReplacedHeader(BlockHeader newHeader) => new(newHeader, Body);
Exemple #10
0
 public Block(BlockHeader blockHeader)
     : this(blockHeader, BlockBody.Empty)
 {
 }
Exemple #11
0
 public Block(BlockHeader blockHeader, IEnumerable <Transaction> transactions, IEnumerable <BlockHeader> uncles)
 {
     Header = blockHeader;
     Body   = new BlockBody(transactions.ToArray(), uncles.ToArray());
 }
Exemple #12
0
 public Block(BlockHeader blockHeader, BlockBody body)
 {
     Header = blockHeader;
     Body   = body;
 }
Exemple #13
0
 public Block(BlockHeader blockHeader, params BlockHeader[] ommers)
     : this(blockHeader, Enumerable.Empty <Transaction>(), ommers)
 {
 }
Exemple #14
0
 public Block(BlockHeader blockHeader, IEnumerable <Transaction> transactions, IEnumerable <BlockHeader> ommers)
 {
     Header       = blockHeader;
     Ommers       = ommers.ToArray();
     Transactions = transactions.ToArray();
 }