public void PostUpdateTx()
        {
            BaseKeyPair keyPair = new BaseKeyPair(TestConstants.BENEFICIARY_PRIVATE_KEY);
            Account     account = nativeClient.GetAccount(keyPair.PublicKey);
            ulong       nonce   = account.Nonce + 1;
            BigInteger  salt    = Crypto.GenerateNamespaceSalt();
            ulong       ttl     = 0;
            string      domain  = TestConstants.DOMAIN + random.Next() + TestConstants.NAMESPACE;

            /** create a new namespace to update later */
            NamePreclaimTransaction namePreclaimTx = nativeClient.CreateNamePreClaimTransaction(keyPair.PublicKey, domain, salt, nonce, ttl);
            UnsignedTx     unsignedTx     = namePreclaimTx.CreateUnsignedTransaction();
            Tx             signedTx       = nativeClient.SignTransaction(unsignedTx, keyPair.PrivateKey);
            PostTxResponse postTxResponse = nativeClient.PostTx(logger, signedTx);

            Assert.AreEqual(postTxResponse.TXHash, Encoding.ComputeTxHash(signedTx.TX));
            BigInteger           fee             = NameServiceBiding.GetDefaultBidFee(domain);
            NameClaimTransaction nameClaimTx     = nativeClient.CreateNameClaimTransaction(keyPair.PublicKey, domain, salt, fee, Constants.BaseConstants.NAME_FEE, nonce + 1, ttl);
            UnsignedTx           unsignedClaimTx = nameClaimTx.CreateUnsignedTransaction();
            Tx             signedClaimTx         = nativeClient.SignTransaction(unsignedClaimTx, keyPair.PrivateKey);
            PostTxResponse postClaimTxResponse   = nativeClient.PostTx(logger, signedClaimTx);
            NameEntry      nameEntry             = nativeClient.GetNameId(domain);
            ulong          initialTTL            = nameEntry.Ttl;

            logger.LogInformation($"Created namespace {domain} with salt {salt} and nameEntry {nameEntry} in tx {postClaimTxResponse.TXHash} for update test");
            /** finished creating namespace */
            ulong nameTtl   = 10000;
            ulong clientTtl = 50;

            account = nativeClient.GetAccount(keyPair.PublicKey);
            nonce   = account.Nonce + 1;
            NameUpdateTransaction nameUpdateTx     = nativeClient.CreateNameUpdateTransaction(keyPair.PublicKey, nameEntry.Id, nonce, ttl, clientTtl, nameTtl, new List <NamePointer>());
            UnsignedTx            unsignedUpdateTx = nameUpdateTx.CreateUnsignedTransaction();
            Tx             signedUpdateTx          = nativeClient.SignTransaction(unsignedUpdateTx, keyPair.PrivateKey);
            PostTxResponse postUpdateTxResponse    = nativeClient.PostTx(logger, signedUpdateTx);

            Assert.AreEqual(postUpdateTxResponse.TXHash, Encoding.ComputeTxHash(signedUpdateTx.TX));
            nameEntry = nativeClient.GetNameId(domain);
            logger.LogInformation($"Updated namespace {domain} with salt {salt} and nameEntry {nameEntry} in tx {postClaimTxResponse.TXHash} for update test");

            ulong updatedTTL = nameEntry.Ttl;
            // subtract 40000 because initial default ttl is 50000 and updated ttl was 10000
            ulong diffTtl = initialTTL - updatedTTL;

            Assert.IsTrue(diffTtl <= 40000);
            if (diffTtl < 40000)
            {
                logger.LogInformation($"Diff of Ttl is {diffTtl}, this happens when meanwhile new blocks are mined");
            }
        }
        public void PostNameClaimTx()
        {
            BaseKeyPair             keyPair        = new BaseKeyPair(TestConstants.BENEFICIARY_PRIVATE_KEY);
            Account                 account        = nativeClient.GetAccount(keyPair.PublicKey);
            BigInteger              salt           = Crypto.GenerateNamespaceSalt();
            ulong                   nonce          = account.Nonce + 1;
            ulong                   ttl            = 0;
            NamePreclaimTransaction namePreclaimTx = nativeClient.CreateNamePreClaimTransaction(keyPair.PublicKey, validDomain, salt, nonce, ttl);
            UnsignedTx              unsignedTx     = namePreclaimTx.CreateUnsignedTransaction();


            NamePreclaimTransaction namePreclaimTxDebug = debugClient.CreateNamePreClaimTransaction(keyPair.PublicKey, validDomain, salt, nonce, ttl);
            UnsignedTx unsignedTxDebug = namePreclaimTxDebug.CreateUnsignedTransaction();

            Assert.AreEqual(unsignedTxDebug.TX, unsignedTx.TX);


            Tx signedTx = nativeClient.SignTransaction(unsignedTx, keyPair.PrivateKey);


            logger.LogInformation("Signed NamePreclaimTx: " + signedTx.TX);
            PostTxResponse postTxResponse = nativeClient.PostTx(logger, signedTx);

            logger.LogInformation("NamePreclaimTx hash: " + postTxResponse.TXHash);
            Assert.AreEqual(postTxResponse.TXHash, Encoding.ComputeTxHash(signedTx.TX));

            BigInteger           fee             = NameServiceBiding.GetDefaultBidFee(validDomain);
            NameClaimTransaction nameClaimTx     = nativeClient.CreateNameClaimTransaction(keyPair.PublicKey, validDomain, salt, fee, Constants.BaseConstants.NAME_FEE, nonce + 1, ttl);
            UnsignedTx           unsignedClaimTx = nameClaimTx.CreateUnsignedTransaction();

            NameClaimTransaction nameClaimTxDebug     = debugClient.CreateNameClaimTransaction(keyPair.PublicKey, validDomain, salt, fee, Constants.BaseConstants.NAME_FEE, nonce + 1, ttl);
            UnsignedTx           unsignedClaimTxDebug = nameClaimTxDebug.CreateUnsignedTransaction();


            Assert.AreEqual(unsignedClaimTxDebug.TX, unsignedClaimTx.TX);


            Tx signedClaimTx = nativeClient.SignTransaction(unsignedClaimTx, keyPair.PrivateKey);

            logger.LogInformation("Signed NameClaimTx: " + signedClaimTx.TX);
            postTxResponse = nativeClient.PostTx(logger, signedClaimTx);
            logger.LogInformation($"Using namespace {validDomain} and salt {salt} for committmentId {Encoding.GenerateCommitmentHash(validDomain, salt)}");
            logger.LogInformation("NameClaimTx hash: " + postTxResponse.TXHash);
        }
Exemplo n.º 3
0
        public async Task <InProgress <Claim> > ClaimDomainAsync(ulong bid_fee = Constants.BaseConstants.NAME_FEE, ulong fee = Constants.BaseConstants.FEE, ulong name_ttl = 0, CancellationToken token = default(CancellationToken))
        {
            Account.ValidatePrivateKey();
            Account.Nonce++;
            Claim cl = new Claim(Domain, Account);

            if (bid_fee == Constants.BaseConstants.NAME_FEE)
            {
                bid_fee = (ulong)NameServiceBiding.GetDefaultBidFee(Domain);
            }


            //NameClaimTransaction t = Account.Client.CreateNameClaimTransaction(Account.KeyPair.PublicKey, Domain, Salt, bid_fee, fee, name_ttl);

            //UnsignedTx tx=t.CreateUnsignedTransaction(false,Account.Client.Configuration.MinimalGasPrice);
            //UnsignedTx tr2 = t.CreateUnsignedTransaction(true, Account.Client.Configuration.MinimalGasPrice);



            await cl.SignAndSendAsync(Account.Client.CreateNameClaimTransaction(Account.KeyPair.PublicKey, Domain, Salt, bid_fee, fee, Account.Nonce, name_ttl), token).ConfigureAwait(false);

            return(new InProgress <Claim>(new WaitForHash(cl)));
        }