Skip to content

Commit

Permalink
work on xrp coin module
Browse files Browse the repository at this point in the history
  • Loading branch information
Salim-belkhir committed Dec 18, 2024
1 parent 3d9ea5c commit 00cf86d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libs/coin-modules/coin-xrp/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function operations(
address: string,
{ limit, start }: Pagination,
): Promise<[Operation[], number]> {
const [ops, index] = await listOperations(address, { limit, mostRecentIndex: start });
const [ops, index] = await listOperations(address, { limit, startAt: start ?? 0 });
return [
ops.map(op => {
const { simpleType, blockHash, blockTime, ...rest } = op;
Expand Down
3 changes: 1 addition & 2 deletions libs/coin-modules/coin-xrp/src/logic/listOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ export async function listOperations(
options = {
...options,
// if there is no ops, it might be after a clear and we prefer to pull from the oldest possible history
ledger_index_min: Math.max(startAt ?? 0, minLedgerVersion),
ledger_index_min: Math.max(startAt, minLedgerVersion),
};
}

const transactions = await getTransactions(address, options);

return [
transactions
.filter(op => op.tx_json.TransactionType === "Payment")
.map(convertToCoreOperation(address)),
transactions.slice(-1)[0].tx_json.ledger_index - 1, // Returns the next index to start from for pagination
];
Expand Down
6 changes: 3 additions & 3 deletions libs/coin-modules/coin-xrp/src/network/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ export const getServerInfos = async (): Promise<ServerInfoResponse> => {

export const getTransactions = async (
address: string,
options: { ledger_index_min?: number; ledger_index_max?: number; limit?: number} | undefined,
options: { ledger_index_min?: number; ledger_index_max?: number; limit?: number } | undefined,
): Promise<XrplOperation[]> => {
const result = await rpcCall<AccountTxResponse>("account_tx", {
account: address,
ledger_index: "validated",
...options,
api_version: 2,
tx_type: "Payment",
});

return result.transactions;
Expand Down Expand Up @@ -110,7 +110,7 @@ async function rpcCall<T extends object>(
});

if (isResponseStatus(result) && result.status !== "success") {
throw new Error(`couldn't fetch ${method} with params ${params}`);
throw new Error(`couldn't fetch ${method} with params ${JSON.stringify(params)}`);
}

return result;
Expand Down

0 comments on commit 00cf86d

Please sign in to comment.