@alephium/web3 0.0.3 → 0.1.0-rc.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/.editorconfig +13 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +21 -0
- package/README.md +2 -2
- package/contracts/add.ral +7 -3
- package/contracts/greeter.ral +3 -1
- package/contracts/greeter_interface.ral +3 -0
- package/contracts/greeter_main.ral +9 -0
- package/contracts/main.ral +3 -5
- package/dev/user.conf +8 -4
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/scripts/check-versions.d.ts +1 -0
- package/dist/scripts/check-versions.js +39 -0
- package/dist/{cli → scripts}/create-project.d.ts +0 -0
- package/dist/scripts/create-project.js +124 -0
- package/dist/scripts/header.d.ts +0 -0
- package/dist/scripts/header.js +18 -0
- package/dist/scripts/rename-gitignore.d.ts +1 -0
- package/dist/scripts/rename-gitignore.js +24 -0
- package/dist/scripts/start-devnet.d.ts +1 -0
- package/dist/scripts/start-devnet.js +131 -0
- package/dist/scripts/stop-devnet.d.ts +1 -0
- package/dist/scripts/stop-devnet.js +32 -0
- package/dist/{api → src/api}/api-alephium.d.ts +287 -168
- package/dist/{api → src/api}/api-alephium.js +497 -115
- package/dist/{api → src/api}/api-explorer.d.ts +117 -19
- package/dist/{api → src/api}/api-explorer.js +206 -46
- package/dist/src/api/index.d.ts +10 -0
- package/dist/src/api/index.js +55 -0
- package/dist/{lib → src}/constants.d.ts +0 -0
- package/dist/{lib → src}/constants.js +0 -0
- package/dist/src/contract/contract.d.ts +182 -0
- package/dist/src/contract/contract.js +760 -0
- package/dist/src/contract/events.d.ts +29 -0
- package/dist/src/contract/events.js +77 -0
- package/dist/src/contract/index.d.ts +3 -0
- package/dist/src/contract/index.js +32 -0
- package/dist/src/contract/ralph.d.ts +12 -0
- package/dist/src/contract/ralph.js +362 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +34 -0
- package/dist/src/signer/index.d.ts +2 -0
- package/dist/src/signer/index.js +31 -0
- package/dist/src/signer/node-wallet.d.ts +13 -0
- package/dist/src/signer/node-wallet.js +60 -0
- package/dist/src/signer/signer.d.ts +143 -0
- package/dist/src/signer/signer.js +184 -0
- package/dist/src/test/index.d.ts +7 -0
- package/dist/src/test/index.js +41 -0
- package/dist/src/test/privatekey-wallet.d.ts +12 -0
- package/dist/src/test/privatekey-wallet.js +68 -0
- package/dist/{lib → src/utils}/address.d.ts +0 -0
- package/dist/{lib → src/utils}/address.js +1 -1
- package/dist/{lib → src/utils}/bs58.d.ts +2 -2
- package/dist/{lib → src/utils}/bs58.js +3 -1
- package/dist/{lib → src/utils}/djb2.d.ts +0 -0
- package/dist/{lib → src/utils}/djb2.js +1 -1
- package/dist/src/utils/index.d.ts +6 -0
- package/dist/src/utils/index.js +35 -0
- package/dist/{lib → src/utils}/password-crypto.d.ts +0 -0
- package/dist/{lib → src/utils}/password-crypto.js +8 -7
- package/dist/src/utils/transaction.d.ts +2 -0
- package/dist/src/utils/transaction.js +58 -0
- package/dist/src/utils/utils.d.ts +30 -0
- package/dist/{lib → src/utils}/utils.js +83 -19
- package/gitignore +5 -4
- package/package.json +56 -40
- package/scripts/create-project.ts +136 -0
- package/scripts/header.js +17 -0
- package/scripts/start-devnet.js +3 -3
- package/src/api/api-alephium.ts +2323 -0
- package/src/api/api-explorer.ts +808 -0
- package/src/api/index.ts +35 -0
- package/src/constants.ts +20 -0
- package/src/contract/contract.ts +1014 -0
- package/src/contract/events.ts +102 -0
- package/src/contract/index.ts +21 -0
- package/src/contract/ralph.test.ts +178 -0
- package/src/contract/ralph.ts +362 -0
- package/src/fixtures/address.json +36 -0
- package/src/fixtures/balance.json +9 -0
- package/src/fixtures/self-clique.json +19 -0
- package/src/fixtures/transaction.json +13 -0
- package/src/fixtures/transactions.json +179 -0
- package/src/index.ts +24 -0
- package/src/signer/fixtures/genesis.json +26 -0
- package/src/signer/fixtures/wallets.json +26 -0
- package/src/signer/index.ts +20 -0
- package/src/signer/node-wallet.ts +74 -0
- package/src/signer/signer.ts +313 -0
- package/src/test/index.ts +32 -0
- package/src/test/privatekey-wallet.ts +58 -0
- package/src/utils/address.test.ts +47 -0
- package/src/utils/address.ts +39 -0
- package/src/utils/bs58.ts +26 -0
- package/src/utils/djb2.test.ts +35 -0
- package/src/utils/djb2.ts +25 -0
- package/src/utils/index.ts +24 -0
- package/src/utils/password-crypto.test.ts +27 -0
- package/src/utils/password-crypto.ts +77 -0
- package/src/utils/transaction.test.ts +50 -0
- package/src/utils/transaction.ts +39 -0
- package/src/utils/utils.test.ts +160 -0
- package/src/utils/utils.ts +209 -0
- package/templates/{README.md → base/README.md} +4 -4
- package/templates/base/package.json +35 -0
- package/templates/base/src/greeter.ts +41 -0
- package/templates/base/tsconfig.json +19 -0
- package/templates/react/README.md +34 -0
- package/templates/react/config-overrides.js +18 -0
- package/templates/react/package.json +66 -0
- package/templates/react/src/App.tsx +42 -0
- package/templates/react/src/artifacts/greeter.ral.json +26 -0
- package/templates/react/src/artifacts/greeter_main.ral.json +22 -0
- package/templates/shared/.eslintrc.json +12 -0
- package/templates/shared/scripts/header.js +0 -0
- package/test/contract.test.ts +161 -0
- package/test/events.test.ts +139 -0
- package/webpack.config.js +1 -1
- package/contracts/greeter-main.ral +0 -8
- package/dist/cli/create-project.js +0 -87
- package/dist/lib/clique.d.ts +0 -23
- package/dist/lib/clique.js +0 -149
- package/dist/lib/contract.d.ts +0 -152
- package/dist/lib/contract.js +0 -711
- package/dist/lib/explorer.d.ts +0 -8
- package/dist/lib/explorer.js +0 -46
- package/dist/lib/index.d.ts +0 -12
- package/dist/lib/index.js +0 -60
- package/dist/lib/node.d.ts +0 -10
- package/dist/lib/node.js +0 -64
- package/dist/lib/numbers.d.ts +0 -7
- package/dist/lib/numbers.js +0 -128
- package/dist/lib/signer.d.ts +0 -17
- package/dist/lib/signer.js +0 -70
- package/dist/lib/storage-browser.d.ts +0 -9
- package/dist/lib/storage-browser.js +0 -52
- package/dist/lib/storage-node.d.ts +0 -9
- package/dist/lib/storage-node.js +0 -65
- package/dist/lib/utils.d.ts +0 -11
- package/dist/lib/wallet.d.ts +0 -30
- package/dist/lib/wallet.js +0 -142
- package/templates/package.json +0 -29
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/*
|
|
4
|
+
* ---------------------------------------------------------------
|
|
5
|
+
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
6
|
+
* ## ##
|
|
7
|
+
* ## AUTHOR: acacode ##
|
|
8
|
+
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
9
|
+
* ---------------------------------------------------------------
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export interface AddressBalance {
|
|
13
|
+
/** @format uint256 */
|
|
14
|
+
balance: string
|
|
15
|
+
|
|
16
|
+
/** @format uint256 */
|
|
17
|
+
lockedBalance: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface AddressInfo {
|
|
21
|
+
/** @format uint256 */
|
|
22
|
+
balance: string
|
|
23
|
+
|
|
24
|
+
/** @format uint256 */
|
|
25
|
+
lockedBalance: string
|
|
26
|
+
txNumber: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface BadRequest {
|
|
30
|
+
detail: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface BlockEntryLite {
|
|
34
|
+
hash: string
|
|
35
|
+
|
|
36
|
+
/** @format int64 */
|
|
37
|
+
timestamp: number
|
|
38
|
+
chainFrom: number
|
|
39
|
+
chainTo: number
|
|
40
|
+
height: number
|
|
41
|
+
txNumber: number
|
|
42
|
+
mainChain: boolean
|
|
43
|
+
|
|
44
|
+
/** @format bigint */
|
|
45
|
+
hashRate: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ConfirmedTransaction {
|
|
49
|
+
hash: string
|
|
50
|
+
blockHash: string
|
|
51
|
+
|
|
52
|
+
/** @format int64 */
|
|
53
|
+
timestamp: number
|
|
54
|
+
inputs?: Input[]
|
|
55
|
+
outputs?: Output[]
|
|
56
|
+
gasAmount: number
|
|
57
|
+
|
|
58
|
+
/** @format uint256 */
|
|
59
|
+
gasPrice: string
|
|
60
|
+
type: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ExplorerInfo {
|
|
64
|
+
releaseVersion: string
|
|
65
|
+
commit: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface Hashrate {
|
|
69
|
+
/** @format int64 */
|
|
70
|
+
timestamp: number
|
|
71
|
+
hashrate: string
|
|
72
|
+
value: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface Input {
|
|
76
|
+
outputRef: OutputRef
|
|
77
|
+
unlockScript?: string
|
|
78
|
+
txHashRef: string
|
|
79
|
+
address: string
|
|
80
|
+
|
|
81
|
+
/** @format uint256 */
|
|
82
|
+
amount: string
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface InternalServerError {
|
|
86
|
+
detail: string
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ListBlocks {
|
|
90
|
+
total: number
|
|
91
|
+
blocks?: BlockEntryLite[]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface NotFound {
|
|
95
|
+
detail: string
|
|
96
|
+
resource: string
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface Output {
|
|
100
|
+
hint: number
|
|
101
|
+
|
|
102
|
+
/** @format 32-byte-hash */
|
|
103
|
+
key: string
|
|
104
|
+
|
|
105
|
+
/** @format uint256 */
|
|
106
|
+
amount: string
|
|
107
|
+
address: string
|
|
108
|
+
|
|
109
|
+
/** @format int64 */
|
|
110
|
+
lockTime?: number
|
|
111
|
+
spent?: string
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface OutputRef {
|
|
115
|
+
hint: number
|
|
116
|
+
|
|
117
|
+
/** @format 32-byte-hash */
|
|
118
|
+
key: string
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface PerChainCount {
|
|
122
|
+
chainFrom: number
|
|
123
|
+
chainTo: number
|
|
124
|
+
|
|
125
|
+
/** @format int64 */
|
|
126
|
+
count: number
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface PerChainDuration {
|
|
130
|
+
chainFrom: number
|
|
131
|
+
chainTo: number
|
|
132
|
+
|
|
133
|
+
/** @format int64 */
|
|
134
|
+
duration: number
|
|
135
|
+
|
|
136
|
+
/** @format int64 */
|
|
137
|
+
value: number
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface PerChainHeight {
|
|
141
|
+
chainFrom: number
|
|
142
|
+
chainTo: number
|
|
143
|
+
|
|
144
|
+
/** @format int64 */
|
|
145
|
+
height: number
|
|
146
|
+
|
|
147
|
+
/** @format int64 */
|
|
148
|
+
value: number
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface PerChainTimedCount {
|
|
152
|
+
/** @format int64 */
|
|
153
|
+
timestamp: number
|
|
154
|
+
totalCountPerChain?: PerChainCount[]
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface ServiceUnavailable {
|
|
158
|
+
detail: string
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface TimedCount {
|
|
162
|
+
/** @format int64 */
|
|
163
|
+
timestamp: number
|
|
164
|
+
|
|
165
|
+
/** @format int64 */
|
|
166
|
+
totalCountAllChains: number
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface TokenSupply {
|
|
170
|
+
/** @format int64 */
|
|
171
|
+
timestamp: number
|
|
172
|
+
|
|
173
|
+
/** @format uint256 */
|
|
174
|
+
total: string
|
|
175
|
+
|
|
176
|
+
/** @format uint256 */
|
|
177
|
+
circulating: string
|
|
178
|
+
|
|
179
|
+
/** @format uint256 */
|
|
180
|
+
reserved: string
|
|
181
|
+
|
|
182
|
+
/** @format uint256 */
|
|
183
|
+
locked: string
|
|
184
|
+
|
|
185
|
+
/** @format uint256 */
|
|
186
|
+
maximum: string
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface Transaction {
|
|
190
|
+
hash: string
|
|
191
|
+
blockHash: string
|
|
192
|
+
|
|
193
|
+
/** @format int64 */
|
|
194
|
+
timestamp: number
|
|
195
|
+
inputs?: Input[]
|
|
196
|
+
outputs?: Output[]
|
|
197
|
+
gasAmount: number
|
|
198
|
+
|
|
199
|
+
/** @format uint256 */
|
|
200
|
+
gasPrice: string
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export type TransactionLike = ConfirmedTransaction | UnconfirmedTransaction
|
|
204
|
+
|
|
205
|
+
export interface UInput {
|
|
206
|
+
outputRef: OutputRef
|
|
207
|
+
unlockScript?: string
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface UOutput {
|
|
211
|
+
/** @format uint256 */
|
|
212
|
+
amount: string
|
|
213
|
+
address: string
|
|
214
|
+
|
|
215
|
+
/** @format int64 */
|
|
216
|
+
lockTime?: number
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface Unauthorized {
|
|
220
|
+
detail: string
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface UnconfirmedTransaction {
|
|
224
|
+
hash: string
|
|
225
|
+
chainFrom: number
|
|
226
|
+
chainTo: number
|
|
227
|
+
inputs?: UInput[]
|
|
228
|
+
outputs?: UOutput[]
|
|
229
|
+
gasAmount: number
|
|
230
|
+
|
|
231
|
+
/** @format uint256 */
|
|
232
|
+
gasPrice: string
|
|
233
|
+
type: string
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
import 'cross-fetch/polyfill'
|
|
237
|
+
|
|
238
|
+
function convertHttpResponse<T>(
|
|
239
|
+
response: HttpResponse<T, { detail: string }> | HttpResponse<T, { detail: string }>
|
|
240
|
+
): T {
|
|
241
|
+
if (response.error) {
|
|
242
|
+
throw new Error(response.error.detail)
|
|
243
|
+
} else {
|
|
244
|
+
return response.data
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export type QueryParamsType = Record<string | number, any>
|
|
249
|
+
export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>
|
|
250
|
+
|
|
251
|
+
export interface FullRequestParams extends Omit<RequestInit, 'body'> {
|
|
252
|
+
/** set parameter to `true` for call `securityWorker` for this request */
|
|
253
|
+
secure?: boolean
|
|
254
|
+
/** request path */
|
|
255
|
+
path: string
|
|
256
|
+
/** content type of request body */
|
|
257
|
+
type?: ContentType
|
|
258
|
+
/** query params */
|
|
259
|
+
query?: QueryParamsType
|
|
260
|
+
/** format of response (i.e. response.json() -> format: "json") */
|
|
261
|
+
format?: ResponseFormat
|
|
262
|
+
/** request body */
|
|
263
|
+
body?: unknown
|
|
264
|
+
/** base url */
|
|
265
|
+
baseUrl?: string
|
|
266
|
+
/** request cancellation token */
|
|
267
|
+
cancelToken?: CancelToken
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>
|
|
271
|
+
|
|
272
|
+
export interface ApiConfig<SecurityDataType = unknown> {
|
|
273
|
+
baseUrl?: string
|
|
274
|
+
baseApiParams?: Omit<RequestParams, 'baseUrl' | 'cancelToken' | 'signal'>
|
|
275
|
+
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void
|
|
276
|
+
customFetch?: typeof fetch
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
|
|
280
|
+
data: D
|
|
281
|
+
error: E
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
type CancelToken = Symbol | string | number
|
|
285
|
+
|
|
286
|
+
export enum ContentType {
|
|
287
|
+
Json = 'application/json',
|
|
288
|
+
FormData = 'multipart/form-data',
|
|
289
|
+
UrlEncoded = 'application/x-www-form-urlencoded'
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export class HttpClient<SecurityDataType = unknown> {
|
|
293
|
+
public baseUrl: string = ''
|
|
294
|
+
private securityData: SecurityDataType | null = null
|
|
295
|
+
private securityWorker?: ApiConfig<SecurityDataType>['securityWorker']
|
|
296
|
+
private abortControllers = new Map<CancelToken, AbortController>()
|
|
297
|
+
private customFetch = (...fetchParams: Parameters<typeof fetch>) => fetch(...fetchParams)
|
|
298
|
+
|
|
299
|
+
private baseApiParams: RequestParams = {
|
|
300
|
+
credentials: 'same-origin',
|
|
301
|
+
headers: {},
|
|
302
|
+
redirect: 'follow',
|
|
303
|
+
referrerPolicy: 'no-referrer'
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
constructor(apiConfig: ApiConfig<SecurityDataType> = {}) {
|
|
307
|
+
Object.assign(this, apiConfig)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
public setSecurityData = (data: SecurityDataType | null) => {
|
|
311
|
+
this.securityData = data
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private encodeQueryParam(key: string, value: any) {
|
|
315
|
+
const encodedKey = encodeURIComponent(key)
|
|
316
|
+
return `${encodedKey}=${encodeURIComponent(typeof value === 'number' ? value : `${value}`)}`
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private addQueryParam(query: QueryParamsType, key: string) {
|
|
320
|
+
return this.encodeQueryParam(key, query[key])
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private addArrayQueryParam(query: QueryParamsType, key: string) {
|
|
324
|
+
const value = query[key]
|
|
325
|
+
return value.map((v: any) => this.encodeQueryParam(key, v)).join('&')
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
protected toQueryString(rawQuery?: QueryParamsType): string {
|
|
329
|
+
const query = rawQuery || {}
|
|
330
|
+
const keys = Object.keys(query).filter((key) => 'undefined' !== typeof query[key])
|
|
331
|
+
return keys
|
|
332
|
+
.map((key) => (Array.isArray(query[key]) ? this.addArrayQueryParam(query, key) : this.addQueryParam(query, key)))
|
|
333
|
+
.join('&')
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
protected addQueryParams(rawQuery?: QueryParamsType): string {
|
|
337
|
+
const queryString = this.toQueryString(rawQuery)
|
|
338
|
+
return queryString ? `?${queryString}` : ''
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
private contentFormatters: Record<ContentType, (input: any) => any> = {
|
|
342
|
+
[ContentType.Json]: (input: any) =>
|
|
343
|
+
input !== null && (typeof input === 'object' || typeof input === 'string') ? JSON.stringify(input) : input,
|
|
344
|
+
[ContentType.FormData]: (input: any) =>
|
|
345
|
+
Object.keys(input || {}).reduce((formData, key) => {
|
|
346
|
+
const property = input[key]
|
|
347
|
+
formData.append(
|
|
348
|
+
key,
|
|
349
|
+
property instanceof Blob
|
|
350
|
+
? property
|
|
351
|
+
: typeof property === 'object' && property !== null
|
|
352
|
+
? JSON.stringify(property)
|
|
353
|
+
: `${property}`
|
|
354
|
+
)
|
|
355
|
+
return formData
|
|
356
|
+
}, new FormData()),
|
|
357
|
+
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
private mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams {
|
|
361
|
+
return {
|
|
362
|
+
...this.baseApiParams,
|
|
363
|
+
...params1,
|
|
364
|
+
...(params2 || {}),
|
|
365
|
+
headers: {
|
|
366
|
+
...(this.baseApiParams.headers || {}),
|
|
367
|
+
...(params1.headers || {}),
|
|
368
|
+
...((params2 && params2.headers) || {})
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private createAbortSignal = (cancelToken: CancelToken): AbortSignal | undefined => {
|
|
374
|
+
if (this.abortControllers.has(cancelToken)) {
|
|
375
|
+
const abortController = this.abortControllers.get(cancelToken)
|
|
376
|
+
if (abortController) {
|
|
377
|
+
return abortController.signal
|
|
378
|
+
}
|
|
379
|
+
return void 0
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const abortController = new AbortController()
|
|
383
|
+
this.abortControllers.set(cancelToken, abortController)
|
|
384
|
+
return abortController.signal
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
public abortRequest = (cancelToken: CancelToken) => {
|
|
388
|
+
const abortController = this.abortControllers.get(cancelToken)
|
|
389
|
+
|
|
390
|
+
if (abortController) {
|
|
391
|
+
abortController.abort()
|
|
392
|
+
this.abortControllers.delete(cancelToken)
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
public request = async <T = any, E = any>({
|
|
397
|
+
body,
|
|
398
|
+
secure,
|
|
399
|
+
path,
|
|
400
|
+
type,
|
|
401
|
+
query,
|
|
402
|
+
format,
|
|
403
|
+
baseUrl,
|
|
404
|
+
cancelToken,
|
|
405
|
+
...params
|
|
406
|
+
}: FullRequestParams): Promise<HttpResponse<T, E>> => {
|
|
407
|
+
const secureParams =
|
|
408
|
+
((typeof secure === 'boolean' ? secure : this.baseApiParams.secure) &&
|
|
409
|
+
this.securityWorker &&
|
|
410
|
+
(await this.securityWorker(this.securityData))) ||
|
|
411
|
+
{}
|
|
412
|
+
const requestParams = this.mergeRequestParams(params, secureParams)
|
|
413
|
+
const queryString = query && this.toQueryString(query)
|
|
414
|
+
const payloadFormatter = this.contentFormatters[type || ContentType.Json]
|
|
415
|
+
const responseFormat = format || requestParams.format
|
|
416
|
+
|
|
417
|
+
return this.customFetch(`${baseUrl || this.baseUrl || ''}${path}${queryString ? `?${queryString}` : ''}`, {
|
|
418
|
+
...requestParams,
|
|
419
|
+
headers: {
|
|
420
|
+
...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {}),
|
|
421
|
+
...(requestParams.headers || {})
|
|
422
|
+
},
|
|
423
|
+
signal: cancelToken ? this.createAbortSignal(cancelToken) : void 0,
|
|
424
|
+
body: typeof body === 'undefined' || body === null ? null : payloadFormatter(body)
|
|
425
|
+
}).then(async (response) => {
|
|
426
|
+
const r = response as HttpResponse<T, E>
|
|
427
|
+
r.data = null as unknown as T
|
|
428
|
+
r.error = null as unknown as E
|
|
429
|
+
|
|
430
|
+
const data = !responseFormat
|
|
431
|
+
? r
|
|
432
|
+
: await response[responseFormat]()
|
|
433
|
+
.then((data) => {
|
|
434
|
+
if (r.ok) {
|
|
435
|
+
r.data = data
|
|
436
|
+
} else {
|
|
437
|
+
r.error = data
|
|
438
|
+
}
|
|
439
|
+
return r
|
|
440
|
+
})
|
|
441
|
+
.catch((e) => {
|
|
442
|
+
r.error = e
|
|
443
|
+
return r
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
if (cancelToken) {
|
|
447
|
+
this.abortControllers.delete(cancelToken)
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (!response.ok) throw data
|
|
451
|
+
return data
|
|
452
|
+
})
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* @title Alephium Explorer API
|
|
458
|
+
* @version 1.0
|
|
459
|
+
*/
|
|
460
|
+
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
461
|
+
blocks = {
|
|
462
|
+
/**
|
|
463
|
+
* @description List blocks within time interval
|
|
464
|
+
*
|
|
465
|
+
* @tags Blocks
|
|
466
|
+
* @name GetBlocks
|
|
467
|
+
* @request GET:/blocks
|
|
468
|
+
*/
|
|
469
|
+
getBlocks: (query?: { page?: number; limit?: number; reverse?: boolean }, params: RequestParams = {}) =>
|
|
470
|
+
this.request<ListBlocks, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
471
|
+
path: `/blocks`,
|
|
472
|
+
method: 'GET',
|
|
473
|
+
query: query,
|
|
474
|
+
format: 'json',
|
|
475
|
+
...params
|
|
476
|
+
}).then(convertHttpResponse),
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* @description Get a block with hash
|
|
480
|
+
*
|
|
481
|
+
* @tags Blocks
|
|
482
|
+
* @name GetBlocksBlockHash
|
|
483
|
+
* @request GET:/blocks/{block-hash}
|
|
484
|
+
*/
|
|
485
|
+
getBlocksBlockHash: (blockHash: string, params: RequestParams = {}) =>
|
|
486
|
+
this.request<BlockEntryLite, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
487
|
+
path: `/blocks/${blockHash}`,
|
|
488
|
+
method: 'GET',
|
|
489
|
+
format: 'json',
|
|
490
|
+
...params
|
|
491
|
+
}).then(convertHttpResponse),
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* @description Get block's transactions
|
|
495
|
+
*
|
|
496
|
+
* @tags Blocks
|
|
497
|
+
* @name GetBlocksBlockHashTransactions
|
|
498
|
+
* @request GET:/blocks/{block-hash}/transactions
|
|
499
|
+
*/
|
|
500
|
+
getBlocksBlockHashTransactions: (
|
|
501
|
+
blockHash: string,
|
|
502
|
+
query?: { page?: number; limit?: number; reverse?: boolean },
|
|
503
|
+
params: RequestParams = {}
|
|
504
|
+
) =>
|
|
505
|
+
this.request<Transaction[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
506
|
+
path: `/blocks/${blockHash}/transactions`,
|
|
507
|
+
method: 'GET',
|
|
508
|
+
query: query,
|
|
509
|
+
format: 'json',
|
|
510
|
+
...params
|
|
511
|
+
}).then(convertHttpResponse)
|
|
512
|
+
}
|
|
513
|
+
transactions = {
|
|
514
|
+
/**
|
|
515
|
+
* @description Get a transaction with hash
|
|
516
|
+
*
|
|
517
|
+
* @tags Transactions
|
|
518
|
+
* @name GetTransactionsTransactionHash
|
|
519
|
+
* @request GET:/transactions/{transaction-hash}
|
|
520
|
+
*/
|
|
521
|
+
getTransactionsTransactionHash: (transactionHash: string, params: RequestParams = {}) =>
|
|
522
|
+
this.request<TransactionLike, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
523
|
+
path: `/transactions/${transactionHash}`,
|
|
524
|
+
method: 'GET',
|
|
525
|
+
format: 'json',
|
|
526
|
+
...params
|
|
527
|
+
}).then(convertHttpResponse)
|
|
528
|
+
}
|
|
529
|
+
addresses = {
|
|
530
|
+
/**
|
|
531
|
+
* @description Get address information
|
|
532
|
+
*
|
|
533
|
+
* @tags Addresses
|
|
534
|
+
* @name GetAddressesAddress
|
|
535
|
+
* @request GET:/addresses/{address}
|
|
536
|
+
*/
|
|
537
|
+
getAddressesAddress: (address: string, params: RequestParams = {}) =>
|
|
538
|
+
this.request<AddressInfo, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
539
|
+
path: `/addresses/${address}`,
|
|
540
|
+
method: 'GET',
|
|
541
|
+
format: 'json',
|
|
542
|
+
...params
|
|
543
|
+
}).then(convertHttpResponse),
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* @description List transactions of a given address
|
|
547
|
+
*
|
|
548
|
+
* @tags Addresses
|
|
549
|
+
* @name GetAddressesAddressTransactions
|
|
550
|
+
* @request GET:/addresses/{address}/transactions
|
|
551
|
+
*/
|
|
552
|
+
getAddressesAddressTransactions: (
|
|
553
|
+
address: string,
|
|
554
|
+
query?: { page?: number; limit?: number; reverse?: boolean },
|
|
555
|
+
params: RequestParams = {}
|
|
556
|
+
) =>
|
|
557
|
+
this.request<Transaction[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
558
|
+
path: `/addresses/${address}/transactions`,
|
|
559
|
+
method: 'GET',
|
|
560
|
+
query: query,
|
|
561
|
+
format: 'json',
|
|
562
|
+
...params
|
|
563
|
+
}).then(convertHttpResponse),
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* @description Get total transactions of a given address
|
|
567
|
+
*
|
|
568
|
+
* @tags Addresses
|
|
569
|
+
* @name GetAddressesAddressTotalTransactions
|
|
570
|
+
* @request GET:/addresses/{address}/total-transactions
|
|
571
|
+
*/
|
|
572
|
+
getAddressesAddressTotalTransactions: (address: string, params: RequestParams = {}) =>
|
|
573
|
+
this.request<number, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
574
|
+
path: `/addresses/${address}/total-transactions`,
|
|
575
|
+
method: 'GET',
|
|
576
|
+
format: 'json',
|
|
577
|
+
...params
|
|
578
|
+
}).then(convertHttpResponse),
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* @description Get address balance
|
|
582
|
+
*
|
|
583
|
+
* @tags Addresses
|
|
584
|
+
* @name GetAddressesAddressBalance
|
|
585
|
+
* @request GET:/addresses/{address}/balance
|
|
586
|
+
*/
|
|
587
|
+
getAddressesAddressBalance: (address: string, params: RequestParams = {}) =>
|
|
588
|
+
this.request<AddressBalance, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
589
|
+
path: `/addresses/${address}/balance`,
|
|
590
|
+
method: 'GET',
|
|
591
|
+
format: 'json',
|
|
592
|
+
...params
|
|
593
|
+
}).then(convertHttpResponse)
|
|
594
|
+
}
|
|
595
|
+
infos = {
|
|
596
|
+
/**
|
|
597
|
+
* @description Get explorer informations
|
|
598
|
+
*
|
|
599
|
+
* @tags Infos
|
|
600
|
+
* @name GetInfos
|
|
601
|
+
* @request GET:/infos
|
|
602
|
+
*/
|
|
603
|
+
getInfos: (params: RequestParams = {}) =>
|
|
604
|
+
this.request<ExplorerInfo, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
605
|
+
path: `/infos`,
|
|
606
|
+
method: 'GET',
|
|
607
|
+
format: 'json',
|
|
608
|
+
...params
|
|
609
|
+
}).then(convertHttpResponse),
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* @description List latest height for each chain
|
|
613
|
+
*
|
|
614
|
+
* @tags Infos
|
|
615
|
+
* @name GetInfosHeights
|
|
616
|
+
* @request GET:/infos/heights
|
|
617
|
+
*/
|
|
618
|
+
getInfosHeights: (params: RequestParams = {}) =>
|
|
619
|
+
this.request<PerChainHeight[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
620
|
+
path: `/infos/heights`,
|
|
621
|
+
method: 'GET',
|
|
622
|
+
format: 'json',
|
|
623
|
+
...params
|
|
624
|
+
}).then(convertHttpResponse),
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* @description Get token supply list
|
|
628
|
+
*
|
|
629
|
+
* @tags Infos
|
|
630
|
+
* @name GetInfosSupply
|
|
631
|
+
* @request GET:/infos/supply
|
|
632
|
+
*/
|
|
633
|
+
getInfosSupply: (query?: { page?: number; limit?: number; reverse?: boolean }, params: RequestParams = {}) =>
|
|
634
|
+
this.request<TokenSupply[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
635
|
+
path: `/infos/supply`,
|
|
636
|
+
method: 'GET',
|
|
637
|
+
query: query,
|
|
638
|
+
format: 'json',
|
|
639
|
+
...params
|
|
640
|
+
}).then(convertHttpResponse),
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* @description Get the ALPH total supply
|
|
644
|
+
*
|
|
645
|
+
* @tags Infos
|
|
646
|
+
* @name GetInfosSupplyTotalAlph
|
|
647
|
+
* @request GET:/infos/supply/total-alph
|
|
648
|
+
*/
|
|
649
|
+
getInfosSupplyTotalAlph: (params: RequestParams = {}) =>
|
|
650
|
+
this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
651
|
+
path: `/infos/supply/total-alph`,
|
|
652
|
+
method: 'GET',
|
|
653
|
+
...params
|
|
654
|
+
}).then(convertHttpResponse),
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* @description Get the ALPH circulating supply
|
|
658
|
+
*
|
|
659
|
+
* @tags Infos
|
|
660
|
+
* @name GetInfosSupplyCirculatingAlph
|
|
661
|
+
* @request GET:/infos/supply/circulating-alph
|
|
662
|
+
*/
|
|
663
|
+
getInfosSupplyCirculatingAlph: (params: RequestParams = {}) =>
|
|
664
|
+
this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
665
|
+
path: `/infos/supply/circulating-alph`,
|
|
666
|
+
method: 'GET',
|
|
667
|
+
...params
|
|
668
|
+
}).then(convertHttpResponse),
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* @description Get the ALPH reserved supply
|
|
672
|
+
*
|
|
673
|
+
* @tags Infos
|
|
674
|
+
* @name GetInfosSupplyReservedAlph
|
|
675
|
+
* @request GET:/infos/supply/reserved-alph
|
|
676
|
+
*/
|
|
677
|
+
getInfosSupplyReservedAlph: (params: RequestParams = {}) =>
|
|
678
|
+
this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
679
|
+
path: `/infos/supply/reserved-alph`,
|
|
680
|
+
method: 'GET',
|
|
681
|
+
...params
|
|
682
|
+
}).then(convertHttpResponse),
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* @description Get the ALPH locked supply
|
|
686
|
+
*
|
|
687
|
+
* @tags Infos
|
|
688
|
+
* @name GetInfosSupplyLockedAlph
|
|
689
|
+
* @request GET:/infos/supply/locked-alph
|
|
690
|
+
*/
|
|
691
|
+
getInfosSupplyLockedAlph: (params: RequestParams = {}) =>
|
|
692
|
+
this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
693
|
+
path: `/infos/supply/locked-alph`,
|
|
694
|
+
method: 'GET',
|
|
695
|
+
...params
|
|
696
|
+
}).then(convertHttpResponse),
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* @description Get the total number of transactions
|
|
700
|
+
*
|
|
701
|
+
* @tags Infos
|
|
702
|
+
* @name GetInfosTotalTransactions
|
|
703
|
+
* @request GET:/infos/total-transactions
|
|
704
|
+
*/
|
|
705
|
+
getInfosTotalTransactions: (params: RequestParams = {}) =>
|
|
706
|
+
this.request<number, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
707
|
+
path: `/infos/total-transactions`,
|
|
708
|
+
method: 'GET',
|
|
709
|
+
...params
|
|
710
|
+
}).then(convertHttpResponse),
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* @description Get the average block time for each chain
|
|
714
|
+
*
|
|
715
|
+
* @tags Infos
|
|
716
|
+
* @name GetInfosAverageBlockTimes
|
|
717
|
+
* @request GET:/infos/average-block-times
|
|
718
|
+
*/
|
|
719
|
+
getInfosAverageBlockTimes: (params: RequestParams = {}) =>
|
|
720
|
+
this.request<PerChainDuration[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>(
|
|
721
|
+
{
|
|
722
|
+
path: `/infos/average-block-times`,
|
|
723
|
+
method: 'GET',
|
|
724
|
+
format: 'json',
|
|
725
|
+
...params
|
|
726
|
+
}
|
|
727
|
+
).then(convertHttpResponse)
|
|
728
|
+
}
|
|
729
|
+
charts = {
|
|
730
|
+
/**
|
|
731
|
+
* @description `interval-type` query param: hourly, daily
|
|
732
|
+
*
|
|
733
|
+
* @tags Charts
|
|
734
|
+
* @name GetChartsHashrates
|
|
735
|
+
* @summary Get hashrate chart in H/s
|
|
736
|
+
* @request GET:/charts/hashrates
|
|
737
|
+
*/
|
|
738
|
+
getChartsHashrates: (
|
|
739
|
+
query: { fromTs: number; toTs: number; 'interval-type': string },
|
|
740
|
+
params: RequestParams = {}
|
|
741
|
+
) =>
|
|
742
|
+
this.request<Hashrate[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
743
|
+
path: `/charts/hashrates`,
|
|
744
|
+
method: 'GET',
|
|
745
|
+
query: query,
|
|
746
|
+
format: 'json',
|
|
747
|
+
...params
|
|
748
|
+
}).then(convertHttpResponse),
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* @description `interval-type` query param: hourly, daily
|
|
752
|
+
*
|
|
753
|
+
* @tags Charts
|
|
754
|
+
* @name GetChartsTransactionsCount
|
|
755
|
+
* @summary Get transaction count history
|
|
756
|
+
* @request GET:/charts/transactions-count
|
|
757
|
+
*/
|
|
758
|
+
getChartsTransactionsCount: (
|
|
759
|
+
query: { fromTs: number; toTs: number; 'interval-type': string },
|
|
760
|
+
params: RequestParams = {}
|
|
761
|
+
) =>
|
|
762
|
+
this.request<TimedCount[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
763
|
+
path: `/charts/transactions-count`,
|
|
764
|
+
method: 'GET',
|
|
765
|
+
query: query,
|
|
766
|
+
format: 'json',
|
|
767
|
+
...params
|
|
768
|
+
}).then(convertHttpResponse),
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* @description `interval-type` query param: hourly, daily
|
|
772
|
+
*
|
|
773
|
+
* @tags Charts
|
|
774
|
+
* @name GetChartsTransactionsCountPerChain
|
|
775
|
+
* @summary Get transaction count history per chain
|
|
776
|
+
* @request GET:/charts/transactions-count-per-chain
|
|
777
|
+
*/
|
|
778
|
+
getChartsTransactionsCountPerChain: (
|
|
779
|
+
query: { fromTs: number; toTs: number; 'interval-type': string },
|
|
780
|
+
params: RequestParams = {}
|
|
781
|
+
) =>
|
|
782
|
+
this.request<
|
|
783
|
+
PerChainTimedCount[],
|
|
784
|
+
BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
|
|
785
|
+
>({
|
|
786
|
+
path: `/charts/transactions-count-per-chain`,
|
|
787
|
+
method: 'GET',
|
|
788
|
+
query: query,
|
|
789
|
+
format: 'json',
|
|
790
|
+
...params
|
|
791
|
+
}).then(convertHttpResponse)
|
|
792
|
+
}
|
|
793
|
+
utils = {
|
|
794
|
+
/**
|
|
795
|
+
* @description Perform a sanity check
|
|
796
|
+
*
|
|
797
|
+
* @tags Utils
|
|
798
|
+
* @name PutUtilsSanityCheck
|
|
799
|
+
* @request PUT:/utils/sanity-check
|
|
800
|
+
*/
|
|
801
|
+
putUtilsSanityCheck: (params: RequestParams = {}) =>
|
|
802
|
+
this.request<void, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
803
|
+
path: `/utils/sanity-check`,
|
|
804
|
+
method: 'PUT',
|
|
805
|
+
...params
|
|
806
|
+
}).then(convertHttpResponse)
|
|
807
|
+
}
|
|
808
|
+
}
|