Example #1
0
 protected async Task HandleValidSubmit()
 {
     _output = null;
     await _network.ExecuteAsync(_input.Gateway, _input.Payer, async client =>
     {
         var hasRenewalAccount = _input.RenewAccount != null && _input.RenewAccount != Address.None;
         var createParams      = new CreateTokenParams
         {
             Name                  = _input.Name,
             Symbol                = _input.Symbol,
             Circulation           = (ulong)_input.Circulation.GetValueOrDefault(),
             Decimals              = (uint)_input.Decimals.GetValueOrDefault(),
             Treasury              = _input.Treasury,
             Administrator         = _input.Administrator != Endorsement.None ? _input.Administrator : null,
             GrantKycEndorsement   = _input.GrantKycEndorsement != Endorsement.None ? _input.GrantKycEndorsement : null,
             SuspendEndorsement    = _input.SuspendEndorsement != Endorsement.None ? _input.SuspendEndorsement : null,
             ConfiscateEndorsement = _input.ConfiscateEndorsement != Endorsement.None ? _input.ConfiscateEndorsement : null,
             SupplyEndorsement     = _input.SupplyEndorsement != Endorsement.None ? _input.SupplyEndorsement : null,
             InitializeSuspended   = _input.InitializeSuspended,
             Expiration            = DateTime.UtcNow.AddDays(90),
             RenewPeriod           = hasRenewalAccount ? TimeSpan.FromDays(90) : null,
             RenewAccount          = hasRenewalAccount ? _input.RenewAccount : null
         };
         _output = await client.CreateTokenAsync(createParams, ctx => ctx.Memo = _input.Memo?.Trim());
     });
 }
 internal static CreateTokenParams CreateParameters(CreateTokenParams createParameters)
 {
     if (createParameters is null)
     {
         throw new ArgumentNullException(nameof(createParameters), "The create parameters are missing. Please check that the argument is not null.");
     }
     if (string.IsNullOrWhiteSpace(createParameters.Name))
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Name), "The name cannot be null or empty.");
     }
     if (string.IsNullOrWhiteSpace(createParameters.Symbol))
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Symbol), "The token symbol must be specified.");
     }
     if (createParameters.Symbol.Trim().Length != createParameters.Symbol.Length)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Symbol), "The token symbol cannot contain leading or trailing white space.");
     }
     if (createParameters.Symbol.Length > 32)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Symbol), "The token symbol cannot exceed 32 characters in length.");
     }
     if (!createParameters.Symbol.Equals(createParameters.Symbol.ToUpperInvariant()))
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Symbol), "The token symbol must contain upper case characters.");
     }
     if (createParameters.Circulation < 1)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Circulation), "The initial circulation of tokens must be greater than zero.");
     }
     if (createParameters.Decimals < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Decimals), "The divisibility of tokens cannot be negative.");
     }
     if (createParameters.Treasury is null || createParameters.Treasury == Hashgraph.Address.None)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Treasury), "The treasury must be specified.");
     }
     if (createParameters.Expiration < DateTime.UtcNow)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Expiration), "The expiration time must be in the future.");
     }
     if (createParameters.RenewAccount.IsNullOrNone() == createParameters.RenewPeriod.HasValue)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.RenewPeriod), "Both the renew account and period must be specified, or not at all.");
     }
     return(createParameters);
 }
Example #3
0
        public async Task CanCreateATokenWithReceipt()
        {
            await using var fxTreasury = await TestAccount.CreateAsync(_network);

            await using var fxRenew = await TestAccount.CreateAsync(_network);

            await using var client = _network.NewClient();
            var createParams = new CreateTokenParams
            {
                Name                  = Generator.Code(50),
                Symbol                = Generator.UppercaseAlphaCode(20),
                Circulation           = (ulong)(Generator.Integer(10, 20) * 100000),
                Decimals              = (uint)Generator.Integer(2, 5),
                Treasury              = fxTreasury.Record.Address,
                Administrator         = fxTreasury.PublicKey,
                GrantKycEndorsement   = fxTreasury.PublicKey,
                SuspendEndorsement    = fxTreasury.PublicKey,
                ConfiscateEndorsement = fxTreasury.PublicKey,
                SupplyEndorsement     = fxTreasury.PublicKey,
                InitializeSuspended   = false,
                Expiration            = Generator.TruncatedFutureDate(2000, 3000),
                RenewAccount          = fxRenew.Record.Address,
                RenewPeriod           = TimeSpan.FromDays(90),
                Signatory             = new Signatory(fxTreasury.PrivateKey, fxRenew.PrivateKey),
                Memo                  = Generator.Code(20)
            };
            var receipt = await client.CreateTokenAsync(createParams);

            Assert.Equal(ResponseCode.Success, receipt.Status);

            var info = await client.GetTokenInfoAsync(receipt.Token);

            Assert.Equal(receipt.Token, info.Token);
            Assert.Equal(createParams.Symbol, info.Symbol);
            Assert.Equal(createParams.Name, info.Name);
            Assert.Equal(fxTreasury.Record.Address, info.Treasury);
            Assert.Equal(createParams.Circulation, info.Circulation);
            Assert.Equal(createParams.Decimals, info.Decimals);
            Assert.Equal(createParams.Administrator, info.Administrator);
            Assert.Equal(createParams.GrantKycEndorsement, info.GrantKycEndorsement);
            Assert.Equal(createParams.SuspendEndorsement, info.SuspendEndorsement);
            Assert.Equal(createParams.ConfiscateEndorsement, info.ConfiscateEndorsement);
            Assert.Equal(createParams.SupplyEndorsement, info.SupplyEndorsement);
            Assert.Equal(TokenTradableStatus.Tradable, info.TradableStatus);
            Assert.Equal(TokenKycStatus.Revoked, info.KycStatus);
            Assert.False(info.Deleted);
            Assert.Equal(createParams.Memo, info.Memo);
        }
 public TokenCreateTransactionBody(CreateTokenParams createParameters) : this()
 {
     if (createParameters is null)
     {
         throw new ArgumentNullException(nameof(createParameters), "The create parameters are missing. Please check that the argument is not null.");
     }
     if (string.IsNullOrWhiteSpace(createParameters.Name))
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Name), "The name cannot be null or empty.");
     }
     if (string.IsNullOrWhiteSpace(createParameters.Symbol))
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Symbol), "The token symbol must be specified.");
     }
     if (createParameters.Symbol.Trim().Length != createParameters.Symbol.Length)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Symbol), "The token symbol cannot contain leading or trailing white space.");
     }
     if (createParameters.Symbol.Length > 32)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Symbol), "The token symbol cannot exceed 32 characters in length.");
     }
     if (!createParameters.Symbol.Equals(createParameters.Symbol.ToUpperInvariant()))
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Symbol), "The token symbol must contain upper case characters.");
     }
     if (createParameters.Circulation < 1)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Circulation), "The initial circulation of tokens must be greater than zero.");
     }
     if (createParameters.Decimals < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Decimals), "The divisibility of tokens cannot be negative.");
     }
     if (createParameters.Treasury is null || createParameters.Treasury == Hashgraph.Address.None)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Treasury), "The treasury must be specified.");
     }
     if (createParameters.Expiration < DateTime.UtcNow)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Expiration), "The expiration time must be in the future.");
     }
     if (createParameters.RenewAccount.IsNullOrNone() == createParameters.RenewPeriod.HasValue)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.RenewPeriod), "Both the renew account and period must be specified, or not at all.");
     }
     if (!string.IsNullOrEmpty(createParameters.Memo))
     {
         if (createParameters.Memo.Trim().Length != createParameters.Memo.Length)
         {
             throw new ArgumentOutOfRangeException(nameof(createParameters.Memo), "The token memo cannot contain leading or trailing white space.");
         }
     }
     Name          = createParameters.Name;
     Symbol        = createParameters.Symbol;
     InitialSupply = createParameters.Circulation;
     Decimals      = createParameters.Decimals;
     Treasury      = new AccountID(createParameters.Treasury);
     if (!createParameters.Administrator.IsNullOrNone())
     {
         AdminKey = new Key(createParameters.Administrator);
     }
     if (!createParameters.GrantKycEndorsement.IsNullOrNone())
     {
         KycKey = new Key(createParameters.GrantKycEndorsement);
     }
     if (!createParameters.SuspendEndorsement.IsNullOrNone())
     {
         FreezeKey = new Key(createParameters.SuspendEndorsement);
     }
     if (!createParameters.ConfiscateEndorsement.IsNullOrNone())
     {
         WipeKey = new Key(createParameters.ConfiscateEndorsement);
     }
     if (!createParameters.SupplyEndorsement.IsNullOrNone())
     {
         SupplyKey = new Key(createParameters.SupplyEndorsement);
     }
     FreezeDefault = createParameters.InitializeSuspended;
     Expiry        = new Timestamp(createParameters.Expiration);
     if (!createParameters.RenewAccount.IsNullOrNone())
     {
         AutoRenewAccount = new AccountID(createParameters.RenewAccount);
     }
     if (createParameters.RenewPeriod.HasValue)
     {
         AutoRenewPeriod = new Duration(createParameters.RenewPeriod.Value);
     }
     Memo = createParameters.Memo;
 }
Example #5
0
 /// <summary>
 /// Creates a new token instance with the given create parameters.
 /// </summary>
 /// <param name="createParameters">
 /// Details regarding the token to instantiate.
 /// </param>
 /// <param name="configure">
 /// Optional callback method providing an opportunity to modify
 /// the execution configuration for just this method call.
 /// It is executed prior to submitting the request to the network.
 /// </param>
 /// <returns>
 /// A transaction record with a description of the newly created token.
 /// </returns>
 /// <exception cref="ArgumentOutOfRangeException">If required arguments are missing.</exception>
 /// <exception cref="InvalidOperationException">If required context configuration is missing.</exception>
 /// <exception cref="PrecheckException">If the gateway node create rejected the request upon submission.</exception>
 /// <exception cref="ConsensusException">If the network was unable to come to consensus before the duration of the transaction expired.</exception>
 /// <exception cref="TransactionException">If the network rejected the create request as invalid or had missing data.</exception>
 public async Task <CreateTokenRecord> CreateTokenWithRecordAsync(CreateTokenParams createParameters, Action <IContext>?configure = null)
 {
     return(new CreateTokenRecord(await ExecuteTransactionAsync(new TokenCreateTransactionBody(createParameters), configure, true, createParameters.Signatory).ConfigureAwait(false)));
 }