@bigmi/core 0.4.0 → 0.4.3
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 +16 -0
- package/dist/cjs/clients/decorators/public.d.ts +2 -2
- package/dist/cjs/clients/decorators/public.js +1 -1
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/errors/request.d.ts +2 -1
- package/dist/cjs/errors/request.js +2 -2
- package/dist/cjs/errors/request.js.map +1 -1
- package/dist/cjs/errors/rpc.d.ts +2 -1
- package/dist/cjs/errors/rpc.js +1 -0
- package/dist/cjs/errors/rpc.js.map +1 -1
- package/dist/cjs/factories/createClient.d.ts +2 -2
- package/dist/cjs/factories/createClient.js.map +1 -1
- package/dist/cjs/index.d.ts +42 -43
- package/dist/cjs/index.js +75 -75
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/transports/ankr/ankr.js +1 -0
- package/dist/cjs/transports/ankr/ankr.js.map +1 -1
- package/dist/cjs/transports/ankr/getBalance.js +2 -1
- package/dist/cjs/transports/ankr/getBalance.js.map +1 -1
- package/dist/cjs/transports/blockchair/blockchair.js +1 -0
- package/dist/cjs/transports/blockchair/blockchair.js.map +1 -1
- package/dist/cjs/transports/blockchair/getBalance.js +7 -2
- package/dist/cjs/transports/blockchair/getBalance.js.map +1 -1
- package/dist/cjs/transports/blockchair/getTransactionFee.js +7 -2
- package/dist/cjs/transports/blockchair/getTransactionFee.js.map +1 -1
- package/dist/cjs/transports/blockchair/getUTXOs.js +4 -1
- package/dist/cjs/transports/blockchair/getUTXOs.js.map +1 -1
- package/dist/cjs/transports/blockcypher/blockcypher.js +1 -0
- package/dist/cjs/transports/blockcypher/blockcypher.js.map +1 -1
- package/dist/cjs/transports/blockcypher/getBalance.js +5 -1
- package/dist/cjs/transports/blockcypher/getBalance.js.map +1 -1
- package/dist/cjs/transports/blockcypher/getTransactionFee.js +2 -1
- package/dist/cjs/transports/blockcypher/getTransactionFee.js.map +1 -1
- package/dist/cjs/transports/blockcypher/getUTXOs.js +3 -2
- package/dist/cjs/transports/blockcypher/getUTXOs.js.map +1 -1
- package/dist/cjs/transports/blockcypher/utils.d.ts +2 -0
- package/dist/cjs/transports/blockcypher/utils.js +11 -0
- package/dist/cjs/transports/blockcypher/utils.js.map +1 -0
- package/dist/cjs/transports/getHttpRpcClient.js +5 -1
- package/dist/cjs/transports/getHttpRpcClient.js.map +1 -1
- package/dist/cjs/transports/mempool/mempool.js +1 -0
- package/dist/cjs/transports/mempool/mempool.js.map +1 -1
- package/dist/cjs/utils/deepEqual.js +1 -1
- package/dist/cjs/utils/deepEqual.js.map +1 -1
- package/dist/cjs/utils/getAction.d.ts +2 -2
- package/dist/cjs/utils/getAction.js.map +1 -1
- package/dist/cjs/utils/poll.js +1 -1
- package/dist/cjs/utils/poll.js.map +1 -1
- package/dist/cjs/utils/withTimeout.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/actions/waitForTransaction.js +1 -1
- package/dist/esm/actions/waitForTransaction.js.map +1 -1
- package/dist/esm/clients/decorators/public.d.ts +2 -2
- package/dist/esm/clients/decorators/public.js +1 -1
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/errors/request.d.ts +2 -1
- package/dist/esm/errors/request.js +2 -2
- package/dist/esm/errors/request.js.map +1 -1
- package/dist/esm/errors/rpc.d.ts +5 -1
- package/dist/esm/errors/rpc.js +4 -0
- package/dist/esm/errors/rpc.js.map +1 -1
- package/dist/esm/factories/createClient.d.ts +2 -2
- package/dist/esm/factories/createClient.js.map +1 -1
- package/dist/esm/index.d.ts +42 -43
- package/dist/esm/index.js +29 -29
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/transports/ankr/ankr.js +1 -0
- package/dist/esm/transports/ankr/ankr.js.map +1 -1
- package/dist/esm/transports/ankr/getBalance.js +2 -1
- package/dist/esm/transports/ankr/getBalance.js.map +1 -1
- package/dist/esm/transports/blockchair/blockchair.js +1 -0
- package/dist/esm/transports/blockchair/blockchair.js.map +1 -1
- package/dist/esm/transports/blockchair/getBalance.js +7 -2
- package/dist/esm/transports/blockchair/getBalance.js.map +1 -1
- package/dist/esm/transports/blockchair/getTransactionFee.js +7 -2
- package/dist/esm/transports/blockchair/getTransactionFee.js.map +1 -1
- package/dist/esm/transports/blockchair/getUTXOs.js +4 -1
- package/dist/esm/transports/blockchair/getUTXOs.js.map +1 -1
- package/dist/esm/transports/blockcypher/blockcypher.js +1 -0
- package/dist/esm/transports/blockcypher/blockcypher.js.map +1 -1
- package/dist/esm/transports/blockcypher/getBalance.js +5 -1
- package/dist/esm/transports/blockcypher/getBalance.js.map +1 -1
- package/dist/esm/transports/blockcypher/getTransactionFee.js +2 -1
- package/dist/esm/transports/blockcypher/getTransactionFee.js.map +1 -1
- package/dist/esm/transports/blockcypher/getUTXOs.js +3 -2
- package/dist/esm/transports/blockcypher/getUTXOs.js.map +1 -1
- package/dist/esm/transports/blockcypher/utils.d.ts +2 -0
- package/dist/esm/transports/blockcypher/utils.js +8 -0
- package/dist/esm/transports/blockcypher/utils.js.map +1 -0
- package/dist/esm/transports/getHttpRpcClient.js +5 -1
- package/dist/esm/transports/getHttpRpcClient.js.map +1 -1
- package/dist/esm/transports/http.js.map +1 -1
- package/dist/esm/transports/mempool/mempool.js +1 -0
- package/dist/esm/transports/mempool/mempool.js.map +1 -1
- package/dist/esm/utils/cancelTransaction.js +1 -1
- package/dist/esm/utils/cancelTransaction.js.map +1 -1
- package/dist/esm/utils/deepEqual.js +2 -2
- package/dist/esm/utils/deepEqual.js.map +1 -1
- package/dist/esm/utils/getAction.d.ts +2 -2
- package/dist/esm/utils/getAction.js.map +1 -1
- package/dist/esm/utils/getAddressInfo.js.map +1 -1
- package/dist/esm/utils/modifyFee.js +1 -1
- package/dist/esm/utils/modifyFee.js.map +1 -1
- package/dist/esm/utils/poll.js +1 -1
- package/dist/esm/utils/poll.js.map +1 -1
- package/dist/esm/utils/withTimeout.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/actions/waitForTransaction.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +2 -2
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/errors/request.d.ts +2 -1
- package/dist/types/errors/request.d.ts.map +1 -1
- package/dist/types/errors/rpc.d.ts +5 -1
- package/dist/types/errors/rpc.d.ts.map +1 -1
- package/dist/types/factories/createClient.d.ts +2 -2
- package/dist/types/factories/createClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +42 -43
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/transports/ankr/ankr.d.ts.map +1 -1
- package/dist/types/transports/ankr/getBalance.d.ts.map +1 -1
- package/dist/types/transports/blockchair/blockchair.d.ts.map +1 -1
- package/dist/types/transports/blockchair/getBalance.d.ts.map +1 -1
- package/dist/types/transports/blockchair/getTransactionFee.d.ts.map +1 -1
- package/dist/types/transports/blockchair/getUTXOs.d.ts.map +1 -1
- package/dist/types/transports/blockcypher/blockcypher.d.ts.map +1 -1
- package/dist/types/transports/blockcypher/getBalance.d.ts.map +1 -1
- package/dist/types/transports/blockcypher/getTransactionFee.d.ts.map +1 -1
- package/dist/types/transports/blockcypher/getUTXOs.d.ts.map +1 -1
- package/dist/types/transports/blockcypher/utils.d.ts +3 -0
- package/dist/types/transports/blockcypher/utils.d.ts.map +1 -0
- package/dist/types/transports/fallback.d.ts.map +1 -1
- package/dist/types/transports/getHttpRpcClient.d.ts.map +1 -1
- package/dist/types/transports/http.d.ts.map +1 -1
- package/dist/types/transports/mempool/mempool.d.ts.map +1 -1
- package/dist/types/utils/cancelTransaction.d.ts.map +1 -1
- package/dist/types/utils/getAction.d.ts +2 -2
- package/dist/types/utils/getAction.d.ts.map +1 -1
- package/dist/types/utils/modifyFee.d.ts.map +1 -1
- package/dist/types/utils/withTimeout.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/package.json.tmp +7 -3
- package/src/actions/waitForTransaction.ts +1 -1
- package/src/clients/decorators/public.ts +6 -7
- package/src/errors/request.ts +3 -1
- package/src/errors/rpc.ts +4 -0
- package/src/factories/createClient.ts +2 -4
- package/src/index.ts +103 -114
- package/src/transports/ankr/ankr.ts +2 -1
- package/src/transports/ankr/getBalance.ts +2 -1
- package/src/transports/blockchair/blockchair.spec.ts +85 -61
- package/src/transports/blockchair/blockchair.ts +1 -1
- package/src/transports/blockchair/getBalance.ts +10 -2
- package/src/transports/blockchair/getTransactionFee.ts +10 -2
- package/src/transports/blockchair/getUTXOs.ts +5 -1
- package/src/transports/blockcypher/blockcypher.ts +1 -0
- package/src/transports/blockcypher/getBalance.ts +5 -1
- package/src/transports/blockcypher/getTransactionFee.ts +2 -1
- package/src/transports/blockcypher/getUTXOs.ts +3 -2
- package/src/transports/blockcypher/utils.ts +8 -0
- package/src/transports/custom.ts +1 -1
- package/src/transports/fallback.ts +3 -3
- package/src/transports/getHttpRpcClient.ts +5 -1
- package/src/transports/http.ts +1 -1
- package/src/transports/mempool/mempool.spec.ts +3 -4
- package/src/transports/mempool/mempool.ts +1 -0
- package/src/utils/cancelTransaction.ts +1 -1
- package/src/utils/deepEqual.ts +2 -2
- package/src/utils/getAction.ts +2 -3
- package/src/utils/getAddressInfo.ts +1 -1
- package/src/utils/modifyFee.ts +1 -1
- package/src/utils/poll.ts +1 -1
- package/src/utils/withTimeout.ts +3 -1
- package/src/version.ts +1 -1
|
@@ -47,20 +47,24 @@ describe('Blockchair Transport', () => {
|
|
|
47
47
|
|
|
48
48
|
describe('getBalance', () => {
|
|
49
49
|
it('should fetch correct balance for valid address', async () => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if (USE_MOCK) {
|
|
51
|
+
vi.spyOn(global, 'fetch').mockResolvedValue(
|
|
52
|
+
createMockResponse(getBalanceReponse as BlockchairAddressBalanceData)
|
|
53
|
+
)
|
|
54
|
+
}
|
|
53
55
|
|
|
54
56
|
const balance = await getBalance(publicClient, { address })
|
|
55
57
|
expect(balance).toBeTypeOf('bigint')
|
|
56
58
|
})
|
|
57
59
|
|
|
58
60
|
it('should throw error for non-existent address', async () => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
if (USE_MOCK) {
|
|
62
|
+
vi.spyOn(global, 'fetch').mockResolvedValue(
|
|
63
|
+
createMockResponse(
|
|
64
|
+
getInvalidBalanceReponse as BlockchairAddressBalanceData
|
|
65
|
+
)
|
|
62
66
|
)
|
|
63
|
-
|
|
67
|
+
}
|
|
64
68
|
|
|
65
69
|
const nonExistentAddress =
|
|
66
70
|
'1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNaNUIBNSUENopnoidsacn'
|
|
@@ -72,11 +76,13 @@ describe('Blockchair Transport', () => {
|
|
|
72
76
|
|
|
73
77
|
describe('getUTXOs', () => {
|
|
74
78
|
it('should return utxos with correct structure', async () => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
if (USE_MOCK) {
|
|
80
|
+
vi.spyOn(global, 'fetch').mockResolvedValue(
|
|
81
|
+
createMockResponse(
|
|
82
|
+
getUTXOsResponse as BlockchairResponse<BlockChairDashboardAddressResponse>
|
|
83
|
+
)
|
|
78
84
|
)
|
|
79
|
-
|
|
85
|
+
}
|
|
80
86
|
|
|
81
87
|
const utxos = await getUTXOs(publicClient, { address })
|
|
82
88
|
|
|
@@ -91,27 +97,29 @@ describe('Blockchair Transport', () => {
|
|
|
91
97
|
})
|
|
92
98
|
|
|
93
99
|
it('should throw error when minValue exceeds balance', async () => {
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
if (USE_MOCK) {
|
|
101
|
+
vi.spyOn(global, 'fetch').mockImplementation((request) => {
|
|
102
|
+
const url = new URL(request.toString())
|
|
96
103
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
if (url.pathname.includes('/addresses/balances')) {
|
|
105
|
+
return Promise.resolve(
|
|
106
|
+
createMockResponse(
|
|
107
|
+
getBalanceReponse as BlockchairAddressBalanceData
|
|
108
|
+
)
|
|
101
109
|
)
|
|
102
|
-
|
|
103
|
-
}
|
|
110
|
+
}
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
if (url.pathname.includes('/dashboards/addresses')) {
|
|
113
|
+
return Promise.resolve(
|
|
114
|
+
createMockResponse(
|
|
115
|
+
getUTXOsResponse as BlockchairResponse<BlockChairDashboardAddressResponse>
|
|
116
|
+
)
|
|
109
117
|
)
|
|
110
|
-
|
|
111
|
-
}
|
|
118
|
+
}
|
|
112
119
|
|
|
113
|
-
|
|
114
|
-
|
|
120
|
+
throw new BaseError(`Unexpected URL: ${url.pathname}`)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
115
123
|
|
|
116
124
|
const hugeValue = 999999999999999999n
|
|
117
125
|
await expect(
|
|
@@ -123,14 +131,26 @@ describe('Blockchair Transport', () => {
|
|
|
123
131
|
})
|
|
124
132
|
|
|
125
133
|
it('should handle empty UTXO response', async () => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
134
|
+
if (USE_MOCK) {
|
|
135
|
+
vi.spyOn(global, 'fetch').mockResolvedValue(
|
|
136
|
+
createMockResponse(
|
|
137
|
+
getUTXOsInvalidResponse as BlockchairResponse<null>
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
}
|
|
129
141
|
|
|
130
142
|
const emptyAddress = '12LRT14SgNFFQ3hMRThAyXNao24BBy5cyU'
|
|
131
|
-
const utxos = await getUTXOs(publicClient, { address: emptyAddress })
|
|
132
143
|
|
|
133
|
-
|
|
144
|
+
if (USE_MOCK) {
|
|
145
|
+
const utxos = await getUTXOs(publicClient, { address: emptyAddress })
|
|
146
|
+
expect(utxos.length).toBe(0)
|
|
147
|
+
} else {
|
|
148
|
+
await expect(
|
|
149
|
+
getUTXOs(publicClient, { address: emptyAddress })
|
|
150
|
+
).rejects.toMatchObject({
|
|
151
|
+
status: 404,
|
|
152
|
+
})
|
|
153
|
+
}
|
|
134
154
|
})
|
|
135
155
|
|
|
136
156
|
describe('pagination', () => {
|
|
@@ -155,37 +175,39 @@ describe('Blockchair Transport', () => {
|
|
|
155
175
|
})
|
|
156
176
|
|
|
157
177
|
it('should handle pagination correctly', async () => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
178
|
+
if (USE_MOCK) {
|
|
179
|
+
vi.spyOn(global, 'fetch').mockImplementation((request) => {
|
|
180
|
+
const url = new URL(request.toString())
|
|
181
|
+
|
|
182
|
+
if (url.pathname.includes('/addresses/balances')) {
|
|
183
|
+
return Promise.resolve(
|
|
184
|
+
createMockResponse({
|
|
185
|
+
data: {
|
|
186
|
+
[addressWithManyUTXOs]: 1000000000000,
|
|
187
|
+
},
|
|
188
|
+
context: { code: 200 },
|
|
189
|
+
} as BlockchairResponse<BlockchairAddressBalanceData>)
|
|
190
|
+
)
|
|
191
|
+
}
|
|
171
192
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
)
|
|
176
|
-
const limit = 100
|
|
177
|
-
return Promise.resolve(
|
|
178
|
-
createMockResponse(
|
|
179
|
-
createPaginatedMockResponse(
|
|
180
|
-
offset,
|
|
181
|
-
limit
|
|
182
|
-
) as BlockchairResponse<BlockChairDashboardAddressResponse>
|
|
193
|
+
if (url.pathname.includes('/dashboards/addresses')) {
|
|
194
|
+
const offset = Number.parseInt(
|
|
195
|
+
url.searchParams.get('offset')?.split(',')[1] || '0'
|
|
183
196
|
)
|
|
184
|
-
|
|
185
|
-
|
|
197
|
+
const limit = 100
|
|
198
|
+
return Promise.resolve(
|
|
199
|
+
createMockResponse(
|
|
200
|
+
createPaginatedMockResponse(
|
|
201
|
+
offset,
|
|
202
|
+
limit
|
|
203
|
+
) as BlockchairResponse<BlockChairDashboardAddressResponse>
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
}
|
|
186
207
|
|
|
187
|
-
|
|
188
|
-
|
|
208
|
+
throw new BaseError(`Unexpected URL: ${url.pathname}`)
|
|
209
|
+
})
|
|
210
|
+
}
|
|
189
211
|
|
|
190
212
|
const utxos = await getUTXOs(publicClient, {
|
|
191
213
|
address: addressWithManyUTXOs,
|
|
@@ -194,7 +216,9 @@ describe('Blockchair Transport', () => {
|
|
|
194
216
|
|
|
195
217
|
expect(utxos.length).toBeGreaterThan(0)
|
|
196
218
|
expect(new Set(utxos.map((utxo) => utxo.txId)).size).toBe(utxos.length)
|
|
197
|
-
|
|
219
|
+
if (USE_MOCK) {
|
|
220
|
+
expect(global.fetch).toHaveBeenCalled()
|
|
221
|
+
}
|
|
198
222
|
|
|
199
223
|
const totalValue = utxos.reduce((sum, utxo) => sum + utxo.value, 0)
|
|
200
224
|
expect(totalValue).toBeGreaterThanOrEqual(minValue)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { TransportConfig } from '../../types/transport.js'
|
|
2
1
|
import type { HttpTransportConfig } from '../http.js'
|
|
3
2
|
import type { UTXOMethod } from '../types.js'
|
|
4
3
|
import { utxo } from '../utxo.js'
|
|
@@ -11,6 +10,7 @@ type BlockchairConfig = {
|
|
|
11
10
|
|
|
12
11
|
export const blockchair = (config?: BlockchairConfig) =>
|
|
13
12
|
utxo(config?.baseUrl || 'https://api.blockchair.com', {
|
|
13
|
+
name: 'Blockchair API',
|
|
14
14
|
key: 'blockchair',
|
|
15
15
|
includeChainToURL: true,
|
|
16
16
|
methods: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RpcErrorCode } from '../../errors/rpc.js'
|
|
1
2
|
import { urlWithParams } from '../../utils/url.js'
|
|
2
3
|
import type { RpcMethodHandler } from '../types.js'
|
|
3
4
|
import type {
|
|
@@ -18,10 +19,17 @@ export const getBalance: RpcMethodHandler<'getBalance'> = async (
|
|
|
18
19
|
url: apiUrl,
|
|
19
20
|
fetchOptions: { method: 'GET' },
|
|
20
21
|
})) as unknown as BlockchairResponse<BlockchairAddressBalanceData>
|
|
21
|
-
if (
|
|
22
|
+
if (
|
|
23
|
+
response.data[address] === undefined ||
|
|
24
|
+
response.context.error ||
|
|
25
|
+
response.context?.code !== 200
|
|
26
|
+
) {
|
|
22
27
|
return {
|
|
23
28
|
error: {
|
|
24
|
-
code:
|
|
29
|
+
code:
|
|
30
|
+
response.context.code === 429
|
|
31
|
+
? RpcErrorCode.ACCESS_DENIED
|
|
32
|
+
: RpcErrorCode.MISC_ERROR,
|
|
25
33
|
message: response.context?.error,
|
|
26
34
|
},
|
|
27
35
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RpcErrorCode } from '../../errors/rpc.js'
|
|
1
2
|
import { urlWithParams } from '../../utils/url.js'
|
|
2
3
|
import type { RpcMethodHandler } from '../types.js'
|
|
3
4
|
import type { BlockchairTransactionResponse } from './blockchair.types.js'
|
|
@@ -17,10 +18,17 @@ export const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (
|
|
|
17
18
|
},
|
|
18
19
|
})) as unknown as BlockchairTransactionResponse
|
|
19
20
|
|
|
20
|
-
if (
|
|
21
|
+
if (
|
|
22
|
+
!response.data[txId] ||
|
|
23
|
+
response.context.error ||
|
|
24
|
+
response.context?.code !== 200
|
|
25
|
+
) {
|
|
21
26
|
return {
|
|
22
27
|
error: {
|
|
23
|
-
code:
|
|
28
|
+
code:
|
|
29
|
+
response.context.code === 429
|
|
30
|
+
? RpcErrorCode.ACCESS_DENIED
|
|
31
|
+
: RpcErrorCode.MISC_ERROR,
|
|
24
32
|
message: response.context?.error,
|
|
25
33
|
},
|
|
26
34
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RpcRequestError } from '../../errors/request.js'
|
|
2
|
+
import { RpcErrorCode } from '../../errors/rpc.js'
|
|
2
3
|
import { InsufficientUTXOBalanceError } from '../../errors/utxo.js'
|
|
3
4
|
import type { UTXO } from '../../types/transaction.js'
|
|
4
5
|
|
|
@@ -57,7 +58,10 @@ export const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (
|
|
|
57
58
|
},
|
|
58
59
|
},
|
|
59
60
|
error: {
|
|
60
|
-
code:
|
|
61
|
+
code:
|
|
62
|
+
response.context.code === 429
|
|
63
|
+
? RpcErrorCode.ACCESS_DENIED
|
|
64
|
+
: RpcErrorCode.MISC_ERROR,
|
|
61
65
|
message: response.context.error || 'Error fetching utxos',
|
|
62
66
|
},
|
|
63
67
|
})
|
|
@@ -10,6 +10,7 @@ type BlockcypherConfig = {
|
|
|
10
10
|
|
|
11
11
|
export const blockcypher = (config?: BlockcypherConfig) =>
|
|
12
12
|
utxo(config?.baseUrl || 'https://api.blockcypher.com/v1/btc/main', {
|
|
13
|
+
name: 'Blockcypher API',
|
|
13
14
|
key: 'blockcypher',
|
|
14
15
|
methods: {
|
|
15
16
|
include: Object.keys(blockcypherMethods) as UTXOMethod[],
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { urlWithParams } from '../../utils/url.js'
|
|
2
2
|
import type { RpcMethodHandler } from '../types.js'
|
|
3
3
|
import type { BlockcypherBalanceResponse } from './blockcypher.types.js'
|
|
4
|
+
import { getRpcErrorCode } from './utils.js'
|
|
4
5
|
|
|
5
6
|
export const getBalance: RpcMethodHandler<'getBalance'> = async (
|
|
6
7
|
client,
|
|
@@ -16,7 +17,10 @@ export const getBalance: RpcMethodHandler<'getBalance'> = async (
|
|
|
16
17
|
})) as unknown as BlockcypherBalanceResponse
|
|
17
18
|
if (response.error) {
|
|
18
19
|
return {
|
|
19
|
-
error: {
|
|
20
|
+
error: {
|
|
21
|
+
code: getRpcErrorCode(response.error),
|
|
22
|
+
message: response.error,
|
|
23
|
+
},
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
return {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { urlWithParams } from '../../utils/url.js'
|
|
2
2
|
import type { RpcMethodHandler } from '../types.js'
|
|
3
3
|
import type { BlockcypherTransactionReponse } from './blockcypher.types.js'
|
|
4
|
+
import { getRpcErrorCode } from './utils.js'
|
|
4
5
|
|
|
5
6
|
export const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (
|
|
6
7
|
client,
|
|
@@ -18,7 +19,7 @@ export const getTransactionFee: RpcMethodHandler<'getTransactionFee'> = async (
|
|
|
18
19
|
|
|
19
20
|
if (response.error) {
|
|
20
21
|
return {
|
|
21
|
-
error: { code:
|
|
22
|
+
error: { code: getRpcErrorCode(response.error), message: response.error },
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
BlockcypherUTXO,
|
|
8
8
|
BlockcypherUTXOsResponse,
|
|
9
9
|
} from './blockcypher.types.js'
|
|
10
|
+
import { getRpcErrorCode } from './utils.js'
|
|
10
11
|
|
|
11
12
|
const blockcypherUTXOTransformer = (utxo: BlockcypherUTXO): UTXO => ({
|
|
12
13
|
blockHeight: utxo.block_height,
|
|
@@ -27,7 +28,7 @@ export const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (
|
|
|
27
28
|
) => {
|
|
28
29
|
async function* fetchUTXOs() {
|
|
29
30
|
let hasMore = true
|
|
30
|
-
let beforeBlock
|
|
31
|
+
let beforeBlock: number | undefined
|
|
31
32
|
|
|
32
33
|
while (hasMore) {
|
|
33
34
|
const apiUrl = urlWithParams(`${baseUrl}/addrs/${address}`, {
|
|
@@ -53,7 +54,7 @@ export const getUTXOs: RpcMethodHandler<'getUTXOs'> = async (
|
|
|
53
54
|
},
|
|
54
55
|
},
|
|
55
56
|
error: {
|
|
56
|
-
code:
|
|
57
|
+
code: getRpcErrorCode(response.error),
|
|
57
58
|
message: response.error,
|
|
58
59
|
},
|
|
59
60
|
})
|
package/src/transports/custom.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type CustomTransportConfig = {
|
|
|
23
23
|
|
|
24
24
|
export type CustomTransport = Transport<
|
|
25
25
|
'custom',
|
|
26
|
-
// biome-ignore lint/complexity/noBannedTypes:
|
|
26
|
+
// biome-ignore lint/complexity/noBannedTypes: part of the types
|
|
27
27
|
{},
|
|
28
28
|
BitcoinProvider['request']
|
|
29
29
|
>
|
|
@@ -43,9 +43,9 @@ type RankOptions = {
|
|
|
43
43
|
/**
|
|
44
44
|
* Ping method to determine latency.
|
|
45
45
|
*/
|
|
46
|
-
ping?: (parameters: {
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
ping?: (parameters: {
|
|
47
|
+
transport: ReturnType<Transport>
|
|
48
|
+
}) => Promise<unknown> | undefined
|
|
49
49
|
/**
|
|
50
50
|
* The number of previous samples to perform ranking on.
|
|
51
51
|
* @default 10
|
|
@@ -98,7 +98,11 @@ export function getHttpRpcClient(
|
|
|
98
98
|
return response
|
|
99
99
|
},
|
|
100
100
|
{
|
|
101
|
-
errorInstance: new TimeoutError({
|
|
101
|
+
errorInstance: new TimeoutError({
|
|
102
|
+
body: body ?? {},
|
|
103
|
+
url: params.url ?? url,
|
|
104
|
+
timeout,
|
|
105
|
+
}),
|
|
102
106
|
timeout,
|
|
103
107
|
signal: true,
|
|
104
108
|
}
|
package/src/transports/http.ts
CHANGED
|
@@ -13,9 +13,9 @@ import type {
|
|
|
13
13
|
} from '../types/transport.js'
|
|
14
14
|
import { createBatchScheduler } from '../utils/createBatchScheduler.js'
|
|
15
15
|
import {
|
|
16
|
+
getHttpRpcClient,
|
|
16
17
|
type HttpRpcClientOptions,
|
|
17
18
|
type RpcRequest,
|
|
18
|
-
getHttpRpcClient,
|
|
19
19
|
} from './getHttpRpcClient.js'
|
|
20
20
|
import { UTXOAPISchemaMethods } from './types.js'
|
|
21
21
|
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
2
|
import { getBalance } from '../../actions/getBalance'
|
|
3
|
+
import { getTransactionFee } from '../../actions/getTransactionFee'
|
|
3
4
|
import { getTransactions } from '../../actions/getTransactions'
|
|
4
5
|
import { bitcoin } from '../../chains/bitcoin'
|
|
6
|
+
import { BaseError } from '../../errors/base'
|
|
5
7
|
import { createClient, rpcSchema } from '../../factories/createClient'
|
|
6
8
|
import { createMockResponse } from '../../test/utils'
|
|
7
|
-
import type { UTXOSchema } from '../types'
|
|
8
|
-
|
|
9
|
-
import { getTransactionFee } from '../../actions/getTransactionFee'
|
|
10
|
-
import { BaseError } from '../../errors/base'
|
|
11
9
|
import {
|
|
12
10
|
INVALID_TX_ID,
|
|
13
11
|
TX_FEE,
|
|
14
12
|
VALID_TX_ID,
|
|
15
13
|
} from '../__mocks__/getTransactionFee'
|
|
14
|
+
import type { UTXOSchema } from '../types'
|
|
16
15
|
import getBalanceInValidResponse from './__mocks__/getBalance/invalid.json'
|
|
17
16
|
import getBalanceValidResponse from './__mocks__/getBalance/valid.json'
|
|
18
17
|
import getTransactionFeeInvalidResponse from './__mocks__/getTransactionFee/invalid.json'
|
package/src/utils/deepEqual.ts
CHANGED
|
@@ -40,7 +40,7 @@ export function deepEqual(a: any, b: any) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
for (i = length; i-- !== 0; ) {
|
|
43
|
-
if (!Object.
|
|
43
|
+
if (!Object.hasOwn(b, keys[i]!)) {
|
|
44
44
|
return false
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -57,6 +57,6 @@ export function deepEqual(a: any, b: any) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// true if both NaN, false otherwise
|
|
60
|
-
// biome-ignore lint/suspicious/noSelfCompare:
|
|
60
|
+
// biome-ignore lint/suspicious/noSelfCompare: allowed in utils
|
|
61
61
|
return a !== a && b !== b
|
|
62
62
|
}
|
package/src/utils/getAction.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { PublicActions } from '../clients/decorators/public.js'
|
|
2
2
|
import type { WalletActions } from '../clients/decorators/wallet.js'
|
|
3
3
|
import type { UTXOSchema } from '../transports/types.js'
|
|
4
|
-
import type { Client } from '../types/client.js'
|
|
5
|
-
import type { Transport } from '../types/transport.js'
|
|
6
|
-
|
|
7
4
|
import type { Account } from '../types/account.js'
|
|
8
5
|
import type { Chain } from '../types/chain.js'
|
|
6
|
+
import type { Client } from '../types/client.js'
|
|
7
|
+
import type { Transport } from '../types/transport.js'
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Retrieves and returns an action from the client (if exists), and falls
|
package/src/utils/modifyFee.ts
CHANGED
package/src/utils/poll.ts
CHANGED
package/src/utils/withTimeout.ts
CHANGED
|
@@ -5,7 +5,9 @@ export type WithTimeoutErrorType = ErrorType
|
|
|
5
5
|
export function withTimeout<data>(
|
|
6
6
|
fn: ({
|
|
7
7
|
signal,
|
|
8
|
-
}: {
|
|
8
|
+
}: {
|
|
9
|
+
signal: AbortController['signal'] | null
|
|
10
|
+
}) => Promise<data>,
|
|
9
11
|
{
|
|
10
12
|
errorInstance = new Error('timed out'),
|
|
11
13
|
timeout,
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@bigmi/core'
|
|
2
|
-
export const version = '0.4.
|
|
2
|
+
export const version = '0.4.3'
|