Skip to content

Commit

Permalink
feat: modify getContractFundedVaults functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Jun 19, 2024
1 parent d95c8ec commit 9f35b9a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 11 additions & 5 deletions src/network-handlers/ethereum-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,25 @@ export class EthereumHandler {
let totalFetched = 0;
const fundedVaults: RawVault[] = [];

while (true) {
let shouldContinue = true;
while (shouldContinue) {
const fetchedVaults: RawVault[] =
await this.ethereumContracts.dlcManagerContract.getAllDLCs(
totalFetched,
totalFetched + amount
);
fundedVaults.push(...fetchedVaults.filter(vault => vault.status === VaultState.Funded));
const filteredVaults = fetchedVaults.filter(vault => vault.status === VaultState.Funded);
fundedVaults.push(...filteredVaults);

totalFetched += amount;
if (fetchedVaults.length !== amount) break;
shouldContinue = fetchedVaults.length === amount;
}

return fundedVaults;
} catch (error: any) {
throw new EthereumError(`Could not fetch Funded Vaults: ${error}`);
} catch (error) {
throw new EthereumError(
`Could not fetch Funded Vaults: ${error instanceof Error ? error.message : error}`
);
}
}
}
16 changes: 11 additions & 5 deletions src/network-handlers/read-only-ethereum-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,25 @@ export class ReadOnlyEthereumHandler {
let totalFetched = 0;
const fundedVaults: RawVault[] = [];

while (true) {
let shouldContinue = true;
while (shouldContinue) {
const fetchedVaults: RawVault[] =
await this.ethereumContracts.dlcManagerContract.getAllDLCs(
totalFetched,
totalFetched + amount
);
fundedVaults.push(...fetchedVaults.filter(vault => vault.status === VaultState.Funded));
const filteredVaults = fetchedVaults.filter(vault => vault.status === VaultState.Funded);
fundedVaults.push(...filteredVaults);

totalFetched += amount;
if (fetchedVaults.length !== amount) break;
shouldContinue = fetchedVaults.length === amount;
}

return fundedVaults;
} catch (error: any) {
throw new EthereumError(`Could not fetch Funded Vaults: ${error}`);
} catch (error) {
throw new EthereumError(
`Could not fetch Funded Vaults: ${error instanceof Error ? error.message : error}`
);
}
}
}

0 comments on commit 9f35b9a

Please sign in to comment.