Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
fix(wallet): add delay to address and utxo calls
Browse files Browse the repository at this point in the history
Add delay to calls to block explorer to prevent blockstream
throttling.

TODO FIXME HACK

ISSUES: #317
  • Loading branch information
waldenraines authored and bucko13 committed Jun 29, 2023
1 parent cb96364 commit d9774c1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/block_explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import axios from "axios";
import BigNumber from "bignumber.js";
import { satoshisToBitcoins, blockExplorerAPIURL } from "unchained-bitcoin";

// FIXME: hack
const delay = () => {
return new Promise((resolve) => setTimeout(resolve, 500));
};

/**
* Fetch information for signing transactions from block explorer API
* @param {string} address - The address from which to obtain the information
Expand All @@ -17,6 +22,9 @@ export async function blockExplorerGetAddresesUTXOs(address, network) {
return await Promise.all(
utxos.map(async (utxo) => {
// FIXME: inefficient, need to cache here by utxo.txid
// FIXME: delay hack to prevent throttling
await delay();

const transactionResult = await axios.get(
blockExplorerAPIURL(`/tx/${utxo.txid}/hex`, network)
);
Expand All @@ -40,6 +48,9 @@ export async function blockExplorerGetAddresesUTXOs(address, network) {

export async function blockExplorerGetAddressStatus(address, network) {
try {
// FIXME: delay hack to prevent throttling
await delay();

const addressesult = await axios.get(
blockExplorerAPIURL(`/address/${address}`, network)
);
Expand Down

0 comments on commit d9774c1

Please sign in to comment.