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); }
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); }
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)); }
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()); }
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))); }
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)); }
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))); }
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(); } }
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))); }
public Task <byte[]> CallAsync(Transaction transaction) { var callOutput = _blockchainBridge.Call(_blockTree.Head?.Header, transaction); return(Task.FromResult(callOutput.OutputData ?? new byte[] { 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 })); }
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))); }