コード例 #1
0
        public async Task call_should_invoke_blockchain_bridge_call_and_return_data()
        {
            Block       head        = Build.A.Block.TestObject;
            Transaction transaction = Build.A.Transaction.TestObject;

            byte[] data = new byte[] { 0, 1, 2 };
            _blockchainBridge.HeadBlock.Returns(head);
            BlockchainBridge.CallOutput output = new BlockchainBridge.CallOutput(data, 0, null);
            _blockchainBridge.Call(head?.Header, transaction, default).Returns(output);
            byte[] result = await _ndmBridge.CallAsync(transaction);

            _blockchainBridge.Received().Call(head?.Header, transaction, default);
            result.Should().BeSameAs(data);
        }
コード例 #2
0
        public async Task call_should_invoke_blockchain_bridge_call_and_return_data()
        {
            var head        = Build.A.BlockHeader.TestObject;
            var transaction = Build.A.Transaction.TestObject;
            var data        = new byte[] { 0, 1, 2 };

            _blockchainBridge.Head.Returns(head);
            var output = new BlockchainBridge.CallOutput(data, 0, null);

            _blockchainBridge.Call(head, transaction).Returns(output);
            var result = await _ndmBridge.CallAsync(transaction);

            _blockchainBridge.Received().Call(head, transaction);
            result.Should().BeSameAs(data);
        }
コード例 #3
0
ファイル: EthModule.cs プロジェクト: phahulin/nethermind
        public ResultWrapper <byte[]> eth_call(TransactionForRpc transactionCall, BlockParameter blockParameter = null)
        {
            BlockHeader block = _blockchainBridge.GetHeader(blockParameter ?? BlockParameter.Latest);

            var tx = transactionCall.ToTransaction();

            tx.GasPrice = 0;
            if (tx.GasLimit < 21000)
            {
                tx.GasLimit = 10000000;
            }

            if (tx.To == null)
            {
                return(ResultWrapper <byte[]> .Fail($"Recipient address not specified on the transaction.", ErrorType.InvalidParams));
            }

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

            if (result.Error != null)
            {
                return(ResultWrapper <byte[]> .Fail($"VM Exception while processing transaction: {result.Error}", ErrorType.ExecutionError, result.OutputData));
            }

            return(ResultWrapper <byte[]> .Success(result.OutputData));
        }
コード例 #4
0
        public UInt256 ReadDepositBalance(Address onBehalfOf, Keccak depositId)
        {
            var         txData      = _abiEncoder.Encode(AbiEncodingStyle.IncludeSignature, ContractData.DepositBalanceAbiSig, depositId.Bytes);
            Transaction transaction = new Transaction();

            transaction.Value         = 0;
            transaction.Data          = txData;
            transaction.To            = _contractAddress;
            transaction.SenderAddress = onBehalfOf;
            transaction.GasLimit      = 100000;
            transaction.GasPrice      = 0.GWei();
            transaction.Nonce         = (UInt256)_blockchainBridge.GetNonce(onBehalfOf);
            _wallet.Sign(transaction, _blockchainBridge.GetNetworkId());
            BlockchainBridge.CallOutput callOutput = _blockchainBridge.Call(_blockchainBridge.Head, transaction);
            return((callOutput.OutputData ?? new byte[] { 0 }).ToUInt256());
        }
コード例 #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);

            using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(_cancellationTokenTimeout);
            CancellationToken cancellationToken = cancellationTokenSource.Token;
            Transaction       tx = transactionCall.ToTransaction();

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

            return(result.Error != null ? ResultWrapper <string> .Fail("VM execution error.", ErrorCodes.ExecutionError, result.Error) : ResultWrapper <string> .Success(result.OutputData.ToHexString(true)));
        }
コード例 #6
0
            public override object[] Call(CallInfo callInfo)
            {
                var transaction = GenerateTransaction(callInfo);
                var result      = _blockchainBridge.Call(callInfo.ParentHeader, transaction, CancellationToken.None);

                if (!string.IsNullOrEmpty(result.Error))
                {
                    throw new AbiException(result.Error);
                }

                return(callInfo.Result = DecodeReturnData(callInfo.FunctionName, result.OutputData));
            }
コード例 #7
0
        public ResultWrapper <string> eth_call(TransactionForRpc transactionCall, BlockParameter blockParameter = null)
        {
            SearchResult <BlockHeader> searchResult = _blockchainBridge.SearchForHeader(blockParameter);

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

            BlockHeader header = searchResult.Object;

            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)));
        }
コード例 #8
0
ファイル: EthModule.cs プロジェクト: chidionyema/nethermind
        public ResultWrapper <byte[]> eth_call(TransactionForRpc transactionCall, BlockParameter blockParameter = null)
        {
            try
            {
                _readerWriterLockSlim.EnterWriteLock();
                BlockHeader block = blockParameter == null ? _blockchainBridge.Head : GetBlock(blockParameter).Data.Header;
                BlockchainBridge.CallOutput result = _blockchainBridge.Call(block, transactionCall.ToTransaction());

                if (result.Error != null)
                {
                    return(ResultWrapper <byte[]> .Fail($"VM Exception while processing transaction: {result.Error}", ErrorType.ExecutionError, result.OutputData));
                }

                return(ResultWrapper <byte[]> .Success(result.OutputData));
            }
            finally
            {
                _readerWriterLockSlim.ExitWriteLock();
            }
        }
コード例 #9
0
        public ResultWrapper <string> eth_call(TransactionForRpc transactionCall, BlockParameter blockParameter = null)
        {
            BlockHeader block = _blockchainBridge.GetHeader(blockParameter ?? BlockParameter.Latest);

            var tx = transactionCall.ToTransaction();

            tx.GasPrice = 0;
            if (tx.GasLimit < 21000)
            {
                tx.GasLimit = 10000000;
            }

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

            if (result.Error != null)
            {
                return(ResultWrapper <string> .Fail("VM execution error.", ErrorType.ExecutionError, result.Error));
            }

            return(ResultWrapper <string> .Success(result.OutputData.ToHexString(true)));
        }
コード例 #10
0
        public Task <byte[]> CallAsync(Transaction transaction)
        {
            var callOutput = _blockchainBridge.Call(_blockTree.Head?.Header, transaction);

            return(Task.FromResult(callOutput.OutputData ?? new byte[] { 0 }));
        }
コード例 #11
0
        public Task <byte[]> CallAsync(Transaction transaction)
        {
            var callOutput = _blockchainBridge.Call(_blockchainBridge.BeamHead?.Header, transaction, CancellationToken.None);

            return(Task.FromResult(callOutput.OutputData ?? new byte[] { 0 }));
        }
コード例 #12
0
ファイル: EthModule.cs プロジェクト: aboussetta/nethermind
 public ResultWrapper <Data> eth_call(Transaction transactionCall, BlockParameter blockParameter)
 {
     Core.Block block  = GetBlock(blockParameter).Data;
     byte[]     result = _blockchainBridge.Call(block, _modelMapper.MapTransaction(transactionCall));
     return(ResultWrapper <Data> .Success(new Data(result)));
 }