-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- remove pending txs from transactions query - properly paginate transactions
- Loading branch information
1 parent
11fbcf0
commit eecbbd3
Showing
34 changed files
with
512 additions
and
613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 20 additions & 15 deletions
35
core/api/src/app/accounts/get-transactions-for-account.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
import { getTransactionsForWallets } from "../wallets" | ||
|
||
import { PartialResult } from "../partial-result" | ||
|
||
import { AccountValidator } from "@/domain/accounts" | ||
import { RepositoryError } from "@/domain/errors" | ||
import { WalletsRepository } from "@/services/mongoose" | ||
|
||
export const getTransactionsForAccountByWalletIds = async ({ | ||
account, | ||
walletIds, | ||
paginationArgs, | ||
rawPaginationArgs, | ||
}: { | ||
account: Account | ||
walletIds: WalletId[] | ||
paginationArgs?: PaginationArgs | ||
}): Promise<PartialResult<PaginatedArray<WalletTransaction>>> => { | ||
walletIds?: WalletId[] | ||
rawPaginationArgs: RawPaginationArgs | ||
}): Promise<PaginatedQueryResult<WalletTransaction> | ApplicationError> => { | ||
const walletsRepo = WalletsRepository() | ||
|
||
const wallets: Wallet[] = [] | ||
for (const walletId of walletIds) { | ||
const wallet = await walletsRepo.findById(walletId) | ||
if (wallet instanceof RepositoryError) return PartialResult.err(wallet) | ||
|
||
const accountValidator = AccountValidator(account) | ||
if (accountValidator instanceof Error) return PartialResult.err(accountValidator) | ||
const validateWallet = accountValidator.validateWalletForAccount(wallet) | ||
if (validateWallet instanceof Error) return PartialResult.err(validateWallet) | ||
if (walletIds) { | ||
for (const walletId of walletIds) { | ||
const wallet = await walletsRepo.findById(walletId) | ||
if (wallet instanceof RepositoryError) return wallet | ||
|
||
const accountValidator = AccountValidator(account) | ||
if (accountValidator instanceof Error) return accountValidator | ||
const validateWallet = accountValidator.validateWalletForAccount(wallet) | ||
if (validateWallet instanceof Error) return validateWallet | ||
|
||
wallets.push(wallet) | ||
wallets.push(wallet) | ||
} | ||
} else { | ||
const accountWallets = await walletsRepo.listByAccountId(account.id) | ||
if (accountWallets instanceof RepositoryError) return accountWallets | ||
wallets.push(...accountWallets) | ||
} | ||
|
||
return getTransactionsForWallets({ wallets, paginationArgs }) | ||
return getTransactionsForWallets({ wallets, rawPaginationArgs }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 32 additions & 38 deletions
70
core/api/src/app/wallets/get-transactions-by-addresses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,55 @@ | ||
import { memoSharingConfig } from "@/config" | ||
import { PartialResult } from "@/app/partial-result" | ||
import { MAX_PAGINATION_PAGE_SIZE, memoSharingConfig } from "@/config" | ||
|
||
import { LedgerError } from "@/domain/ledger" | ||
import { WalletTransactionHistory } from "@/domain/wallets" | ||
import { CouldNotFindError } from "@/domain/errors" | ||
|
||
import { getNonEndUserWalletIds, LedgerService } from "@/services/ledger" | ||
import { WalletOnChainPendingReceiveRepository } from "@/services/mongoose" | ||
import { checkedToPaginatedQueryArgs } from "@/domain/primitives" | ||
|
||
export const getTransactionsForWalletsByAddresses = async ({ | ||
wallets, | ||
addresses, | ||
paginationArgs, | ||
rawPaginationArgs, | ||
}: { | ||
wallets: Wallet[] | ||
addresses: OnChainAddress[] | ||
paginationArgs?: PaginationArgs | ||
}): Promise<PartialResult<PaginatedArray<WalletTransaction>>> => { | ||
const walletIds = wallets.map((wallet) => wallet.id) | ||
rawPaginationArgs: RawPaginationArgs | ||
}): Promise<PaginatedQueryResult<WalletTransaction> | ApplicationError> => { | ||
const paginationArgs = checkedToPaginatedQueryArgs({ | ||
paginationArgs: rawPaginationArgs, | ||
maxPageSize: MAX_PAGINATION_PAGE_SIZE, | ||
}) | ||
|
||
let pendingHistory = | ||
await WalletOnChainPendingReceiveRepository().listByWalletIdsAndAddresses({ | ||
walletIds, | ||
addresses, | ||
}) | ||
if (pendingHistory instanceof Error) { | ||
if (pendingHistory instanceof CouldNotFindError) { | ||
pendingHistory = [] | ||
} else { | ||
return PartialResult.err(pendingHistory) | ||
} | ||
if (paginationArgs instanceof Error) { | ||
return paginationArgs | ||
} | ||
|
||
const confirmedLedgerTxns = await LedgerService().getTransactionsByWalletIds({ | ||
const walletIds = wallets.map((wallet) => wallet.id) | ||
|
||
const ledgerTxs = await LedgerService().getTransactionsByWalletIdsAndAddresses({ | ||
walletIds, | ||
paginationArgs, | ||
addresses, | ||
}) | ||
if (confirmedLedgerTxns instanceof LedgerError) { | ||
return PartialResult.partial( | ||
{ slice: pendingHistory, total: pendingHistory.length }, | ||
confirmedLedgerTxns, | ||
) | ||
|
||
if (ledgerTxs instanceof LedgerError) { | ||
return ledgerTxs | ||
} | ||
const ledgerTransactions = confirmedLedgerTxns.slice.filter( | ||
(tx) => tx.address && addresses.includes(tx.address), | ||
) | ||
|
||
const confirmedHistory = WalletTransactionHistory.fromLedger({ | ||
ledgerTransactions, | ||
nonEndUserWalletIds: Object.values(await getNonEndUserWalletIds()), | ||
memoSharingConfig, | ||
}) | ||
|
||
const transactions = [...pendingHistory, ...confirmedHistory.transactions] | ||
const nonEndUserWalletIds = Object.values(await getNonEndUserWalletIds()) | ||
|
||
const txEdges = ledgerTxs.edges.map((edge) => { | ||
const transaction = WalletTransactionHistory.fromLedger({ | ||
txn: edge.node, | ||
nonEndUserWalletIds, | ||
memoSharingConfig, | ||
}) | ||
|
||
return PartialResult.ok({ | ||
slice: transactions, | ||
total: transactions.length, | ||
return { | ||
cursor: edge.cursor, | ||
node: transaction, | ||
} | ||
}) | ||
|
||
return { ...ledgerTxs, edges: txEdges } | ||
} |
Oops, something went wrong.