Пример #1
0
        public async void TestChinese()
        {
            var account         = new Account("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7");
            var web3            = new Web3(account, ClientFactory.GetClient());
            var pollingService  = new TransactionReceiptPollingService(web3.TransactionManager);
            var contractAddress = await pollingService.DeployContractAndGetAddressAsync(() =>
                                                                                        CoinService.DeployContractAsync(web3, account.Address, new HexBigInteger(4000000)));

            var coinService = new CoinService(web3, contractAddress);

            var input = new RaiseEventMetadataInput()
            {
                Creator     = account.Address,
                Id          = 101,
                Description = @"中国,China",
                Metadata    = @"中国,China"
            };

            var txn = await coinService.RaiseEventMetadataAsync(account.Address, input, new HexBigInteger(4000000));

            var receipt = await pollingService.PollForReceiptAsync(txn);

            var metadataEvent = coinService.GetEventMetadataEvent();
            var metadata      = await metadataEvent.GetAllChanges <MetadataEventEventDTO>(metadataEvent.CreateFilterInput());

            var result = metadata[0].Event;

            Assert.Equal(result.Creator.ToLower(), account.Address.ToLower());
            Assert.Equal(result.Id, 101);
            Assert.Equal(result.Metadata, @"中国,China");
            Assert.Equal(result.Description, @"中国,China");
        }
Пример #2
0
        public async void Test()
        {
            var account         = new Account("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7");
            var web3            = new Web3(account, ClientFactory.GetClient());
            var pollingService  = new TransactionReceiptPollingService(web3.TransactionManager);
            var contractAddress = await pollingService.DeployContractAndGetAddressAsync(() =>
                                                                                        CoinService.DeployContractAsync(web3, account.Address, new HexBigInteger(4000000)));

            var coinService = new CoinService(web3, contractAddress);
            var txn         = await coinService.MintAsync(account.Address, account.Address, 100, new HexBigInteger(4000000));

            var receipt = await pollingService.PollForReceiptAsync(txn);

            var eventSent = coinService.GetEventSent();
            var sent      = await eventSent.GetAllChanges <SentEventDTO>(eventSent.CreateFilterInput());

            txn = await coinService.RaiseEventMetadataAsync(account.Address, account.Address, 100, "Description", "The metadata created here blah blah blah", new HexBigInteger(4000000));

            receipt = await pollingService.PollForReceiptAsync(txn);

            var metadataEvent = coinService.GetEventMetadataEvent();
            var metadata      = await metadataEvent.GetAllChanges <MetadataEventEventDTO>(metadataEvent.CreateFilterInput(new BlockParameter(receipt.BlockNumber)));

            var result = metadata[0].Event;

            Assert.Equal(result.Creator.ToLower(), account.Address.ToLower());
            Assert.Equal(result.Id, 100);
            Assert.Equal(result.Metadata, "The metadata created here blah blah blah");
            Assert.Equal(result.Description, "Description");
        }
Пример #3
0
        public async void Test()
        {
            var web3            = _ethereumClientIntegrationFixture.GetWeb3();
            var account         = AccountFactory.GetAccount();
            var pollingService  = new TransactionReceiptPollingService(web3.TransactionManager);
            var contractAddress = await pollingService.DeployContractAndGetAddressAsync(() =>
                                                                                        CoinService.DeployContractAsync(web3, account.Address, new HexBigInteger(4000000)));

            var coinService = new CoinService(web3, contractAddress);
            var txn         = await coinService.MintAsync(account.Address, account.Address, 100, new HexBigInteger(4000000));

            var receipt = await pollingService.PollForReceiptAsync(txn);

            var eventSent = coinService.GetEventSent();
            var sent      = await eventSent.GetAllChanges <SentEventDTO>(eventSent.CreateFilterInput());

            txn = await coinService.RaiseEventMetadataAsync(account.Address, account.Address, 100, "Description",
                                                            "The metadata created here blah blah blah", new HexBigInteger(4000000));

            receipt = await pollingService.PollForReceiptAsync(txn);

            var metadataEvent = coinService.GetEventMetadataEvent();
            var metadata      =
                await metadataEvent.GetAllChanges <MetadataEventEventDTO>(
                    metadataEvent.CreateFilterInput(new BlockParameter(receipt.BlockNumber), null));

            var result = metadata[0].Event;

            Assert.Equal(result.Creator.ToLower(), account.Address.ToLower());
            Assert.Equal(100, result.Id);
            Assert.Equal("The metadata created here blah blah blah", result.Metadata);
            Assert.Equal("Description", result.Description);
        }
Пример #4
0
        public async void TestChinese()
        {
            var web3            = _ethereumClientIntegrationFixture.GetWeb3();
            var accountAddresss = EthereumClientIntegrationFixture.AccountAddress;
            var pollingService  = new TransactionReceiptPollingService(web3.TransactionManager);
            var contractAddress = await pollingService.DeployContractAndGetAddressAsync(() =>
                                                                                        CoinService.DeployContractAsync(web3, accountAddresss, new HexBigInteger(4000000)))
                                  .ConfigureAwait(false);

            var coinService = new CoinService(web3, contractAddress);

            var input = new RaiseEventMetadataInput
            {
                Creator     = accountAddresss,
                Id          = 101,
                Description = @"中国,China",
                Metadata    = @"中国,China"
            };

            var txn = await coinService.RaiseEventMetadataAsync(accountAddresss, input, new HexBigInteger(4000000))
                      .ConfigureAwait(false);

            var receipt = await pollingService.PollForReceiptAsync(txn).ConfigureAwait(false);

            var metadataEvent = coinService.GetEventMetadataEvent();
            var metadata      = await metadataEvent
                                .GetAllChangesAsync <MetadataEventEventDTO>(metadataEvent.CreateFilterInput()).ConfigureAwait(false);

            var result = metadata[0].Event;

            Assert.Equal(result.Creator.ToLower(), accountAddresss.ToLower());
            Assert.Equal(101, result.Id);
            Assert.Equal(@"中国,China", result.Metadata);
            Assert.Equal(@"中国,China", result.Description);
        }
Пример #5
0
        public async Task ShouldBeAbleToDeployAContractUsingPrivateKey()
        {
            var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
            var privateKey    = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
            var abi           = @"[{""constant"":false,""inputs"":[{""name"":""val"",""type"":""int256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""int256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""int256""}],""type"":""constructor""}]";
            var byteCode      =
                "0x60606040526040516020806052833950608060405251600081905550602b8060276000396000f3606060405260e060020a60003504631df4f1448114601a575b005b600054600435026060908152602090f3";

            var multiplier = 7;

            var web3 = new Web3(new Account(privateKey), ClientFactory.GetClient());

            var web3Geth = new Web3Geth(ClientFactory.GetClient());
            await web3Geth.Miner.Start.SendRequestAsync();

            var transactionPolling = new TransactionReceiptPollingService(web3);

            //assumed client is mining already
            var contractAddress = await
                                  transactionPolling.DeployContractAndGetAddressAsync(
                () => web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), multiplier)
                );

            await web3Geth.Miner.Stop.SendRequestAsync();

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

            var multiplyFunction = contract.GetFunction("multiply");

            var result = await multiplyFunction.CallAsync <int>(7);

            Assert.Equal(49, result);
        }
Пример #6
0
        public async Task ShouldBeAbleToDeployAContractUsingPersonalUnlock()
        {
            var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
            var password      = "******";
            var abi           = @"[{""constant"":false,""inputs"":[{""name"":""val"",""type"":""int256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""int256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""int256""}],""type"":""constructor""}]";
            var byteCode      =
                "0x60606040526040516020806052833950608060405251600081905550602b8060276000396000f3606060405260e060020a60003504631df4f1448114601a575b005b600054600435026060908152602090f3";

            var multiplier = 7;

            var web3 = new Web3(new ManagedAccount(senderAddress, password), ClientFactory.GetClient());

            var transactionPolling = new TransactionReceiptPollingService(web3);

            var web3Geth = new Web3Geth(ClientFactory.GetClient());
            await web3Geth.Miner.Start.SendRequestAsync();

            var contractAddress = await
                                  transactionPolling.DeployContractAndGetAddressAsync(
                () => web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000), multiplier)
                );

            await web3Geth.Miner.Stop.SendRequestAsync();

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

            var multiplyFunction = contract.GetFunction("multiply");

            var result = await multiplyFunction.CallAsync <int>(7);

            Assert.Equal(49, result);
        }
Пример #7
0
        public async Task ShouldBeAbleToDeployAContractLoadingEncryptedPrivateKey()
        {
            var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
            var password      = "******";
            //this is your wallet key file which can be found on

            //Linux: ~/.ethereum/keystore
            //Mac: /Library/Ethereum/keystore
            //Windows: %APPDATA%/Ethereum

            var keyStoreEncryptedJson =
                @"{""crypto"":{""cipher"":""aes-128-ctr"",""ciphertext"":""b4f42e48903879b16239cd5508bc5278e5d3e02307deccbec25b3f5638b85f91"",""cipherparams"":{""iv"":""dc3f37d304047997aa4ef85f044feb45""},""kdf"":""scrypt"",""mac"":""ada930e08702b89c852759bac80533bd71fc4c1ef502291e802232b74bd0081a"",""kdfparams"":{""n"":65536,""r"":1,""p"":8,""dklen"":32,""salt"":""2c39648840b3a59903352b20386f8c41d5146ab88627eaed7c0f2cc8d5d95bd4""}},""id"":""19883438-6d67-4ab8-84b9-76a846ce544b"",""address"":""12890d2cce102216644c59dae5baed380d84830c"",""version"":3}";

            var abi =
                @"[{""constant"":false,""inputs"":[{""name"":""val"",""type"":""int256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""int256""}],""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""int256""}],""type"":""constructor""}]";
            var byteCode =
                "0x60606040526040516020806052833950608060405251600081905550602b8060276000396000f3606060405260e060020a60003504631df4f1448114601a575b005b600054600435026060908152602090f3";

            var multiplier = 7;

            //if not using portable or netstandard (^net45) you can use LoadFromKeyStoreFile to load the file from the file system.

            var keyStoreService = new KeyStore.KeyStoreService();
            var key             = keyStoreService.DecryptKeyStoreFromJson(password, keyStoreEncryptedJson);


            var web3 = new Web3.Web3(new Account(key));

            var transactionPolling = new TransactionReceiptPollingService(web3);

            //assumed client is mining already
            var contractAddress = await
                                  transactionPolling.DeployContractAndGetAddressAsync(
                () =>
                web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000),
                                                         multiplier)
                );

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

            var multiplyFunction = contract.GetFunction("multiply");

            var result = await multiplyFunction.CallAsync <int>(7);

            Assert.Equal(49, result);
        }
        public async Task ShouldSendSignTransaction()
        {
            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 Web3Geth(new Account(privateKey));
            await web3.Miner.Start.SendRequestAsync(4);

            var transactionReceiptService = new TransactionReceiptPollingService(web3);
            var contractAddress           = await transactionReceiptService.DeployContractAndGetAddressAsync(() =>
                                                                                                             web3.Eth.DeployContract.SendRequestAsync(abi, contractByteCode, senderAddress,
                                                                                                                                                      new HexBigInteger(900000), 7));

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

            var transactions = new Func <Task <string> >[] {
                () => multiplyFunction.SendTransactionAsync(senderAddress, new HexBigInteger(900000), new HexBigInteger(0), 69),
                () => multiplyFunction.SendTransactionAsync(senderAddress, new HexBigInteger(900000), new HexBigInteger(0), 7),
                () => multiplyFunction.SendTransactionAsync(senderAddress, new HexBigInteger(900000), new HexBigInteger(0), 8),
                () => multiplyFunction.SendTransactionAsync(senderAddress, new HexBigInteger(900000), new HexBigInteger(0), 8)
            };

            var transactionsReceipts = await transactionReceiptService.SendRequestAsync(transactions);

            await web3.Miner.Stop.SendRequestAsync();

            Assert.Equal(4, transactionsReceipts.Count);
        }
Пример #9
0
        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);
        }