Ejemplo n.º 1
0
        public Task <SubmitTransactionResponse> SubmitTransaction(FeeBumpTransaction feeBump)
        {
            var options = new SubmitTransactionOptions {
                FeeBumpTransaction = true
            };

            return(SubmitTransaction(feeBump.ToEnvelopeXdrBase64(), options));
        }
Ejemplo n.º 2
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}");
            }
        }
Ejemplo n.º 4
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);
        }
        public static FeeBumpTransaction FromEnvelopeXdr(TransactionEnvelope envelope)
        {
            {
                switch (envelope.Discriminant.InnerValue)
                {
                case EnvelopeType.EnvelopeTypeEnum.ENVELOPE_TYPE_TX_FEE_BUMP:
                    var tx        = envelope.FeeBump.Tx;
                    var fee       = tx.Fee.InnerValue;
                    var feeSource = MuxedAccount.FromXdrMuxedAccount(tx.FeeSource);
                    var innerTx   = Transaction.FromEnvelopeXdrV1(tx.InnerTx.V1);

                    var transaction = new FeeBumpTransaction(feeSource, innerTx, fee);
                    foreach (var signature in envelope.FeeBump.Signatures)
                    {
                        transaction.Signatures.Add(signature);
                    }

                    return(transaction);

                default:
                    throw new ArgumentException($"Invalid TransactionEnvelope: expected an ENVELOPE_TYPE_TX_FEE_BUMP but received {envelope.Discriminant.InnerValue}");
                }
            }
        }
Ejemplo n.º 6
0
 public Task <SubmitTransactionResponse> SubmitTransaction(FeeBumpTransaction feeBump, SubmitTransactionOptions options)
 {
     options.FeeBumpTransaction = true;
     return(SubmitTransaction(feeBump.ToEnvelopeXdrBase64(), options));
 }