Beispiel #1
0
        /// <summary>
        /// Submit a transaction to the network.
        ///
        /// This method will check if any of the destination accounts require a memo.  Change the SkipMemoRequiredCheck
        /// options to change this behaviour.
        /// </summary>
        /// <param name="transactionEnvelopeBase64"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <SubmitTransactionResponse> SubmitTransaction(string transactionEnvelopeBase64, SubmitTransactionOptions options)
        {
            if (!options.SkipMemoRequiredCheck)
            {
                TransactionBase tx;

                if (options.FeeBumpTransaction)
                {
                    tx = FeeBumpTransaction.FromEnvelopeXdr(transactionEnvelopeBase64);
                }
                else
                {
                    tx = Transaction.FromEnvelopeXdr(transactionEnvelopeBase64);
                }

                await CheckMemoRequired(tx);
            }

            var transactionUri = new UriBuilder(_serverUri).SetPath("/transactions").Uri;

            var paramsPairs = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("tx", transactionEnvelopeBase64)
            };

            var response = await _httpClient.PostAsync(transactionUri, new FormUrlEncodedContent(paramsPairs.ToArray()));

            if (options.EnsureSuccess && !response.IsSuccessStatusCode)
            {
                string responseString = string.Empty;
                if (response.Content != null)
                {
                    responseString = await response.Content.ReadAsStringAsync();
                }

                throw new ConnectionErrorException($"Status code ({response.StatusCode}) is not success.{ (!string.IsNullOrEmpty(responseString) ? " Content: " + responseString : "") }");
            }

            if (response.Content != null)
            {
                var responseString = await response.Content.ReadAsStringAsync();

                var submitTransactionResponse = JsonSingleton.GetInstance <SubmitTransactionResponse>(responseString);
                return(submitTransactionResponse);
            }

            return(null);
        }
        public static TransactionBase FromEnvelopeXdr(TransactionEnvelope envelope)
        {
            switch (envelope.Discriminant.InnerValue)
            {
            case EnvelopeType.EnvelopeTypeEnum.ENVELOPE_TYPE_TX_V0:
                return(Transaction.FromEnvelopeXdr(envelope));

            case EnvelopeType.EnvelopeTypeEnum.ENVELOPE_TYPE_TX:
                return(Transaction.FromEnvelopeXdr(envelope));

            case EnvelopeType.EnvelopeTypeEnum.ENVELOPE_TYPE_TX_FEE_BUMP:
                return(FeeBumpTransaction.FromEnvelopeXdr(envelope));

            default:
                throw new ArgumentException($"Unknown envelope type {envelope.Discriminant.InnerValue}");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Submit a transaction to the network.
        ///
        /// This method will check if any of the destination accounts require a memo.  Change the SkipMemoRequiredCheck
        /// options to change this behaviour.
        /// </summary>
        /// <param name="transactionEnvelopeBase64"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <SubmitTransactionResponse> SubmitTransaction(string transactionEnvelopeBase64, SubmitTransactionOptions options)
        {
            if (!options.SkipMemoRequiredCheck)
            {
                TransactionBase tx;

                if (options.FeeBumpTransaction)
                {
                    tx = FeeBumpTransaction.FromEnvelopeXdr(transactionEnvelopeBase64);
                }
                else
                {
                    tx = Transaction.FromEnvelopeXdr(transactionEnvelopeBase64);
                }

                await CheckMemoRequired(tx);
            }

            var transactionUri = new UriBuilder(_serverUri).SetPath("/transactions").Uri;

            var paramsPairs = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("tx", transactionEnvelopeBase64)
            };

            var response = await _httpClient.PostAsync(transactionUri, new FormUrlEncodedContent(paramsPairs.ToArray()));

            if (response.Content != null)
            {
                var responseString = await response.Content.ReadAsStringAsync();

                var submitTransactionResponse = JsonSingleton.GetInstance <SubmitTransactionResponse>(responseString);
                return(submitTransactionResponse);
            }

            return(null);
        }