public async Task <ActionResult> GetAddressHistory(string paymentAddress, int noTxList = 0, int?from = null, int?to = null)
        {
            if (!Validations.IsValidPaymentAddress(paymentAddress))
            {
                return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, paymentAddress + " is not a valid Base58 address"));
            }

            Utils.CheckIfChainIsFresh(chain_, config_.AcceptStaleRequests);
            var balance = await GetBalance(paymentAddress);

            var historyJson = new GetAddressHistoryResponse();

            historyJson.addrStr          = paymentAddress;
            historyJson.balance          = Utils.SatoshisToCoinUnits(balance.Balance);
            historyJson.balanceSat       = balance.Balance;
            historyJson.totalReceived    = Utils.SatoshisToCoinUnits(balance.Received);
            historyJson.totalReceivedSat = balance.Received;
            historyJson.totalSent        = Utils.SatoshisToCoinUnits(balance.Sent);
            historyJson.totalSentSat     = balance.Sent;
            historyJson.txApperances     = balance.Transactions.Count;
            Tuple <uint, Int64> unconfirmedSummary = await GetUnconfirmedSummary(paymentAddress);

            historyJson.unconfirmedBalance       = Utils.SatoshisToCoinUnits(unconfirmedSummary.Item2);
            historyJson.unconfirmedBalanceSat    = unconfirmedSummary.Item2;
            historyJson.unconfirmedTxAppearances = unconfirmedSummary.Item1;
            if (noTxList == 0)
            {
                Tuple <string[], string> addressTxs = GetAddressTransactions(balance.Transactions, from, to);
                if (addressTxs.Item1 == null)
                {
                    return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, addressTxs.Item2));
                }
                historyJson.transactions = addressTxs.Item1;
            }
            return(Json(historyJson));
        }
Beispiel #2
0
        public async Task <ActionResult> GetAddressHistory([FromRoute] string paymentAddress, [FromQuery] int noTxList = 0, [FromQuery] int from = 0,
                                                           [FromQuery] int to = 0, [FromQuery] bool returnLegacyAddresses = false)
        {
            Stopwatch stopWatch = Stopwatch.StartNew();

            if (!PaymentAddress.TryParse(paymentAddress, out PaymentAddress paymentAddressObject))
            {
                return(BadRequest(paymentAddress + " is not a valid address"));
            }

            statsGetAddressHistory[0] = stopWatch.ElapsedMilliseconds;

            Utils.CheckIfChainIsFresh(chain_, config_.AcceptStaleRequests);

            var balance = await GetBalance(paymentAddress, noTxList == 0, stopWatch);

            statsGetAddressHistory[4] = stopWatch.ElapsedMilliseconds;

            var historyJson = new GetAddressHistoryResponse
            {
                addrStr          = Utils.FormatAddress(paymentAddressObject, returnLegacyAddresses),
                balance          = Utils.SatoshisToCoinUnits(balance.Balance),
                balanceSat       = balance.Balance,
                totalReceived    = Utils.SatoshisToCoinUnits(balance.Received),
                totalReceivedSat = balance.Received,
                totalSent        = Utils.SatoshisToCoinUnits(balance.Sent),
                totalSentSat     = balance.Sent,
                txAppearances    = balance.TxCount,
                txApperances     = balance.TxCount
            };

            Tuple <ulong, Int64> unconfirmedSummary = await GetUnconfirmedSummary(paymentAddress);

            statsGetAddressHistory[5] = stopWatch.ElapsedMilliseconds;

            historyJson.unconfirmedBalance       = Utils.SatoshisToCoinUnits(unconfirmedSummary.Item2);
            historyJson.unconfirmedBalanceSat    = unconfirmedSummary.Item2;
            historyJson.unconfirmedTxAppearances = unconfirmedSummary.Item1;
            historyJson.unconfirmedTxApperances  = unconfirmedSummary.Item1;

            if (noTxList == 0)
            {
                Tuple <string[], string> addressTxs = GetAddressTransactions(balance.Transactions, from, to);
                statsGetAddressHistory[6] = stopWatch.ElapsedMilliseconds;

                if (addressTxs.Item1 == null)
                {
                    return(BadRequest(addressTxs.Item2));
                }
                historyJson.transactions = addressTxs.Item1;
            }
            else
            {
                historyJson.transactions = new string[0];
            }

            statsGetAddressHistory[7] = stopWatch.ElapsedMilliseconds;
            logger_.LogDebug("Finished process addr request (ms): " + statsGetAddressHistory[0] + "\t" + statsGetAddressHistory[1] + "\t" + statsGetAddressHistory[2] + "\t" + statsGetAddressHistory[3]
                             + "\t" + statsGetAddressHistory[4] + "\t" + statsGetAddressHistory[5] + "\t" + statsGetAddressHistory[6] + "\t" + statsGetAddressHistory[7]);
            return(Json(historyJson));
        }