Skip to content

Commit

Permalink
Fetch legacy and shelley utxos together
Browse files Browse the repository at this point in the history
  • Loading branch information
refi93 committed Oct 15, 2021
1 parent cfd8bb6 commit a7e3a8a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 1 addition & 3 deletions app/frontend/actions/common.ts
Expand Up @@ -49,11 +49,9 @@ export default (store: Store) => {
const prepareTxPlan = async (args: TxPlanArgs): Promise<TxPlanResult> => {
const state = getState()
try {
const utxos = getSourceAccountInfo(state).utxos

return await getWallet()
.getAccount(state.sourceAccountIndex)
.getTxPlan(args, utxos)
.getTxPlan(args, getSourceAccountInfo(state).utxos)
} catch (e) {
// TODO: refactor setErrorState to check all errors if there unexpected
if (
Expand Down
4 changes: 1 addition & 3 deletions app/frontend/wallet/account.ts
Expand Up @@ -438,9 +438,7 @@ const Account = ({config, cryptoProvider, blockchainExplorer, accountIndex}: Acc

async function getUtxos(): Promise<Array<UTxO>> {
const {legacy, base} = await myAddresses.discoverAllAddresses()
const baseUtxos = await blockchainExplorer.fetchUnspentTxOutputs(base)
const nonStakingUtxos = await blockchainExplorer.fetchUnspentTxOutputs(legacy)
return [...nonStakingUtxos, ...baseUtxos]
return await blockchainExplorer.fetchUnspentTxOutputs([...legacy, ...base])
}

async function getVisibleAddresses() {
Expand Down
11 changes: 8 additions & 3 deletions app/frontend/wallet/blockchain-explorer.ts
Expand Up @@ -233,17 +233,22 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
}

async function fetchUnspentTxOutputs(addresses: Array<string>): Promise<UTxO[]> {
const chunks = range(0, Math.ceil(addresses.length / gapLimit))
// utxos can be fetched by chunks of 50 (backend limit) instead of discovery gap limit, because
// differently from the rest of calls, these are not involved in address discovery
// so they don't have to align with the gap limit in order to always request the same
// addresses to hit the cache (the caching key is the stringified list of addresses requested)
const chunkSize = 50
const chunks = range(0, Math.ceil(addresses.length / chunkSize))

const url = `${ADALITE_CONFIG.ADALITE_BLOCKCHAIN_EXPLORER_URL}/api/bulk/addresses/utxo`
const response = (
await Promise.all(
chunks.map(async (index) => {
const beginIndex = index * gapLimit
const beginIndex = index * chunkSize
const response: BulkAdressesUtxoResponse = await request(
url,
'POST',
JSON.stringify(addresses.slice(beginIndex, beginIndex + gapLimit)),
JSON.stringify(addresses.slice(beginIndex, beginIndex + chunkSize)),
{
'Accept': 'application/json',
'Content-Type': 'application/json',
Expand Down

0 comments on commit a7e3a8a

Please sign in to comment.