Esempio n. 1
0
 public void Initialize()
 {
     Web3                  = new Web3($"http://localhost:7545");
     EnsUtil               = new EnsUtil();
     ENSRegistryService    = new ENSRegistryService(Web3, ENSRegistryAddress);
     FIFSRegistrarService  = new FIFSRegistrarService(Web3, FIFSRegistrarAddress);
     PublicResolverService = new PublicResolverService(Web3, PublicResolverAddress);
 }
Esempio n. 2
0
        public async void ShouldCreateEnsRegistarResolverAndRegiterandResolveANewAddress()
        {
            //Ignoring parity due to https://github.com/paritytech/parity-ethereum/issues/8675
            if (_ethereumClientIntegrationFixture.Geth)
            {
                //The address we want to resolve when using "test.eth"
                var addressToResolve = "0x12890D2cce102216644c59daE5baed380d84830c";


                var addressFrom = "0x12890D2cce102216644c59daE5baed380d84830c";

                var web3 = _ethereumClientIntegrationFixture.GetWeb3();


                //deploy ENS contract
                var ensDeploymentReceipt =
                    await ENSRegistryService.DeployContractAndWaitForReceiptAsync(web3, new ENSRegistryDeployment());

                var ensUtil = new EnsUtil();
                var ethNode = ensUtil.GetNameHash("eth");

                //create a new First in First service registrar for "eth"
                var fifsDeploymentReceipt = await FIFSRegistrarService.DeployContractAndWaitForReceiptAsync(web3,
                                                                                                            new FIFSRegistrarDeployment()
                {
                    EnsAddr = ensDeploymentReceipt.ContractAddress,
                    Node    = ethNode.HexToByteArray()
                });


                var publicResolverDeploymentReceipt = await PublicResolverService.DeployContractAndWaitForReceiptAsync(
                    web3,
                    new PublicResolverDeployment()
                {
                    Ens = ensDeploymentReceipt.ContractAddress
                }
                    );


                var ensRegistryService = new ENSRegistryService(web3, ensDeploymentReceipt.ContractAddress);

                //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.GetLabelHash("eth");

                var receipt = await ensRegistryService.SetSubnodeOwnerRequestAndWaitForReceiptAsync(
                    ensUtil.GetNameHash("").HexToByteArray(),
                    ethLabel.HexToByteArray(),
                    fifsDeploymentReceipt.ContractAddress
                    );


                //Now the owner of Eth is the FIFS
                var ownerOfEth =
                    await ensRegistryService.OwnerQueryAsync(ethNode.HexToByteArray());

                Assert.Equal(fifsDeploymentReceipt.ContractAddress.ToLower(), ownerOfEth.ToLower());
                /**** setup done **/

                //registration of "myname"

                //create a service for the registrar
                var fifsService = new FIFSRegistrarService(web3, fifsDeploymentReceipt.ContractAddress);

                //create a label
                var testLabel = ensUtil.GetLabelHash("myname");
                //submit the registration using the label bytes, and set ourselves as the owner
                await fifsService.RegisterRequestAndWaitForReceiptAsync(new RegisterFunction()
                {
                    Owner   = addressFrom,
                    Subnode = testLabel.HexToByteArray()
                });



                //now using the the full name
                var fullNameNode = ensUtil.GetNameHash("myname.eth");

                var ownerOfMyName =
                    await ensRegistryService.OwnerQueryAsync(fullNameNode.HexToByteArray());

                //set the resolver (the public one)
                await ensRegistryService.SetResolverRequestAndWaitForReceiptAsync(
                    new SetResolverFunction()
                {
                    Resolver = publicResolverDeploymentReceipt.ContractAddress,
                    Node     = fullNameNode.HexToByteArray()
                });


                var publicResolverService =
                    new PublicResolverService(web3, publicResolverDeploymentReceipt.ContractAddress);
                // set the address in the resolver which we want to resolve, ownership is validated using ENS in the background

                //Fails here
                await publicResolverService.SetAddrRequestAndWaitForReceiptAsync(fullNameNode.HexToByteArray(),
                                                                                 addressToResolve
                                                                                 );


                //Now as "end user" we can start resolving...

                //get the resolver address from ENS
                var resolverAddress = await ensRegistryService.ResolverQueryAsync(
                    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.AddrQueryAsync(fullNameNode.HexToByteArray());

                Assert.Equal(addressToResolve.ToLower(), theAddress.ToLower());
            }
        }
Esempio n. 3
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);
        }