private void EndpointURL_TextChanged(object sender, TextChangedEventArgs e) { if (client == null) { client = new RippleRestClient(this.EndpointURL.Text); } client.EndpointURL = this.EndpointURL.Text; }
/// <summary> /// Gets the string content of the HTTP request created by calling one of the methods of <see cref="RippleRestClient"/> /// in <paramref name="methodCall"/>. /// </summary> /// <param name="methodCall">Action that calls method on <see cref="RippleRestClient"/>.</param> /// <returns></returns> protected string GetRequestContent(Action <RippleRestClient> methodCall) { string requestContent = null; var responseMessage = new HttpResponseMessage(HttpStatusCode.OK); // FIXME: return proper response responseMessage.Content = new StringContent("{ \"success\": true }"); var mockHandler = new Mock <MockableHttpClientHandler>(); mockHandler.CallBase = true; mockHandler.Setup(h => h.Send(It.IsAny <HttpRequestMessage>())) .Returns(responseMessage) .Callback <HttpRequestMessage>(async(request) => { requestContent = await request.Content.ReadAsStringAsync(); }); var client = new RippleRestClient("http://localhost:5990", mockHandler.Object); methodCall.Invoke(client); mockHandler.Verify(h => h.Send(It.IsAny <HttpRequestMessage>()), Times.Once); return(requestContent); }
/// <summary> /// Sets AccountSettings for this account. /// </summary> /// <param name="value">A AccountSettings instance.</param> /// <param name="client">A RippleRestClient used for this request.</param> /// <returns>AccountSettings instance</returns> /// <exception cref="RippleRestException">Request failed.</exception> public AccountSettings SetSettings(RippleRestClient client, AccountSettings value) { var data = new SetSettingsRequest { Settings = value, Secret = this.Secret }; var result = client.RestClient.Execute<GetSettingsResponse>(client.CreatePostRequest(data, "v1/accounts/{0}/settings", Address)); client.HandleRestResponseErrors(result); result.Data.Settings.Account = this.Address; return result.Data.Settings; }
/// <summary> /// Browse historical payments in bulk. /// </summary> /// <param name="client">A RippleRestClient used for this request.</param> /// <param name="options">A QueryPaymentsOptions instance</param> /// <returns>A list of Payment instances</returns> /// <exception cref="RippleRestException">Request failed.</exception> public List<Payment> QueryPayments(RippleRestClient client, QueryPaymentsOptions options) { var request = client.CreateGetRequest("v1/accounts/{0}/payments", Address); if (options != null) { var args = new Dictionary<string, string>(); if (options.SourceAccount != null) args.Add("source_account", options.SourceAccount); if (options.DestinationAccount != null) args.Add("destination_account", options.DestinationAccount); if (options.EarliestFirst != null) args.Add("earliest_first", options.EarliestFirst.Value ? "true" : "false"); if (options.ExcludeFailed != null) args.Add("exclude_failed", options.ExcludeFailed.Value ? "true" : "false"); if (options.StartLedger != null) args.Add("start_ledger", options.StartLedger); if (options.EndLedger != null) args.Add("end_ledger", options.EndLedger); if (options.Page != null) args.Add("page", options.Page.Value.ToString()); if (options.ResultsPerPage != null) args.Add("results_per_page", options.ResultsPerPage.Value.ToString()); foreach (var item in args) request.AddParameter(item.Key, item.Value, ParameterType.QueryString); } var result = client.RestClient.Execute<QueryPaymentsResponse>(request); client.HandleRestResponseErrors(result); return result.Data.Payments.ConvertAll((o) => { o.Payment.ClientResourceId = o.ClientResourceId; return o.Payment; }); }
/// <summary> /// Browse historical payments in bulk. /// </summary> /// <param name="client">A RippleRestClient used for this request.</param> /// <param name="options">A QueryPaymentsOptions instance</param> /// <returns>A list of Payment instances</returns> /// <exception cref="RippleRestException">Request failed.</exception> public List<Payment> QueryPayments(RippleRestClient client) { return QueryPayments(client, null); }
/// <summary> /// Returns Trustlines for this account. /// </summary> /// <param name="client">A RippleRestClient used for this request.</param> /// <returns>A list of Trustline</returns> /// <exception cref="RippleRestException">Request failed.</exception> public List<Trustline> GetTrustlines(RippleRestClient client) { var result = client.RestClient.Execute<GetTrustlinesResponse>(client.CreateGetRequest("v1/accounts/{0}/trustlines", Address)); client.HandleRestResponseErrors(result); return result.Data.Trustlines; }
/// <summary> /// Returns AccountSettings for this account. /// </summary> /// <param name="client">A RippleRestClient used for this request.</param> /// <returns>AccountSettings instance</returns> /// <exception cref="RippleRestException">Request failed.</exception> public AccountSettings GetSettings(RippleRestClient client) { var result = client.RestClient.Execute<GetSettingsResponse>(client.CreateGetRequest("v1/accounts/{0}/settings", Address)); client.HandleRestResponseErrors(result); result.Data.Settings.Account = this.Address; return result.Data.Settings; }
/// <summary> /// Add trustline for this account. /// </summary> /// <param name="trustline">A trustline object.</param> /// <param name="client">A RippleRestClient used for this request.</param> /// <returns>An instance of AddTrustlineResponse</returns> /// <exception cref="RippleRestException">Request failed.</exception> public AddTrustlineResponse AddTrustline(RippleRestClient client, Trustline trustline) { return AddTrustline(client, trustline, true); }
/// <summary> /// Query `rippled` for possible payment "paths" through the Ripple Network to deliver the given amount to the specified `destination_account`. If the `destination_amount` issuer is not specified, paths will be returned for all of the issuers from whom the `destination_account` accepts the given currency. /// </summary> /// <param name="client">A RippleRestClient used for this request.</param> /// <param name="destinationAccount">Destination account</param> /// <param name="destinationAmount">Destination amount</param> /// <param name="sourceCurrencies">an array of source currencies that can be used to constrain the results returned (e.g. `["XRP", "USD+r...", "BTC+r..."]`) Currencies can be denoted by their currency code (e.g. USD) or by their currency code and issuer (e.g. `USD+r...`). If no issuer is specified for a currency other than XRP, the results will be limited to the specified currencies but any issuer for that currency will do.</param> /// <returns>Payment instances</returns> /// <exception cref="RippleRestException">Request failed.</exception> public List<Payment> FindPaymentPaths(RippleRestClient client, string destinationAccount, string destinationAmount, List<string> sourceCurrencies) { var srcCury = ""; if (sourceCurrencies != null && sourceCurrencies.Count > 0) { srcCury = "?" + String.Join(",", sourceCurrencies); } var request = client.CreateGetRequest("v1/accounts/{0}/payments/paths/{1}/{2}{3}", Address, destinationAccount, destinationAmount, srcCury); var result = client.RestClient.Execute<FindPaymentPathsResponse>(request); client.HandleRestResponseErrors(result); return result.Data.Payments; }
/// <summary> /// Query `rippled` for possible payment "paths" through the Ripple Network to deliver the given amount to the specified `destination_account`. If the `destination_amount` issuer is not specified, paths will be returned for all of the issuers from whom the `destination_account` accepts the given currency. /// </summary> /// <param name="client">A RippleRestClient used for this request.</param> /// <param name="destinationAccount">Destination account</param> /// <param name="destinationAmount">Destination amount</param> /// <param name="sourceCurrencies">an array of source currencies that can be used to constrain the results returned (e.g. `["XRP", "USD+r...", "BTC+r..."]`) Currencies can be denoted by their currency code (e.g. USD) or by their currency code and issuer (e.g. `USD+r...`). If no issuer is specified for a currency other than XRP, the results will be limited to the specified currencies but any issuer for that currency will do.</param> /// <returns>Payment instances</returns> /// <exception cref="RippleRestException">Request failed.</exception> public List<Payment> FindPaymentPaths(RippleRestClient client, string destinationAccount, string destinationAmount, List<Balance> sourceCurrencies) { return FindPaymentPaths(client, destinationAccount, destinationAmount, sourceCurrencies == null ? null : sourceCurrencies.ConvertAll((o) => o.ToCurrencyString())); }
/// <summary> /// Query `rippled` for possible payment "paths" through the Ripple Network to deliver the given amount to the specified `destination_account`. If the `destination_amount` issuer is not specified, paths will be returned for all of the issuers from whom the `destination_account` accepts the given currency. /// </summary> /// <param name="client">A RippleRestClient used for this request.</param> /// <param name="destinationAccount">Destination account</param> /// <param name="destinationAmount">Destination amount</param> /// <returns>Payment instances</returns> /// <exception cref="RippleRestException">Request failed.</exception> public List<Payment> FindPaymentPaths(RippleRestClient client, string destinationAccount, string destinationAmount) { return FindPaymentPaths(client, destinationAccount, destinationAmount, (List<string>) null); }
/// <summary> /// Query `rippled` for possible payment "paths" through the Ripple Network to deliver the given amount to the specified `destination_account`. If the `destination_amount` issuer is not specified, paths will be returned for all of the issuers from whom the `destination_account` accepts the given currency. /// </summary> /// <param name="client">A RippleRestClient used for this request.</param> /// <param name="destinationAccount">Destination account</param> /// <param name="destinationAmount">Destination amount</param> /// <param name="sourceCurrencies">an array of source currencies that can be used to constrain the results returned (e.g. `["XRP", "USD+r...", "BTC+r..."]`) Currencies can be denoted by their currency code (e.g. USD) or by their currency code and issuer (e.g. `USD+r...`). If no issuer is specified for a currency other than XRP, the results will be limited to the specified currencies but any issuer for that currency will do.</param> /// <returns>Payment instances</returns> /// <exception cref="RippleRestException">Request failed.</exception> public List<Payment> FindPaymentPaths(RippleRestClient client, string destinationAccount, Amount destinationAmount, List<string> sourceCurrencies) { return FindPaymentPaths(client, destinationAccount, destinationAmount.ToString(), sourceCurrencies); }
/// <summary> /// Query `rippled` for possible payment "paths" through the Ripple Network to deliver the given amount to the specified `destination_account`. If the `destination_amount` issuer is not specified, paths will be returned for all of the issuers from whom the `destination_account` accepts the given currency. /// </summary> /// <param name="client">A RippleRestClient used for this request.</param> /// <param name="destinationAccount">Destination account</param> /// <param name="destinationAmount">Destination amount</param> /// <returns>Payment instances</returns> /// <exception cref="RippleRestException">Request failed.</exception> public List<Payment> FindPaymentPaths(RippleRestClient client, string destinationAccount, Amount destinationAmount) { return FindPaymentPaths(client, destinationAccount, destinationAmount.ToString()); }
/// <summary> /// Add trustline for this account. /// </summary> /// <param name="allowRippling">Defaults to true. See [here](https://ripple.com/wiki/No_Ripple) for details</param> /// <param name="trustline">A trustline object.</param> /// <param name="client">A RippleRestClient used for this request.</param> /// <returns>An instance of AddTrustlineResponse</returns> /// <exception cref="RippleRestException">Request failed.</exception> public AddTrustlineResponse AddTrustline(RippleRestClient client, Trustline trustline, bool allowRippling) { var request = new AddTrustlineRequest(); request.Secret = this.Secret; request.Trustline = trustline; request.AllowRippling = allowRippling; var result = client.RestClient.Execute<AddTrustlineResponse>(client.CreatePostRequest(request, "v1/accounts/{0}/trustlines", Address)); client.HandleRestResponseErrors(result); return result.Data; }
/// <summary> /// Submits a payment /// </summary> /// <param name="client">A RippleRestClient used for this request.</param> /// <param name="payment">Payment object</param> /// <returns>Original Payment object with Client Resource Id filled</returns> /// <exception cref="RippleRestException">Request failed.</exception> public Payment SubmitPayment(RippleRestClient client, Payment payment) { payment.ClientResourceId = client.GenerateUUID(); payment.SourceAccount = this.Address; var data = new SubmitPaymentRequest { Payment = payment, Secret = this.Secret, ClientResourceId = payment.ClientResourceId }; var result = client.RestClient.Execute<SubmitPaymentResponse>(client.CreatePostRequest(data, "v1/payments", Address)); client.HandleRestResponseErrors(result); payment.ClientResourceId = result.Data.ClientResourceId; return payment; }
private void EndpointURL_TextChanged(object sender, TextChangedEventArgs e) { if (client == null) client = new RippleRestClient(this.EndpointURL.Text); client.EndpointURL = this.EndpointURL.Text; }
/// <summary> /// Get notifications. /// /// Clients using notifications to monitor their account activity should pay particular attention to the `state` and `result` fields. The `state` field will either be `validated` or `failed` and represents the finalized status of that transaction. The `result` field will be `tesSUCCESS` if the `state` was validated. If the transaction failed, `result` will contain the `rippled` or `ripple-lib` error code. /// /// Notifications have `next_notification_url` and `previous_notification_url`'s. Account notifications can be polled by continuously following the `next_notification_url`, and handling the resultant notifications, until the `next_notification_url` is an empty string. This means that there are no new notifications but, as soon as there are, querying the same URL that produced this notification in the first place will return the same notification but with the `next_notification_url` set. /// /// </summary> /// <param name="hash">Notification hash</param> /// <param name="client">A RippleRestClient used for this request.</param> /// <returns>Notification instance</returns> /// <exception cref="RippleRestException">Request failed.</exception> public Notification GetNotification(RippleRestClient client, string hash) { var result = client.RestClient.Execute<GetNotificationResponse>(client.CreateGetRequest("v1/accounts/{0}/notifications/{1}", Address, hash)); client.HandleRestResponseErrors(result); result.Data.Notification.Account = this.Address; return result.Data.Notification; }
public void InitializeTest() { client = new RippleRestClient(restServer); }
/// <summary> /// Returns an individual payment. /// </summary> /// <param name="hash">Payment hash or client resource ID</param> /// <param name="client">A RippleRestClient used for this request.</param> /// <returns>Payment instance</returns> /// <exception cref="RippleRestException">Request failed.</exception> public Payment GetPayment(RippleRestClient client, string hash) { var result = client.RestClient.Execute<GetPaymentResponse>(client.CreateGetRequest("v1/accounts/{0}/payments/{1}", Address, hash)); client.HandleRestResponseErrors(result); return result.Data.Payment; }