コード例 #1
0
        /// <summary>
        /// Retrieves the records associated with an contract that are presently
        /// held within the network.
        /// </summary>
        /// <param name="contract">
        /// The Hedera Network Contract Address to retrieve associated records.
        /// </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 detailed description of the account.
        /// </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>
        public async Task <TransactionRecord[]> GetContractRecordsAsync(Address contract, Action <IContext>?configure = null)
        {
            contract = RequireInputParameter.Contract(contract);
            await using var context = CreateChildContext(configure);
            var query = new Query
            {
                ContractGetRecords = new ContractGetRecordsQuery
                {
                    Header     = Transactions.CreateAskCostHeader(),
                    ContractID = Protobuf.ToContractID(contract)
                }
            };
            var response = await Transactions.ExecuteUnsignedAskRequestWithRetryAsync(context, query, getRequestMethod, getResponseHeader);

            long cost = (long)response.ContractGetRecordsResponse.Header.Cost;

            if (cost > 0)
            {
                var transactionId = Transactions.GetOrCreateTransactionID(context);
                query.ContractGetRecords.Header = await Transactions.CreateAndSignQueryHeaderAsync(context, cost, transactionId);

                response = await Transactions.ExecuteSignedRequestWithRetryAsync(context, query, getRequestMethod, getResponseHeader);

                ValidateResult.ResponseHeader(transactionId, getResponseHeader(response));
            }
            return(response.ContractGetRecordsResponse.Records.Select(record =>
            {
                var result = new TransactionRecord();
                Protobuf.FillRecordProperties(record, result);
                return result;
            }).ToArray());
コード例 #2
0
        /// <summary>
        /// Retrieves the account records associated with an account that are presently
        /// held within the network.
        /// </summary>
        /// <param name="address">
        /// The Hedera Network Address to retrieve associated records.
        /// </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 detailed description of the account.
        /// </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>
        public async Task <TransactionRecord[]> GetAccountRecordsAsync(Address address, Action <IContext>?configure = null)
        {
            address = RequireInputParameter.Address(address);
            var context         = CreateChildContext(configure);
            var gateway         = RequireInContext.Gateway(context);
            var payer           = RequireInContext.Payer(context);
            var transfers       = Transactions.CreateCryptoTransferList((payer, -context.FeeLimit), (gateway, context.FeeLimit));
            var transactionId   = Transactions.GetOrCreateTransactionID(context);
            var transactionBody = Transactions.CreateCryptoTransferTransactionBody(context, transfers, transactionId, "Get Account Records");
            var query           = new Query
            {
                CryptoGetAccountRecords = new CryptoGetAccountRecordsQuery
                {
                    Header    = Transactions.SignQueryHeader(transactionBody, payer),
                    AccountID = Protobuf.ToAccountID(address)
                }
            };
            var response = await Transactions.ExecuteRequestWithRetryAsync(context, query, getRequestMethod, getResponseCode);

            ValidateResult.PreCheck(transactionId, getResponseCode(response));
            return(response.CryptoGetAccountRecords.Records.Select(record =>
            {
                var result = new TransactionRecord();
                Protobuf.FillRecordProperties(record, result);
                return result;
            }).ToArray());
コード例 #3
0
        /// <summary>
        /// Retrieves the transaction record for a given transaction ID.
        /// </summary>
        /// <param name="transaction">
        /// Transaction identifier of the record
        /// </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 the specified id, or an exception if not found.
        /// </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="TransactionException">If the network has no record of the transaction or request has invalid or had missing data.</exception>
        public async Task <TransactionRecord> GetTransactionRecordAsync(TxId transaction, Action <IContext>?configure = null)
        {
            transaction             = RequireInputParameter.Transaction(transaction);
            await using var context = CreateChildContext(configure);
            var transactionId = Protobuf.ToTransactionID(transaction);
            // For the public version of this method, we do not know
            // if the transaction in question has come to consensus so
            // we need to get the receipt first (and wait if necessary).
            var query = new Query
            {
                TransactionGetReceipt = new TransactionGetReceiptQuery
                {
                    TransactionID = transactionId
                }
            };
            await Transactions.ExecuteNetworkRequestWithRetryAsync(context, query, getServerMethod, shouldRetry);

            // The Receipt status returned does notmatter in this case.
            // We may be retrieving a failed record (the status would not equal OK).
            var record = await GetTransactionRecordAsync(context, transactionId);

            var result = new TransactionRecord();

            Protobuf.FillRecordProperties(record, result);
            return(result);
コード例 #4
0
        /// <summary>
        /// Retrieves the account records associated with an account that are presently
        /// held within the network because they exceeded the receive or send threshold
        /// values for autogeneration of records.
        /// </summary>
        /// <param name="address">
        /// The Hedera Network Address to retrieve associated records.
        /// </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 detailed description of the account.
        /// </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>
        public async Task <TransactionRecord[]> GetAccountRecordsAsync(Address address, Action <IContext>?configure = null)
        {
            address = RequireInputParameter.Address(address);
            await using var context = CreateChildContext(configure);
            var query = new Query
            {
                CryptoGetAccountRecords = new CryptoGetAccountRecordsQuery
                {
                    Header    = Transactions.CreateAskCostHeader(),
                    AccountID = Protobuf.ToAccountID(address)
                }
            };
            var response = await Transactions.ExecuteUnsignedAskRequestWithRetryAsync(context, query, getRequestMethod, getResponseHeader);

            long cost = (long)response.CryptoGetAccountRecords.Header.Cost;

            if (cost > 0)
            {
                var transactionId = Transactions.GetOrCreateTransactionID(context);
                query.CryptoGetAccountRecords.Header = await Transactions.CreateAndSignQueryHeaderAsync(context, cost, transactionId);

                response = await Transactions.ExecuteSignedRequestWithRetryAsync(context, query, getRequestMethod, getResponseHeader);

                var precheckCode = getResponseHeader(response)?.NodeTransactionPrecheckCode ?? ResponseCodeEnum.Unknown;
                if (precheckCode != ResponseCodeEnum.Ok)
                {
                    throw new TransactionException("Unable to retrieve transaction records.", Protobuf.FromTransactionId(transactionId), (ResponseCode)precheckCode);
                }
            }
            return(response.CryptoGetAccountRecords.Records.Select(record =>
            {
                var result = new TransactionRecord();
                Protobuf.FillRecordProperties(record, result);
                return result;
            }).ToArray());
コード例 #5
0
        /// <summary>
        /// Retrieves the transaction record for a given transaction ID.
        /// </summary>
        /// <param name="transaction">
        /// Transaction identifier of the record
        /// </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 the specified id, or an exception if not found.
        /// </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="TransactionException">If the network rejected the create request as invalid or had missing data.</exception>
        public async Task <TransactionRecord> GetTransactionRecordAsync(TxId transaction, Action <IContext>?configure = null)
        {
            transaction = RequireInputParameter.Transaction(transaction);
            var context       = CreateChildContext(configure);
            var transactionId = Protobuf.ToTransactionID(transaction);
            var record        = await GetTransactionRecordAsync(context, transactionId);

            var result = new TransactionRecord();

            Protobuf.FillRecordProperties(record, result);
            return(result);
        }
コード例 #6
0
 private void FillCommonProperties(Hashgraph.TransactionRecord record)
 {
     record.Id             = TransactionID.ToTxId();
     record.Status         = (ResponseCode)Receipt.Status;
     record.Hash           = TransactionHash?.ToByteArray();
     record.Concensus      = ConsensusTimestamp?.ToDateTime();
     record.Memo           = Memo;
     record.Fee            = TransactionFee;
     record.Transfers      = TransferList.ToTransfers();
     record.TokenTransfers = TokenTransferLists.ToTransfers();
     if (Receipt.ExchangeRate != null)
     {
         record.CurrentExchangeRate = Receipt.ExchangeRate.CurrentRate?.ToExchangeRate();
         record.NextExchangeRate    = Receipt.ExchangeRate.NextRate?.ToExchangeRate();
     }
 }
コード例 #7
0
 internal Hashgraph.TransactionRecord FillProperties(Hashgraph.TransactionRecord record)
 {
     FillCommonProperties(record);
     return(record);
 }