Пример #1
0
        /// <summary>
        /// Internal helper method implementing the file update service.
        /// </summary>
        public async Task <TResult> UpdateFileImplementationAsync <TResult>(UpdateFileParams 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 updateFileBody = new FileUpdateTransactionBody
            {
                FileID = Protobuf.ToFileId(updateParameters.File)
            };

            if (!(updateParameters.Endorsements is null))
            {
                updateFileBody.Keys = Protobuf.ToPublicKeyList(updateParameters.Endorsements);
            }
            if (updateParameters.Contents.HasValue)
            {
                updateFileBody.Contents = ByteString.CopyFrom(updateParameters.Contents.Value.ToArray());
            }
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = Transactions.CreateTransactionBody(context, transactionId);

            transactionBody.FileUpdate = updateFileBody;
            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 update 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);
Пример #2
0
        /// <summary>
        /// Internal helper method implementing the file update service.
        /// </summary>
        public async Task <TResult> UpdateFileImplementationAsync <TResult>(UpdateFileParams 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 updateFileBody = new FileUpdateTransactionBody
            {
                FileID = new FileID(updateParameters.File)
            };

            if (!(updateParameters.Endorsements is null))
            {
                updateFileBody.Keys = new KeyList(updateParameters.Endorsements);
            }
            if (updateParameters.Contents.HasValue)
            {
                updateFileBody.Contents = ByteString.CopyFrom(updateParameters.Contents.Value.ToArray());
            }
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = new TransactionBody(context, transactionId);

            transactionBody.FileUpdate = updateFileBody;
            var receipt = await transactionBody.SignAndExecuteWithRetryAsync(signatory, context);

            if (receipt.Status != ResponseCodeEnum.Success)
            {
                throw new TransactionException($"Unable to update 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);
        }