internal FileAppendTransactionBody(Hashgraph.AppendFileParams appendParameters) : this()
 {
     if (appendParameters is null)
     {
         throw new ArgumentNullException(nameof(appendParameters), "File Update Parameters argument is missing. Please check that it is not null.");
     }
     if (appendParameters.File is null)
     {
         throw new ArgumentNullException(nameof(appendParameters.File), "File identifier is missing. Please check that it is not null.");
     }
     FileID   = new FileID(appendParameters.File);
     Contents = ByteString.CopyFrom(appendParameters.Contents.ToArray());
 }
Beispiel #2
0
        /// <summary>
        /// Internal helper function implementing file append services.
        /// </summary>
        public async Task <TResult> AppendFileImplementationAsync <TResult>(AppendFileParams appendParameters, Action <IContext>?configure = null) where TResult : new()
        {
            appendParameters        = RequireInputParameter.AppendParameters(appendParameters);
            await using var context = CreateChildContext(configure);
            RequireInContext.Gateway(context);
            var payer          = RequireInContext.Payer(context);
            var signatory      = Transactions.GatherSignatories(context, appendParameters.Signatory);
            var appendFileBody = new FileAppendTransactionBody
            {
                FileID   = Protobuf.ToFileId(appendParameters.File),
                Contents = ByteString.CopyFrom(appendParameters.Contents.ToArray())
            };
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = Transactions.CreateTransactionBody(context, transactionId);

            transactionBody.FileAppend = appendFileBody;
            var request = await Transactions.SignTransactionAsync(transactionBody, signatory);

            var precheck = await Transactions.ExecuteSignedRequestWithRetryAsync(context, request, getRequestMethod, getResponseCode);

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

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

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

                Protobuf.FillRecordProperties(record, rec);
            }
            else if (result is TransactionReceipt rcpt)
            {
                Protobuf.FillReceiptProperties(transactionId, receipt, rcpt);
            }
            return(result);
Beispiel #3
0
        /// <summary>
        /// Internal helper function implementing file append services.
        /// </summary>
        public async Task <TResult> AppendFileImplementationAsync <TResult>(AppendFileParams appendParameters, Action <IContext>?configure = null) where TResult : new()
        {
            appendParameters        = RequireInputParameter.AppendParameters(appendParameters);
            await using var context = CreateChildContext(configure);
            RequireInContext.Gateway(context);
            var payer          = RequireInContext.Payer(context);
            var signatory      = Transactions.GatherSignatories(context, appendParameters.Signatory);
            var appendFileBody = new FileAppendTransactionBody
            {
                FileID   = new FileID(appendParameters.File),
                Contents = ByteString.CopyFrom(appendParameters.Contents.ToArray())
            };
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = new TransactionBody(context, transactionId);

            transactionBody.FileAppend = appendFileBody;
            var receipt = await transactionBody.SignAndExecuteWithRetryAsync(signatory, context);

            if (receipt.Status != ResponseCodeEnum.Success)
            {
                throw new TransactionException($"Unable to append to file, 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);
        }
Beispiel #4
0
 /// <summary>
 /// Appends content to an existing file.
 /// </summary>
 /// <param name="appendParameters">
 /// Configuration object identifying the file and contents to append.
 /// </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 containing the details of the transaction & fees.
 /// </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> AppendFileWithRecordAsync(AppendFileParams appendParameters, Action <IContext>?configure = null)
 {
     return(new TransactionRecord(await ExecuteTransactionAsync(new FileAppendTransactionBody(appendParameters), configure, true, appendParameters.Signatory).ConfigureAwait(false)));
 }
Beispiel #5
0
 /// <summary>
 /// Appends content to an existing file.
 /// </summary>
 /// <param name="appendParameters">
 /// Configuration object identifying the file and contents to append.
 /// </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 containing the details of the transaction & fees.
 /// </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> AppendFileWithRecordAsync(AppendFileParams appendParameters, Action <IContext>?configure = null)
 {
     return(AppendFileImplementationAsync <TransactionRecord>(appendParameters, configure));
 }