Example #1
0
        public static InvocationResult CallSystemContract(SystemContractExecutionFrame currentFrame, UInt160 contractAddress, UInt160 sender, string methodSignature, params dynamic[] values)
        {
            var context = currentFrame.InvocationContext.NextContext(sender);
            var input   = ContractEncoder.Encode(methodSignature, values);

            // TODO: pass correct gas amount
            return(ContractInvoker.Invoke(contractAddress, context, input, 100_000_000));
        }
        public void Resolve_Ok(string contractName)
        {
            IContractInvokerSelector resolver = new ContractInvokerSelector();

            ContractInvoker invoker = new ContractInvoker(new ServerRuntimeConfiguration());

            invoker.Contract = BoltFramework.GetContract(typeof(IContract));

            Assert.NotNull(resolver.Resolve(new[] { invoker }, contractName.AsReadOnlySpan()));
        }
Example #3
0
        private OperatingError _InvokeContract(
            UInt160 addressTo, byte[] input, TransactionReceipt receipt,
            IBlockchainSnapshot snapshot, bool isSystemContract
            )
        {
            var transaction = receipt.Transaction;
            var context     = new InvocationContext(receipt.Transaction.From, snapshot, receipt);

            try
            {
                if (receipt.GasUsed > transaction.GasLimit)
                {
                    return(OperatingError.OutOfGas);
                }
                var result = ContractInvoker.Invoke(addressTo, context, input, transaction.GasLimit - receipt.GasUsed);
                receipt.GasUsed += result.GasUsed;
                if (result.Status != ExecutionStatus.Ok)
                {
                    return(OperatingError.ContractFailed);
                }

                if (receipt.GasUsed > transaction.GasLimit)
                {
                    return(OperatingError.OutOfGas);
                }
                /* this OnSystemContractInvoked is useful for internal communication (for example - during keyGeneration) */
                if (isSystemContract)
                {
                    OnSystemContractInvoked?.Invoke(this, context);
                }
                return(OperatingError.Ok);
            }
            catch (OutOfGasException e)
            {
                receipt.GasUsed += e.GasUsed;
            }
            catch (Exception e)
            {
                Logger.LogWarning($"Failed contract execution: {e}");
                return(OperatingError.InvalidContract);
            }

            return(OperatingError.OutOfGas);
        }