public async Task <int> ShouldBeAbleToConnectTo7NodesPrivate() { var ipAddress = DefaultSettings.QuorumIPAddress; var node1Port = "8545"; var urlNode1 = ipAddress + ":" + node1Port; var address = "0x274ab43196161928d04143cb6ee56429bbc38da1"; var abi = "[{'constant':true,'inputs':[],'name':'totalSupply','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'','type':'address'}],'name':'issuers','outputs':[{'name':'','type':'bool'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'','type':'address'}],'name':'accounts','outputs':[{'name':'bankAccount','type':'bytes12'},{'name':'id','type':'address'},{'name':'bankId','type':'address'},{'name':'balance','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'','type':'address'}],'name':'banks','outputs':[{'name':'id','type':'address'},{'name':'name','type':'bytes32'},{'name':'balance','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'inputs':[],'payable':false,'stateMutability':'nonpayable','type':'constructor'},{'anonymous':false,'inputs':[{'indexed':true,'name':'_issuer','type':'address'},{'indexed':true,'name':'_bank','type':'address'},{'indexed':false,'name':'_amount','type':'uint256'},{'indexed':false,'name':'_totalSupply','type':'uint256'}],'name':'Issued','type':'event'},{'anonymous':false,'inputs':[{'indexed':true,'name':'_id','type':'address'},{'indexed':false,'name':'_name','type':'string'}],'name':'BankCreated','type':'event'},{'anonymous':false,'inputs':[{'indexed':false,'name':'_bankAddress','type':'address'},{'indexed':false,'name':'_accountAddress','type':'address'}],'name':'AccountCreated','type':'event'},{'anonymous':false,'inputs':[{'indexed':true,'name':'_bankAddress','type':'address'},{'indexed':true,'name':'_accountAddress','type':'address'},{'indexed':false,'name':'_amount','type':'uint256'}],'name':'CashedIn','type':'event'},{'anonymous':false,'inputs':[{'indexed':true,'name':'_accountAddress','type':'address'},{'indexed':true,'name':'_bankAddress','type':'address'},{'indexed':false,'name':'_amount','type':'uint256'}],'name':'CashedOut','type':'event'},{'anonymous':false,'inputs':[{'indexed':true,'name':'_from','type':'address'},{'indexed':true,'name':'_to','type':'address'},{'indexed':false,'name':'_amount','type':'uint256'}],'name':'Transfered','type':'event'},{'constant':true,'inputs':[{'name':'_id','type':'address'}],'name':'isIssuer','outputs':[{'name':'','type':'bool'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_amount','type':'uint256'},{'name':'_bank_address','type':'address'}],'name':'issue','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_bankAddress','type':'address'},{'name':'_bankName','type':'string'}],'name':'createBank','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'_id','type':'address'}],'name':'getBank','outputs':[{'name':'','type':'address'},{'name':'','type':'string'},{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'_bank_address','type':'address'}],'name':'getBankBalance','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_accountAddress','type':'address'},{'name':'_bankAccount','type':'string'}],'name':'createAccount','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'_id','type':'address'}],'name':'getAccount','outputs':[{'name':'','type':'address'},{'name':'','type':'uint256'},{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'_bankAccount','type':'string'}],'name':'getAddressOfBankAccount','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'_accountAddress','type':'address'}],'name':'getAccountBalance','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_accountAddress','type':'address'},{'name':'_amount','type':'uint256'}],'name':'cashIn','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_amount','type':'uint256'}],'name':'cashOut','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_to','type':'string'},{'name':'_amount','type':'uint256'}],'name':'transfer','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'}]"; var web3Node1 = new ConexionBC(urlNode1); var transactionService = new TransactionReceiptPollingService(web3Node1.TransactionManager); var account = await web3Node1.Eth.CoinBase.SendRequestAsync(); var contract = web3Node1.Eth.GetContract(abi, address); var functionSet = contract.GetFunction("accounts"); //set the private for var privateFor = new List <string>(new[] { "0x88f4549c58d5dc8a8374272a999222a639daa149" }); web3Node1.SetPrivateRequestParameters(privateFor); //send transaction var txnHash = await transactionService.SendRequestAndWaitForReceiptAsync(() => functionSet.SendTransactionAsync(account, 0)); var node1Value = await GetValue(abi, address, urlNode1); txnHash = await transactionService.SendRequestAndWaitForReceiptAsync(() => functionSet.SendTransactionAsync(account, 42)); //node1 return(node1Value = await GetValue(abi, address, urlNode1)); //private.set(4,{from:eth.coinbase,privateFor:["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]}); }
public async void ShouldBeAbleToConnectTo7NodesPrivate() { var ipAddress = DefaultSettings.QuorumIPAddress; var node1Port = "22000"; var node2Port = "22001"; var node7Port = "22006"; var urlNode1 = ipAddress + ":" + node1Port; var urlNode2 = ipAddress + ":" + node2Port; var urlNode7 = ipAddress + ":" + node7Port; var address = "0x1932c48b2bf8102ba33b4a6b545c32236e342f34"; var abi = "[{ 'constant':true,'inputs':[],'name':'storedData','outputs':[{'name':'','type':'uint256'}],'payable':false,'type':'function'},{'constant':false,'inputs':[{'name':'x','type':'uint256'}],'name':'set','outputs':[],'payable':false,'type':'function'},{'constant':true,'inputs':[],'name':'get','outputs':[{'name':'retVal','type':'uint256'}],'payable':false,'type':'function'},{'inputs':[{'name':'initVal','type':'uint256'}],'type':'constructor'}]"; var web3Node1 = new Web3Quorum(urlNode1); var transactionService = new TransactionReceiptPollingService(web3Node1.TransactionManager); var account = await web3Node1.Eth.CoinBase.SendRequestAsync(); var contract = web3Node1.Eth.GetContract(abi, address); var functionSet = contract.GetFunction("set"); //set the private for var privateFor = new List <string>(new[] { "ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc=" }); web3Node1.SetPrivateRequestParameters(privateFor); //send transaction var txnHash = await transactionService.SendRequestAndWaitForReceiptAsync(() => functionSet.SendTransactionAsync(account, 4)); var node1Value = await GetValue(abi, address, urlNode1); Assert.Equal(4, node1Value); var node2Value = await GetValue(abi, address, urlNode2); Assert.Equal(0, node2Value); var node7Value = await GetValue(abi, address, urlNode7); Assert.Equal(4, node7Value); txnHash = await transactionService.SendRequestAndWaitForReceiptAsync(() => functionSet.SendTransactionAsync(account, 42)); //node1 node1Value = await GetValue(abi, address, urlNode1); Assert.Equal(42, node1Value); node2Value = await GetValue(abi, address, urlNode2); Assert.Equal(0, node2Value); node7Value = await GetValue(abi, address, urlNode7); Assert.Equal(42, node7Value); //private.set(4,{from:eth.coinbase,privateFor:["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]}); }
// [HttpPost] public async Task <TransactionReceipt> TransferETH(string senderAddr, string senderPassword, string receiverAddr, decimal amount) { var web3 = new Nethereum.Web3.Web3(ClientURL); var unlockResult = await web3.Personal.UnlockAccount.SendRequestAsync(senderAddr, senderPassword, UnLockAccountDurationInSeconds); unlockResult = true; if (unlockResult != true) { throw new Exception("Account not unlocked"); } amount = 1; var amountInWei = Web3.Convert.ToWei(amount); var pollingService = new TransactionReceiptPollingService(web3.TransactionManager); var receipt = await pollingService.SendRequestAndWaitForReceiptAsync(new TransactionInput { From = senderAddr, To = receiverAddr, Value = new HexBigInteger(amountInWei) }); return(receipt); }
public async void ShouldCreateEnsRegistarResolverAndRegiterandResolveANewAddress() { //The address we want to resolve when using "test.eth" var addressToResolve = "0x12890d2cce102216644c59dae5baed380d84830c"; var defaultGas = new HexBigInteger(900000); var addressFrom = "0x12890d2cce102216644c59dae5baed380d84830c"; var pass = "******"; var web3 = _ethereumClientIntegrationFixture.GetWeb3(); var txService = new TransactionReceiptPollingService(web3.TransactionManager); // var addressFrom = (await web3.Eth.Accounts.SendRequestAsync()).First(); //uncomment to use geth instead of test-rpc //deploy ENS contract var ensAddress = await txService.DeployContractAndGetAddressAsync(() => EnsService.DeployContractAsync(web3, addressFrom, defaultGas)); var ensUtil = new EnsUtil(); var ethNode = ensUtil.GetEnsNameHash("eth"); //create a new First in First service registrar for "eth" var fifsAddress = await txService.DeployContractAndGetAddressAsync(() => FIFSRegistrarService.DeployContractAsync(web3, addressFrom, ensAddress, ethNode.HexToByteArray(), defaultGas)); //create a public registry, which will allow us to find the registered address var publicResolverAddress = await txService.DeployContractAndGetAddressAsync( () => PublicResolverService.DeployContractAsync(web3, addressFrom, ensAddress, defaultGas)); var ensService = new EnsService(web3, ensAddress); //set ownership of "eth" to the fifs service //we are owners of "", so a subnode label "eth" will now be owned by the FIFS registar, which will allow to also to set ownership in Ens of further subnodes of Eth. var ethLabel = ensUtil.GetEnsLabelHash("eth"); await txService.SendRequestAndWaitForReceiptAsync(() => ensService.SetSubnodeOwnerAsync(addressFrom, ensUtil.GetEnsNameHash("").HexToByteArray(), ethLabel.HexToByteArray(), fifsAddress, defaultGas)); //Now the owner of Eth is the FIFS var ownerOfEth = await ensService.OwnerAsyncCall(ethNode.HexToByteArray()); Assert.Equal(fifsAddress, ownerOfEth); /**** setup done **/ //registration of "myname" //create a service for the registrar var fifsService = new FIFSRegistrarService(web3, fifsAddress); //create a label var testLabel = ensUtil.GetEnsLabelHash("myname"); //submit the registration using the label bytes, and set ourselves as the owner await txService.SendRequestAndWaitForReceiptAsync(() => fifsService.RegisterAsync(addressFrom, testLabel.HexToByteArray(), addressFrom, defaultGas)); //now using the the full name var fullNameNode = ensUtil.GetEnsNameHash("myname.eth"); //set the resolver (the public one) await txService.SendRequestAndWaitForReceiptAsync(() => ensService.SetResolverAsync(addressFrom, fullNameNode.HexToByteArray(), publicResolverAddress, defaultGas)); var publicResolverService = new PublicResolverService(web3, publicResolverAddress); // set the address in the resolver which we want to resolve, ownership is validated using ENS in the background await txService.SendRequestAndWaitForReceiptAsync(() => publicResolverService.SetAddrAsync(addressFrom, fullNameNode.HexToByteArray(), addressToResolve, defaultGas)); //Now as "end user" we can start resolving... //get the resolver address from ENS var resolverAddress = await ensService.ResolverAsyncCall(fullNameNode.HexToByteArray()); //using the resolver address we can create our service (should be an abstract / interface based on abi as we can have many) var resolverService = new PublicResolverService(web3, resolverAddress); //and get the address from the resolver var theAddress = await resolverService.AddrAsyncCall(fullNameNode.HexToByteArray()); Assert.Equal(addressToResolve, theAddress); }