예제 #1
2
 public void CheckProposal()
 {
     var abi =
         @"[{ ""constant"": true, ""inputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""name"": ""proposals"", ""outputs"": [{ ""name"": ""recipient"", ""type"": ""address"" }, { ""name"": ""amount"", ""type"": ""uint256"" }, { ""name"": ""description"", ""type"": ""string"" }, { ""name"": ""votingDeadline"", ""type"": ""uint256"" }, { ""name"": ""open"", ""type"": ""bool"" }, { ""name"": ""proposalPassed"", ""type"": ""bool"" }, { ""name"": ""proposalHash"", ""type"": ""bytes32"" }, { ""name"": ""proposalDeposit"", ""type"": ""uint256"" }, { ""name"": ""newCurator"", ""type"": ""bool"" }, { ""name"": ""yea"", ""type"": ""uint256"" }, { ""name"": ""nay"", ""type"": ""uint256"" }, { ""name"": ""creator"", ""type"": ""address"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_spender"", ""type"": ""address"" }, { ""name"": ""_amount"", ""type"": ""uint256"" }], ""name"": ""approve"", ""outputs"": [{ ""name"": ""success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""minTokensToCreate"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""rewardAccount"", ""outputs"": [{ ""name"": """", ""type"": ""address"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""daoCreator"", ""outputs"": [{ ""name"": """", ""type"": ""address"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""totalSupply"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""divisor"", ""outputs"": [{ ""name"": ""divisor"", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""extraBalance"", ""outputs"": [{ ""name"": """", ""type"": ""address"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_proposalID"", ""type"": ""uint256"" }, { ""name"": ""_transactionData"", ""type"": ""bytes"" }], ""name"": ""executeProposal"", ""outputs"": [{ ""name"": ""_success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_from"", ""type"": ""address"" }, { ""name"": ""_to"", ""type"": ""address"" }, { ""name"": ""_value"", ""type"": ""uint256"" }], ""name"": ""transferFrom"", ""outputs"": [{ ""name"": ""success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [], ""name"": ""unblockMe"", ""outputs"": [{ ""name"": """", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""totalRewardToken"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""actualBalance"", ""outputs"": [{ ""name"": ""_actualBalance"", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""closingTime"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [{ ""name"": """", ""type"": ""address"" }], ""name"": ""allowedRecipients"", ""outputs"": [{ ""name"": """", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_to"", ""type"": ""address"" }, { ""name"": ""_value"", ""type"": ""uint256"" }], ""name"": ""transferWithoutReward"", ""outputs"": [{ ""name"": ""success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [], ""name"": ""refund"", ""outputs"": [], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_recipient"", ""type"": ""address"" }, { ""name"": ""_amount"", ""type"": ""uint256"" }, { ""name"": ""_description"", ""type"": ""string"" }, { ""name"": ""_transactionData"", ""type"": ""bytes"" }, { ""name"": ""_debatingPeriod"", ""type"": ""uint256"" }, { ""name"": ""_newCurator"", ""type"": ""bool"" }], ""name"": ""newProposal"", ""outputs"": [{ ""name"": ""_proposalID"", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [{ ""name"": """", ""type"": ""address"" }], ""name"": ""DAOpaidOut"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""minQuorumDivisor"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_newContract"", ""type"": ""address"" }], ""name"": ""newContract"", ""outputs"": [], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [{ ""name"": ""_owner"", ""type"": ""address"" }], ""name"": ""balanceOf"", ""outputs"": [{ ""name"": ""balance"", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_recipient"", ""type"": ""address"" }, { ""name"": ""_allowed"", ""type"": ""bool"" }], ""name"": ""changeAllowedRecipients"", ""outputs"": [{ ""name"": ""_success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [], ""name"": ""halveMinQuorum"", ""outputs"": [{ ""name"": ""_success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [{ ""name"": """", ""type"": ""address"" }], ""name"": ""paidOut"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_proposalID"", ""type"": ""uint256"" }, { ""name"": ""_newCurator"", ""type"": ""address"" }], ""name"": ""splitDAO"", ""outputs"": [{ ""name"": ""_success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""DAOrewardAccount"", ""outputs"": [{ ""name"": """", ""type"": ""address"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""proposalDeposit"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""numberOfProposals"", ""outputs"": [{ ""name"": ""_numberOfProposals"", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""lastTimeMinQuorumMet"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_toMembers"", ""type"": ""bool"" }], ""name"": ""retrieveDAOReward"", ""outputs"": [{ ""name"": ""_success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [], ""name"": ""receiveEther"", ""outputs"": [{ ""name"": """", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_to"", ""type"": ""address"" }, { ""name"": ""_value"", ""type"": ""uint256"" }], ""name"": ""transfer"", ""outputs"": [{ ""name"": ""success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""isFueled"", ""outputs"": [{ ""name"": """", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_tokenHolder"", ""type"": ""address"" }], ""name"": ""createTokenProxy"", ""outputs"": [{ ""name"": ""success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [{ ""name"": ""_proposalID"", ""type"": ""uint256"" }], ""name"": ""getNewDAOAddress"", ""outputs"": [{ ""name"": ""_newDAO"", ""type"": ""address"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_proposalID"", ""type"": ""uint256"" }, { ""name"": ""_supportsProposal"", ""type"": ""bool"" }], ""name"": ""vote"", ""outputs"": [{ ""name"": ""_voteID"", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [], ""name"": ""getMyReward"", ""outputs"": [{ ""name"": ""_success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [{ ""name"": """", ""type"": ""address"" }], ""name"": ""rewardToken"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_from"", ""type"": ""address"" }, { ""name"": ""_to"", ""type"": ""address"" }, { ""name"": ""_value"", ""type"": ""uint256"" }], ""name"": ""transferFromWithoutReward"", ""outputs"": [{ ""name"": ""success"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [{ ""name"": ""_owner"", ""type"": ""address"" }, { ""name"": ""_spender"", ""type"": ""address"" }], ""name"": ""allowance"", ""outputs"": [{ ""name"": ""remaining"", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": false, ""inputs"": [{ ""name"": ""_proposalDeposit"", ""type"": ""uint256"" }], ""name"": ""changeProposalDeposit"", ""outputs"": [], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [{ ""name"": """", ""type"": ""address"" }], ""name"": ""blocked"", ""outputs"": [{ ""name"": """", ""type"": ""uint256"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""curator"", ""outputs"": [{ ""name"": """", ""type"": ""address"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [{ ""name"": ""_proposalID"", ""type"": ""uint256"" }, { ""name"": ""_recipient"", ""type"": ""address"" }, { ""name"": ""_amount"", ""type"": ""uint256"" }, { ""name"": ""_transactionData"", ""type"": ""bytes"" }], ""name"": ""checkProposalCode"", ""outputs"": [{ ""name"": ""_codeChecksOut"", ""type"": ""bool"" }], ""type"": ""function"" }, { ""constant"": true, ""inputs"": [], ""name"": ""privateCreation"", ""outputs"": [{ ""name"": """", ""type"": ""address"" }], ""type"": ""function"" }, { ""inputs"": [{ ""name"": ""_curator"", ""type"": ""address"" }, { ""name"": ""_daoCreator"", ""type"": ""address"" }, { ""name"": ""_proposalDeposit"", ""type"": ""uint256"" }, { ""name"": ""_minTokensToCreate"", ""type"": ""uint256"" }, { ""name"": ""_closingTime"", ""type"": ""uint256"" }, { ""name"": ""_privateCreation"", ""type"": ""address"" }], ""type"": ""constructor"" }, { ""anonymous"": false, ""inputs"": [{ ""indexed"": true, ""name"": ""_from"", ""type"": ""address"" }, { ""indexed"": true, ""name"": ""_to"", ""type"": ""address"" }, { ""indexed"": false, ""name"": ""_amount"", ""type"": ""uint256"" }], ""name"": ""Transfer"", ""type"": ""event"" }, { ""anonymous"": false, ""inputs"": [{ ""indexed"": true, ""name"": ""_owner"", ""type"": ""address"" }, { ""indexed"": true, ""name"": ""_spender"", ""type"": ""address"" }, { ""indexed"": false, ""name"": ""_amount"", ""type"": ""uint256"" }], ""name"": ""Approval"", ""type"": ""event"" }, { ""anonymous"": false, ""inputs"": [{ ""indexed"": false, ""name"": ""value"", ""type"": ""uint256"" }], ""name"": ""FuelingToDate"", ""type"": ""event"" }, { ""anonymous"": false, ""inputs"": [{ ""indexed"": true, ""name"": ""to"", ""type"": ""address"" }, { ""indexed"": false, ""name"": ""amount"", ""type"": ""uint256"" }], ""name"": ""CreatedToken"", ""type"": ""event"" }, { ""anonymous"": false, ""inputs"": [{ ""indexed"": true, ""name"": ""to"", ""type"": ""address"" }, { ""indexed"": false, ""name"": ""value"", ""type"": ""uint256"" }], ""name"": ""Refund"", ""type"": ""event"" }, { ""anonymous"": false, ""inputs"": [{ ""indexed"": true, ""name"": ""proposalID"", ""type"": ""uint256"" }, { ""indexed"": false, ""name"": ""recipient"", ""type"": ""address"" }, { ""indexed"": false, ""name"": ""amount"", ""type"": ""uint256"" }, { ""indexed"": false, ""name"": ""newCurator"", ""type"": ""bool"" }, { ""indexed"": false, ""name"": ""description"", ""type"": ""string"" }], ""name"": ""ProposalAdded"", ""type"": ""event"" }, { ""anonymous"": false, ""inputs"": [{ ""indexed"": true, ""name"": ""proposalID"", ""type"": ""uint256"" }, { ""indexed"": false, ""name"": ""position"", ""type"": ""bool"" }, { ""indexed"": true, ""name"": ""voter"", ""type"": ""address"" }], ""name"": ""Voted"", ""type"": ""event"" }, { ""anonymous"": false, ""inputs"": [{ ""indexed"": true, ""name"": ""proposalID"", ""type"": ""uint256"" }, { ""indexed"": false, ""name"": ""result"", ""type"": ""bool"" }, { ""indexed"": false, ""name"": ""quorum"", ""type"": ""uint256"" }], ""name"": ""ProposalTallied"", ""type"": ""event"" }, { ""anonymous"": false, ""inputs"": [{ ""indexed"": true, ""name"": ""_newCurator"", ""type"": ""address"" }], ""name"": ""NewCurator"", ""type"": ""event"" }, { ""anonymous"": false, ""inputs"": [{ ""indexed"": true, ""name"": ""_recipient"", ""type"": ""address"" }, { ""indexed"": false, ""name"": ""_allowed"", ""type"": ""bool"" }], ""name"": ""AllowedRecipientChanged"", ""type"": ""event"" }]";
     var contractAddress = "0xbb9bc244d798123fde783fcc1c72d3bb8c189413";
     var web3 = new Web3();
     var contract = web3.Eth.GetContract(abi, contractAddress);
     var proposalsFunction = contract.GetFunction("proposals");
     var result = proposalsFunction.CallDeserializingToObjectAsync<Proposal>(5).Result;
     Assert.True(result.Creator == "0xd68ba7734753e2ee54103116323aba2d94c78dc5");
 }
        public async void ShouldDeployUsingMultipleParameters()
        {
            var contractByteCode =
              "0x606060408181528060bd833960a090525160805160009182556001556095908190602890396000f3606060405260e060020a60003504631df4f1448114601c575b6002565b34600257608360043560015460005460408051918402909202808252915173ffffffffffffffffffffffffffffffffffffffff33169184917f841774c8b4d8511a3974d7040b5bc3c603d304c926ad25d168dacd04e25c4bed9181900360200190a3919050565b60408051918252519081900360200190f3";

            var abi =
                @"[{'constant':false,'inputs':[{'name':'a','type':'int256'}],'name':'multiply','outputs':[{'name':'r','type':'int256'}],'payable':false,'type':'function'},{'inputs':[{'name':'multiplier','type':'int256'},{'name':'another','type':'int256'}],'type':'constructor'},{'anonymous':false,'inputs':[{'indexed':true,'name':'a','type':'int256'},{'indexed':true,'name':'sender','type':'address'},{'indexed':false,'name':'result','type':'int256'}],'name':'Multiplied','type':'event'}]";

            var web3 = new Web3(ClientFactory.GetClient());

            var gethTester = GethTesterFactory.GetLocal(web3);

            await web3.Miner.Start.SendRequestAsync(6);
            var transaction =
                await
                    web3.Eth.DeployContract.SignAndSendRequestAsync(gethTester.Password, abi, contractByteCode,
                        gethTester.Account, new HexBigInteger(900000), 7, 8);

            var receipt = await gethTester.GetTransactionReceipt(transaction);

            await web3.Miner.Stop.SendRequestAsync();

            var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);

            //get the function by name
            var multiplyFunction = contract.GetFunction("multiply");

            //do a function call (not transaction) and get the result
            var callResult = await multiplyFunction.CallAsync<int>(69);
            Assert.Equal(3864, callResult);
        }
        public async Task<bool> ShouldSignAndSendRawTransaction()
        {
            var privateKey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
            var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
            var receiveAddress = "0x13f022d72158410433cbd66f5dd8bf6d2d129924";
            var web3 = new Web3();

            var txCount = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(senderAddress);
            var encoded = web3.OfflineTransactionSigning.SignTransaction(privateKey, receiveAddress, 10,
                txCount.Value);

            Assert.True(web3.OfflineTransactionSigning.VerifyTransaction(encoded));

            Debug.WriteLine(web3.OfflineTransactionSigning.GetSenderAddress(encoded));
            Assert.Equal(senderAddress.ToLower(), "0x" + web3.OfflineTransactionSigning.GetSenderAddress(encoded));

            var txId = await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync("0x" + encoded);
            await web3.Miner.Start.SendRequestAsync(4);
            var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);
            while (receipt == null)
            {
                Thread.Sleep(1000);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);
            }
            await web3.Miner.Stop.SendRequestAsync();
            Assert.Equal(txId, receipt.TransactionHash);
            return true;
        }
        public async void ShouldDeployAContractAndPerformACall()
        {
            //The compiled solidity contract to be deployed
            //contract test { function multiply(uint a) returns(uint d) { return a * 7; } }
            var contractByteCode =
                "0x606060405260728060106000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146037576035565b005b604b60048080359060200190919050506061565b6040518082815260200191505060405180910390f35b6000600782029050606d565b91905056";

            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""}]";

            var web3 = new Web3(ClientFactory.GetClient());
            var gethTester = GethTesterFactory.GetLocal(web3);

            var receipt = await gethTester.DeployTestContractLocal(contractByteCode);

            var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);

            //get the function by name
            var multiplyFunction = contract.GetFunction("multiply");
            
            //do a function call (not transaction) and get the result
            var callResult = await multiplyFunction.CallAsync<int>(69);
            Assert.Equal(483, callResult);

        }
        public void ShouldDecodeMultipleParamsIncludingArray()
        {

            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""},{""name"":""b"",""type"":""string""},{""name"":""c"",""type"":""uint[3]""} ],""name"":""test"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""}]";

            var web3 = new Web3(ClientFactory.GetClient());

            var contract = web3.Eth.GetContract(abi, "ContractAddress");
   
            //get the function by name
            var testFunction = contract.GetFunction("test");
            var array = new int[] {1, 2, 3};

            var str = "hello";
            var data = testFunction.GetData(69, str, array);
            var decode = testFunction.DecodeInput(data);

            Assert.Equal(69, (BigInteger)decode[0].Result);
            Assert.Equal(str, (string)decode[1].Result);

            var listObjects = decode[2].Result as List<object>;

            if (listObjects != null)
            {
                var newArray = System.Array.ConvertAll(listObjects.ToArray(), x => (int)((BigInteger)x));
                Assert.Equal(array, newArray);
            }
        }
예제 #6
0
        public async Task<TransactionReceipt[]> SendAndMineTransactionsAsync(Web3.Web3 web3, string addressFrom,
            string pass, params Func<Task<string>>[] transactionsTask)
        {
            var result = await web3.Personal.UnlockAccount.SendRequestAsync(addressFrom, pass, new HexBigInteger(600000));
            if (result != true) throw new Exception("Acccount not unlocked");

            result = await web3.Miner.Start.SendRequestAsync(6);

            if (result != true) throw new Exception("Could not start mining");

            var txIds = new List<string>();

            foreach (var transactionTask in transactionsTask)
            {
               var txId = await transactionTask();
                txIds.Add(txId);
            }

            var receipts = new List<TransactionReceipt>();

            foreach (var txId in txIds)
            {
                receipts.Add(await TransactionReceipt(web3, txId));
            }

            result = await web3.Miner.Stop.SendRequestAsync();

            if (result != true) throw new Exception("Could not stop mining");
            return receipts.ToArray();
        }
        public async void Test()
        {
            /* 
             contract Hashes{
                
                function sha3Test(string _myvalue) returns (bytes32 val){
                    return sha3(_myvalue);
                }
    
                bytes32 public myHash;
    
                function storeMyHash(bytes32 _myHash){
                    myHash = _myHash;    
                }
            }
            */

            var text = "code monkeys are great";
            var hash = "0x1c21348936d43dc62d853ff6238cff94e361f8dcee9fde6fd5fbfed9ff663150";
            var web3 = new Web3(ClientFactory.GetClient());

            var sha3Hello = web3.Sha3(text);
            Assert.Equal(hash, "0x" + sha3Hello);

            var contractByteCode =
               "0x6060604052610154806100126000396000f360606040526000357c0100000000000000000000000000000000000000000000000000000000900480632bb49eb71461004f5780637c886096146100bd578063b6f61649146100d55761004d565b005b6100a36004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509090919050506100fc565b604051808260001916815260200191505060405180910390f35b6100d3600480803590602001909190505061013d565b005b6100e2600480505061014b565b604051808260001916815260200191505060405180910390f35b600081604051808280519060200190808383829060006004602084601f0104600f02600301f15090500191505060405180910390209050610138565b919050565b806000600050819055505b50565b6000600050548156";

            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""_myvalue"",""type"":""string""}],""name"":""sha3Test"",""outputs"":[{""name"":""val"",""type"":""bytes32""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""_myHash"",""type"":""bytes32""}],""name"":""storeMyHash"",""outputs"":[],""type"":""function""},{""constant"":true,""inputs"":[],""name"":""myHash"",""outputs"":[{""name"":"""",""type"":""bytes32""}],""type"":""function""}]";

           
            var gethTester = GethTesterFactory.GetLocal(web3);

            var receipt = await gethTester.DeployTestContractLocal(contractByteCode);

            //"0x350b79547251fdb18b64ec17cf3783e7d854bd30" (prev deployed contract)

            var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);

            var sha3Function = contract.GetFunction("sha3Test");
            var result = await sha3Function.CallAsync<byte[]>(text);
            Assert.Equal(hash, "0x" + result.ToHex());

            var storeMyHash = contract.GetFunction("storeMyHash");
            await gethTester.StartMining();
            await gethTester.UnlockAccount();
            var txn = await storeMyHash.SendTransactionAsync(gethTester.Account, hash.HexToByteArray());
            await gethTester.GetTransactionReceipt(txn);
            await gethTester.StopMining();


            var myHashFuction = contract.GetFunction("myHash");
            result = await myHashFuction.CallAsync<byte[]>();
            Assert.Equal(hash, "0x" + result.ToHex());

        }
        public async Task<string> Test()
        {
            //The compiled solidity contract to be deployed
            /*
               contract test { 

               uint _multiplier;

               function test(uint multiplier){
                   _multiplier = multiplier;
               }

               function multiply(uint a) returns(uint d) { return a * _multiplier; }

           }
           */

            var contractByteCode =
                "0x606060405260405160208060ae833981016040528080519060200190919050505b806000600050819055505b5060768060386000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146037576035565b005b604b60048080359060200190919050506061565b6040518082815260200191505060405180910390f35b6000600060005054820290506071565b91905056";

            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""uint256""}],""type"":""constructor""}]";

            var addressFrom = "0x12890d2cce102216644c59dae5baed380d84830c";

            var web3 = new Web3();

            //deploy the contract, including abi and a paramter of 7. 
            var transactionHash = await web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode, addressFrom, 7);

            //the contract should be mining now

            //get the contract address 
            TransactionReceipt receipt = null;
            //wait for the contract to be mined to the address
            while (receipt == null)
            {
                await Task.Delay(500);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
            }

            var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);

            //get the function by name
            var multiplyFunction = contract.GetFunction("multiply");

            //do a function call (not transaction) and get the result
            var result = await multiplyFunction.CallAsync<int>(69);
            //visual test 
            return "The result of deploying a contract and calling a function to multiply 7 by 69 is: " + result +
                   " and should be 483";
        }
예제 #9
0
        public async void GetBlock()
        {
            var web3 = new Web3(ClientFactory.GetClient());
            var block = await web3.Eth.Blocks.GetBlockWithTransactionsHashesByNumber.SendRequestAsync(new HexBigInteger(1139657));
            var transaction =
                await
                    web3.Eth.Transactions.GetTransactionByHash.SendRequestAsync(
                        "0x9122a4bba873e30c9c6e71481bd60ef61f559f60e26e50a38272f3324b7befca");

            var receipt = await
                web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(
                    "0x9122a4bba873e30c9c6e71481bd60ef61f559f60e26e50a38272f3324b7befca");
           
        }
예제 #10
0
        public void MordenTest()
        {
            string abi = @"[{""constant"":false,""inputs"":[{""name"":""multihash"",""type"":""bytes""}],""name"":""uploadBatch"",""outputs"":[{""name"":"""",""type"":""bool""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""_blockHeight"",""type"":""uint256""},{""name"":""_contentBy"",""type"":""address""},{""name"":""_changeCount"",""type"":""uint256""},{""name"":""_totalRexRewarded"",""type"":""uint256""}],""name"":""issueContentReward"",""outputs"":[],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""_address"",""type"":""address""}],""name"":""updateCoordinator"",""outputs"":[],""type"":""function""},{""constant"":true,""inputs"":[],""name"":""uploadCount"",""outputs"":[{""name"":"""",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""_dataFeedCoordinatorAddress"",""type"":""address""},{""name"":""feedCode"",""type"":""bytes4""}],""type"":""constructor""},{""anonymous"":false,""inputs"":[{""indexed"":false,""name"":"""",""type"":""address""},{""indexed"":false,""name"":"""",""type"":""bytes""}],""name"":""BatchUploaded"",""type"":""event""},{""anonymous"":false,""inputs"":[{""indexed"":false,""name"":""blockHeight"",""type"":""uint256""},{""indexed"":false,""name"":""contentBy"",""type"":""address""},{""indexed"":false,""name"":""changeCount"",""type"":""uint256""},{""indexed"":false,""name"":""totalRewards"",""type"":""uint256""}],""name"":""ContentRewarded"",""type"":""event""}]";
            string contractAddress = "0xe8d75008917c6a460473e62d5d4cefd3bbe4d85b";

            var web3 = new Web3("http://localhost:8545");
            var dataFeedContract = web3.Eth.GetContract(abi, contractAddress);

            //var filterAllContract = dataFeedContract.CreateFilterAsync().Result;
            //var logs = web3.Eth.Filters.GetFilterChangesForEthNewFilter.SendRequestAsync(filterAllContract).Result;

            Nethereum.Web3.Event e = dataFeedContract.GetEvent("BatchUploaded");
            var filterId = e.CreateFilterAsync(new Nethereum.RPC.Eth.DTOs.BlockParameter(500000)).Result;
            var changes = e.GetAllChanges<EventBatchUploaded>(filterId).Result;
        }
예제 #11
0
        public async Task<TransactionReceipt> MineAndGetReceiptAsync(Web3.Web3 web3, string transactionHash){

          var miningResult = await web3.Miner.Start.SendRequestAsync(6);
          Assert.True(miningResult);
          
          var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);

          while(receipt == null){
              Thread.Sleep(1000);
              receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
          }
          
          miningResult = await web3.Miner.Stop.SendRequestAsync();
          Assert.True(miningResult);
          return receipt;
        }
        public void ShouldDecodeInt()
        { 
            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""}]";

            var web3 = new Web3(ClientFactory.GetClient());
          
            var contract = web3.Eth.GetContract(abi, "ContractAddress");

            //get the function by name
            var multiplyFunction = contract.GetFunction("multiply");
            var data = multiplyFunction.GetData(69);
            var decode = multiplyFunction.DecodeInput(data);
            Assert.Equal((BigInteger)decode[0].Result, 69);

        }
        public async Task ShouldIntereceptContractDeploymentAndContractTrasanctionWithRawTransaction()
        {
          
            var contractByteCode =
              "0x6060604052604060405190810160405280600a81526020017f4d756c7469706c6965720000000000000000000000000000000000000000000081526020015060016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061008c57805160ff19168380011785556100bd565b828001600101855582156100bd579182015b828111156100bc57825182600050559160200191906001019061009e565b5b5090506100e891906100ca565b808211156100e457600081815060009055506001016100ca565b5090565b5050604051602080610303833981016040528080519060200190919050505b806000600050819055505b506101e2806101216000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806340490a901461004f57806375d0c0dc14610072578063c6888fa1146100ed5761004d565b005b61005c6004805050610119565b6040518082815260200191505060405180910390f35b61007f6004805050610141565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156100df5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610103600480803590602001909190505061012b565b6040518082815260200191505060405180910390f35b60006000600050549050610128565b90565b60006000600050548202905061013c565b919050565b60016000508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101da5780601f106101af576101008083540402835291602001916101da565b820191906000526020600020905b8154815290600101906020018083116101bd57829003601f168201915b50505050508156";

            var abi =
                @"[{""constant"":true,""inputs"":[],""name"":""getMultiplier"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""constant"":true,""inputs"":[],""name"":""contractName"",""outputs"":[{""name"":"""",""type"":""string""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""uint256""}],""type"":""constructor""}]";


            var privateKey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
            var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";

            var web3 = new Web3();
            var transactionInterceptor = new TransactionRequestToOfflineSignedTransactionInterceptor(senderAddress, privateKey, web3);
            web3.Client.OverridingRequestInterceptor = transactionInterceptor;

            var txId = await web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode, senderAddress, new HexBigInteger(900000), 7);


            await web3.Miner.Start.SendRequestAsync(4);
            var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);
            while (receipt == null)
            {
                Thread.Sleep(1000);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);
            }

            Assert.Equal(txId, receipt.TransactionHash);
            Assert.NotNull(receipt.ContractAddress);

            var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);
            var multiplyFunction = contract.GetFunction("multiply");

            txId = await multiplyFunction.SendTransactionAsync(senderAddress, new HexBigInteger(900000), new HexBigInteger(0), 69);

            receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);
            while (receipt == null)
            {
                Thread.Sleep(1000);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);
            }

            await web3.Miner.Stop.SendRequestAsync();

            Assert.Equal(txId, receipt.TransactionHash);
        }
        public async Task ShouldIntereceptAndSendRawTransaction()
        {
            var privateKey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
            var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
            var receiveAddress = "0x13f022d72158410433cbd66f5dd8bf6d2d129924";
            var web3 = new Web3();
            var transactionInterceptor = new TransactionRequestToOfflineSignedTransactionInterceptor(senderAddress, privateKey, web3);
            web3.Client.OverridingRequestInterceptor = transactionInterceptor;

            var txId = await web3.Eth.Transactions.SendTransaction.SendRequestAsync(new RPC.Eth.DTOs.TransactionInput() { From = senderAddress, To = receiveAddress, Value = new Hex.HexTypes.HexBigInteger(10) });

            await web3.Miner.Start.SendRequestAsync(4);
            var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);
            while (receipt == null)
            {
                Thread.Sleep(1000);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txId);
            }
            await web3.Miner.Stop.SendRequestAsync();
            Assert.Equal(txId, receipt.TransactionHash);

        }
        public async void ShouldDeployAContractWithConstructor()
        {
            //The compiled solidity contract to be deployed
            /*
               contract test { 

               uint _multiplier;

               function test(uint multiplier){
                   _multiplier = multiplier;
               }

               function getMultiplier() constant returns(uint d){
                    return _multiplier;
               }

               function multiply(uint a) returns(uint d) { return a * _multiplier; }

               string public contractName = "Multiplier";
           }
           */

            var contractByteCode =
                "0x6060604052604060405190810160405280600a81526020017f4d756c7469706c6965720000000000000000000000000000000000000000000081526020015060016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061008c57805160ff19168380011785556100bd565b828001600101855582156100bd579182015b828111156100bc57825182600050559160200191906001019061009e565b5b5090506100e891906100ca565b808211156100e457600081815060009055506001016100ca565b5090565b5050604051602080610303833981016040528080519060200190919050505b806000600050819055505b506101e2806101216000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806340490a901461004f57806375d0c0dc14610072578063c6888fa1146100ed5761004d565b005b61005c6004805050610119565b6040518082815260200191505060405180910390f35b61007f6004805050610141565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156100df5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610103600480803590602001909190505061012b565b6040518082815260200191505060405180910390f35b60006000600050549050610128565b90565b60006000600050548202905061013c565b919050565b60016000508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101da5780601f106101af576101008083540402835291602001916101da565b820191906000526020600020905b8154815290600101906020018083116101bd57829003601f168201915b50505050508156";

            var abi =
                @"[{""constant"":true,""inputs"":[],""name"":""getMultiplier"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""constant"":true,""inputs"":[],""name"":""contractName"",""outputs"":[{""name"":"""",""type"":""string""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""uint256""}],""type"":""constructor""}]";

            var addressFrom = "0x398e41717cfe68eeef4938677676a63667f35c4e";
            var pass = "******";

            var web3 = new Web3(ClientFactory.GetClient());
            var result = true;
            result = await web3.Personal.UnlockAccount.SendRequestAsync(addressFrom, pass, new HexBigInteger(600));
            Assert.True(result, "Account should be unlocked");

            //deploy the contract, including abi and a paramter of 7. 
            var transactionHash = await web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode, addressFrom, new HexBigInteger(900000), 7);

            Assert.NotNull(transactionHash);

           // result = await web3.Personal.LockAccount.SendRequestAsync(addressFrom);
            Assert.True(result, "Account should be locked");

            result = await web3.Miner.Start.SendRequestAsync();
            Assert.True(result, "Mining should have started");
            ////the contract should be mining now

            //get the contract address 
            TransactionReceipt receipt = null;
            //wait for the contract to be mined to the address
            while (receipt == null)
            {
                Thread.Sleep(1000);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
            }

            Assert.NotNull(receipt.ContractAddress);

            result = await web3.Miner.Stop.SendRequestAsync();
            Assert.True(result, "Mining should have stopped");

            var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);
            
            //get the function by name
            var multiplyFunction = contract.GetFunction("multiply");

            //do a function call (not transaction) and get the result
            var callResult = await multiplyFunction.CallAsync<int>(69);
            Assert.Equal(483, callResult);

            var multiplierFunction = contract.GetFunction("getMultiplier");

            var multiplier = await multiplierFunction.CallAsync<int>();

            Assert.Equal(7, multiplier);

            var contractNameFunction = contract.GetFunction("contractName");

            var name = await contractNameFunction.CallAsync<string>();

            Assert.Equal("Multiplier", name);
            
        }
        /// <summary>
        /// Deploy smart contract, other than contract's abi, bytecode, sender address,
        /// it must include any parameters for contract's constructor.
        /// </summary>
        /// <param name="name">Contract name</param>
        /// <param name="abi"></param>
        /// <param name="byteCode"></param>
        /// <param name="senderAddress">Contract owner</param>
        /// <param name="senderPassword"></param>
        /// <param name="gas"></param>
        /// <returns></returns>
        public async Task <DeploymentResult> Deploy(
            string name,
            string abi,
            string byteCode,
            string senderAddress,
            string senderPassword,
            BigInteger gas)
        {
            // var isNameUnique = CheckUniqueContractName(name);
            // if(!isNameUnique)
            //     return new DeployResponse(){
            //     Success = false,
            //     StatusMessage = "Name exists. Please choose another name"};

            var account = new ManagedAccount(senderAddress, senderPassword);
            var web3    = new Web3(account, Config.GetSection(Constants.GETH_RPC).Value);

            string transactionHash = null;

            try
            {
                transactionHash = await web3.Eth.DeployContract
                                  .SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(gas));
            }
            catch (Exception ex)
            {
                Logger.LogError("Deployment failed!\n" + ex.StackTrace);
                return(new DeploymentResult()
                {
                    Success = false, StatusMessage = "Deployment failed!"
                });
            }

            var transactionReceipt = await TryGetReceipt(web3, transactionHash);

            string contractAddress = null;

            try
            {
                contractAddress = transactionReceipt.ContractAddress;
            }
            catch (Exception ex)
            {
                Logger.LogError("Error retrieving address: \n" + ex.StackTrace);
            }

            var contract = await Task.Run(() => web3.Eth.GetContract(abi, contractAddress));

            ContractDAO contractDAO = new ContractDAO()
            {
                Contract        = contract,
                Name            = name,
                Address         = contractAddress,
                Abi             = abi,
                CodeHash        = byteCode,
                StorageHash     = byteCode,
                CreatedDateTime = DateTime.Now.ToUniversalTime()
            };
            await Task.Run(() => SaveContractToXml(contractDAO, name));

            List <ContractDAO> contractList = null;

            if (!Cache.TryGetValue(Constants.CACHE_CONTRACT_LIST, out contractList))
            {
                contractList = new List <ContractDAO>();
            }

            contractList.Add(contractDAO);
            Cache.Set(Constants.CACHE_CONTRACT_LIST, contractList);

            return(new DeploymentResult()
            {
                ContractAddress = contractAddress,
                TransactionReceipt = transactionReceipt,
                TransactionHash = transactionHash,
                DeployedAtBlock = transactionReceipt.BlockNumber,
                OwnerAddress = senderAddress,
                GasPrice = transactionReceipt.GasUsed,
                Success = true
            });
        }
예제 #17
0
        protected virtual async Task <Dictionary <string, TransactionReceipt> > DeployContract(Web3 web3, IEnumerable <string> contracts, bool isMining,
                                                                                               Action <Dictionary <string, TransactionReceipt> > saveContract = null)
        {
            var receipts = new Dictionary <string, TransactionReceipt>();

            var unlockResult =
                await web3.Personal.UnlockAccount.SendRequestAsync(AccountAddress, PassPhrase, 120);

            unlockResult.Should().BeTrue();

            foreach (var contract in contracts)
            {
                string deploy;
                switch (contract)
                {
                default:
                    deploy = await web3.Eth.DeployContract.SendRequestAsync(Abi[contract], Code[contract], AccountAddress, new HexBigInteger(2000000));

                    break;
                }

                var receipt = await MineAndGetReceiptAsync(web3, deploy, isMining);

                receipts.Add(contract, receipt);
            }

            saveContract?.Invoke(receipts);

            return(receipts);
        }
예제 #18
0
        public static async Task <TheOtherService> DeployContractAndGetServiceAsync(Web3 web3, TheOtherDeployment theOtherDeployment, CancellationTokenSource cancellationTokenSource = null)
        {
            var receipt = await DeployContractAndWaitForReceiptAsync(web3, theOtherDeployment, cancellationTokenSource).ConfigureAwait(false);

            return(new TheOtherService(web3, receipt.ContractAddress));
        }
 public BankDemoAppR3Service(Web3 web3, string address)
 {
     this.web3     = web3;
     this.contract = web3.Eth.GetContract(ABI, address);
 }
예제 #20
0
 public StorageVsMemoryService(Web3 web3, string address)
 {
     this.web3     = web3;
     this.contract = web3.Eth.GetContract(ABI, address);
 }
예제 #21
0
        protected override async Task <TransactionReceipt> ExecuteAsync(RuntimeContext context, string contractAddress, Web3 web3)
        {
            var algoStream = new AlgoStream(contractAddress, web3, context.GasPriceProvider);

            return(await algoStream.TerminateAsync());
        }
 public StandardTokenService(Web3 web3, string address)
 {
     this.Web3            = web3;
     this.Contract        = web3.Eth.GetContract(abi, address);
     this.ContractHandler = web3.Eth.GetContractHandler(address);
 }
예제 #23
0
 public EthereumClient(Web3 web3, NethereumOptions nethereumOptions)
 {
     _web3 = web3;
     _expectedConfirmationsCount = nethereumOptions.TransactionConfirmationsCount ?? DefaultTransactionConfirmationsCount;
 }
예제 #24
0
 public NonceCalculator(Web3 web3)
 {
     _getTransactionCount = new EthGetTransactionCount(web3.Client);
     _client = web3.Client;
 }
예제 #25
0
 public static GethTester GetLocal(Web3 web3)
 {
     return new GethTester(web3, "0x12890d2cce102216644c59dae5baed380d84830c", "password");
 }
 public Contract GetContract(Web3 web3, string contractAddress)
 {
     _contract = web3.Eth.GetContract(_abi, contractAddress);
     return(_contract);
 }
예제 #27
0
        static void Main(string[] args)
        {
            if(! File.Exists(@"settings.json"))
            {
                Console.WriteLine("Error a settings.json file must be provided with required settings");
                return;
            }
            Console.WriteLine("Settings file is " + Path.GetFullPath("settings.json"));
            IConfiguration config = new ConfigurationBuilder()
              .AddJsonFile(Path.GetFullPath("settings.json"), true, true)
              .Build();

            /*"searchpath": [ "C:\\inuka_proj\\gitStorageDecodegit\\contracttest\\contracts" ],
               "inputfile": "C:\\inuka_proj\\gitStorageDecodegit\\contracttest\\contracts\\TestClassSimple.sol",
               "MapVariables": {
                    "simpleMap": [ "4", "5", "6", "7" ],
                    "var2": [ "7", "8", "9" ]
            }*/
            List<string> searchpath = config.GetSection("searchpath").Get<List<string>>();
            String inputfile = config.GetSection("inputfile").Value;
            Console.WriteLine("inuput file is " + inputfile);
            var varsection = config.GetSection("MapVariables").GetChildren();
            foreach(var chld in varsection)
            {
                List<string> keys= chld.Get<List<string>>();
                foreach (string ky in keys)
                    MultiKeyDecodeList.AddKey(chld.Key, ky);
                //SolidityMap.
            }
            string address = config["address"];
            string ethURL = config["ethURL"];
            if(string.IsNullOrEmpty(address))
            {
                Console.WriteLine("address field is required");
                return;
            }
            if(string.IsNullOrEmpty(ethURL))
            {
                Console.WriteLine("URL to the ethereum node or Ganache must be provided");
                return;
            }
            /*check node and web3 connectivity */
            Web3 web = new Web3(ethURL);
            try
            {
                var currentBlock = web.Eth.Blocks.GetBlockNumber.SendRequestAsync();
                currentBlock.Wait();
            }
            catch(Exception exp)
            {
                Console.WriteLine("ERROR: not able to connect to Ethereum node or Ganache with the following error "+exp.Message);
                return;
            }
            string className = config["className"]; //for the case where multiple contracts are in the same file.
            string isdebug = config["debug"];
            if(!string.IsNullOrEmpty(isdebug) && isdebug.ToLower()=="true")
            {
                ethGlobal.IsDebug = true;
            }
            if (!File.Exists(inputfile))
            {
                Console.WriteLine("Error the input file does not exist :" + inputfile);
                return;
            }
            searchpath.Add(Path.GetDirectoryName(inputfile));
            Dictionary<string, string> subContracts = SplitContractFiles(inputfile);
            if(subContracts.Keys.Count>1 && String.IsNullOrEmpty(className))
            {
                Console.WriteLine("Error class name needs to be provied for file containing multiple contracts");
                return;
            }
            RunDecodingAndPrint(inputfile, address, ethURL, searchpath, subContracts, className);

        }
예제 #28
0
 protected abstract Task <TransactionReceipt> ExecuteAsync(RuntimeContext context, Web3 web3);
 public static Task <string> DeployContractAsync(Web3 web3, string addressFrom, HexBigInteger gas = null, HexBigInteger valueAmount = null)
 {
     return(web3.Eth.DeployContract.SendRequestAsync(ABI, BYTE_CODE, addressFrom, gas, valueAmount));
 }
예제 #30
0
        async Task IMusicAssetTransferService.UpdateLicenceTransaction(Guid id, Guid musicId)
        {
            var transfer = musicAssetTransferRepository.GetSC(id);

            if (transfer == null)
            {
                throw new ArgumentException("Id does not exist in the system.", nameof(id));
            }
            uint currentTime = (uint)DateTime.UtcNow.ToUnixTimestamp();

            var music = musicRepository.Get(musicId);

            if (music == null)
            {
                throw new ArgumentException("Music Id does not exist in the system.", nameof(musicId));
            }

            transfer.IsConfirmed     = true;
            transfer.DateTransferred = currentTime;
            transfer.Key2            = music.Key2;

            var  deployContract    = ethereumService.DeployContract();
            bool isCreatedContract = false;

            do
            {
                var receipt = deployContract.Result;
                if (receipt == null)
                {
                    continue;
                }
                if (receipt.Status.Value == (new HexBigInteger(1)).Value)
                {
                    isCreatedContract = true;

                    var function        = ethereumService.GetFunction(EthereumFunctions.AddTransactionMusic);
                    var transactionHash = await function.SendTransactionAsync(
                        ethereumService.GetEthereumAccount(),
                        new HexBigInteger(6000000),
                        new HexBigInteger(Nethereum.Web3.Web3.Convert.ToWei(10, UnitConversion.EthUnit.Gwei)),
                        new HexBigInteger(0),
                        functionInput : new object[] {
                        transfer.Id.ToString(),
                        transfer.MusicId.ToString(),
                        transfer.FromId.ToString(),
                        transfer.ToId.ToString(),
                        transfer.Key2,
                        transfer.TranType,
                        transfer.FanType,
                        transfer.DateStart,
                        transfer.DateEnd,
                        transfer.IsPermanent,
                        transfer.IsConfirmed
                    });

                    transfer.ContractAddress = ethereumService.GetMasterContractAddress();
                    transfer.TransactionHash = transactionHash;
                    musicAssetTransferRepository.Update(transfer);

                    music.OwnerId = (uint)transfer.BuyerId;
                    musicRepository.Update(music);
                }
            }while (isCreatedContract != true);

            var privateKey = musicAssetTransferRepository.GetUserInfo(transfer.BuyerId).OwnerPrivateKey;
            //var privateKey = "0xC40B82DCA66F1B0F117851AEF8E40D197F55499B09858B89AF2F8FF3B4FE83F3";
            var  account     = new Account(privateKey);
            Web3 web3        = new Web3(account, "https://ropsten.infura.io/v3/aaceb4b7c236404e9eb5416bef5292e0");
            var  transaction = web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(transfer.ToId.ToString(), transfer.AmountValue);

            BackgroundJob.Schedule <IMusicAssetTransferUndergroundJob>(
                job => job.WaitForTransactionToSuccessThenFinishCreating(transfer),
                TimeSpan.FromSeconds(3)
                );
        }
예제 #31
0
 public static Task <string> DeployContractAsync(Web3 web3, TheOtherDeployment theOtherDeployment)
 {
     return(web3.Eth.GetContractDeploymentHandler <TheOtherDeployment>().SendRequestAsync(theOtherDeployment));
 }
예제 #32
0
        async Task <Guid> IMusicAssetTransferService.Create(Guid musicId, string fromUserId, string toUserId, int buyerId, TranTypes tranType, FanTypes fanType, int duration, decimal amountValue, string key2)
        {
            var      music            = musicRepository.Get(musicId);
            DateTime startDate        = DateTime.UtcNow;
            uint     currentTime      = (uint)startDate.ToUnixTimestamp();
            DateTime endDate          = startDate.AddDays(duration);
            uint     endDateTimeStamp = (uint)endDate.ToUnixTimestamp();

            var transfer = new MusicAssetTransfer()
            {
                MusicId         = music.Id,
                FromId          = fromUserId,
                ToId            = toUserId,
                BuyerId         = buyerId,
                Key2            = key2,
                DateTransferred = currentTime,
                TranType        = tranType,
                FanType         = fanType,
                DateStart       = currentTime,
                DateEnd         = endDateTimeStamp,
                IsPermanent     = false,
                IsConfirmed     = true,
                DateCreated     = DateTime.UtcNow,
                AmountValue     = amountValue
            };

            var newTransferId = musicAssetTransferRepository.CreateAndReturnId(transfer);


            var  deployContract    = ethereumService.DeployContract();
            bool isCreatedContract = false;

            do
            {
                var receipt = deployContract.Result;
                if (receipt == null)
                {
                    continue;
                }
                if (receipt.Status.Value == (new HexBigInteger(1)).Value)
                {
                    isCreatedContract = true;

                    var function = ethereumService.GetFunction(EthereumFunctions.AddTransactionMusic);

                    var transactionHash = await function.SendTransactionAsync(
                        ethereumService.GetEthereumAccount(),
                        new HexBigInteger(6000000),
                        new HexBigInteger(Nethereum.Web3.Web3.Convert.ToWei(10, UnitConversion.EthUnit.Gwei)),
                        new HexBigInteger(0),
                        functionInput : new object[] {
                        newTransferId.ToString(),
                        transfer.MusicId.ToString(),
                        transfer.FromId.ToString(),
                        transfer.ToId.ToString(),
                        transfer.Key2,
                        transfer.TranType,
                        transfer.FanType,
                        transfer.DateStart,
                        transfer.DateEnd,
                        transfer.IsPermanent,
                        transfer.IsConfirmed
                    });

                    var privateKey = musicAssetTransferRepository.GetUserInfo(buyerId).OwnerPrivateKey;
                    //var privateKey = "0xC40B82DCA66F1B0F117851AEF8E40D197F55499B09858B89AF2F8FF3B4FE83F3";
                    var  account     = new Account(privateKey);
                    Web3 web3        = new Web3(account, "https://ropsten.infura.io/v3/aaceb4b7c236404e9eb5416bef5292e0");
                    var  transaction = web3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(transfer.ToId.ToString(), amountValue);

                    transfer.TransactionHash = transactionHash;
                    transfer.ContractAddress = ethereumService.GetMasterContractAddress();
                    musicAssetTransferRepository.Update(transfer);
                }
            }while (isCreatedContract != true);


            BackgroundJob.Schedule <IMusicAssetTransferUndergroundJob>(
                job => job.WaitForTransactionToSuccessThenFinishCreating(transfer),
                TimeSpan.FromSeconds(3)
                );

            return(newTransferId);
        }
예제 #33
0
 public TheOtherService(Web3 web3, string contractAddress)
 {
     Web3            = web3;
     ContractHandler = web3.Eth.GetContractHandler(contractAddress);
 }
예제 #34
0
 public static Task <TransactionReceipt> DeployContractAndWaitForReceiptAsync(Web3 web3, Constructor10Deployment constructor10Deployment, CancellationTokenSource cancellationTokenSource = null)
 {
     return(web3.Eth.GetContractDeploymentHandler <Constructor10Deployment>().SendRequestAndWaitForReceiptAsync(constructor10Deployment, cancellationTokenSource));
 }
예제 #35
0
 public NethereumTestsBase(IEnumerable <string> contracts)
 {
     Contracts = contracts;
     Web3      = new Web3();
 }
예제 #36
0
        public static async Task <Constructor10Service> DeployContractAndGetServiceAsync(Web3 web3, Constructor10Deployment constructor10Deployment, CancellationTokenSource cancellationTokenSource = null)
        {
            var receipt = await DeployContractAndWaitForReceiptAsync(web3, constructor10Deployment, cancellationTokenSource);

            return(new Constructor10Service(web3, receipt.ContractAddress));
        }
예제 #37
0
 public GethTester(Web3 web3, string account, string password)
 {
     this.Web3     = new Web3(new ManagedAccount(account, password), web3.Client);
     this.Account  = account;
     this.Password = password;
 }
예제 #38
0
        public async Task <HexBigInteger> GetBalance(string address)
        {
            var web3 = new Web3(this.Network);

            return(await web3.Eth.GetBalance.SendRequestAsync(address));
        }
예제 #39
0
 public static Task <string> DeployContractAsync(Web3 web3, Constructor10Deployment constructor10Deployment)
 {
     return(web3.Eth.GetContractDeploymentHandler <Constructor10Deployment>().SendRequestAsync(constructor10Deployment));
 }
예제 #40
0
 public async Task<TransactionReceipt> SendAndMineTransactionAsync(Web3.Web3 web3, string addressFrom,
     string pass, Func<Task<string>> transactionTask)
 {
     var receitps =  await SendAndMineTransactionsAsync(web3, addressFrom, pass, transactionTask);
     return receitps[0];
 }
예제 #41
0
 public Constructor10Service(Web3 web3, string contractAddress)
 {
     Web3            = web3;
     ContractHandler = web3.Eth.GetContractHandler(contractAddress);
 }
예제 #42
0
        private static async Task<TransactionReceipt> TransactionReceipt(Web3.Web3 web3, string transaction)
        {
            
            var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transaction);

            while (receipt == null)
            {
                Thread.Sleep(5000);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transaction);
            }
            return receipt;
        }
예제 #43
0
        public async Task<string> Test()
        {
            //The compiled solidity contract to be deployed
            /*
            contract test { 
    
                uint _multiplier;
    
                event Multiplied(uint indexed a);
    
                function test(uint multiplier){
                    _multiplier = multiplier;
                }
    
                function multiply(uint a, uint id) returns(uint d) { 
        
                    Multiplied(a);
        
                    return a * _multiplier; 
        
                }
    
            }
           
           */

            var contractByteCode =
                "606060405260405160208060de833981016040528080519060200190919050505b806000600050819055505b5060a68060386000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa1146037576035565b005b604b60048080359060200190919050506061565b6040518082815260200191505060405180910390f35b6000817f61aa1562c4ed1a53026a57ad595b672e1b7c648166127b904365b44401821b7960405180905060405180910390a26000600050548202905060a1565b91905056";

            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""uint256""}],""type"":""constructor""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""a"",""type"":""uint256""}],""name"":""Multiplied"",""type"":""event""}]
";

            var addressFrom = "0x12890d2cce102216644c59dae5baed380d84830c";

            var web3 = new Web3();

            //deploy the contract, including abi and a paramter of 7. 
            var transactionHash = await web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode, addressFrom, 7);

            


            //the contract should be mining now

            //get the contract address 
            TransactionReceipt receipt = null;
            //wait for the contract to be mined to the address
            while (receipt == null)
            {
                await Task.Delay(5000);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
            }

            var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);

            var multipliedEvent = contract.GetEvent("Multiplied");
            var filterAll = await multipliedEvent.CreateFilterAsync();
            //filter first indexed parameter
            var filter69 = await multipliedEvent.CreateFilterAsync(new object[] {69});
            

            await Task.Delay(2000);

            //get the function by name
            var multiplyFunction = contract.GetFunction("multiply");
        
            var transaction69 = await multiplyFunction.SendTransactionAsync(addressFrom, null, 69);
            var transaction18 = await multiplyFunction.SendTransactionAsync(addressFrom, null, 18);
            var transaction7 =  await multiplyFunction.SendTransactionAsync(addressFrom, null, 7);


            TransactionReceipt receiptTransaction = null;

            while (receiptTransaction == null)
            {
                await Task.Delay(5000);
                receiptTransaction = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transaction7);
            }

            var logsAll = await web3.Eth.Filters.GetFilterChangesForEthNewFilter.SendRequestAsync(filterAll);
            var logs69 = await web3.Eth.Filters.GetFilterChangesForEthNewFilter.SendRequestAsync(filter69);
            


            return "All logs :" + logsAll.Length + " Logs for 69 " + logs69.Length;

        }
예제 #44
0
        public async Task<string> Test()
        {
            //The compiled solidity contract to be deployed
            /*
           contract test { 
    
                uint _multiplier;
    
                event Multiplied(uint indexed a, uint indexed result);
    
                event MultipliedLog(uint indexed a, uint indexed result, address sender, string hello );
    
                function test(uint multiplier){
                    _multiplier = multiplier;
                }
    
                function multiply(uint a) returns(uint d) {
                    d = a * _multiplier;
                    Multiplied(a, d);
                    MultipliedLog(a, d, msg.sender, "Hello world");
                    return d;
                }
    
                function multiply1(uint a) returns(uint d) {
                    return a * _multiplier;
                }
    
                function multiply2(uint a, uint b) returns(uint d){
                    return a * b;
                }
    
            }
           
           */

            var contractByteCode =
                "0x6060604052604051602080610216833981016040528080519060200190919050505b806000600050819055505b506101db8061003b6000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806361325dbc1461004f578063c23f4e3e1461007b578063c6888fa1146100b05761004d565b005b61006560048080359060200190919050506101b3565b6040518082815260200191505060405180910390f35b61009a60048080359060200190919080359060200190919050506101c9565b6040518082815260200191505060405180910390f35b6100c660048080359060200190919050506100dc565b6040518082815260200191505060405180910390f35b600060006000505482029050805080827f51ae5c4fa89d1aa731ff280d425357e6e5c838c6fc8ed6ca0139ea31716bbd5760405180905060405180910390a380827fffc23845ca34f573c322267502cda1440fac565d162e9c3a5b2a9caca600d91d33604051808273ffffffffffffffffffffffffffffffffffffffff168152602001806020018281038252600b8152602001807f48656c6c6f20776f726c640000000000000000000000000000000000000000008152602001506020019250505060405180910390a38090506101ae565b919050565b6000600060005054820290506101c4565b919050565b600081830290506101d5565b9291505056";

            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply1"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""},{""name"":""b"",""type"":""uint256""}],""name"":""multiply2"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""uint256""}],""type"":""constructor""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""a"",""type"":""uint256""},{""indexed"":true,""name"":""result"",""type"":""uint256""}],""name"":""Multiplied"",""type"":""event""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""a"",""type"":""uint256""},{""indexed"":true,""name"":""result"",""type"":""uint256""},{""indexed"":false,""name"":""sender"",""type"":""address""},{""indexed"":false,""name"":""hello"",""type"":""string""}],""name"":""MultipliedLog"",""type"":""event""}]";

            var addressFrom = "0x12890d2cce102216644c59dae5baed380d84830c";
        
            var web3 = new Web3();
            var eth = web3.Eth;
            var transactions = eth.Transactions;

            //deploy the contract, including abi and a paramter of 7. 
            var transactionHash = await eth.DeployContract.SendRequestAsync(abi, contractByteCode, addressFrom, new HexBigInteger(900000), 7);

            //the contract should be mining now

            //get the contract address 
            TransactionReceipt receipt = null;
            //wait for the contract to be mined to the address
            while (receipt == null)
            {
                await Task.Delay(5000);
                receipt = await transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
            }

            var code = await web3.Eth.GetCode.SendRequestAsync(receipt.ContractAddress);

            if (String.IsNullOrEmpty(code))
            {
                throw new Exception("Code was not deployed correctly, verify bytecode or enough gas was uto deploy the contract");
            }
       
   
            var contract = eth.GetContract(abi, receipt.ContractAddress);

            var multipliedEvent = contract.GetEvent("Multiplied");
            var filterAllContract = await contract.CreateFilterAsync();
            var filterAll = await multipliedEvent.CreateFilterAsync();
            //filter on the first indexed parameter
            var filter69 = await multipliedEvent.CreateFilterAsync(69);
            //filter on the second indexed parameter
            var filter49 = await multipliedEvent.CreateFilterAsync<object, int>(null, 49);
            //filter OR on the first indexed parameter
            var filter69And18 = await multipliedEvent.CreateFilterAsync(new[] { 69, 18 });


            var multipliedEventLog =  contract.GetEvent("MultipliedLog");
            var filterAllLog = await multipliedEventLog.CreateFilterAsync();

            //get the function by name
            var multiplyFunction = contract.GetFunction("multiply");
           
            
            var transaction69 = await multiplyFunction.SendTransactionAsync(addressFrom, 69);
            var transaction18 = await multiplyFunction.SendTransactionAsync(addressFrom, 18);
            var transaction7 = await multiplyFunction.SendTransactionAsync(addressFrom, 7);

            var multiplyFunction2 = contract.GetFunction("multiply2");
            var callResult = await multiplyFunction2.CallAsync<int>(7, 7);

            TransactionReceipt receiptTransaction = null;

            while (receiptTransaction == null)
            {
                await Task.Delay(5000);
                receiptTransaction = await transactions.GetTransactionReceipt.SendRequestAsync(transaction7);
            }

            var logs = await eth.Filters.GetFilterChangesForEthNewFilter.SendRequestAsync(filterAllContract);    
            var eventLogsAll = await multipliedEvent.GetFilterChanges<EventMultiplied>(filterAll);
            var eventLogs69 = await multipliedEvent.GetFilterChanges<EventMultiplied>(filter69);
            var eventLogsResult49 = await multipliedEvent.GetFilterChanges<EventMultiplied>(filter49);
            var eventLogsFor69and18 = await multipliedEvent.GetFilterChanges<EventMultiplied>(filter69And18);

            var multipliedLogEvents = await multipliedEventLog.GetFilterChanges<EventMultipliedSenderLog>(filterAllLog);

            return "All logs :" + eventLogsAll.Count + " Multiplied by 69 result: " +
                   eventLogs69.First().Event.Result + " Address is " + multipliedLogEvents.First().Event.Sender;
        } 
 public RegistryService(Web3 web3, string key, string address)
 {
     this.web3 = web3;
     this._transactionService = new ConstantGasTransactionService(key, web3);
     this.contract            = web3.Eth.GetContract(ABI, address);
 }
예제 #46
0
        protected override async Task <object> ExecuteAsync(RuntimeContext context, string contractAddress, Web3 web3)
        {
            var algoToken = new AlgoTokenV1(contractAddress, web3, context.GasPriceProvider);

            return(await algoToken.TotalSupplyAsync());
        }
예제 #47
0
 public async Task<string> DeployContract(Web3.Web3 web3, string addressFrom, string pass, string bytecode, bool mineIt)
 {
     if (mineIt) return await DeployContract(web3, addressFrom, pass, bytecode);
     var receipt = await SendTransactionAsync(web3, addressFrom, pass, () => web3.Eth.DeployContract.SendRequestAsync(bytecode, addressFrom, new HexBigInteger(900000)));
     return receipt.ContractAddress;
 }
예제 #48
0
 public AttributeFacade(Web3 web3, ICertificateFacade certificateFacade, IContentService contentService, IAccountService accountService) : base(web3, accountService)
 {
     _certificateFacade = certificateFacade;
     _contentService    = contentService;
 }
예제 #49
0
 public TokenBalanceService(HttpClient httpClient, Web3 web3)
 {
     _httpClient = httpClient;
     _web3       = web3;
 }
예제 #50
0
        public async Task Test()
        {
            //The compiled solidity contract to be deployed
            /*
          contract test { 
    
                uint _multiplier;
    
                event Multiplied(uint indexed a, uint indexed result);
    
                event MultipliedLog(uint indexed a, uint indexed result, string indexed hello, address sender );
    
                function test(uint multiplier){
                    _multiplier = multiplier;
                }
    
                function multiply(uint a) returns(uint d) {
                    d = a * _multiplier;
                    Multiplied(a, d);
                    MultipliedLog(a, d, "Hello world", msg.sender);
                    return d;
                }
    
                function multiply1(uint a) returns(uint d) {
                    return a * _multiplier;
                }
    
                function multiply2(uint a, uint b) returns(uint d){
                    return a * b;
                }
    
            }
           
           */

            var contractByteCode =
                "0x6060604052604051602080610213833981016040528080519060200190919050505b806000600050819055505b506101d88061003b6000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806361325dbc1461004f578063c23f4e3e1461007b578063c6888fa1146100b05761004d565b005b61006560048080359060200190919050506100dc565b6040518082815260200191505060405180910390f35b61009a60048080359060200190919080359060200190919050506100f2565b6040518082815260200191505060405180910390f35b6100c66004808035906020019091905050610104565b6040518082815260200191505060405180910390f35b6000600060005054820290506100ed565b919050565b600081830290506100fe565b92915050565b600060006000505482029050805080827f51ae5c4fa89d1aa731ff280d425357e6e5c838c6fc8ed6ca0139ea31716bbd5760405180905060405180910390a360405180807f48656c6c6f20776f726c64000000000000000000000000000000000000000000815260200150600b019050604051809103902081837f74053123e4f45ba0f8cbf86301034a4ab00cdc75cd155a0df7c5d815bd97dcb533604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a48090506101d3565b91905056";

            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply1"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""},{""name"":""b"",""type"":""uint256""}],""name"":""multiply2"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""a"",""type"":""uint256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""uint256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""uint256""}],""type"":""constructor""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""a"",""type"":""uint256""},{""indexed"":true,""name"":""result"",""type"":""uint256""}],""name"":""Multiplied"",""type"":""event""},{""anonymous"":false,""inputs"":[{""indexed"":true,""name"":""a"",""type"":""uint256""},{""indexed"":true,""name"":""result"",""type"":""uint256""},{""indexed"":true,""name"":""sender"",""type"":""string""},{""indexed"":false,""name"":""hello"",""type"":""address""}],""name"":""MultipliedLog"",""type"":""event""}]";

            var addressFrom = "0x12890d2cce102216644c59dae5baed380d84830c";
            var pass = "******";

            var web3 = new Web3(ClientFactory.GetClient());

            var result = await web3.Personal.UnlockAccount.SendRequestAsync(addressFrom, pass, new HexBigInteger(600000));
            Assert.True(result, "Account should be unlocked");

           

            var eth = web3.Eth;
            var transactions = eth.Transactions;

            //deploy the contract, including abi and a paramter of 7. 
            var transactionHash = await eth.DeployContract.SendRequestAsync(abi, contractByteCode, addressFrom, new HexBigInteger(900000), 7);

            Assert.NotNull(transactionHash);

            result = await web3.Miner.Start.SendRequestAsync(4);
            Assert.True(result, "Mining should have started");

            //the contract should be mining now

            //get the contract address 
            TransactionReceipt receipt = null;
            //wait for the contract to be mined to the address
            while (receipt == null)
            {
                await Task.Delay(5000);
                receipt = await transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
            }

            var code = await web3.Eth.GetCode.SendRequestAsync(receipt.ContractAddress);

            if (String.IsNullOrEmpty(code))
            {
                throw new Exception("Code was not deployed correctly, verify bytecode or enough gas was uto deploy the contract");
            }
       
   
            var contract = eth.GetContract(abi, receipt.ContractAddress);

            var multipliedEvent = contract.GetEvent("Multiplied");
            var filterAllContract = await contract.CreateFilterAsync();
            var filterAll = await multipliedEvent.CreateFilterAsync();
            //filter on the first indexed parameter
            var filter69 = await multipliedEvent.CreateFilterAsync(69);
            //filter on the second indexed parameter
            var filter49 = await multipliedEvent.CreateFilterAsync<object, int>(null, 49);
            //filter OR on the first indexed parameter
            var filter69And18 = await multipliedEvent.CreateFilterAsync(new[] { 69, 18 });


            var multipliedEventLog =  contract.GetEvent("MultipliedLog");
            var filterAllLog = await multipliedEventLog.CreateFilterAsync();

            //get the function by name
            var multiplyFunction = contract.GetFunction("multiply");
           
            var gas = await multiplyFunction.EstimateGasAsync(69);
            var transaction69 = await multiplyFunction.SendTransactionAsync(addressFrom, 69);
            var transaction18 = await multiplyFunction.SendTransactionAsync(addressFrom, 18);
            var transaction7 = await multiplyFunction.SendTransactionAsync(addressFrom, 7);

            var multiplyFunction2 = contract.GetFunction("multiply2");
            var callResult = await multiplyFunction2.CallAsync<int>(7, 7);

            TransactionReceipt receiptTransaction = null;

            while (receiptTransaction == null)
            {
                await Task.Delay(5000);
                receiptTransaction = await transactions.GetTransactionReceipt.SendRequestAsync(transaction7);
            }

            result = await web3.Miner.Stop.SendRequestAsync();
            Assert.True(result, "Mining should have stopped");

            var logs = await eth.Filters.GetFilterChangesForEthNewFilter.SendRequestAsync(filterAllContract);    
            var eventLogsAll = await multipliedEvent.GetFilterChanges<EventMultiplied>(filterAll);
            var eventLogs69 = await multipliedEvent.GetFilterChanges<EventMultiplied>(filter69);
            var eventLogsResult49 = await multipliedEvent.GetFilterChanges<EventMultiplied>(filter49);
            var eventLogsFor69and18 = await multipliedEvent.GetFilterChanges<EventMultiplied>(filter69And18);

            
            var multipliedLogEvents = await multipliedEventLog.GetFilterChanges<EventMultipliedSenderLog>(filterAllLog);

            Assert.Equal(eventLogs69.First().Event.Result, 483);
            Assert.Equal(multipliedLogEvents.First().Event.Hello, "0xed6c11b0b5b808960df26f5bfc471d04c1995b0ffd2055925ad1be28d6baadfd"); //The sha3 keccak of "Hello world" as it is an indexed string
            Assert.Equal(multipliedLogEvents.First().Event.Sender, addressFrom);

       
        } 
예제 #51
0
 public GethTester(Web3 web3, string account, string password)
 {
     Web3 = web3;
     Account = account;
     Password = password;
 }
예제 #52
0
 public ConsoleService(Web3 web3, CoffeeEconomyService coffeeEconomyService)
 {
     _web3 = web3;
     _coffeeEconomyService = coffeeEconomyService;
 }
예제 #53
0
        public async Task<string> Test()
        {
            //The compiled solidity contract to be deployed
            /*
              contract test { 
    
    
                function test1() returns(int) { 
                   int d = 3457987492347979798742;
                   return d;
                }
    
                  function test2(int d) returns(int) { 
                   return d;
                }
    
                function test3(int d)returns(int){
                    int x = d + 1 -1;
                    return x;
                }
    
                function test4(int d)returns(bool){
                    return d == 3457987492347979798742;
                }
    
                function test5(int d)returns(bool){
                    return d == -3457987492347979798742;
                }
    
                function test6(int d)returns(bool){
                    return d == 500;
                }
    
                function test7(int256 d)returns(bool){
                    return d == 74923479797565;
                }
    
                function test8(int256 d)returns(bool){
                    return d == 9223372036854775808;
                }
            }
           }
           */

            var contractByteCode =
                "60606040526102b7806100126000396000f36060604052361561008a576000357c01000000000000000000000000000000000000000000000000000000009004806311da9d8c1461008c5780631c2a1101146100b857806363798981146100e45780636b59084d146101105780639e71212514610133578063a605861c1461015f578063e42d455b1461018b578063e92b09da146101b75761008a565b005b6100a26004808035906020019091905050610243565b6040518082815260200191505060405180910390f35b6100ce600480803590602001909190505061020e565b6040518082815260200191505060405180910390f35b6100fa60048080359060200190919050506101ff565b6040518082815260200191505060405180910390f35b61011d60048050506101e3565b6040518082815260200191505060405180910390f35b6101496004808035906020019091905050610229565b6040518082815260200191505060405180910390f35b6101756004808035906020019091905050610274565b6040518082815260200191505060405180910390f35b6101a1600480803590602001909190505061029e565b6040518082815260200191505060405180910390f35b6101cd6004808035906020019091905050610287565b6040518082815260200191505060405180910390f35b6000600068bb75377716692498d690508091506101fb565b5090565b6000819050610209565b919050565b60006000600160018401039050809150610223565b50919050565b600068bb75377716692498d68214905061023e565b919050565b60007fffffffffffffffffffffffffffffffffffffffffffffff448ac888e996db672a8214905061026f565b919050565b60006101f482149050610282565b919050565b60006544247b660f3d82149050610299565b919050565b6000678000000000000000821490506102b2565b91905056";

            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""d"",""type"":""int256""}],""name"":""test5"",""outputs"":[{""name"":"""",""type"":""bool""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""d"",""type"":""int256""}],""name"":""test3"",""outputs"":[{""name"":"""",""type"":""int256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""d"",""type"":""int256""}],""name"":""test2"",""outputs"":[{""name"":"""",""type"":""int256""}],""type"":""function""},{""constant"":false,""inputs"":[],""name"":""test1"",""outputs"":[{""name"":"""",""type"":""int256""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""d"",""type"":""int256""}],""name"":""test4"",""outputs"":[{""name"":"""",""type"":""bool""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""d"",""type"":""int256""}],""name"":""test6"",""outputs"":[{""name"":"""",""type"":""bool""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""d"",""type"":""int256""}],""name"":""test8"",""outputs"":[{""name"":"""",""type"":""bool""}],""type"":""function""},{""constant"":false,""inputs"":[{""name"":""d"",""type"":""int256""}],""name"":""test7"",""outputs"":[{""name"":"""",""type"":""bool""}],""type"":""function""}]";

            var addressFrom = "0x12890d2cce102216644c59dae5baed380d84830c";

            var web3 = new Web3();

          
            var pass = "******";
            var result = await web3.Personal.UnlockAccount.SendRequestAsync(addressFrom, pass, new HexBigInteger(600));

            //deploy the contract, including abi and a paramter of 7. 
            var transactionHash =
                await
                    web3.Eth.DeployContract.SendRequestAsync(contractByteCode, addressFrom,
                        new HexBigInteger(900000));

            //get the contract address 
            TransactionReceipt receipt = null;
            //wait for the contract to be mined to the address
            while (receipt == null)
            {
                await Task.Delay(500);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
            }

            var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);
            var test1 = contract.GetFunction("test1");
            Assert.Equal("3457987492347979798742", (await test1.CallAsync<BigInteger>()).ToString());
            var test2 = contract.GetFunction("test2");
            Assert.Equal("3457987492347979798742", (await test2.CallAsync<BigInteger>(BigInteger.Parse("3457987492347979798742"))).ToString());

            var test3 = contract.GetFunction("test3");
            Assert.Equal("3457987492347979798742", (await test3.CallAsync<BigInteger>(BigInteger.Parse("3457987492347979798742"))).ToString());

            var test4 = contract.GetFunction("test4");
            Assert.True(await test4.CallAsync<bool>(BigInteger.Parse("3457987492347979798742")));

            var test5 = contract.GetFunction("test5");
            Assert.True(await test5.CallAsync<bool>(BigInteger.Parse("-3457987492347979798742")));

            var test6 = contract.GetFunction("test6");
            Assert.True(await test6.CallAsync<bool>(BigInteger.Parse("500")));

            var test8 = contract.GetFunction("test8");
            Assert.True(await test8.CallAsync<bool>(BigInteger.Parse("9223372036854775808")));




            return "OK";
        }
예제 #54
0
        public RecoverModel EcRecover(Address sender, Signature signature, byte[] data)
        {
            var hash = Hash.Of(Web3.Sha3(System.Convert.ToBase64String(data)));

            return(EcRecover(sender, signature, hash));
        }
        public async void ShouldDeployAContractWithValueAndSendAValue()
        {
            var contractByteCode =
                "0x6060604052600180546c0100000000000000000000000033810204600160a060020a03199091161790556002340460008190556002023414603e576002565b6103258061004c6000396000f3606060405236156100615760e060020a600035046308551a53811461006657806335a063b41461007d5780633fa4f245146100a05780637150d8ae146100ae57806373fac6f0146100c5578063c19d93fb146100e8578063d696069714610101575b610002565b346100025761011f600154600160a060020a031681565b346100025761013b60015433600160a060020a0390811691161461014f57610002565b346100025761013d60005481565b346100025761011f600254600160a060020a031681565b346100025761013b60025433600160a060020a039081169116146101e457610002565b346100025761013d60025460ff60a060020a9091041681565b61013b60025460009060ff60a060020a90910416156102a457610002565b60408051600160a060020a039092168252519081900360200190f35b005b60408051918252519081900360200190f35b60025460009060a060020a900460ff161561016957610002565b6040517f80b62b7017bb13cf105e22749ee2a06a417ffba8c7f57b665057e0f3c2e925d990600090a16040516002805460a160020a60a060020a60ff0219909116179055600154600160a060020a0390811691309091163180156108fc02916000818181858888f1935050505015156101e157610002565b50565b60025460019060a060020a900460ff1681146101ff57610002565b6040517f64ea507aa320f07ae13c28b5e9bf6b4833ab544315f5f2aa67308e21c252d47d90600090a16040516002805460a060020a60ff02191660a160020a179081905560008054600160a060020a03909216926108fc8315029291818181858888f19350505050158061029a5750600154604051600160a060020a039182169130163180156108fc02916000818181858888f19350505050155b156101e157610002565b6000546002023414806102b657610002565b6040517f764326667cab2f2f13cad5f7b7665c704653bd1acc250dcb7b422bce726896b490600090a150506002805460a060020a73ffffffffffffffffffffffffffffffffffffffff199091166c01000000000000000000000000338102041760a060020a60ff02191617905556";

            var abi =
                "[{'constant':true,'inputs':[],'name':'seller','outputs':[{'name':'','type':'address'}],'payable':false,'type':'function'},{'constant':false,'inputs':[],'name':'abort','outputs':[],'payable':false,'type':'function'},{'constant':true,'inputs':[],'name':'value','outputs':[{'name':'','type':'uint256'}],'payable':false,'type':'function'},{'constant':true,'inputs':[],'name':'buyer','outputs':[{'name':'','type':'address'}],'payable':false,'type':'function'},{'constant':false,'inputs':[],'name':'confirmReceived','outputs':[],'payable':false,'type':'function'},{'constant':true,'inputs':[],'name':'state','outputs':[{'name':'','type':'uint8'}],'payable':false,'type':'function'},{'constant':false,'inputs':[],'name':'confirmPurchase','outputs':[],'payable':true,'type':'function'},{'inputs':[],'type':'constructor'},{'anonymous':false,'inputs':[],'name':'aborted','type':'event'},{'anonymous':false,'inputs':[],'name':'purchaseConfirmed','type':'event'},{'anonymous':false,'inputs':[],'name':'itemReceived','type':'event'}]";

            var web3 = new Web3(ClientFactory.GetClient());

            var gethTester = GethTesterFactory.GetLocal(web3);

            await gethTester.StartMining();
            await gethTester.UnlockAccount();
            
            var transaction =
                await
                    web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode,
                        gethTester.Account, new HexBigInteger(900000), new HexBigInteger(10000));

            var receipt = await gethTester.GetTransactionReceipt(transaction);

            await gethTester.StopMining();

            var contract = web3.Eth.GetContract(abi, receipt.ContractAddress);

            //get the function by name
            var valueFuntion = contract.GetFunction("value");

            //do a function call (not transaction) and get the result
            var callResult = await valueFuntion.CallAsync<int>();
            Assert.Equal(5000, callResult);

            var confirmPurchaseFunction = contract.GetFunction("confirmPurchase");
            var tx = await confirmPurchaseFunction.SendTransactionAsync(gethTester.Account,
                new HexBigInteger(900000), new HexBigInteger(10000));
            await gethTester.StartMining();
            receipt = await gethTester.GetTransactionReceipt(tx);
            await gethTester.StopMining();

            var stateFunction = contract.GetFunction("state");
            callResult = await stateFunction.CallAsync<int>();
            Assert.Equal(1, callResult);

        }
예제 #56
-1
        public async Task<string> Test()
        {

            var web3 = new Web3("http://192.168.2.22:8545");
            var address = "0x63c2ee74201b99de5e76198a7b2e6540bca83347";
            var pass = "******";
            var result = await web3.Personal.UnlockAccount.SendRequestAsync(address, pass, new HexBigInteger(600));
            var newAccount = await web3.Personal.NewAccount.SendRequestAsync("password");
            var accounts = await web3.Personal.ListAccounts.SendRequestAsync();
            return "New account : " + newAccount + " all accounts: " + string.Join(",", accounts);
        }