示例#1
0
 public DeployContract(IClient client)
 {
     this.client                 = client;
     this.ethSendTransaction     = new EthSendTransaction(client);
     this.constructorCallEncoder = new ConstructorCallEncoder();
     this.abiDeserialiser        = new ABIDeserialiser();
 }
示例#2
0
        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");
        }
 public DeployContract(IClient client)
 {
     this.client                    = client;
     ethSendTransaction             = new EthSendTransaction(client);
     personalSignAndSendTransaction = new PersonalSignAndSendTransaction(client);
     constructorCallEncoder         = new ConstructorCallEncoder();
     abiDeserialiser                = new ABIDeserialiser();
 }
        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);
        }
示例#6
0
        /*
         *
         * 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  = "0x606060405260728060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146037576035565b005b604b60048080359060200190919050506061565b6040518082815260200191505060405180910390f35b6000600782029050606d565b91905056";
            var ethSendTransation = new EthSendTransaction(client);
            var transactionInput  = new TransactionInput();

            transactionInput.Data = contractByteCode;
            transactionInput.From = "0x12890d2cce102216644c59dae5baed380d84830c";
            return(await ethSendTransation.SendRequestAsync(transactionInput));
        }
示例#7
0
        protected FunctionBase(IClient rpcClient, Contract contract, FunctionABI functionABI)
        {
            FunctionABI             = functionABI;
            this.rpcClient          = rpcClient;
            this.contract           = contract;
            this.ethCall            = new EthCall(rpcClient);
            this.ethSendTransaction = new EthSendTransaction(rpcClient);

            this.FunctionCallDecoder = new FunctionCallDecoder();
            this.FunctionCallEncoder = new FunctionCallEncoder();
        }
示例#8
0
        /*
         *
         * 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 = "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));
        }
        /*

         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);

        }
 public EthApiTransactionsService(IClient client) : base(client)
 {
     Call        = new EthCall(client);
     EstimateGas = new EthEstimateGas(client);
     GetTransactionByBlockHashAndIndex   = new EthGetTransactionByBlockHashAndIndex(client);
     GetTransactionByBlockNumberAndIndex = new EthGetTransactionByBlockNumberAndIndex(client);
     GetTransactionByHash  = new EthGetTransactionByHash(client);
     GetTransactionCount   = new EthGetTransactionCount(client);
     GetTransactionReceipt = new EthGetTransactionReceipt(client);
     SendRawTransaction    = new EthSendRawTransaction(client);
     SendTransaction       = new EthSendTransaction(client);
 }
 public EthTransactionsService(IClient client) : base(client)
 {
     Call = new EthCall(client);
     EstimateGas = new EthEstimateGas(client);
     GetTransactionByBlockHashAndIndex = new EthGetTransactionByBlockHashAndIndex(client);
     GetTransactionByBlockNumberAndIndex = new EthGetTransactionByBlockNumberAndIndex(client);
     GetTransactionByHash = new EthGetTransactionByHash(client);
     GetTransactionCount = new EthGetTransactionCount(client);
     GetTransactionReceipt = new EthGetTransactionReceipt(client);
     SendRawTransaction = new EthSendRawTransaction(client);
     SendTransaction = new EthSendTransaction(client);
 }
示例#12
0
 protected FunctionBase(IClient rpcClient, Contract contract, FunctionABI functionABI)
 {
     FunctionABI                    = functionABI;
     this.rpcClient                 = rpcClient;
     this.contract                  = contract;
     ethCall                        = new EthCall(rpcClient);
     ethSendTransaction             = new EthSendTransaction(rpcClient);
     ethEstimateGas                 = new EthEstimateGas(rpcClient);
     personalSignAndSendTransaction = new PersonalSignAndSendTransaction(rpcClient);
     FunctionCallDecoder            = new FunctionCallDecoder();
     FunctionCallEncoder            = new FunctionCallEncoder();
 }
示例#13
0
 public PrivacyService(IClient client) : base(client)
 {
     DistributePrivateTransaction = new EthDistributePrivateTransaction(client);
     FillTransaction              = new EthFillTransaction(client);
     GetContractPrivacyMetadata   = new EthGetContractPrivacyMetadata(client);
     GetPrivacyPrecompileAddress  = new EthGetPrivacyPrecompileAddress(client);
     GetPrivateTransactionByHash  = new EthGetPrivateTransactionByHash(client);
     GetPrivateTransactionReceipt = new EthGetPrivateTransactionReceipt(client);
     GetPsi                    = new EthGetPSI(client);
     GetQuorumPayload          = new EthGetQuorumPayload(client);
     SendRawPrivateTransaction = new EthSendRawPrivateTransaction(client);
     SendTransaction           = new EthSendTransaction(client);
 }
        private static async Task SendTransaction(RpcClient 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);
        }
        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);
        }
示例#16
0
        public override async Task <string> ExecuteAsync(IClient 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 = Settings.GetDefaultAccount();
            // retrieve the hash

            var minerStart       = new MinerStart(client);
            var minerStartResult = await minerStart.SendRequestAsync();

            var personalUnlock = new PersonalUnlockAccount(client);
            var unlockResult   = await personalUnlock.SendRequestAsync(transactionInput.From, Settings.GetDefaultAccountPassword(), new HexBigInteger(90));

            var transactionHash = await ethSendTransation.SendRequestAsync(transactionInput);

            var personalock = new PersonalLockAccount(client);
            var lockResult  = await personalock.SendRequestAsync(transactionInput.From);

            //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)
            {
                await Task.Delay(1000);

                receipt = await ethGetTransactionReceipt.SendRequestAsync(transactionHash);
            }



            var minerStop       = new MinerStop(client);
            var minerStopResult = await minerStop.SendRequestAsync();

            //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"));
            var message = "The result of deploying a contract and calling a function to multiply 7 by 69 is: " + output +
                          " and should be 483";

            Assert.Equal(483, output);

            return(message);
        }
示例#17
0
        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");
        }
        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");
        }