/// <summary>
        /// Retrieves the network address associated with the specified smart contract id.
        /// </summary>
        /// <param name="smartContractId">
        /// The smart contract ID to look up.
        /// </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>
        /// The network address associated with the smart contract ID.
        /// </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 <Address> GetAddressFromSmartContractId(string smartContractId, Action <IContext>?configure = null)
        {
            smartContractId = RequireInputParameter.SmartContractId(smartContractId);
            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 Contract By Solidity ID");
            var query           = new Query
            {
                GetBySolidityID = new GetBySolidityIDQuery
                {
                    Header     = Transactions.SignQueryHeader(transactionBody, payer),
                    SolidityID = smartContractId
                }
            };
            var response = await Transactions.ExecuteRequestWithRetryAsync(context, query, getRequestMethod, getResponseCode);

            ValidateResult.PreCheck(transactionId, getResponseCode(response));
            var data = response.GetBySolidityID;

            if (data.ContractID != null)
            {
                return(Protobuf.FromContractID(data.ContractID));
            }
            if (data.AccountID != null)
            {
                return(Protobuf.FromAccountID(data.AccountID));
            }
            if (data.FileID != null)
            {
                return(Protobuf.FromFileID(data.FileID));
            }
            throw new TransactionException($"Address from Smart Contract ID {smartContractId} was not found.", Protobuf.FromTransactionId(transactionId), ResponseCode.Unknown);
Example #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);