예제 #1
0
        /// <summary>
        /// Internal implementation of the update Token functionality.
        /// </summary>
        private async Task <TResult> UpdateTokenImplementationAsync <TResult>(UpdateTokenParams updateParameters, Action <IContext>?configure) where TResult : new()
        {
            updateParameters        = RequireInputParameter.UpdateParameters(updateParameters);
            await using var context = CreateChildContext(configure);
            RequireInContext.Gateway(context);
            var payer           = RequireInContext.Payer(context);
            var signatory       = Transactions.GatherSignatories(context, updateParameters.Signatory);
            var updateTokenBody = new TokenUpdateTransactionBody
            {
                Token = new TokenID(updateParameters.Token)
            };

            if (!(updateParameters.Treasury is null))
            {
                updateTokenBody.Treasury = new AccountID(updateParameters.Treasury);
            }
            if (!(updateParameters.Administrator is null))
            {
                updateTokenBody.AdminKey = new Key(updateParameters.Administrator);
            }
            if (!(updateParameters.GrantKycEndorsement is null))
            {
                updateTokenBody.KycKey = new Key(updateParameters.GrantKycEndorsement);
            }
            if (!(updateParameters.SuspendEndorsement is null))
            {
                updateTokenBody.FreezeKey = new Key(updateParameters.SuspendEndorsement);
            }
            if (!(updateParameters.ConfiscateEndorsement is null))
            {
                updateTokenBody.WipeKey = new Key(updateParameters.ConfiscateEndorsement);
            }
            if (!(updateParameters.SupplyEndorsement is null))
            {
                updateTokenBody.SupplyKey = new Key(updateParameters.SupplyEndorsement);
            }
            if (!string.IsNullOrWhiteSpace(updateParameters.Symbol))
            {
                updateTokenBody.Symbol = updateParameters.Symbol;
            }
            if (!string.IsNullOrWhiteSpace(updateParameters.Name))
            {
                updateTokenBody.Name = updateParameters.Name;
            }
            if (updateParameters.Expiration.HasValue)
            {
                updateTokenBody.Expiry = new Timestamp(updateParameters.Expiration.Value);
            }
            if (updateParameters.RenewPeriod.HasValue)
            {
                updateTokenBody.AutoRenewPeriod = new Duration(updateParameters.RenewPeriod.Value);
            }
            if (!(updateParameters.RenewAccount is null))
            {
                updateTokenBody.AutoRenewAccount = new AccountID(updateParameters.RenewAccount);
            }
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = new TransactionBody(context, transactionId);

            transactionBody.TokenUpdate = updateTokenBody;
            var receipt = await transactionBody.SignAndExecuteWithRetryAsync(signatory, context);

            if (receipt.Status != ResponseCodeEnum.Success)
            {
                throw new TransactionException($"Unable to update Token, status: {receipt.Status}", transactionId.ToTxId(), (ResponseCode)receipt.Status);
            }
            var result = new TResult();

            if (result is TransactionRecord rec)
            {
                var record = await GetTransactionRecordAsync(context, transactionId);

                record.FillProperties(rec);
            }
            else if (result is TransactionReceipt rcpt)
            {
                receipt.FillProperties(transactionId, rcpt);
            }
            return(result);
        }
예제 #2
0
 /// <summary>
 /// Updates the changeable properties of a hedera network Token.
 /// </summary>
 /// <param name="updateParameters">
 /// The Token update parameters, includes a required
 /// <see cref="Address"/> or <code>Symbol</code> reference to the Token
 /// to update plus a number of changeable properties of the Token.
 /// </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 containing the details of the results.
 /// of the request.
 /// </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 <TransactionRecord> UpdateTokenWithRecordAsync(UpdateTokenParams updateParameters, Action <IContext>?configure = null)
 {
     return(new TransactionRecord(await ExecuteTransactionAsync(new TokenUpdateTransactionBody(updateParameters), configure, true, updateParameters.Signatory).ConfigureAwait(false)));
 }
예제 #3
0
 /// <summary>
 /// Updates the changeable properties of a hedera network Token.
 /// </summary>
 /// <param name="updateParameters">
 /// The Token update parameters, includes a required
 /// <see cref="Address"/> or <code>Symbol</code> reference to the Token
 /// to update plus a number of changeable properties of the Token.
 /// </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 containing the details of the results.
 /// of the request.
 /// </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 Task <TransactionRecord> UpdateTokenWithRecordAsync(UpdateTokenParams updateParameters, Action <IContext>?configure = null)
 {
     return(UpdateTokenImplementationAsync <TransactionRecord>(updateParameters, configure));
 }
 internal TokenUpdateTransactionBody(Hashgraph.UpdateTokenParams updateParameters) : this()
 {
     if (updateParameters is null)
     {
         throw new ArgumentNullException(nameof(updateParameters), "Token Update Parameters argument is missing. Please check that it is not null.");
     }
     if (updateParameters.Token.IsNullOrNone())
     {
         throw new ArgumentNullException(nameof(updateParameters.Token), "The Token is missing.  Please check that it is not null or empty.");
     }
     if (updateParameters.Treasury is null &&
         updateParameters.Administrator is null &&
         updateParameters.GrantKycEndorsement is null &&
         updateParameters.SuspendEndorsement is null &&
         updateParameters.PauseEndorsement is null &&
         updateParameters.ConfiscateEndorsement is null &&
         updateParameters.SupplyEndorsement is null &&
         updateParameters.RoyaltiesEndorsement is null &&
         string.IsNullOrWhiteSpace(updateParameters.Symbol) &&
         string.IsNullOrWhiteSpace(updateParameters.Name) &&
         !updateParameters.Expiration.HasValue &&
         !updateParameters.RenewPeriod.HasValue &&
         updateParameters.RenewAccount is null &&
         updateParameters.Memo is null)
     {
         throw new ArgumentException("The Topic Updates contain no update properties, it is blank.", nameof(updateParameters));
     }
     Token = new TokenID(updateParameters.Token);
     if (!string.IsNullOrWhiteSpace(updateParameters.Symbol))
     {
         if (updateParameters.Symbol.Trim().Length != updateParameters.Symbol.Length)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Symbol), "The new token symbol cannot contain leading or trailing white space.");
         }
         if (updateParameters.Symbol.Length > 32)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Symbol), "The new token symbol cannot exceed 32 characters in length.");
         }
         if (!updateParameters.Symbol.Equals(updateParameters.Symbol.ToUpperInvariant()))
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Symbol), "The new token symbol must contain upper case characters.");
         }
         Symbol = updateParameters.Symbol;
     }
     if (!string.IsNullOrWhiteSpace(updateParameters.Name))
     {
         if (updateParameters.Name.Trim().Length != updateParameters.Name.Length)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Name), "The new token name cannot contain leading or trailing white space.");
         }
         Name = updateParameters.Name;
     }
     if (updateParameters.Expiration.HasValue)
     {
         if (updateParameters.Expiration.Value < DateTime.UtcNow)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Expiration), "The new expiration can not be set to the past.");
         }
         Expiry = new Timestamp(updateParameters.Expiration.Value);
     }
     if (updateParameters.RenewPeriod.HasValue)
     {
         if (updateParameters.RenewPeriod.Value.TotalSeconds < 1)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.RenewPeriod), "The renew period must be non negative.");
         }
         AutoRenewPeriod = new Duration(updateParameters.RenewPeriod.Value);
     }
     if (updateParameters.Memo is not null)
     {
         if (updateParameters.Memo.Trim().Length != updateParameters.Memo.Length)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.Memo), "The new token memo cannot contain leading or trailing white space.");
         }
         Memo = updateParameters.Memo;
     }
     if (!(updateParameters.Treasury is null))
     {
         Treasury = new AccountID(updateParameters.Treasury);
     }
     if (!(updateParameters.Administrator is null))
     {
         AdminKey = new Key(updateParameters.Administrator);
     }
     if (!(updateParameters.GrantKycEndorsement is null))
     {
         KycKey = new Key(updateParameters.GrantKycEndorsement);
     }
     if (!(updateParameters.SuspendEndorsement is null))
     {
         FreezeKey = new Key(updateParameters.SuspendEndorsement);
     }
     if (!(updateParameters.PauseEndorsement is null))
     {
         PauseKey = new Key(updateParameters.PauseEndorsement);
     }
     if (!(updateParameters.ConfiscateEndorsement is null))
     {
         WipeKey = new Key(updateParameters.ConfiscateEndorsement);
     }
     if (!(updateParameters.SupplyEndorsement is null))
     {
         SupplyKey = new Key(updateParameters.SupplyEndorsement);
     }
     if (!(updateParameters.RoyaltiesEndorsement is null))
     {
         FeeScheduleKey = new Key(updateParameters.RoyaltiesEndorsement);
     }
     if (!(updateParameters.RenewAccount is null))
     {
         AutoRenewAccount = new AccountID(updateParameters.RenewAccount);
     }
 }