@alephium/web3 0.28.1 → 0.29.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/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +29 -1
- package/dist/src/api/api-alephium.js +17 -1
- package/dist/src/api/api-explorer.d.ts +59 -2
- package/dist/src/api/api-explorer.js +48 -0
- package/dist/src/api/explorer-provider.d.ts +1 -0
- package/dist/src/api/explorer-provider.js +1 -0
- package/dist/src/api/node-provider.js +1 -0
- package/dist/src/api/types.d.ts +1 -0
- package/dist/src/api/types.js +33 -2
- package/dist/src/contract/contract.d.ts +1 -0
- package/dist/src/debug.d.ts +3 -0
- package/dist/src/debug.js +33 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/signer/types.d.ts +1 -0
- package/package.json +3 -3
- package/src/api/api-alephium.ts +43 -1
- package/src/api/api-explorer.ts +99 -2
- package/src/api/explorer-provider.ts +2 -0
- package/src/api/node-provider.ts +3 -1
- package/src/api/types.ts +32 -1
- package/src/contract/contract.ts +1 -0
- package/src/debug.ts +31 -0
- package/src/index.ts +1 -0
- package/src/signer/types.ts +1 -0
|
@@ -40,6 +40,7 @@ export class ExplorerProvider {
|
|
|
40
40
|
readonly charts: ExplorerApi<string>['charts']
|
|
41
41
|
readonly contractEvents: ExplorerApi<string>['contractEvents']
|
|
42
42
|
readonly contracts: ExplorerApi<string>['contracts']
|
|
43
|
+
readonly market: ExplorerApi<string>['market']
|
|
43
44
|
readonly utils: ExplorerApi<string>['utils']
|
|
44
45
|
|
|
45
46
|
constructor(baseUrl: string, apiKey?: string, customFetch?: typeof fetch)
|
|
@@ -65,6 +66,7 @@ export class ExplorerProvider {
|
|
|
65
66
|
this.charts = { ...explorerApi.charts }
|
|
66
67
|
this.utils = { ...explorerApi.utils }
|
|
67
68
|
this.contracts = { ...explorerApi.contracts }
|
|
69
|
+
this.market = { ...explorerApi.market }
|
|
68
70
|
this.contractEvents = { ...explorerApi.contractEvents }
|
|
69
71
|
}
|
|
70
72
|
|
package/src/api/node-provider.ts
CHANGED
|
@@ -24,7 +24,8 @@ import {
|
|
|
24
24
|
FungibleTokenMetaData,
|
|
25
25
|
NFTMetaData,
|
|
26
26
|
NFTCollectionMetaData,
|
|
27
|
-
StdInterfaceIds
|
|
27
|
+
StdInterfaceIds,
|
|
28
|
+
requestWithLog
|
|
28
29
|
} from './types'
|
|
29
30
|
import { Api as NodeApi, CallContractFailed, CallContractSucceeded } from './api-alephium'
|
|
30
31
|
import { HexString, tryGetCallResult } from '../contract'
|
|
@@ -100,6 +101,7 @@ export class NodeProvider implements NodeProviderApis {
|
|
|
100
101
|
this.utils = { ...nodeApi.utils }
|
|
101
102
|
this.miners = { ...nodeApi.miners }
|
|
102
103
|
this.events = { ...nodeApi.events }
|
|
104
|
+
requestWithLog(this)
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
request = (args: ApiRequestArguments): Promise<any> => {
|
package/src/api/types.ts
CHANGED
|
@@ -17,6 +17,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { ZERO_ADDRESS } from '../constants'
|
|
20
|
+
import { isDebugModeEnabled } from '../debug'
|
|
20
21
|
import { assertType, bs58, Eq, isBase58, isHexString } from '../utils'
|
|
21
22
|
import * as node from './api-alephium'
|
|
22
23
|
|
|
@@ -267,12 +268,42 @@ export interface ApiRequestArguments {
|
|
|
267
268
|
}
|
|
268
269
|
export type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>
|
|
269
270
|
|
|
271
|
+
async function call(args: ApiRequestArguments, handler: ApiRequestHandler): Promise<any> {
|
|
272
|
+
const debugModeEnabled = isDebugModeEnabled()
|
|
273
|
+
const { path, method, params } = args
|
|
274
|
+
if (debugModeEnabled) {
|
|
275
|
+
console.log(`[REQUEST] ${path} ${method} ${JSON.stringify(params)}`)
|
|
276
|
+
}
|
|
277
|
+
try {
|
|
278
|
+
const response = await handler(args)
|
|
279
|
+
if (debugModeEnabled) {
|
|
280
|
+
console.log(`[RESPONSE] ${path} ${method} ${JSON.stringify(response)}`)
|
|
281
|
+
}
|
|
282
|
+
return response
|
|
283
|
+
} catch (error) {
|
|
284
|
+
if (debugModeEnabled) {
|
|
285
|
+
console.error(`[ERROR] ${path} ${method} `, error)
|
|
286
|
+
}
|
|
287
|
+
throw error
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
270
291
|
export function forwardRequests(api: Record<string, any>, handler: ApiRequestHandler): void {
|
|
271
292
|
// Update class properties to forward requests
|
|
272
293
|
for (const [path, pathObject] of Object.entries(api)) {
|
|
273
294
|
for (const method of Object.keys(pathObject)) {
|
|
274
295
|
pathObject[`${method}`] = async (...params: any): Promise<any> => {
|
|
275
|
-
return
|
|
296
|
+
return call({ path, method, params }, handler)
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function requestWithLog(api: Record<string, any>) {
|
|
303
|
+
for (const [path, pathObject] of Object.entries(api)) {
|
|
304
|
+
for (const [method, handler] of Object.entries(pathObject)) {
|
|
305
|
+
pathObject[`${method}`] = async (...params: any): Promise<any> => {
|
|
306
|
+
return call({ path, method, params }, () => (handler as (...any) => Promise<any>)(...params))
|
|
276
307
|
}
|
|
277
308
|
}
|
|
278
309
|
}
|
package/src/contract/contract.ts
CHANGED
|
@@ -1410,6 +1410,7 @@ export interface DeployContractParams<P extends Fields = Fields> {
|
|
|
1410
1410
|
initialAttoAlphAmount?: Number256
|
|
1411
1411
|
initialTokenAmounts?: Token[]
|
|
1412
1412
|
issueTokenAmount?: Number256
|
|
1413
|
+
issueTokenTo?: string
|
|
1413
1414
|
gasAmount?: number
|
|
1414
1415
|
gasPrice?: Number256
|
|
1415
1416
|
}
|
package/src/debug.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
+
This file is part of the alephium project.
|
|
4
|
+
|
|
5
|
+
The library is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
The library is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Lesser General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
let debugModeEnabled = false
|
|
20
|
+
|
|
21
|
+
export function isDebugModeEnabled() {
|
|
22
|
+
return debugModeEnabled
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function enableDebugMode() {
|
|
26
|
+
debugModeEnabled = true
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function disableDebugMode() {
|
|
30
|
+
debugModeEnabled = false
|
|
31
|
+
}
|
package/src/index.ts
CHANGED