public async Task<dynamic> ExecuteTestAsync(RpcClient client)
        {

            
            //The compiled solidity contract to be deployed
            //contract test { function multiply(uint a) returns(uint d) { return a * 7; } }
            var contractByteCode = "0x606060405260728060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146037576035565b005b604b60048080359060200190919050506061565b6040518082815260200191505060405180910390f35b6000600782029050606d565b91905056";

            //Create a new Eth Send Transanction RPC Handler
            var ethSendTransation = new EthSendTransaction(client);
            //As the input the compiled contract is the Data, together with our address
            var transactionInput = new TransactionInput();
            transactionInput.Data = contractByteCode;
            transactionInput.From = "0x12890d2cce102216644c59dae5baed380d84830c";
            // retrieve the hash
            var transactionHash =  await ethSendTransation.SendRequestAsync( transactionInput);
            
            //the contract should be mining now

            //get contract address 
            var ethGetTransactionReceipt = new EthGetTransactionReceipt(client);
            TransactionReceipt receipt = null;
            //wait for the contract to be mined to the address
            while (receipt == null)
            {
                receipt = await ethGetTransactionReceipt.SendRequestAsync( transactionHash);
            }

            //Encode and build function parameters 
            var function = new FunctionCallEncoder();

            //Input the function method Sha3Encoded (4 bytes) 
            var sha3Signature = "c6888fa1";
            //Define input parameters
            var inputParameters = new[] { new Parameter("uint", "a") };
            //encode the function call (function + parameter input)
           
            //using 69 as the input
            var functionCall = function.EncodeRequest(sha3Signature, inputParameters, 69);
            //reuse the transaction input, (just the address) 
            //the destination address is the contract address
            transactionInput.To = receipt.ContractAddress;
            //use as data the function call
            transactionInput.Data = functionCall;
            // rpc method to do the call
            var ethCall = new EthCall(client);
            // call and get the result
            var resultFunction = await ethCall.SendRequestAsync( transactionInput);
            // decode the output
            var functionDecoder = new FunctionCallDecoder();

            var output = functionDecoder.DecodeOutput<int>(resultFunction, new Parameter("uint", "d"));
            //visual test 
            return "The result of deploying a contract and calling a function to multiply 7 by 69 is: " + output  + " and should be 483";

           

        }
        //Web3 tests will cover this
        /*

         curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"0x65180b8c813457b21dad6cc6363d195231b4d2e9","data":"0x606060405260728060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146037576035565b005b604b60048080359060200190919050506061565b6040518082815260200191505060405180910390f35b6000600782029050606d565b91905056"}],"id":1}' http://localhost:8545
         */

        public async Task<object> ExecuteTestAsync(IClient client)
        {
            var contractByteCode =
                "0x606060405260728060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146037576035565b005b604b60048080359060200190919050506061565b6040518082815260200191505060405180910390f35b6000600782029050606d565b91905056";
            var ethSendTransation = new EthSendTransaction(client);
            var transactionInput = new TransactionInput();
            transactionInput.Data = contractByteCode;
            transactionInput.From = "0x12890d2cce102216644c59dae5baed380d84830c";
            return await ethSendTransation.SendRequestAsync(transactionInput);
        }
        /*

         curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"0x65180b8c813457b21dad6cc6363d195231b4d2e9","data":"0x606060405260728060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146037576035565b005b604b60048080359060200190919050506061565b6040518082815260200191505060405180910390f35b6000600782029050606d565b91905056"}],"id":1}' http://localhost:8545

         */
        public async Task<dynamic> ExecuteTestAsync(RpcClient client)
        {
            var contractByteCode = "0xc6888fa10000000000000000000000000000000000000000000000000000000000000045";
            var to = "0x32eb97b8ad202b072fd9066c03878892426320ed";
            var ethSendTransation = new EthSendTransaction(client);
            var transactionInput = new TransactionInput();
            transactionInput.Data = contractByteCode;
            transactionInput.To = to;
            transactionInput.From = "0x12890d2cce102216644c59dae5baed380d84830c";
            return await ethSendTransation.SendRequestAsync( transactionInput);

        }
Пример #4
0
        public static TransactionInput ConvertToTransactionInput(this Transaction txn)
        {
            var txnInput = new TransactionInput
            {
                Data     = txn.Input,
                Gas      = txn.Gas,
                GasPrice = txn.GasPrice,
                Nonce    = txn.Nonce,
                Value    = txn.Value,
                From     = txn.From,
                To       = txn.To
            };

            return(txnInput);
        }
Пример #5
0
        public static TransactionInput ConvertToTransactionInput(this Transaction txn)
        {
            var txnInput = new TransactionInput
            {
                Data                 = txn.Input,
                Gas                  = txn.Gas,
                GasPrice             = txn.GasPrice,
                Nonce                = txn.Nonce,
                Value                = txn.Value,
                From                 = txn.From,
                To                   = txn.To,
                Type                 = txn.Type,
                AccessList           = txn.AccessList,
                MaxFeePerGas         = txn.MaxFeePerGas,
                MaxPriorityFeePerGas = txn.MaxPriorityFeePerGas,
            };

            return(txnInput);
        }
        public async Task<object> ExecuteTestAsync(IClient client)
        {
            /* This is the example contract containing an event raised every time we call multiply
            contract test { 
    
                event Multiplied(uint indexed a, address sender);
    
                function multiply(uint a) returns(uint d) 
                { 
                    Multiplied(a, msg.sender);
                    return a * 7; 
                    
                } 
    
            }*/

            //The contract byte code already compiled
            var contractByteCode =
                "606060405260c08060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146037576035565b005b604b60048080359060200190919050506061565b6040518082815260200191505060405180910390f35b6000817f10f82b5dc139f3677a16d7bfb70c65252e78143313768d2c52e07db775e1c7ab33604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a260078202905060bb565b91905056";

            //Create a new Eth Send Transanction RPC Handler
            var ethSendTransation = new EthSendTransaction(client);

            //Create the transaction input for the new contract

            //On transaction input the compiled contract is the Data, together with our sender address 
            var transactionInput = new TransactionInput();
            transactionInput.Data = contractByteCode;
            transactionInput.From = "0x12890d2cce102216644c59dae5baed380d84830c";
            // retrieve the transaction hash, as we need to get a transaction sreceipt with the contract address
            var transactionHash = await ethSendTransation.SendRequestAsync(transactionInput);

            //the contract should be mining now

            //Get the transaction receipt using the transactionHash
            var ethGetTransactionReceipt = new EthGetTransactionReceipt(client);
            TransactionReceipt receipt = null;
            //wait for the contract to be mined to the address
            while (receipt == null)
            {
                receipt = await ethGetTransactionReceipt.SendRequestAsync(transactionHash);
            }

            //sha3 the event call, we can use this to validate our topics 

            var eventCallSh3 = await new Web3Sha3(client).SendRequestAsync(new HexUTF8String("Multiplied(uint256,address)"));
            //create a filter 
            //just listen to anything no more filter topics (ie int indexed number)
            var ethFilterInput = new NewFilterInput();
            ethFilterInput.FromBlock.SetValue(receipt.BlockNumber);
            ethFilterInput.ToBlock = BlockParameter.CreateLatest();
            ethFilterInput.Address = new[] {receipt.ContractAddress};
            //no topics
            //ethFilterInput.Topics = new object[]{};

            var newEthFilter = new EthNewFilter(client);
            var filterId = await newEthFilter.SendRequestAsync(ethFilterInput);


            //create a transaction which will raise the event
            await SendTransaction(client, transactionInput.From, receipt.ContractAddress);

            //get filter changes
            var ethGetFilterChangesForEthNewFilter = new EthGetFilterChangesForEthNewFilter(client);
            FilterLog[] logs = null;

            while (logs == null || logs.Length < 1)
            {
                //Get the filter changes logs
                logs = await ethGetFilterChangesForEthNewFilter.SendRequestAsync(filterId);

                if (logs.Length > 0)
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("Topic 0: " + logs[0].Topics[0] +
                                  " should be the same as the SH3 encoded event signature " + eventCallSh3);
                    Assert.Equal(logs[0].Topics[0], eventCallSh3);
                    sb.AppendLine("Topic 1: " + logs[0].Topics[1] + " should be 69 hex  0x45, padded");
                   
                    sb.AppendLine("Data " + logs[0].Data + " should be the same as the address padded 32 bytes " +
                                  transactionInput.From);
                  
                    return sb.ToString();
                }
                
            }
           throw new Exception("Execution failed");
        }
        private static async Task SendTransaction(IClient client, string addressFrom,
            string contractAddress)
        {
            var transactionInput = new TransactionInput();
            var ethSendTransaction = new EthSendTransaction(client);
            var function = new FunctionCallEncoder();
            //Input the function method Sha3Encoded (4 bytes) 
            var sha3Signature = "c6888fa1";
            //Define input parameters
            var inputParameters = new[] {new Parameter("uint", "a")};
            //encode the function call (function + parameter input)
            //using 69 as the input
            var functionCall = function.EncodeRequest(sha3Signature, inputParameters, 69);
            transactionInput.From = addressFrom;
            //the destination address is the contract address
            transactionInput.To = contractAddress;
            //use as data the function call
            transactionInput.Data = functionCall;

            var transactionHashFunction = await ethSendTransaction.SendRequestAsync(transactionInput);
        }
Пример #8
0
        public IEnumerator SendRequest(Nethereum.RPC.Eth.DTOs.TransactionInput input)
        {
            var request = _ethSendTransaction.BuildRequest(input);

            yield return(SendRequest(request));
        }
Пример #9
0
        public IEnumerator SendRequest(Nethereum.RPC.Eth.DTOs.TransactionInput txn, System.String password)
        {
            var request = _personalSignAndSendTransaction.BuildRequest(txn, password);

            yield return(SendRequest(request));
        }