Exemple #1
0
        private async Task <List <RippleTransaction> > GetRippleTransactions(string address)
        {
            var    txs          = new List <RippleTransaction>();
            object pagingMarker = null;

            do
            {
                var request = new FlurlRequest(_settings.RpcUrl);

                request.Settings.JsonSerializer = new NewtonsoftJsonSerializer(new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                });

                if (!string.IsNullOrEmpty(_settings.RpcUsername))
                {
                    request = request.WithBasicAuth(_settings.RpcUsername, _settings.RpcPassword);
                }

                var response = await request
                               .PostJsonAsync(new RippleAccountTransactionsRequest(address, marker : pagingMarker))
                               .ReceiveJson <RippleAccountTransactionsResponse>();

                if (!string.IsNullOrEmpty(response.Result.Error))
                {
                    throw new InvalidOperationException($"XRP request error: {response.Result.ErrorMessage ?? response.Result.Error}");
                }

                txs.AddRange(response.Result.Transactions);

                pagingMarker = response.Result.Marker;
            } while (pagingMarker != null);

            return(txs);
        }
        public async Task <IRwsResponse> SendRequestAsync(IRwsRequest request, int?timeout = null)
        {
            var client = new FlurlRequest(Url.Combine(BaseUrl, request.UrlPath()));

            if (timeout != null)
            {
                client.WithTimeout((int)timeout);
            }

            if (request.RequiresAuthentication)
            {
                client.WithBasicAuth(_username, _password);
            }

            client.WithHeaders(request.Headers);

            var stopwatch = Stopwatch.StartNew();

            HttpResponseMessage response = null;

            try {
                response = await client.AllowAnyHttpStatus().SendAsync(request.Method, request.RequestBody);
            } catch (FlurlHttpTimeoutException ex)
            {
                throw new RwsException($"Connection timeout for {client.Url.ToString()}", ex);
            }

            stopwatch.Stop();

            LastResult  = response;
            RequestTime = stopwatch.Elapsed;

            RwsExceptionHandler.Parse(response);

            return(request.Result(response));
        }