Esempio n. 1
0
 internal FileCreateTransactionBody(Hashgraph.CreateFileParams createParameters) : this()
 {
     if (createParameters is null)
     {
         throw new ArgumentNullException(nameof(createParameters), "The create parameters are missing. Please check that the argument is not null.");
     }
     if (createParameters.Endorsements is null)
     {
         throw new ArgumentOutOfRangeException(nameof(createParameters.Endorsements), "Endorsements are required.");
     }
     ExpirationTime = new Timestamp(createParameters.Expiration);
     Keys           = new KeyList(createParameters.Endorsements);
     Contents       = ByteString.CopyFrom(createParameters.Contents.ToArray());
     Memo           = createParameters.Memo ?? "";
 }
Esempio n. 2
0
        /// <summary>
        /// Internal implementation of the Create File service.
        /// </summary>
        public async Task <TResult> CreateFileImplementationAsync <TResult>(CreateFileParams createParameters, Action <IContext>?configure) where TResult : new()
        {
            createParameters        = RequireInputParameter.CreateParameters(createParameters);
            await using var context = CreateChildContext(configure);
            var gateway         = RequireInContext.Gateway(context);
            var payer           = RequireInContext.Payer(context);
            var signatory       = Transactions.GatherSignatories(context, createParameters.Signatory);
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = Transactions.CreateTransactionBody(context, transactionId);

            transactionBody.FileCreate = new FileCreateTransactionBody
            {
                ExpirationTime = Protobuf.ToTimestamp(createParameters.Expiration),
                Keys           = Protobuf.ToPublicKeyList(createParameters.Endorsements),
                Contents       = ByteString.CopyFrom(createParameters.Contents.ToArray()),
            };
            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 create file, status: {receipt.Status}", Protobuf.FromTransactionId(transactionId), (ResponseCode)receipt.Status);
            }
            var result = new TResult();

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

                Protobuf.FillRecordProperties(record, rec);
                rec.File = Protobuf.FromFileID(receipt.FileID);
            }
            else if (result is FileReceipt rcpt)
            {
                Protobuf.FillReceiptProperties(transactionId, receipt, rcpt);
                rcpt.File = Protobuf.FromFileID(receipt.FileID);
            }
            return(result);
Esempio n. 3
0
        /// <summary>
        /// Internal implementation of the Create File service.
        /// </summary>
        public async Task <TResult> CreateFileImplementationAsync <TResult>(CreateFileParams createParameters, Action <IContext>?configure) where TResult : new()
        {
            createParameters        = RequireInputParameter.CreateParameters(createParameters);
            await using var context = CreateChildContext(configure);
            var gateway         = RequireInContext.Gateway(context);
            var payer           = RequireInContext.Payer(context);
            var signatory       = Transactions.GatherSignatories(context, createParameters.Signatory);
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = new TransactionBody(context, transactionId);

            transactionBody.FileCreate = new FileCreateTransactionBody
            {
                ExpirationTime = new Timestamp(createParameters.Expiration),
                Keys           = new KeyList(createParameters.Endorsements),
                Contents       = ByteString.CopyFrom(createParameters.Contents.ToArray()),
            };
            var receipt = await transactionBody.SignAndExecuteWithRetryAsync(signatory, context);

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

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

                record.FillProperties(rec);
            }
            else if (result is FileReceipt rcpt)
            {
                receipt.FillProperties(transactionId, rcpt);
            }
            return(result);
        }
Esempio n. 4
0
 /// <summary>
 /// Creates a new file with the given content.
 /// </summary>
 /// <param name="createParameters">
 /// File creation parameters specifying contents and ownership of the file.
 /// </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 with a description of the newly created file & fees.
 /// and record information.
 /// </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 <FileRecord> CreateFileWithRecordAsync(CreateFileParams createParameters, Action <IContext>?configure = null)
 {
     return(CreateFileImplementationAsync <FileRecord>(createParameters, configure));
 }
Esempio n. 5
0
 /// <summary>
 /// Creates a new file with the given content.
 /// </summary>
 /// <param name="createParameters">
 /// File creation parameters specifying contents and ownership of the file.
 /// </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 with a description of the newly created file & fees.
 /// and record information.
 /// </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 <FileRecord> CreateFileWithRecordAsync(CreateFileParams createParameters, Action <IContext>?configure = null)
 {
     return(new FileRecord(await ExecuteTransactionAsync(new FileCreateTransactionBody(createParameters), configure, true, createParameters.Signatory).ConfigureAwait(false)));
 }