public BlockchainBridge.CallOutput EstimateGas(BlockHeader header, Transaction tx, CancellationToken cancellationToken)
        {
            ReadOnlyTxProcessingEnv txProcessingEnv = _readOnlyTxProcessingEnvFactory.Create();

            using IReadOnlyTransactionProcessor transactionProcessor = txProcessingEnv.Build(header.StateRoot !);

            EstimateGasTracer estimateGasTracer = new();

            (bool Success, string Error)tryCallResult = TryCallAndRestore(
                transactionProcessor,
                header,
                UInt256.Max(header.Timestamp + 1, _timestamper.UnixTime.Seconds),
                tx,
                true,
                estimateGasTracer.WithCancellation(cancellationToken));

            GasEstimator gasEstimator = new(transactionProcessor, _stateProvider, _specProvider);
            long         estimate     = gasEstimator.Estimate(tx, header, estimateGasTracer);

            return(new BlockchainBridge.CallOutput
            {
                Error = tryCallResult.Success ? estimateGasTracer.Error : tryCallResult.Error,
                GasSpent = estimate,
                InputError = !tryCallResult.Success
            });
        }
示例#2
0
 public void SetUp()
 {
     _block = new Block(Build.A.BlockHeader.TestObject, new BlockBody());
     _transactionProcessor = Substitute.For <IReadOnlyTransactionProcessor>();
     _readOnlyTransactionProcessorSource = Substitute.For <IReadOnlyTransactionProcessorSource>();
     _readOnlyTransactionProcessorSource.Get(TestItem.KeccakA).Returns(_transactionProcessor);
     _stateProvider = Substitute.For <IStateProvider>();
     _stateProvider.StateRoot.Returns(TestItem.KeccakA);
 }
            protected override object[] CallRaw(CallInfo callInfo, IReadOnlyTransactionProcessor readOnlyTransactionProcessor)
            {
                if (callInfo is PermissionCallInfo transactionPermissionCallInfo)
                {
                    transactionPermissionCallInfo.ToIsContract = readOnlyTransactionProcessor.IsContractDeployed(transactionPermissionCallInfo.To);
                }

                return(base.CallRaw(callInfo, readOnlyTransactionProcessor));
            }
示例#4
0
            protected virtual object[] CallRaw(CallInfo callInfo, IReadOnlyTransactionProcessor readOnlyTransactionProcessor)
            {
                var transaction = GenerateTransaction(callInfo);

                if (_contract.ContractAddress is not null && readOnlyTransactionProcessor.IsContractDeployed(_contract.ContractAddress))
                {
                    var result = CallCore(callInfo, readOnlyTransactionProcessor, transaction);
                    return(callInfo.Result = _contract.DecodeReturnData(callInfo.FunctionName, result));
                }
示例#5
0
            protected virtual object[] CallRaw(CallInfo callInfo, IReadOnlyTransactionProcessor readOnlyTransactionProcessor)
            {
                var transaction = GenerateTransaction(callInfo);

                if (readOnlyTransactionProcessor.IsContractDeployed(_contract.ContractAddress))
                {
                    var result = CallCore(callInfo, readOnlyTransactionProcessor, transaction);
                    return(callInfo.Result = _contract.DecodeReturnData(callInfo.FunctionName, result));
                }
                else if (callInfo.MissingContractResult != null)
                {
                    return(callInfo.MissingContractResult);
                }
                else
                {
                    throw new AbiException($"Missing contract on address {_contract.ContractAddress} when calling function {callInfo.FunctionName}.");
                }
            }
示例#6
0
 protected byte[] CallCore(CallInfo callInfo, IReadOnlyTransactionProcessor readOnlyTransactionProcessor, Transaction transaction) =>
 _contract.CallCore(readOnlyTransactionProcessor, callInfo.ParentHeader, callInfo.FunctionName, transaction, true);