Beispiel #1
0
 protected async Task HandleValidSubmit()
 {
     _output = null;
     await _network.ExecuteAsync(_input.Gateway, _input.Payer, async client =>
     {
         var updateParams = new UpdateAccountParams
         {
             Address = _input.Address
         };
         if (_input.UpdateEndorsement)
         {
             updateParams.Endorsement = _input.Endorsement;
         }
         if (_input.UpdateReceiveSignatureRequired)
         {
             updateParams.RequireReceiveSignature = _input.ReceiveSignatureRequired;
         }
         _output = await client.UpdateAccountAsync(updateParams, ctx => ctx.Memo = _input.Memo?.Trim());
     });
 }
 internal static UpdateAccountParams UpdateParameters(UpdateAccountParams updateParameters)
 {
     if (updateParameters is null)
     {
         throw new ArgumentNullException(nameof(updateParameters), "Account Update Parameters argument is missing. Please check that it is not null.");
     }
     if (updateParameters.Account is null)
     {
         throw new ArgumentNullException(nameof(updateParameters.Account), "Account is missing. Please check that it is not null.");
     }
     if (updateParameters.Endorsement is null &&
         updateParameters.SendThresholdCreateRecord is null &&
         updateParameters.ReceiveThresholdCreateRecord is null &&
         updateParameters.Expiration is null &&
         updateParameters.AutoRenewPeriod is null)
     {
         throw new ArgumentException(nameof(updateParameters), "The Account Updates contains no update properties, it is blank.");
     }
     return(updateParameters);
 }
    // Code Example:  Docs / Recipe / Crypto / Update Account
    static async Task Main(string[] args)
    {                                                    // For Example:
        var gatewayUrl           = args[0];              //   2.testnet.hedera.com:50211
        var gatewayAccountNo     = long.Parse(args[1]);  //   5 (gateway node 0.0.5)
        var payerAccountNo       = long.Parse(args[2]);  //   20 (account 0.0.20)
        var payerPrivateKey      = Hex.ToBytes(args[3]); //   302e0201... (Ed25519 private in hex)
        var targetAccountNo      = long.Parse(args[4]);  //   2023 (account 0.0.2023)
        var targetPrivateKey     = Hex.ToBytes(args[5]); //   302e0201... (Ed25519 private in hex)
        var targetAccountNewMemo = args[6];              //   New Memo to Associate with Target

        try
        {
            await using var client = new Client(ctx =>
            {
                ctx.Gateway   = new Gateway(gatewayUrl, 0, 0, gatewayAccountNo);
                ctx.Payer     = new Address(0, 0, payerAccountNo);
                ctx.Signatory = new Signatory(payerPrivateKey);
            });

            var updateParams = new UpdateAccountParams
            {
                Address   = new Address(0, 0, targetAccountNo),
                Signatory = new Signatory(targetPrivateKey),
                Memo      = targetAccountNewMemo
            };

            var receipt = await client.UpdateAccountAsync(updateParams);

            Console.WriteLine($"Status: {receipt.Status}");
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex.Message);
            Console.Error.WriteLine(ex.StackTrace);
        }
    }
 internal static UpdateAccountParams UpdateParameters(UpdateAccountParams updateParameters)
 {
     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)
     {
         throw new ArgumentException(nameof(updateParameters), "The Account Updates contains no update properties, it is blank.");
     }
     return(updateParameters);
 }
Beispiel #5
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)));
 }