Пример #1
0
        /// <summary>
        /// Sends bitcoin from your wallet to a single address.
        /// </summary>
        /// <param name="toAddress">Recipient bitcoin address</param>
        /// <param name="amount">Amount to send</param>
        /// <param name="fromAddress">Specific address to send from</param>
        /// <param name="fee">Transaction fee. Must be greater than the default fee</param>
        /// <param name="note">Public note to include with the transaction</param>
        /// <returns>An instance of the PaymentResponse class</returns>
        /// <exception cref="ServerApiException">If the server returns an error</exception>
        public async Task <PaymentResponse> SendAsync(string toAddress, BitcoinValue amount,
                                                      string fromAddress = null, BitcoinValue fee = null, string note = null)
        {
            if (string.IsNullOrWhiteSpace(toAddress))
            {
                throw new ArgumentNullException(nameof(toAddress));
            }
            if (amount.GetBtc() <= 0)
            {
                throw new ArgumentException("Amount sent must be greater than 0", nameof(amount));
            }

            QueryString queryString = new QueryString();

            queryString.Add("password", password);
            queryString.Add("to", toAddress);
            queryString.Add("amount", amount.Satoshis.ToString());
            if (!string.IsNullOrWhiteSpace(secondPassword))
            {
                queryString.Add("second_password", secondPassword);
            }
            if (!string.IsNullOrWhiteSpace(fromAddress))
            {
                queryString.Add("from", fromAddress);
            }
            if (!string.IsNullOrWhiteSpace(note))
            {
                queryString.Add("note", note);
            }
            if (fee != null)
            {
                queryString.Add("fee", fee.ToString());
            }

            string route = $"merchant/{identifier}/payment";

            PaymentResponse paymentResponse = await httpClient.GetAsync <PaymentResponse>(route, queryString);

            return(paymentResponse);
        }
        /// <summary>
        /// Sends bitcoin from your wallet to multiple addresses.
        /// </summary>
        /// <param name="recipients">Dictionary with the structure of 'address':amount
        /// (string:BitcoinValue)</param>
        /// <param name="fromAddress">Specific address to send from</param>
        /// <param name="fee">Transaction fee. Must be greater than the default fee</param>
        /// <param name="note">Public note to include with the transaction</param>
        /// <returns>An instance of the PaymentResponse class</returns>
        /// <exception cref="ServerApiException">If the server returns an error</exception>
        public async Task <PaymentResponse> SendManyAsync(Dictionary <string, BitcoinValue> recipients,
                                                          string fromAddress = null, BitcoinValue?fee = null, string note = null)
        {
            if (recipients == null || recipients.Count == 0)
            {
                throw new ArgumentException("Sending bitcoin from your wallet requires at least one receipient.", nameof(recipients));
            }

            QueryString queryString = new QueryString();

            queryString.Add("password", this.password);
            string recipientsJson = JsonConvert.SerializeObject(recipients, Formatting.None, new BitcoinValueJsonConverter());

            queryString.Add("recipients", recipientsJson);
            if (!string.IsNullOrWhiteSpace(this.secondPassword))
            {
                queryString.Add("second_password", this.secondPassword);
            }
            if (!string.IsNullOrWhiteSpace(fromAddress))
            {
                queryString.Add("from", fromAddress);
            }
            if (!string.IsNullOrWhiteSpace(note))
            {
                queryString.Add("note", note);
            }
            if (fee != null)
            {
                queryString.Add("fee", fee.ToString());
            }

            string route = $"merchant/{this.identifier}/sendmany";

            PaymentResponse paymentResponse = await this.httpClient.GetAsync <PaymentResponse>(route, queryString);

            return(paymentResponse);
        }