@ledgerhq/coin-stellar 6.26.0 → 6.26.1
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/.oxlintrc.json +7 -0
- package/CHANGELOG.md +6 -0
- package/LICENSE +194 -0
- package/knip.json +12 -0
- package/lib/api/index.d.ts +5 -5
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +12 -10
- package/lib/api/index.js.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +2 -0
- package/lib/config.js.map +1 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +3 -1
- package/lib/constants.js.map +1 -1
- package/lib/logic/broadcast.d.ts.map +1 -1
- package/lib/logic/broadcast.js +2 -0
- package/lib/logic/broadcast.js.map +1 -1
- package/lib/logic/combine.d.ts +1 -1
- package/lib/logic/combine.d.ts.map +1 -1
- package/lib/logic/combine.js +2 -0
- package/lib/logic/combine.js.map +1 -1
- package/lib/logic/common.d.ts +1 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js +4 -2
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +10 -8
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +2 -0
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +4 -2
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +39 -34
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getBlockInfo.d.ts +1 -1
- package/lib/logic/getBlockInfo.d.ts.map +1 -1
- package/lib/logic/getBlockInfo.js +2 -0
- package/lib/logic/getBlockInfo.js.map +1 -1
- package/lib/logic/index.d.ts +12 -12
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +2 -0
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/lastBlock.d.ts +1 -1
- package/lib/logic/lastBlock.d.ts.map +1 -1
- package/lib/logic/lastBlock.js +2 -0
- package/lib/logic/lastBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +6 -4
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/sdkWrapper.d.ts +1 -1
- package/lib/logic/sdkWrapper.d.ts.map +1 -1
- package/lib/logic/sdkWrapper.js +2 -0
- package/lib/logic/sdkWrapper.js.map +1 -1
- package/lib/logic/utils.d.ts.map +1 -1
- package/lib/logic/utils.js +4 -2
- package/lib/logic/utils.js.map +1 -1
- package/lib/logic/validateAddress.d.ts +1 -1
- package/lib/logic/validateAddress.d.ts.map +1 -1
- package/lib/logic/validateAddress.js +2 -0
- package/lib/logic/validateAddress.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +2 -2
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js +21 -19
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic/validateMemo.d.ts +1 -1
- package/lib/logic/validateMemo.d.ts.map +1 -1
- package/lib/logic/validateMemo.js +7 -5
- package/lib/logic/validateMemo.js.map +1 -1
- package/lib/network/horizon.d.ts +6 -7
- package/lib/network/horizon.d.ts.map +1 -1
- package/lib/network/horizon.js +71 -68
- package/lib/network/horizon.js.map +1 -1
- package/lib/network/horizonLedgerErrors.d.ts.map +1 -1
- package/lib/network/horizonLedgerErrors.js +5 -3
- package/lib/network/horizonLedgerErrors.js.map +1 -1
- package/lib/network/index.d.ts +1 -1
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +2 -0
- package/lib/network/index.js.map +1 -1
- package/lib/network/serialization.d.ts +6 -4
- package/lib/network/serialization.d.ts.map +1 -1
- package/lib/network/serialization.js +95 -91
- package/lib/network/serialization.js.map +1 -1
- package/lib/polyfill.d.ts.map +1 -1
- package/lib/polyfill.js +6 -4
- package/lib/polyfill.js.map +1 -1
- package/lib/supportedFeatures.d.ts +1 -1
- package/lib/supportedFeatures.d.ts.map +1 -1
- package/lib/supportedFeatures.js +3 -1
- package/lib/supportedFeatures.js.map +1 -1
- package/lib/types/errors.d.ts.map +1 -1
- package/lib/types/errors.js +14 -12
- package/lib/types/errors.js.map +1 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +2 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/model.d.ts +6 -6
- package/lib/types/model.d.ts.map +1 -1
- package/lib/types/model.js +7 -5
- package/lib/types/model.js.map +1 -1
- package/lib-es/api/index.d.ts +5 -5
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +20 -18
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/config.d.ts +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +3 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +3 -1
- package/lib-es/constants.js.map +1 -1
- package/lib-es/logic/broadcast.d.ts.map +1 -1
- package/lib-es/logic/broadcast.js +3 -1
- package/lib-es/logic/broadcast.js.map +1 -1
- package/lib-es/logic/combine.d.ts +1 -1
- package/lib-es/logic/combine.d.ts.map +1 -1
- package/lib-es/logic/combine.js +3 -1
- package/lib-es/logic/combine.js.map +1 -1
- package/lib-es/logic/common.d.ts +1 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +5 -3
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +15 -13
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +3 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +5 -3
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +42 -37
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getBlockInfo.d.ts +1 -1
- package/lib-es/logic/getBlockInfo.d.ts.map +1 -1
- package/lib-es/logic/getBlockInfo.js +3 -1
- package/lib-es/logic/getBlockInfo.js.map +1 -1
- package/lib-es/logic/index.d.ts +12 -12
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +14 -12
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/lastBlock.d.ts +1 -1
- package/lib-es/logic/lastBlock.d.ts.map +1 -1
- package/lib-es/logic/lastBlock.js +3 -1
- package/lib-es/logic/lastBlock.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +7 -5
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/sdkWrapper.d.ts +1 -1
- package/lib-es/logic/sdkWrapper.d.ts.map +1 -1
- package/lib-es/logic/sdkWrapper.js +4 -2
- package/lib-es/logic/sdkWrapper.js.map +1 -1
- package/lib-es/logic/utils.d.ts.map +1 -1
- package/lib-es/logic/utils.js +6 -4
- package/lib-es/logic/utils.js.map +1 -1
- package/lib-es/logic/validateAddress.d.ts +1 -1
- package/lib-es/logic/validateAddress.d.ts.map +1 -1
- package/lib-es/logic/validateAddress.js +3 -1
- package/lib-es/logic/validateAddress.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +2 -2
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js +30 -28
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic/validateMemo.d.ts +1 -1
- package/lib-es/logic/validateMemo.d.ts.map +1 -1
- package/lib-es/logic/validateMemo.js +8 -6
- package/lib-es/logic/validateMemo.js.map +1 -1
- package/lib-es/network/horizon.d.ts +6 -7
- package/lib-es/network/horizon.d.ts.map +1 -1
- package/lib-es/network/horizon.js +80 -77
- package/lib-es/network/horizon.js.map +1 -1
- package/lib-es/network/horizonLedgerErrors.d.ts.map +1 -1
- package/lib-es/network/horizonLedgerErrors.js +7 -5
- package/lib-es/network/horizonLedgerErrors.js.map +1 -1
- package/lib-es/network/index.d.ts +1 -1
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +3 -1
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/network/serialization.d.ts +6 -4
- package/lib-es/network/serialization.d.ts.map +1 -1
- package/lib-es/network/serialization.js +97 -95
- package/lib-es/network/serialization.js.map +1 -1
- package/lib-es/polyfill.d.ts.map +1 -1
- package/lib-es/polyfill.js +7 -5
- package/lib-es/polyfill.js.map +1 -1
- package/lib-es/supportedFeatures.d.ts +1 -1
- package/lib-es/supportedFeatures.d.ts.map +1 -1
- package/lib-es/supportedFeatures.js +3 -1
- package/lib-es/supportedFeatures.js.map +1 -1
- package/lib-es/types/errors.d.ts.map +1 -1
- package/lib-es/types/errors.js +15 -13
- package/lib-es/types/errors.js.map +1 -1
- package/lib-es/types/index.d.ts +2 -2
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js +4 -2
- package/lib-es/types/index.js.map +1 -1
- package/lib-es/types/model.d.ts +6 -6
- package/lib-es/types/model.d.ts.map +1 -1
- package/lib-es/types/model.js +7 -5
- package/lib-es/types/model.js.map +1 -1
- package/package.json +13 -16
- package/src/api/index.integ.test.ts +165 -162
- package/src/api/index.test.ts +106 -103
- package/src/api/index.ts +49 -46
- package/src/api/index_error.test.ts +48 -25
- package/src/config.ts +15 -12
- package/src/constants.ts +4 -1
- package/src/globals.d.ts +7 -5
- package/src/logic/broadcast.integ.test.ts +22 -19
- package/src/logic/broadcast.ts +5 -2
- package/src/logic/combine.test.ts +18 -15
- package/src/logic/combine.ts +8 -5
- package/src/logic/common.ts +9 -6
- package/src/logic/craftTransaction.test.ts +76 -75
- package/src/logic/craftTransaction.ts +46 -43
- package/src/logic/estimateFees.ts +6 -3
- package/src/logic/getBalance.test.ts +31 -28
- package/src/logic/getBalance.ts +13 -10
- package/src/logic/getBlock.integ.test.ts +40 -39
- package/src/logic/getBlock.test.ts +462 -415
- package/src/logic/getBlock.ts +142 -127
- package/src/logic/getBlockInfo.test.ts +72 -69
- package/src/logic/getBlockInfo.ts +15 -12
- package/src/logic/index.ts +15 -12
- package/src/logic/lastBlock.ts +6 -3
- package/src/logic/listOperations.ts +14 -11
- package/src/logic/listOperations.unit.test.ts +212 -209
- package/src/logic/networkWrappers.test.ts +32 -29
- package/src/logic/sdkWrapper.ts +19 -16
- package/src/logic/utils.ts +13 -10
- package/src/logic/validateAddress.test.ts +21 -18
- package/src/logic/validateAddress.ts +7 -4
- package/src/logic/validateIntent.test.ts +62 -59
- package/src/logic/validateIntent.ts +87 -84
- package/src/logic/validateMemo.test.ts +50 -47
- package/src/logic/validateMemo.ts +16 -13
- package/src/network/broadcastTransaction.test.ts +60 -60
- package/src/network/fetchLedgerOperations.unit.test.ts +155 -0
- package/src/network/horizon.integ.test.ts +45 -42
- package/src/network/horizon.test.ts +17 -14
- package/src/network/horizon.ts +279 -281
- package/src/network/horizon.unit.test.ts +238 -237
- package/src/network/horizonLedgerErrors.test.ts +81 -78
- package/src/network/horizonLedgerErrors.ts +22 -19
- package/src/network/index.ts +4 -1
- package/src/network/registerHorizonInterceptors.test.ts +163 -160
- package/src/network/serialization.ts +232 -227
- package/src/network/serialization.unit.test.ts +801 -798
- package/src/polyfill.ts +18 -15
- package/src/supportedFeatures.ts +6 -3
- package/src/types/errors.ts +33 -32
- package/src/types/index.ts +5 -2
- package/src/types/model.ts +55 -52
- package/tsconfig.json +1 -1
- package/.unimportedrc.json +0 -17
- package/LICENSE.txt +0 -21
- package/src/network/fetchLedgerOperations.nock.unit.test.ts +0 -156
|
@@ -1,112 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { LedgerAPI4xx, LedgerAPI5xx, NetworkDown } from '@ledgerhq/errors'
|
|
5
|
+
import { NetworkError, NotFoundError } from '@stellar/stellar-sdk'
|
|
3
6
|
import {
|
|
4
7
|
messageFromHorizonUnknown,
|
|
5
8
|
throwHorizonLedgerOrOperationsError,
|
|
6
|
-
} from
|
|
9
|
+
} from './horizonLedgerErrors'
|
|
7
10
|
|
|
8
|
-
describe(
|
|
9
|
-
it(
|
|
10
|
-
expect(messageFromHorizonUnknown(new Error(
|
|
11
|
-
})
|
|
11
|
+
describe('messageFromHorizonUnknown', () => {
|
|
12
|
+
it('returns message for Error', () => {
|
|
13
|
+
expect(messageFromHorizonUnknown(new Error('hello'))).toBe('hello')
|
|
14
|
+
})
|
|
12
15
|
|
|
13
|
-
it(
|
|
14
|
-
expect(messageFromHorizonUnknown(
|
|
15
|
-
})
|
|
16
|
+
it('returns string as-is', () => {
|
|
17
|
+
expect(messageFromHorizonUnknown('plain')).toBe('plain')
|
|
18
|
+
})
|
|
16
19
|
|
|
17
|
-
it(
|
|
18
|
-
expect(messageFromHorizonUnknown({ code: 1 })).toBe(
|
|
19
|
-
expect(messageFromHorizonUnknown(null)).toBe(
|
|
20
|
-
expect(messageFromHorizonUnknown(undefined)).toBe(
|
|
21
|
-
})
|
|
22
|
-
})
|
|
20
|
+
it('returns empty string for non-Error non-string', () => {
|
|
21
|
+
expect(messageFromHorizonUnknown({ code: 1 })).toBe('')
|
|
22
|
+
expect(messageFromHorizonUnknown(null)).toBe('')
|
|
23
|
+
expect(messageFromHorizonUnknown(undefined)).toBe('')
|
|
24
|
+
})
|
|
25
|
+
})
|
|
23
26
|
|
|
24
|
-
describe(
|
|
25
|
-
const notFound =
|
|
27
|
+
describe('throwHorizonLedgerOrOperationsError', () => {
|
|
28
|
+
const notFound = 'ledger not found'
|
|
26
29
|
|
|
27
|
-
it(
|
|
30
|
+
it('throws notFoundMessage for NotFoundError', () => {
|
|
28
31
|
expect(() =>
|
|
29
|
-
throwHorizonLedgerOrOperationsError(new NotFoundError(
|
|
30
|
-
).toThrow(notFound)
|
|
31
|
-
})
|
|
32
|
+
throwHorizonLedgerOrOperationsError(new NotFoundError('gone', {}), notFound)
|
|
33
|
+
).toThrow(notFound)
|
|
34
|
+
})
|
|
32
35
|
|
|
33
|
-
it(
|
|
36
|
+
it('throws notFoundMessage when message contains status code 404', () => {
|
|
34
37
|
expect(() =>
|
|
35
|
-
throwHorizonLedgerOrOperationsError(new Error(
|
|
36
|
-
).toThrow(notFound)
|
|
37
|
-
})
|
|
38
|
+
throwHorizonLedgerOrOperationsError(new Error('Request failed: status code 404'), notFound)
|
|
39
|
+
).toThrow(notFound)
|
|
40
|
+
})
|
|
38
41
|
|
|
39
|
-
it(
|
|
42
|
+
it('throws LedgerAPI4xx 429 for too many requests in message', () => {
|
|
40
43
|
expect(() =>
|
|
41
|
-
throwHorizonLedgerOrOperationsError(new Error(
|
|
42
|
-
).toThrow(LedgerAPI4xx)
|
|
43
|
-
})
|
|
44
|
+
throwHorizonLedgerOrOperationsError(new Error('Too Many Requests'), notFound)
|
|
45
|
+
).toThrow(LedgerAPI4xx)
|
|
46
|
+
})
|
|
44
47
|
|
|
45
|
-
it(
|
|
48
|
+
it('throws LedgerAPI4xx for other 4xx status in message', () => {
|
|
46
49
|
expect(() =>
|
|
47
|
-
throwHorizonLedgerOrOperationsError(new Error(
|
|
48
|
-
).toThrow(LedgerAPI4xx)
|
|
49
|
-
})
|
|
50
|
+
throwHorizonLedgerOrOperationsError(new Error('status code 400'), notFound)
|
|
51
|
+
).toThrow(LedgerAPI4xx)
|
|
52
|
+
})
|
|
50
53
|
|
|
51
|
-
test.each([[
|
|
52
|
-
|
|
53
|
-
code => {
|
|
54
|
+
test.each([['401'], ['403']])(
|
|
55
|
+
'throws LedgerAPI4xx when message contains status code %s',
|
|
56
|
+
(code) => {
|
|
54
57
|
expect(() =>
|
|
55
58
|
throwHorizonLedgerOrOperationsError(
|
|
56
59
|
new Error(`Request failed: status code ${code}`),
|
|
57
|
-
notFound
|
|
58
|
-
)
|
|
59
|
-
).toThrow(LedgerAPI4xx)
|
|
60
|
-
}
|
|
61
|
-
)
|
|
60
|
+
notFound
|
|
61
|
+
)
|
|
62
|
+
).toThrow(LedgerAPI4xx)
|
|
63
|
+
}
|
|
64
|
+
)
|
|
62
65
|
|
|
63
|
-
it(
|
|
66
|
+
it('throws LedgerAPI5xx for 5xx status in message', () => {
|
|
64
67
|
expect(() =>
|
|
65
|
-
throwHorizonLedgerOrOperationsError(new Error(
|
|
66
|
-
).toThrow(LedgerAPI5xx)
|
|
67
|
-
})
|
|
68
|
+
throwHorizonLedgerOrOperationsError(new Error('status code 503'), notFound)
|
|
69
|
+
).toThrow(LedgerAPI5xx)
|
|
70
|
+
})
|
|
68
71
|
|
|
69
|
-
test.each([[
|
|
70
|
-
|
|
71
|
-
code => {
|
|
72
|
+
test.each([['502'], ['500']])(
|
|
73
|
+
'throws LedgerAPI5xx when message contains status code %s',
|
|
74
|
+
(code) => {
|
|
72
75
|
expect(() =>
|
|
73
|
-
throwHorizonLedgerOrOperationsError(new Error(`upstream status code ${code}`), notFound)
|
|
74
|
-
).toThrow(LedgerAPI5xx)
|
|
75
|
-
}
|
|
76
|
-
)
|
|
76
|
+
throwHorizonLedgerOrOperationsError(new Error(`upstream status code ${code}`), notFound)
|
|
77
|
+
).toThrow(LedgerAPI5xx)
|
|
78
|
+
}
|
|
79
|
+
)
|
|
77
80
|
|
|
78
|
-
it(
|
|
81
|
+
it('throws NetworkDown for NetworkError', () => {
|
|
79
82
|
expect(() =>
|
|
80
|
-
throwHorizonLedgerOrOperationsError(new NetworkError(
|
|
81
|
-
).toThrow(NetworkDown)
|
|
82
|
-
})
|
|
83
|
+
throwHorizonLedgerOrOperationsError(new NetworkError('net', {}), notFound)
|
|
84
|
+
).toThrow(NetworkDown)
|
|
85
|
+
})
|
|
83
86
|
|
|
84
87
|
test.each([
|
|
85
|
-
[
|
|
86
|
-
[
|
|
87
|
-
[
|
|
88
|
-
[
|
|
89
|
-
[
|
|
90
|
-
])(
|
|
88
|
+
['ECONNRESET', 'ECONNRESET on read'],
|
|
89
|
+
['ECONNREFUSED', 'connect ECONNREFUSED 127.0.0.1:443'],
|
|
90
|
+
['ENOTFOUND', 'getaddrinfo ENOTFOUND horizon.example'],
|
|
91
|
+
['EPIPE', 'write EPIPE broken pipe'],
|
|
92
|
+
['ETIMEDOUT', 'connect ETIMEDOUT 10.0.0.1:443'],
|
|
93
|
+
])('throws NetworkDown when message contains %s', (_label, message) => {
|
|
91
94
|
expect(() => throwHorizonLedgerOrOperationsError(new Error(message), notFound)).toThrow(
|
|
92
|
-
NetworkDown
|
|
93
|
-
)
|
|
94
|
-
})
|
|
95
|
+
NetworkDown
|
|
96
|
+
)
|
|
97
|
+
})
|
|
95
98
|
|
|
96
|
-
it(
|
|
99
|
+
it('throws NetworkDown for undefined is not an object in message', () => {
|
|
97
100
|
expect(() =>
|
|
98
|
-
throwHorizonLedgerOrOperationsError(new Error(
|
|
99
|
-
).toThrow(NetworkDown)
|
|
100
|
-
})
|
|
101
|
+
throwHorizonLedgerOrOperationsError(new Error('undefined is not an object'), notFound)
|
|
102
|
+
).toThrow(NetworkDown)
|
|
103
|
+
})
|
|
101
104
|
|
|
102
|
-
it(
|
|
103
|
-
const o = { custom: true }
|
|
105
|
+
it('rethrows unknown errors', () => {
|
|
106
|
+
const o = { custom: true }
|
|
104
107
|
try {
|
|
105
|
-
throwHorizonLedgerOrOperationsError(o, notFound)
|
|
108
|
+
throwHorizonLedgerOrOperationsError(o, notFound)
|
|
106
109
|
} catch (e) {
|
|
107
|
-
expect(e).toBe(o)
|
|
108
|
-
return
|
|
110
|
+
expect(e).toBe(o)
|
|
111
|
+
return
|
|
109
112
|
}
|
|
110
|
-
throw new Error(
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
+
throw new Error('expected throw')
|
|
114
|
+
})
|
|
115
|
+
})
|
|
@@ -1,45 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { LedgerAPI4xx, LedgerAPI5xx, NetworkDown } from '@ledgerhq/errors'
|
|
5
|
+
import { NetworkError, NotFoundError } from '@stellar/stellar-sdk'
|
|
3
6
|
|
|
4
7
|
export function messageFromHorizonUnknown(e: unknown): string {
|
|
5
8
|
if (e instanceof Error) {
|
|
6
|
-
return e.message
|
|
9
|
+
return e.message
|
|
7
10
|
}
|
|
8
|
-
if (typeof e ===
|
|
9
|
-
return e
|
|
11
|
+
if (typeof e === 'string') {
|
|
12
|
+
return e
|
|
10
13
|
}
|
|
11
|
-
return
|
|
14
|
+
return ''
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
const HORIZON_STATUS_404 = /status code 404
|
|
15
|
-
const HORIZON_TOO_MANY_REQUESTS = /too many requests/i
|
|
16
|
-
const HORIZON_STATUS_4XX = /status code 4\d{2}
|
|
17
|
-
const HORIZON_STATUS_5XX = /status code 5\d{2}
|
|
18
|
-
const HORIZON_NETWORK_DOWN = /ECONNRESET|ECONNREFUSED|ENOTFOUND|EPIPE|ETIMEDOUT
|
|
19
|
-
const HORIZON_UNDEFINED_OBJECT = /undefined is not an object
|
|
17
|
+
const HORIZON_STATUS_404 = /status code 404/
|
|
18
|
+
const HORIZON_TOO_MANY_REQUESTS = /too many requests/i
|
|
19
|
+
const HORIZON_STATUS_4XX = /status code 4\d{2}/
|
|
20
|
+
const HORIZON_STATUS_5XX = /status code 5\d{2}/
|
|
21
|
+
const HORIZON_NETWORK_DOWN = /ECONNRESET|ECONNREFUSED|ENOTFOUND|EPIPE|ETIMEDOUT/
|
|
22
|
+
const HORIZON_UNDEFINED_OBJECT = /undefined is not an object/
|
|
20
23
|
|
|
21
24
|
export function throwHorizonLedgerOrOperationsError(e: unknown, notFoundMessage: string): never {
|
|
22
|
-
const errorMsg = messageFromHorizonUnknown(e)
|
|
25
|
+
const errorMsg = messageFromHorizonUnknown(e)
|
|
23
26
|
|
|
24
27
|
if (e instanceof NotFoundError || HORIZON_STATUS_404.exec(errorMsg)) {
|
|
25
|
-
throw new Error(notFoundMessage)
|
|
28
|
+
throw new Error(notFoundMessage)
|
|
26
29
|
}
|
|
27
30
|
if (HORIZON_TOO_MANY_REQUESTS.exec(errorMsg)) {
|
|
28
|
-
throw new LedgerAPI4xx(
|
|
31
|
+
throw new LedgerAPI4xx('status code 4xx', { status: 429, url: undefined, method: 'GET' })
|
|
29
32
|
}
|
|
30
33
|
if (HORIZON_STATUS_4XX.exec(errorMsg)) {
|
|
31
|
-
throw new LedgerAPI4xx()
|
|
34
|
+
throw new LedgerAPI4xx()
|
|
32
35
|
}
|
|
33
36
|
if (HORIZON_STATUS_5XX.exec(errorMsg)) {
|
|
34
|
-
throw new LedgerAPI5xx()
|
|
37
|
+
throw new LedgerAPI5xx()
|
|
35
38
|
}
|
|
36
39
|
if (
|
|
37
40
|
e instanceof NetworkError ||
|
|
38
41
|
HORIZON_NETWORK_DOWN.exec(errorMsg) ||
|
|
39
42
|
HORIZON_UNDEFINED_OBJECT.exec(errorMsg)
|
|
40
43
|
) {
|
|
41
|
-
throw new NetworkDown()
|
|
44
|
+
throw new NetworkDown()
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
throw e
|
|
47
|
+
throw e
|
|
45
48
|
}
|
package/src/network/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
1
4
|
export {
|
|
2
5
|
broadcastTransaction,
|
|
3
6
|
fetchAccount,
|
|
@@ -13,4 +16,4 @@ export {
|
|
|
13
16
|
getRecipientAccount,
|
|
14
17
|
loadAccount,
|
|
15
18
|
registerHorizonInterceptors,
|
|
16
|
-
} from
|
|
19
|
+
} from './horizon'
|