internal CryptoUpdateTransactionBody(Hashgraph.UpdateAccountParams updateParameters) : this()
 {
     if (updateParameters is null)
     {
         throw new ArgumentNullException(nameof(updateParameters), "Account Update Parameters argument is missing. Please check that it is not null.");
     }
     if (updateParameters.Address is null)
     {
         throw new ArgumentNullException(nameof(updateParameters.Address), "Account is missing. Please check that it is not null.");
     }
     if (Hashgraph.Endorsement.None.Equals(updateParameters.Endorsement))
     {
         throw new ArgumentOutOfRangeException(nameof(updateParameters.Endorsement), "Endorsement can not be 'None', it must contain at least one key requirement.");
     }
     if (updateParameters.Endorsement is null &&
         updateParameters.RequireReceiveSignature is null &&
         updateParameters.Expiration is null &&
         updateParameters.AutoRenewPeriod is null &&
         updateParameters.Proxy is null &&
         updateParameters.Memo is null &&
         updateParameters.AutoAssociationLimit is null)
     {
         throw new ArgumentException(nameof(updateParameters), "The Account Updates contains no update properties, it is blank.");
     }
     AccountIDToUpdate = new AccountID(updateParameters.Address);
     if (!(updateParameters.Endorsement is null))
     {
         Key = new Key(updateParameters.Endorsement);
     }
     if (updateParameters.RequireReceiveSignature.HasValue)
     {
         ReceiverSigRequiredWrapper = updateParameters.RequireReceiveSignature.Value;
     }
     if (updateParameters.AutoRenewPeriod.HasValue)
     {
         AutoRenewPeriod = new Duration(updateParameters.AutoRenewPeriod.Value);
     }
     if (updateParameters.Expiration.HasValue)
     {
         ExpirationTime = new Timestamp(updateParameters.Expiration.Value);
     }
     if (!(updateParameters.Proxy is null))
     {
         ProxyAccountID = new AccountID(updateParameters.Proxy);
     }
     if (!(updateParameters.Memo is null))
     {
         Memo = updateParameters.Memo;
     }
     if (!(updateParameters.AutoAssociationLimit is null))
     {
         var limit = updateParameters.AutoAssociationLimit.Value;
         if (limit < 0 || limit > 1000)
         {
             throw new ArgumentOutOfRangeException(nameof(updateParameters.AutoAssociationLimit), "The maximum number of auto-associaitons must be between zero and 1000.");
         }
         MaxAutomaticTokenAssociations = updateParameters.AutoAssociationLimit.Value;
     }
 }
Example #2
0
        /// <summary>
        /// Internal implementation of the update account functionality.
        /// </summary>
        private async Task <TResult> UpdateAccountImplementationAsync <TResult>(UpdateAccountParams 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 updateAccountBody = new CryptoUpdateTransactionBody
            {
                AccountIDToUpdate = new AccountID(updateParameters.Address)
            };

            if (!(updateParameters.Endorsement is null))
            {
                updateAccountBody.Key = new Key(updateParameters.Endorsement);
            }
            if (updateParameters.RequireReceiveSignature.HasValue)
            {
                updateAccountBody.ReceiverSigRequiredWrapper = updateParameters.RequireReceiveSignature.Value;
            }
            if (updateParameters.AutoRenewPeriod.HasValue)
            {
                updateAccountBody.AutoRenewPeriod = new Duration(updateParameters.AutoRenewPeriod.Value);
            }
            if (updateParameters.Expiration.HasValue)
            {
                updateAccountBody.ExpirationTime = new Timestamp(updateParameters.Expiration.Value);
            }
            if (!(updateParameters.Proxy is null))
            {
                updateAccountBody.ProxyAccountID = new AccountID(updateParameters.Proxy);
            }
            var signatory       = Transactions.GatherSignatories(context, updateParameters.Signatory);
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = new TransactionBody(context, transactionId);

            transactionBody.CryptoUpdateAccount = updateAccountBody;
            var receipt = await transactionBody.SignAndExecuteWithRetryAsync(signatory, context);

            if (receipt.Status != ResponseCodeEnum.Success)
            {
                throw new TransactionException($"Unable to update account, 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);
        }
Example #3
0
 /// <summary>
 /// Updates the changeable properties of a hedera network account.
 /// </summary>
 /// <param name="updateParameters">
 /// The account update parameters, includes a required
 /// <see cref="Address"/> reference to the account to update plus
 /// a number of changeable properties of the account.
 /// </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> UpdateAccountWithRecordAsync(UpdateAccountParams updateParameters, Action <IContext>?configure = null)
 {
     return(new TransactionRecord(await ExecuteTransactionAsync(new CryptoUpdateTransactionBody(updateParameters), configure, true, updateParameters.Signatory).ConfigureAwait(false)));
 }
Example #4
0
 /// <summary>
 /// Updates the changeable properties of a hedera network account.
 /// </summary>
 /// <param name="updateParameters">
 /// The account update parameters, includes a required
 /// <see cref="Address"/> reference to the account to update plus
 /// a number of changeable properties of the account.
 /// </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> UpdateAccountWithRecordAsync(UpdateAccountParams updateParameters, Action <IContext>?configure = null)
 {
     return(UpdateAccountImplementationAsync <TransactionRecord>(updateParameters, configure));
 }
Example #5
0
        /// <summary>
        /// Internal implementation of the update account functionality.
        /// </summary>
        private async Task <TResult> UpdateAccountImplementationAsync <TResult>(UpdateAccountParams updateParameters, Action <IContext>?configure) where TResult : new()
        {
            updateParameters = RequireInputParameter.UpdateParameters(updateParameters);
            var context = CreateChildContext(configure);

            RequireInContext.Gateway(context);
            var payer             = RequireInContext.Payer(context);
            var updateAccountBody = new CryptoUpdateTransactionBody
            {
                AccountIDToUpdate = Protobuf.ToAccountID(updateParameters.Account)
            };

            if (!(updateParameters.Endorsement is null))
            {
                updateAccountBody.Key = Protobuf.ToPublicKey(updateParameters.Endorsement);
            }
            if (updateParameters.SendThresholdCreateRecord.HasValue)
            {
                updateAccountBody.SendRecordThresholdWrapper = updateParameters.SendThresholdCreateRecord.Value;
            }
            if (updateParameters.ReceiveThresholdCreateRecord.HasValue)
            {
                updateAccountBody.ReceiveRecordThresholdWrapper = updateParameters.ReceiveThresholdCreateRecord.Value;
            }
            if (updateParameters.AutoRenewPeriod.HasValue)
            {
                updateAccountBody.AutoRenewPeriod = Protobuf.ToDuration(updateParameters.AutoRenewPeriod.Value);
            }
            if (updateParameters.Expiration.HasValue)
            {
                updateAccountBody.ExpirationTime = Protobuf.ToTimestamp(updateParameters.Expiration.Value);
            }
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = Transactions.CreateEmptyTransactionBody(context, transactionId, "Update Account");

            transactionBody.CryptoUpdateAccount = updateAccountBody;
            var request  = Transactions.SignTransaction(transactionBody, updateParameters.Account, payer);
            var precheck = await Transactions.ExecuteRequestWithRetryAsync(context, request, getRequestMethod, getResponseCode);

            ValidateResult.PreCheck(transactionId, precheck.NodeTransactionPrecheckCode);
            var receipt = await GetReceiptAsync(context, transactionId);

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

            if (result is AccountRecord arec)
            {
                var record = await GetTransactionRecordAsync(context, transactionId);

                Protobuf.FillRecordProperties(record, arec);
                arec.Address = Protobuf.FromAccountID(receipt.AccountID);
            }
            else if (result is AccountReceipt arcpt)
            {
                Protobuf.FillReceiptProperties(transactionId, receipt, arcpt);
                arcpt.Address = Protobuf.FromAccountID(receipt.AccountID);
            }
            return(result);
Example #6
0
 /// <summary>
 /// Updates the changeable properties of a hedera network account.
 /// </summary>
 /// <param name="updateParameters">
 /// The account update parameters, includes a required
 /// <see cref="Address"/> reference to the account to update plus
 /// a number of changeable properties of the account.
 /// </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 receipt indicating success of the operation.
 /// 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 <AccountReceipt> UpdateAccountAsync(UpdateAccountParams updateParameters, Action <IContext>?configure = null)
 {
     return(UpdateAccountImplementationAsync <AccountReceipt>(updateParameters, configure));
 }