@ledgerhq/coin-hypercore 0.4.0 → 0.4.2
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/CHANGELOG.md +12 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +2 -1
- package/lib/api/index.js.map +1 -1
- package/lib/api/lastBlock.d.ts +3 -0
- package/lib/api/lastBlock.d.ts.map +1 -0
- package/lib/api/lastBlock.js +16 -0
- package/lib/api/lastBlock.js.map +1 -0
- package/lib/api/listOperations.d.ts +1 -1
- package/lib/api/listOperations.d.ts.map +1 -1
- package/lib/api/listOperations.js +3 -10
- package/lib/api/listOperations.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +2 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/lastBlock.d.ts +3 -0
- package/lib-es/api/lastBlock.d.ts.map +1 -0
- package/lib-es/api/lastBlock.js +13 -0
- package/lib-es/api/lastBlock.js.map +1 -0
- package/lib-es/api/listOperations.d.ts +1 -1
- package/lib-es/api/listOperations.d.ts.map +1 -1
- package/lib-es/api/listOperations.js +3 -10
- package/lib-es/api/listOperations.js.map +1 -1
- package/package.json +2 -2
- package/src/api/index.integ.test.ts +3 -5
- package/src/api/index.ts +2 -1
- package/src/api/lastBlock.test.ts +17 -0
- package/src/api/lastBlock.ts +15 -0
- package/src/api/listOperations.test.ts +9 -11
- package/src/api/listOperations.ts +3 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ledgerhq/coin-hypercore
|
|
2
2
|
|
|
3
|
+
## 0.4.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#754](https://github.com/LedgerHQ/coin-modules/pull/754) [`207701b`](https://github.com/LedgerHQ/coin-modules/commit/207701baed385e19350dd49d407ad51877940745) Thanks [@YazhuEth](https://github.com/YazhuEth)! - Implement `lastBlock` so the generic coin framework can synchronize HyperCore accounts. It previously threw `notSupported`, which broke account discovery/import. The perps proxy exposes no block height for actions, so both `lastBlock` and `listOperations` now use a unix-second timestamp as a monotonic pseudo-height (settlement time for operations, current time for `lastBlock`). This keeps settled deposits/withdrawals showing as confirmed instead of stuck "pending".
|
|
8
|
+
|
|
9
|
+
## 0.4.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#740](https://github.com/LedgerHQ/coin-modules/pull/740) [`0f6c4b1`](https://github.com/LedgerHQ/coin-modules/commit/0f6c4b1398b83ec4d291f69b7b112ff1a019ef14) Thanks [@YazhuEth](https://github.com/YazhuEth)! - Make `listOperations` lenient: ignore `minHeight` and `order` instead of throwing, consistent with the other coin-modules
|
|
14
|
+
|
|
3
15
|
## 0.4.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/lib/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,2CAA2C,CAAA;AAC5F,OAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,2CAA2C,CAAA;AAC5F,OAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAK5D,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,aAAa,CAuBhE"}
|
package/lib/api/index.js
CHANGED
|
@@ -9,11 +9,12 @@ exports.createApi = createApi;
|
|
|
9
9
|
const index_1 = require("@ledgerhq/coin-module-framework/api/index");
|
|
10
10
|
const config_1 = __importDefault(require("../config"));
|
|
11
11
|
const getBalance_1 = require("./getBalance");
|
|
12
|
+
const lastBlock_1 = require("./lastBlock");
|
|
12
13
|
const listOperations_1 = require("./listOperations");
|
|
13
14
|
function createApi(config) {
|
|
14
15
|
config_1.default.setCoinConfig(() => ({ ...config, status: { type: 'active' } }));
|
|
15
16
|
return {
|
|
16
|
-
lastBlock:
|
|
17
|
+
lastBlock: lastBlock_1.lastBlock,
|
|
17
18
|
getBlockInfo: (0, index_1.notSupported)('getBlockInfo'),
|
|
18
19
|
getBlock: (0, index_1.notSupported)('getBlock'),
|
|
19
20
|
call: (0, index_1.notSupported)('call'),
|
package/lib/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;;;;AAQtC,8BAuBC;AA7BD,qEAA4F;AAC5F,uDAA4D;AAC5D,6CAAyC;AACzC,2CAAuC;AACvC,qDAAiD;AAEjD,SAAgB,SAAS,CAAC,MAAuB;IAC/C,gBAAU,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAA;IAE3E,OAAO;QACL,SAAS,EAAT,qBAAS;QACT,YAAY,EAAE,IAAA,oBAAY,EAAC,cAAc,CAAC;QAC1C,QAAQ,EAAE,IAAA,oBAAY,EAAC,UAAU,CAAC;QAClC,IAAI,EAAE,IAAA,oBAAY,EAAC,MAAM,CAAC;QAC1B,aAAa,EAAE,IAAA,oBAAY,EAAC,eAAe,CAAC;QAC5C,UAAU,EAAV,uBAAU;QACV,cAAc,EAAd,+BAAc;QACd,SAAS,EAAE,IAAA,oBAAY,EAAC,WAAW,CAAC;QACpC,UAAU,EAAE,IAAA,oBAAY,EAAC,YAAY,CAAC;QACtC,gBAAgB,EAAE,IAAA,oBAAY,EAAC,kBAAkB,CAAC;QAClD,mBAAmB,EAAE,IAAA,oBAAY,EAAC,qBAAqB,CAAC;QACxD,YAAY,EAAE,IAAA,oBAAY,EAAC,cAAc,CAAC;QAC1C,OAAO,EAAE,IAAA,oBAAY,EAAC,SAAS,CAAC;QAChC,SAAS,EAAE,IAAA,oBAAY,EAAC,WAAW,CAAC;QACpC,cAAc,EAAE,IAAA,oBAAY,EAAC,gBAAgB,CAAC;QAC9C,eAAe,EAAE,IAAA,oBAAY,EAAC,iBAAiB,CAAC;QAChD,eAAe,EAAE,IAAA,oBAAY,EAAC,iBAAiB,CAAC;QAChD,oBAAoB,EAAE,IAAA,oBAAY,EAAC,sBAAsB,CAAC;KAC3D,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lastBlock.d.ts","sourceRoot":"","sources":["../../src/api/lastBlock.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAA;AAI1E,wBAAsB,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,CAOpD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.lastBlock = lastBlock;
|
|
6
|
+
// The proxy exposes no block height; use a unix-second timestamp as a monotonic height (matching
|
|
7
|
+
// listOperations) so operations resolve as confirmed.
|
|
8
|
+
async function lastBlock() {
|
|
9
|
+
const time = new Date();
|
|
10
|
+
return {
|
|
11
|
+
height: Math.floor(time.getTime() / 1000),
|
|
12
|
+
hash: '',
|
|
13
|
+
time,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=lastBlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lastBlock.js","sourceRoot":"","sources":["../../src/api/lastBlock.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAMtC,8BAOC;AATD,iGAAiG;AACjG,sDAAsD;AAC/C,KAAK,UAAU,SAAS;IAC7B,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;IACvB,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;QACzC,IAAI,EAAE,EAAE;QACR,IAAI;KACL,CAAA;AACH,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ListOperationsOptions, Operation, Page } from '@ledgerhq/coin-module-framework/api/types';
|
|
2
|
-
export declare function listOperations(address: string, {
|
|
2
|
+
export declare function listOperations(address: string, { cursor, limit }: ListOperationsOptions): Promise<Page<Operation>>;
|
|
3
3
|
//# sourceMappingURL=listOperations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qBAAqB,EACrB,SAAS,EACT,IAAI,EACL,MAAM,2CAA2C,CAAA;AAmDlD,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,EAAE,
|
|
1
|
+
{"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qBAAqB,EACrB,SAAS,EACT,IAAI,EACL,MAAM,2CAA2C,CAAA;AAmDlD,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,qBAAqB,GACvC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAc1B"}
|
|
@@ -24,8 +24,8 @@ function toOperation(address, dto) {
|
|
|
24
24
|
asset: { type: 'native' },
|
|
25
25
|
tx: {
|
|
26
26
|
hash: dto.id,
|
|
27
|
-
//
|
|
28
|
-
block: { height:
|
|
27
|
+
// No block height from the proxy; use the settlement time (unix seconds) as a monotonic height.
|
|
28
|
+
block: { height: Math.floor(date.getTime() / 1000), hash: '', time: date },
|
|
29
29
|
fees: 0n,
|
|
30
30
|
date,
|
|
31
31
|
failed: dto.status.toUpperCase() === 'FAILED',
|
|
@@ -42,14 +42,7 @@ function parseCursor(cursor) {
|
|
|
42
42
|
}
|
|
43
43
|
return offset;
|
|
44
44
|
}
|
|
45
|
-
async function listOperations(address, {
|
|
46
|
-
// The proxy has no block height and always returns actions newest-first (descending).
|
|
47
|
-
if (minHeight > 0) {
|
|
48
|
-
throw new Error('listOperations with a minHeight is not supported');
|
|
49
|
-
}
|
|
50
|
-
if (order === 'asc') {
|
|
51
|
-
throw new Error('listOperations with an ascending order is not supported');
|
|
52
|
-
}
|
|
45
|
+
async function listOperations(address, { cursor, limit }) {
|
|
53
46
|
const offset = parseCursor(cursor);
|
|
54
47
|
const pageLimit = limit ?? DEFAULT_LIMIT;
|
|
55
48
|
const page = await (0, yield_1.fetchActions)(address, offset, pageLimit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAyDtC,
|
|
1
|
+
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,sCAAsC;;AAyDtC,wCAiBC;AAnED,4CAMyB;AACzB,oCAAwC;AAExC,MAAM,aAAa,GAAG,GAAG,CAAA;AAEzB,4FAA4F;AAC5F,SAAS,iBAAiB,CAAC,MAAiB;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,KAAK,mBAAW,IAAI,MAAM,CAAC,MAAM,KAAK,uBAAe,CAAA;I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M,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,8CAA8C,MAAM,EAAE,CAAC,CAAA;IACzE,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAEM,KAAK,UAAU,cAAc,CAClC,OAAe,EACf,EAAE,MAAM,EAAE,KAAK,EAAyB;IAExC,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IAClC,MAAM,SAAS,GAAG,KAAK,IAAI,aAAa,CAAA;IACxC,MAAM,IAAI,GAAG,MAAM,IAAA,oBAAY,EAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;IAE3D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;IAEhG,kFAAkF;IAClF,uFAAuF;IACvF,8CAA8C;IAC9C,MAAM,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;IAC7C,MAAM,IAAI,GAAG,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAErE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AACxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,2CAA2C,CAAA;AAC5F,OAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,2CAA2C,CAAA;AAC5F,OAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAK5D,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,aAAa,CAuBhE"}
|
package/lib-es/api/index.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
import { notSupported } from '@ledgerhq/coin-module-framework/api/index';
|
|
4
4
|
import coinConfig from '../config';
|
|
5
5
|
import { getBalance } from './getBalance';
|
|
6
|
+
import { lastBlock } from './lastBlock';
|
|
6
7
|
import { listOperations } from './listOperations';
|
|
7
8
|
export function createApi(config) {
|
|
8
9
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: 'active' } }));
|
|
9
10
|
return {
|
|
10
|
-
lastBlock
|
|
11
|
+
lastBlock,
|
|
11
12
|
getBlockInfo: notSupported('getBlockInfo'),
|
|
12
13
|
getBlock: notSupported('getBlock'),
|
|
13
14
|
call: notSupported('call'),
|
package/lib-es/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAEtC,OAAO,EAAsB,YAAY,EAAE,MAAM,2CAA2C,CAAA;AAC5F,OAAO,UAAoC,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,MAAM,UAAU,SAAS,CAAC,MAAuB;IAC/C,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAA;IAE3E,OAAO;QACL,SAAS
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,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ot":"","sources":["../../src/api/lastBlock.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAA;AAI1E,wBAAsB,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,CAOpD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// The proxy exposes no block height; use a unix-second timestamp as a monotonic height (matching
|
|
4
|
+
// listOperations) so operations resolve as confirmed.
|
|
5
|
+
export async function lastBlock() {
|
|
6
|
+
const time = new Date();
|
|
7
|
+
return {
|
|
8
|
+
height: Math.floor(time.getTime() / 1000),
|
|
9
|
+
hash: '',
|
|
10
|
+
time,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=lastBlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lastBlock.js","sourceRoot":"","sources":["../../src/api/lastBlock.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAItC,iGAAiG;AACjG,sDAAsD;AACtD,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAA;IACvB,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;QACzC,IAAI,EAAE,EAAE;QACR,IAAI;KACL,CAAA;AACH,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ListOperationsOptions, Operation, Page } from '@ledgerhq/coin-module-framework/api/types';
|
|
2
|
-
export declare function listOperations(address: string, {
|
|
2
|
+
export declare function listOperations(address: string, { cursor, limit }: ListOperationsOptions): Promise<Page<Operation>>;
|
|
3
3
|
//# sourceMappingURL=listOperations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qBAAqB,EACrB,SAAS,EACT,IAAI,EACL,MAAM,2CAA2C,CAAA;AAmDlD,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,EAAE,
|
|
1
|
+
{"version":3,"file":"listOperations.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qBAAqB,EACrB,SAAS,EACT,IAAI,EACL,MAAM,2CAA2C,CAAA;AAmDlD,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,qBAAqB,GACvC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAc1B"}
|
|
@@ -21,8 +21,8 @@ function toOperation(address, dto) {
|
|
|
21
21
|
asset: { type: 'native' },
|
|
22
22
|
tx: {
|
|
23
23
|
hash: dto.id,
|
|
24
|
-
//
|
|
25
|
-
block: { height:
|
|
24
|
+
// No block height from the proxy; use the settlement time (unix seconds) as a monotonic height.
|
|
25
|
+
block: { height: Math.floor(date.getTime() / 1000), hash: '', time: date },
|
|
26
26
|
fees: 0n,
|
|
27
27
|
date,
|
|
28
28
|
failed: dto.status.toUpperCase() === 'FAILED',
|
|
@@ -39,14 +39,7 @@ function parseCursor(cursor) {
|
|
|
39
39
|
}
|
|
40
40
|
return offset;
|
|
41
41
|
}
|
|
42
|
-
export async function listOperations(address, {
|
|
43
|
-
// The proxy has no block height and always returns actions newest-first (descending).
|
|
44
|
-
if (minHeight > 0) {
|
|
45
|
-
throw new Error('listOperations with a minHeight is not supported');
|
|
46
|
-
}
|
|
47
|
-
if (order === 'asc') {
|
|
48
|
-
throw new Error('listOperations with an ascending order is not supported');
|
|
49
|
-
}
|
|
42
|
+
export async function listOperations(address, { cursor, limit }) {
|
|
50
43
|
const offset = parseCursor(cursor);
|
|
51
44
|
const pageLimit = limit ?? DEFAULT_LIMIT;
|
|
52
45
|
const page = await fetchActions(address, offset, pageLimit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listOperations.js","sourceRoot":"","sources":["../../src/api/listOperations.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAOtC,OAAO,EAEL,WAAW,EACX,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,aAAa,GAAG,GAAG,CAAA;AAEzB,4FAA4F;AAC5F,SAAS,iBAAiB,CAAC,MAAiB;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,KAAK,eAAe,CAAA;IACrF,OAAO,UAAU,IAAI,MAAM,CAAC,WAAW,KAAK,IAAI,CAAA;AAClD,CAAC;AAED,SAAS,WAAW,CAAC,OAAe,EAAE,GAAc;IAClD,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,KAAK,WAAW,CAAA;IAC5C,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,CAAA;IACzC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;IAEvD,OAAO;QACL,EAAE,EAAE,GAAG,OAAO,IAAI,GAAG,CAAC,EAAE,EAAE;QAC1B,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;QAC9B,OAAO,EAAE,CAAC,OAAO,CAAC;QAClB,UAAU,EAAE,CAAC,OAAO,CAAC;QACrB,KAAK,EAAE,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC;QAC3C,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzB,EAAE,EAAE;YACF,IAAI,EAAE,GAAG,CAAC,EA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CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAErE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-hypercore",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Ledger Hypercore Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"author": "LEDGER SAS",
|
|
66
66
|
"license": "Apache-2.0",
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@ledgerhq/coin-module-framework": "^4.0.
|
|
68
|
+
"@ledgerhq/coin-module-framework": "^4.0.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@swc/core": "1.15.11",
|
|
@@ -11,7 +11,6 @@ describe('Hypercore Api (Alpaca stub)', () => {
|
|
|
11
11
|
const api = createApi({ node: 'https://api.hyperliquid.xyz' })
|
|
12
12
|
|
|
13
13
|
it.each<keyof typeof api>([
|
|
14
|
-
'lastBlock',
|
|
15
14
|
'getBlockInfo',
|
|
16
15
|
'getBlock',
|
|
17
16
|
'getValidators',
|
|
@@ -73,10 +72,9 @@ describe('Hypercore Api (Alpaca)', () => {
|
|
|
73
72
|
expect(all.some((op) => op.type === 'OUT')).toBe(true)
|
|
74
73
|
})
|
|
75
74
|
|
|
76
|
-
it('
|
|
77
|
-
await
|
|
78
|
-
|
|
79
|
-
)
|
|
75
|
+
it('ignores minHeight and order (returns results, no throw)', async () => {
|
|
76
|
+
const { items } = await api.listOperations(ADDRESS, { minHeight: 1, order: 'asc' })
|
|
77
|
+
expect(items.length).toBeGreaterThan(0)
|
|
80
78
|
})
|
|
81
79
|
})
|
|
82
80
|
})
|
package/src/api/index.ts
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
import { type CoinModuleApi, notSupported } from '@ledgerhq/coin-module-framework/api/index'
|
|
5
5
|
import coinConfig, { type HypercoreConfig } from '../config'
|
|
6
6
|
import { getBalance } from './getBalance'
|
|
7
|
+
import { lastBlock } from './lastBlock'
|
|
7
8
|
import { listOperations } from './listOperations'
|
|
8
9
|
|
|
9
10
|
export function createApi(config: HypercoreConfig): CoinModuleApi {
|
|
10
11
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: 'active' } }))
|
|
11
12
|
|
|
12
13
|
return {
|
|
13
|
-
lastBlock
|
|
14
|
+
lastBlock,
|
|
14
15
|
getBlockInfo: notSupported('getBlockInfo'),
|
|
15
16
|
getBlock: notSupported('getBlock'),
|
|
16
17
|
call: notSupported('call'),
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { lastBlock } from './lastBlock'
|
|
5
|
+
|
|
6
|
+
describe('lastBlock', () => {
|
|
7
|
+
it('returns a unix-second timestamp as a monotonic height (proxy exposes no block)', async () => {
|
|
8
|
+
const before = Math.floor(Date.now() / 1000)
|
|
9
|
+
const block = await lastBlock()
|
|
10
|
+
const after = Math.floor(Date.now() / 1000)
|
|
11
|
+
|
|
12
|
+
expect(block.height).toBeGreaterThanOrEqual(before)
|
|
13
|
+
expect(block.height).toBeLessThanOrEqual(after)
|
|
14
|
+
expect(block.hash).toBe('')
|
|
15
|
+
expect(block.time).toBeInstanceOf(Date)
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { BlockInfo } from '@ledgerhq/coin-module-framework/api/types'
|
|
5
|
+
|
|
6
|
+
// The proxy exposes no block height; use a unix-second timestamp as a monotonic height (matching
|
|
7
|
+
// listOperations) so operations resolve as confirmed.
|
|
8
|
+
export async function lastBlock(): Promise<BlockInfo> {
|
|
9
|
+
const time = new Date()
|
|
10
|
+
return {
|
|
11
|
+
height: Math.floor(time.getTime() / 1000),
|
|
12
|
+
hash: '',
|
|
13
|
+
time,
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -140,18 +140,16 @@ describe('listOperations', () => {
|
|
|
140
140
|
)
|
|
141
141
|
})
|
|
142
142
|
|
|
143
|
-
it('
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
})
|
|
143
|
+
it('ignores minHeight and order instead of throwing', async () => {
|
|
144
|
+
mockNetwork.mockResolvedValueOnce({
|
|
145
|
+
status: 200,
|
|
146
|
+
data: { total: 1, offset: 0, limit: 100, items: [action({ id: 'dep' })] },
|
|
147
|
+
})
|
|
149
148
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
)
|
|
154
|
-
expect(mockNetwork).not.toHaveBeenCalled()
|
|
149
|
+
const { items } = await listOperations(ADDRESS, { minHeight: 5, order: 'asc' })
|
|
150
|
+
|
|
151
|
+
expect(items).toHaveLength(1)
|
|
152
|
+
expect(mockNetwork).toHaveBeenCalled()
|
|
155
153
|
})
|
|
156
154
|
|
|
157
155
|
it('rejects an invalid cursor', async () => {
|
|
@@ -37,8 +37,8 @@ function toOperation(address: string, dto: ActionDto): Operation {
|
|
|
37
37
|
asset: { type: 'native' },
|
|
38
38
|
tx: {
|
|
39
39
|
hash: dto.id,
|
|
40
|
-
//
|
|
41
|
-
block: { height:
|
|
40
|
+
// No block height from the proxy; use the settlement time (unix seconds) as a monotonic height.
|
|
41
|
+
block: { height: Math.floor(date.getTime() / 1000), hash: '', time: date },
|
|
42
42
|
fees: 0n,
|
|
43
43
|
date,
|
|
44
44
|
failed: dto.status.toUpperCase() === 'FAILED',
|
|
@@ -58,16 +58,8 @@ function parseCursor(cursor: string | undefined): number {
|
|
|
58
58
|
|
|
59
59
|
export async function listOperations(
|
|
60
60
|
address: string,
|
|
61
|
-
{
|
|
61
|
+
{ cursor, limit }: ListOperationsOptions
|
|
62
62
|
): Promise<Page<Operation>> {
|
|
63
|
-
// The proxy has no block height and always returns actions newest-first (descending).
|
|
64
|
-
if (minHeight > 0) {
|
|
65
|
-
throw new Error('listOperations with a minHeight is not supported')
|
|
66
|
-
}
|
|
67
|
-
if (order === 'asc') {
|
|
68
|
-
throw new Error('listOperations with an ascending order is not supported')
|
|
69
|
-
}
|
|
70
|
-
|
|
71
63
|
const offset = parseCursor(cursor)
|
|
72
64
|
const pageLimit = limit ?? DEFAULT_LIMIT
|
|
73
65
|
const page = await fetchActions(address, offset, pageLimit)
|