@ledgerhq/coin-sui 0.12.0-nightly.3 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +24 -23
- package/lib/api/index.integration.test.js +2 -9
- package/lib/api/index.integration.test.js.map +1 -1
- package/lib/api/index.test.js +2 -2
- package/lib/api/index.test.js.map +1 -1
- package/lib/logic/listOperations.d.ts +3 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +3 -3
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +39 -43
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/network/index.d.ts +1 -1
- package/lib/network/sdk.d.ts +5 -9
- package/lib/network/sdk.d.ts.map +1 -1
- package/lib/network/sdk.js +26 -53
- package/lib/network/sdk.js.map +1 -1
- package/lib/network/sdk.test.js +170 -272
- package/lib/network/sdk.test.js.map +1 -1
- package/lib-es/api/index.integration.test.js +2 -9
- package/lib-es/api/index.integration.test.js.map +1 -1
- package/lib-es/api/index.test.js +2 -2
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +3 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +4 -4
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +40 -44
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/network/index.d.ts +1 -1
- package/lib-es/network/sdk.d.ts +5 -9
- package/lib-es/network/sdk.d.ts.map +1 -1
- package/lib-es/network/sdk.js +26 -53
- package/lib-es/network/sdk.js.map +1 -1
- package/lib-es/network/sdk.test.js +170 -272
- package/lib-es/network/sdk.test.js.map +1 -1
- package/package.json +9 -9
- package/src/api/index.integration.test.ts +2 -10
- package/src/api/index.test.ts +2 -2
- package/src/logic/listOperations.test.ts +41 -45
- package/src/logic/listOperations.ts +4 -4
- package/src/network/sdk.test.ts +207 -312
- package/src/network/sdk.ts +31 -69
package/src/network/sdk.ts
CHANGED
|
@@ -24,7 +24,6 @@ import type {
|
|
|
24
24
|
BlockTransaction,
|
|
25
25
|
BlockOperation,
|
|
26
26
|
Operation as Op,
|
|
27
|
-
Page,
|
|
28
27
|
Stake,
|
|
29
28
|
StakeState,
|
|
30
29
|
AssetInfo,
|
|
@@ -319,7 +318,6 @@ export function transactionToOperation(
|
|
|
319
318
|
return {
|
|
320
319
|
id: encodeOperationId(accountId, hash, type),
|
|
321
320
|
accountId,
|
|
322
|
-
// warning this is false:
|
|
323
321
|
blockHash: hash,
|
|
324
322
|
blockHeight: BLOCK_HEIGHT,
|
|
325
323
|
date: getOperationDate(transaction),
|
|
@@ -349,6 +347,7 @@ export function transactionToOp(address: string, transaction: SuiTransactionBloc
|
|
|
349
347
|
block: {
|
|
350
348
|
// agreed to return bigint
|
|
351
349
|
height: BigInt(transaction.checkpoint || "") as unknown as number,
|
|
350
|
+
hash,
|
|
352
351
|
time: getOperationDate(transaction),
|
|
353
352
|
},
|
|
354
353
|
},
|
|
@@ -450,22 +449,14 @@ export const getOperations = async (
|
|
|
450
449
|
accountId: string,
|
|
451
450
|
addr: string,
|
|
452
451
|
cursor?: QueryTransactionBlocksParams["cursor"],
|
|
453
|
-
order?: "asc" | "desc",
|
|
454
452
|
): Promise<Operation[]> =>
|
|
455
453
|
withApi(async api => {
|
|
456
|
-
|
|
457
|
-
if (order) {
|
|
458
|
-
rpcOrder = order === "asc" ? "ascending" : "descending";
|
|
459
|
-
} else {
|
|
460
|
-
rpcOrder = cursor ? "ascending" : "descending";
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
const sendOps = await loadOperations({
|
|
454
|
+
const sentOps = await loadOperations({
|
|
464
455
|
api,
|
|
465
456
|
addr,
|
|
466
457
|
type: "OUT",
|
|
467
458
|
cursor,
|
|
468
|
-
order:
|
|
459
|
+
order: cursor ? "ascending" : "descending",
|
|
469
460
|
operations: [],
|
|
470
461
|
});
|
|
471
462
|
const receivedOps = await loadOperations({
|
|
@@ -473,51 +464,38 @@ export const getOperations = async (
|
|
|
473
464
|
addr,
|
|
474
465
|
type: "IN",
|
|
475
466
|
cursor,
|
|
476
|
-
order:
|
|
467
|
+
order: cursor ? "ascending" : "descending",
|
|
477
468
|
operations: [],
|
|
478
469
|
});
|
|
479
|
-
|
|
480
|
-
const rawTransactions = filterOperations(sendOps, receivedOps, rpcOrder, !cursor);
|
|
470
|
+
const rawTransactions = filterOperations(sentOps, receivedOps, cursor);
|
|
481
471
|
|
|
482
|
-
return rawTransactions.
|
|
483
|
-
transactionToOperation(accountId, addr, transaction),
|
|
484
|
-
);
|
|
472
|
+
return rawTransactions.map(transaction => transactionToOperation(accountId, addr, transaction));
|
|
485
473
|
});
|
|
486
474
|
|
|
487
475
|
export const filterOperations = (
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
// When we've reached the limit for either sent or received operations,
|
|
476
|
+
operationList1: SuiTransactionBlockResponse[],
|
|
477
|
+
operationList2: SuiTransactionBlockResponse[],
|
|
478
|
+
cursor: string | null | undefined,
|
|
479
|
+
) => {
|
|
480
|
+
let filterTimestamp = 0;
|
|
481
|
+
|
|
482
|
+
// When restoring state (no cursor provided) and we've reached the limit for either sent or received operations,
|
|
496
483
|
// we filter out extra operations to maintain correct chronological order
|
|
497
484
|
if (
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
(
|
|
502
|
-
receiveOps.operations.length === TRANSACTIONS_LIMIT)
|
|
485
|
+
!cursor &&
|
|
486
|
+
operationList1.length &&
|
|
487
|
+
operationList2.length &&
|
|
488
|
+
(operationList1.length === TRANSACTIONS_LIMIT || operationList2.length === TRANSACTIONS_LIMIT)
|
|
503
489
|
) {
|
|
504
|
-
const
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
);
|
|
508
|
-
if (sendTime >= receiveTime) {
|
|
509
|
-
nextCursor = sendOps.cursor;
|
|
510
|
-
filterTimestamp = sendTime;
|
|
511
|
-
} else {
|
|
512
|
-
nextCursor = receiveOps.cursor;
|
|
513
|
-
filterTimestamp = receiveTime;
|
|
514
|
-
}
|
|
490
|
+
const aTime = operationList1[operationList1.length - 1].timestampMs ?? 0;
|
|
491
|
+
const bTime = operationList2[operationList2.length - 1].timestampMs ?? 0;
|
|
492
|
+
filterTimestamp = Math.max(Number(aTime), Number(bTime));
|
|
515
493
|
}
|
|
516
|
-
const result = [...
|
|
494
|
+
const result = [...operationList1, ...operationList2]
|
|
517
495
|
.sort((a, b) => Number(b.timestampMs) - Number(a.timestampMs))
|
|
518
496
|
.filter(op => Number(op.timestampMs) >= filterTimestamp);
|
|
519
497
|
|
|
520
|
-
return
|
|
498
|
+
return uniqBy(result, tx => tx.digest);
|
|
521
499
|
};
|
|
522
500
|
|
|
523
501
|
/**
|
|
@@ -527,22 +505,14 @@ export const getListOperations = async (
|
|
|
527
505
|
addr: string,
|
|
528
506
|
cursor: QueryTransactionBlocksParams["cursor"] = null,
|
|
529
507
|
withApiImpl: typeof withApi = withApi,
|
|
530
|
-
|
|
531
|
-
): Promise<Page<Op>> =>
|
|
508
|
+
): Promise<Op[]> =>
|
|
532
509
|
withApiImpl(async api => {
|
|
533
|
-
let rpcOrder: "ascending" | "descending";
|
|
534
|
-
if (order) {
|
|
535
|
-
rpcOrder = order === "asc" ? "ascending" : "descending";
|
|
536
|
-
} else {
|
|
537
|
-
rpcOrder = cursor ? "ascending" : "descending";
|
|
538
|
-
}
|
|
539
|
-
|
|
540
510
|
const opsOut = await loadOperations({
|
|
541
511
|
api,
|
|
542
512
|
addr,
|
|
543
513
|
type: "OUT",
|
|
544
514
|
cursor,
|
|
545
|
-
order:
|
|
515
|
+
order: cursor ? "ascending" : "descending",
|
|
546
516
|
operations: [],
|
|
547
517
|
});
|
|
548
518
|
const opsIn = await loadOperations({
|
|
@@ -550,15 +520,12 @@ export const getListOperations = async (
|
|
|
550
520
|
addr,
|
|
551
521
|
type: "IN",
|
|
552
522
|
cursor,
|
|
553
|
-
order:
|
|
523
|
+
order: cursor ? "ascending" : "descending",
|
|
554
524
|
operations: [],
|
|
555
525
|
});
|
|
556
|
-
const list = filterOperations(opsIn, opsOut,
|
|
526
|
+
const list = filterOperations(opsIn, opsOut, cursor);
|
|
557
527
|
|
|
558
|
-
return
|
|
559
|
-
items: list.operations.map(t => transactionToOp(addr, t)),
|
|
560
|
-
next: list.cursor ?? undefined,
|
|
561
|
-
};
|
|
528
|
+
return list.map(t => transactionToOp(addr, t));
|
|
562
529
|
});
|
|
563
530
|
|
|
564
531
|
/**
|
|
@@ -748,11 +715,6 @@ export const executeTransactionBlock = async (params: ExecuteTransactionBlockPar
|
|
|
748
715
|
return api.executeTransactionBlock(params);
|
|
749
716
|
});
|
|
750
717
|
|
|
751
|
-
type LoadOperationResponse = {
|
|
752
|
-
operations: SuiTransactionBlockResponse[];
|
|
753
|
-
cursor?: QueryTransactionBlocksParams["cursor"];
|
|
754
|
-
};
|
|
755
|
-
|
|
756
718
|
/**
|
|
757
719
|
* Fetch operations for a specific address and type until the limit is reached
|
|
758
720
|
*/
|
|
@@ -768,10 +730,10 @@ export const loadOperations = async ({
|
|
|
768
730
|
operations: PaginatedTransactionResponse["data"];
|
|
769
731
|
order: "ascending" | "descending";
|
|
770
732
|
cursor?: QueryTransactionBlocksParams["cursor"];
|
|
771
|
-
}): Promise<
|
|
733
|
+
}): Promise<PaginatedTransactionResponse["data"]> => {
|
|
772
734
|
try {
|
|
773
735
|
if (order === "descending" && operations.length >= TRANSACTIONS_LIMIT) {
|
|
774
|
-
return
|
|
736
|
+
return operations;
|
|
775
737
|
}
|
|
776
738
|
|
|
777
739
|
const { data, nextCursor, hasNextPage } = await queryTransactions({
|
|
@@ -782,7 +744,7 @@ export const loadOperations = async ({
|
|
|
782
744
|
|
|
783
745
|
operations.push(...data);
|
|
784
746
|
if (!hasNextPage) {
|
|
785
|
-
return
|
|
747
|
+
return operations;
|
|
786
748
|
}
|
|
787
749
|
|
|
788
750
|
await loadOperations({ ...params, cursor: nextCursor, operations, order });
|
|
@@ -797,7 +759,7 @@ export const loadOperations = async ({
|
|
|
797
759
|
}
|
|
798
760
|
}
|
|
799
761
|
|
|
800
|
-
return
|
|
762
|
+
return operations;
|
|
801
763
|
};
|
|
802
764
|
|
|
803
765
|
/**
|