示例#1
0
        private Transaction CreateContractMethodCallTx(string method, IMessage args)
        {
            var methodTx = new ContractMethodCall
            {
                Method = method,
                Args   = args.ToByteString()
            };

            var requestBytes = new Request
            {
                ContentType = EncodingType.Protobuf3,
                Accept      = EncodingType.Protobuf3,
                Body        = methodTx.ToByteString()
            }.ToByteString();

            var callTxBytes = new CallTx
            {
                VmType = VMType.Plugin,
                Input  = requestBytes
            }.ToByteString();

            var msgTxBytes = new MessageTx
            {
                From = this.Caller,
                To   = this.Address,
                Data = callTxBytes
            }.ToByteString();

            return(new Transaction
            {
                Id = 2,
                Data = msgTxBytes
            });
        }
        /// <summary>
        /// Calls a contract with the given arguments.
        /// Each call generates a new transaction that's committed to the Loom DAppChain.
        /// </summary>
        /// <param name="caller">Address of the caller.</param>
        /// <param name="contract">Address of a contract on the Loom DAppChain.</param>
        /// <param name="method">Qualified name of the contract method to call in the format "contractName.methodName".</param>
        /// <param name="args">Arguments to pass to the contract.</param>
        /// <returns>Commit metadata.</returns>
        public async Task <BroadcastTxResult> CallAsync(Address caller, Address contract, string method, IMessage args)
        {
            var methodTx = new ContractMethodCall
            {
                Method = method,
                Data   = Google.Protobuf.WellKnownTypes.Any.Pack(args)
            };
            var requestBytes = new Request
            {
                ContentType = EncodingType.Protobuf3,
                Body        = methodTx.ToByteString()
            }.ToByteString();

            var callTxBytes = new CallTx
            {
                VmType = VMType.Plugin,
                Input  = requestBytes
            }.ToByteString();

            var msgTxBytes = new MessageTx
            {
                From = caller,
                To   = contract,
                Data = callTxBytes
            }.ToByteString();

            var tx = new Transaction
            {
                Id   = 2,
                Data = msgTxBytes
            };

            return(await this.CommitTxAsync(tx));
        }
示例#3
0
        internal Transaction CreateContractMethodCallTx(ByteString callTxInput, VMType vmType)
        {
            var callTxBytes = new CallTx
            {
                VmType = vmType,
                Input  = callTxInput
            }.ToByteString();

            var msgTxBytes = new MessageTx
            {
                From = this.Caller.ToProtobufAddress(),
                To   = this.Address.ToProtobufAddress(),
                Data = callTxBytes
            }.ToByteString();

            return(new Transaction
            {
                Id = 2,
                Data = msgTxBytes
            });
        }