@alephium/web3 0.28.1 → 0.29.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/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -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/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/package.json +2 -2
- 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/debug.ts +31 -0
- package/src/index.ts +1 -0
|
@@ -37,6 +37,9 @@ export interface AddressTokenBalance {
|
|
|
37
37
|
/** @format uint256 */
|
|
38
38
|
lockedBalance: string;
|
|
39
39
|
}
|
|
40
|
+
export interface AmountHistory {
|
|
41
|
+
amountHistory?: TimedAmount[];
|
|
42
|
+
}
|
|
40
43
|
export interface AssetOutput {
|
|
41
44
|
/** @format int32 */
|
|
42
45
|
hint: number;
|
|
@@ -145,7 +148,8 @@ export interface InternalServerError {
|
|
|
145
148
|
}
|
|
146
149
|
export declare enum IntervalType {
|
|
147
150
|
Daily = "daily",
|
|
148
|
-
Hourly = "hourly"
|
|
151
|
+
Hourly = "hourly",
|
|
152
|
+
Weekly = "weekly"
|
|
149
153
|
}
|
|
150
154
|
export interface ListBlocks {
|
|
151
155
|
/** @format int32 */
|
|
@@ -253,12 +257,22 @@ export interface ServiceUnavailable {
|
|
|
253
257
|
export interface SubContracts {
|
|
254
258
|
subContracts?: string[];
|
|
255
259
|
}
|
|
260
|
+
export interface TimedAmount {
|
|
261
|
+
/** @format int64 */
|
|
262
|
+
timestamp: number;
|
|
263
|
+
/** @format bigint */
|
|
264
|
+
amount: string;
|
|
265
|
+
}
|
|
256
266
|
export interface TimedCount {
|
|
257
267
|
/** @format int64 */
|
|
258
268
|
timestamp: number;
|
|
259
269
|
/** @format int64 */
|
|
260
270
|
totalCountAllChains: number;
|
|
261
271
|
}
|
|
272
|
+
export interface TimedPrices {
|
|
273
|
+
timestamps?: number[];
|
|
274
|
+
prices?: number[];
|
|
275
|
+
}
|
|
262
276
|
export interface Token {
|
|
263
277
|
/** @format 32-byte-hash */
|
|
264
278
|
id: string;
|
|
@@ -662,6 +676,27 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
662
676
|
*/
|
|
663
677
|
toTs: number;
|
|
664
678
|
}, params?: RequestParams) => Promise<string>;
|
|
679
|
+
/**
|
|
680
|
+
* No description
|
|
681
|
+
*
|
|
682
|
+
* @tags Addresses
|
|
683
|
+
* @name GetAddressesAddressAmountHistoryDeprecated
|
|
684
|
+
* @request GET:/addresses/{address}/amount-history-DEPRECATED
|
|
685
|
+
* @deprecated
|
|
686
|
+
*/
|
|
687
|
+
getAddressesAddressAmountHistoryDeprecated: (address: string, query: {
|
|
688
|
+
/**
|
|
689
|
+
* @format int64
|
|
690
|
+
* @min 0
|
|
691
|
+
*/
|
|
692
|
+
fromTs: number;
|
|
693
|
+
/**
|
|
694
|
+
* @format int64
|
|
695
|
+
* @min 0
|
|
696
|
+
*/
|
|
697
|
+
toTs: number;
|
|
698
|
+
'interval-type': IntervalType;
|
|
699
|
+
}, params?: RequestParams) => Promise<string>;
|
|
665
700
|
/**
|
|
666
701
|
* No description
|
|
667
702
|
*
|
|
@@ -681,7 +716,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
681
716
|
*/
|
|
682
717
|
toTs: number;
|
|
683
718
|
'interval-type': IntervalType;
|
|
684
|
-
}, params?: RequestParams) => Promise<
|
|
719
|
+
}, params?: RequestParams) => Promise<AmountHistory>;
|
|
685
720
|
};
|
|
686
721
|
infos: {
|
|
687
722
|
/**
|
|
@@ -1008,6 +1043,28 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1008
1043
|
limit?: number;
|
|
1009
1044
|
}, params?: RequestParams) => Promise<SubContracts>;
|
|
1010
1045
|
};
|
|
1046
|
+
market: {
|
|
1047
|
+
/**
|
|
1048
|
+
* No description
|
|
1049
|
+
*
|
|
1050
|
+
* @tags Market
|
|
1051
|
+
* @name PostMarketPrices
|
|
1052
|
+
* @request POST:/market/prices
|
|
1053
|
+
*/
|
|
1054
|
+
postMarketPrices: (query: {
|
|
1055
|
+
currency: string;
|
|
1056
|
+
}, data?: string[], params?: RequestParams) => Promise<number[]>;
|
|
1057
|
+
/**
|
|
1058
|
+
* No description
|
|
1059
|
+
*
|
|
1060
|
+
* @tags Market
|
|
1061
|
+
* @name GetMarketPricesSymbolCharts
|
|
1062
|
+
* @request GET:/market/prices/{symbol}/charts
|
|
1063
|
+
*/
|
|
1064
|
+
getMarketPricesSymbolCharts: (symbol: string, query: {
|
|
1065
|
+
currency: string;
|
|
1066
|
+
}, params?: RequestParams) => Promise<TimedPrices>;
|
|
1067
|
+
};
|
|
1011
1068
|
utils: {
|
|
1012
1069
|
/**
|
|
1013
1070
|
* @description Perform a sanity check
|
|
@@ -15,6 +15,7 @@ var IntervalType;
|
|
|
15
15
|
(function (IntervalType) {
|
|
16
16
|
IntervalType["Daily"] = "daily";
|
|
17
17
|
IntervalType["Hourly"] = "hourly";
|
|
18
|
+
IntervalType["Weekly"] = "weekly";
|
|
18
19
|
})(IntervalType = exports.IntervalType || (exports.IntervalType = {}));
|
|
19
20
|
var TokenStdInterfaceId;
|
|
20
21
|
(function (TokenStdInterfaceId) {
|
|
@@ -415,6 +416,21 @@ class Api extends HttpClient {
|
|
|
415
416
|
format: 'text',
|
|
416
417
|
...params
|
|
417
418
|
}).then(utils_1.convertHttpResponse),
|
|
419
|
+
/**
|
|
420
|
+
* No description
|
|
421
|
+
*
|
|
422
|
+
* @tags Addresses
|
|
423
|
+
* @name GetAddressesAddressAmountHistoryDeprecated
|
|
424
|
+
* @request GET:/addresses/{address}/amount-history-DEPRECATED
|
|
425
|
+
* @deprecated
|
|
426
|
+
*/
|
|
427
|
+
getAddressesAddressAmountHistoryDeprecated: (address, query, params = {}) => this.request({
|
|
428
|
+
path: `/addresses/${address}/amount-history-DEPRECATED`,
|
|
429
|
+
method: 'GET',
|
|
430
|
+
query: query,
|
|
431
|
+
format: 'json',
|
|
432
|
+
...params
|
|
433
|
+
}).then(utils_1.convertHttpResponse),
|
|
418
434
|
/**
|
|
419
435
|
* No description
|
|
420
436
|
*
|
|
@@ -775,6 +791,38 @@ class Api extends HttpClient {
|
|
|
775
791
|
...params
|
|
776
792
|
}).then(utils_1.convertHttpResponse)
|
|
777
793
|
};
|
|
794
|
+
this.market = {
|
|
795
|
+
/**
|
|
796
|
+
* No description
|
|
797
|
+
*
|
|
798
|
+
* @tags Market
|
|
799
|
+
* @name PostMarketPrices
|
|
800
|
+
* @request POST:/market/prices
|
|
801
|
+
*/
|
|
802
|
+
postMarketPrices: (query, data, params = {}) => this.request({
|
|
803
|
+
path: `/market/prices`,
|
|
804
|
+
method: 'POST',
|
|
805
|
+
query: query,
|
|
806
|
+
body: data,
|
|
807
|
+
type: ContentType.Json,
|
|
808
|
+
format: 'json',
|
|
809
|
+
...params
|
|
810
|
+
}).then(utils_1.convertHttpResponse),
|
|
811
|
+
/**
|
|
812
|
+
* No description
|
|
813
|
+
*
|
|
814
|
+
* @tags Market
|
|
815
|
+
* @name GetMarketPricesSymbolCharts
|
|
816
|
+
* @request GET:/market/prices/{symbol}/charts
|
|
817
|
+
*/
|
|
818
|
+
getMarketPricesSymbolCharts: (symbol, query, params = {}) => this.request({
|
|
819
|
+
path: `/market/prices/${symbol}/charts`,
|
|
820
|
+
method: 'GET',
|
|
821
|
+
query: query,
|
|
822
|
+
format: 'json',
|
|
823
|
+
...params
|
|
824
|
+
}).then(utils_1.convertHttpResponse)
|
|
825
|
+
};
|
|
778
826
|
this.utils = {
|
|
779
827
|
/**
|
|
780
828
|
* @description Perform a sanity check
|
|
@@ -10,6 +10,7 @@ export declare class ExplorerProvider {
|
|
|
10
10
|
readonly charts: ExplorerApi<string>['charts'];
|
|
11
11
|
readonly contractEvents: ExplorerApi<string>['contractEvents'];
|
|
12
12
|
readonly contracts: ExplorerApi<string>['contracts'];
|
|
13
|
+
readonly market: ExplorerApi<string>['market'];
|
|
13
14
|
readonly utils: ExplorerApi<string>['utils'];
|
|
14
15
|
constructor(baseUrl: string, apiKey?: string, customFetch?: typeof fetch);
|
|
15
16
|
constructor(provider: ExplorerProvider);
|
|
@@ -55,6 +55,7 @@ class ExplorerProvider {
|
|
|
55
55
|
this.charts = { ...explorerApi.charts };
|
|
56
56
|
this.utils = { ...explorerApi.utils };
|
|
57
57
|
this.contracts = { ...explorerApi.contracts };
|
|
58
|
+
this.market = { ...explorerApi.market };
|
|
58
59
|
this.contractEvents = { ...explorerApi.contractEvents };
|
|
59
60
|
}
|
|
60
61
|
// This can prevent the proxied explorer provider from being modified
|
|
@@ -160,6 +160,7 @@ class NodeProvider {
|
|
|
160
160
|
this.utils = { ...nodeApi.utils };
|
|
161
161
|
this.miners = { ...nodeApi.miners };
|
|
162
162
|
this.events = { ...nodeApi.events };
|
|
163
|
+
(0, types_1.requestWithLog)(this);
|
|
163
164
|
}
|
|
164
165
|
// This can prevent the proxied node provider from being modified
|
|
165
166
|
static Proxy(nodeProvider) {
|
package/dist/src/api/types.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface ApiRequestArguments {
|
|
|
30
30
|
}
|
|
31
31
|
export type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
|
|
32
32
|
export declare function forwardRequests(api: Record<string, any>, handler: ApiRequestHandler): void;
|
|
33
|
+
export declare function requestWithLog(api: Record<string, any>): void;
|
|
33
34
|
export declare function request(provider: Record<string, any>, args: ApiRequestArguments): Promise<any>;
|
|
34
35
|
export declare enum StdInterfaceIds {
|
|
35
36
|
FungibleToken = "0001",
|
package/dist/src/api/types.js
CHANGED
|
@@ -17,8 +17,9 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.StdInterfaceIds = exports.request = exports.forwardRequests = exports.typeLength = exports.getDefaultValue = exports.fromApiVal = exports.fromApiArray = exports.fromApiVals = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = void 0;
|
|
20
|
+
exports.StdInterfaceIds = exports.request = exports.requestWithLog = exports.forwardRequests = exports.typeLength = exports.getDefaultValue = exports.fromApiVal = exports.fromApiArray = exports.fromApiVals = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = void 0;
|
|
21
21
|
const constants_1 = require("../constants");
|
|
22
|
+
const debug_1 = require("../debug");
|
|
22
23
|
const utils_1 = require("../utils");
|
|
23
24
|
utils_1.assertType;
|
|
24
25
|
function toApiToken(token) {
|
|
@@ -263,17 +264,47 @@ function typeLength(tpe) {
|
|
|
263
264
|
return dims.reduce((a, b) => a * b);
|
|
264
265
|
}
|
|
265
266
|
exports.typeLength = typeLength;
|
|
267
|
+
async function call(args, handler) {
|
|
268
|
+
const debugModeEnabled = (0, debug_1.isDebugModeEnabled)();
|
|
269
|
+
const { path, method, params } = args;
|
|
270
|
+
if (debugModeEnabled) {
|
|
271
|
+
console.log(`[REQUEST] ${path} ${method} ${JSON.stringify(params)}`);
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
const response = await handler(args);
|
|
275
|
+
if (debugModeEnabled) {
|
|
276
|
+
console.log(`[RESPONSE] ${path} ${method} ${JSON.stringify(response)}`);
|
|
277
|
+
}
|
|
278
|
+
return response;
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
if (debugModeEnabled) {
|
|
282
|
+
console.error(`[ERROR] ${path} ${method} `, error);
|
|
283
|
+
}
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
266
287
|
function forwardRequests(api, handler) {
|
|
267
288
|
// Update class properties to forward requests
|
|
268
289
|
for (const [path, pathObject] of Object.entries(api)) {
|
|
269
290
|
for (const method of Object.keys(pathObject)) {
|
|
270
291
|
pathObject[`${method}`] = async (...params) => {
|
|
271
|
-
return
|
|
292
|
+
return call({ path, method, params }, handler);
|
|
272
293
|
};
|
|
273
294
|
}
|
|
274
295
|
}
|
|
275
296
|
}
|
|
276
297
|
exports.forwardRequests = forwardRequests;
|
|
298
|
+
function requestWithLog(api) {
|
|
299
|
+
for (const [path, pathObject] of Object.entries(api)) {
|
|
300
|
+
for (const [method, handler] of Object.entries(pathObject)) {
|
|
301
|
+
pathObject[`${method}`] = async (...params) => {
|
|
302
|
+
return call({ path, method, params }, () => handler(...params));
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
exports.requestWithLog = requestWithLog;
|
|
277
308
|
async function request(provider, args) {
|
|
278
309
|
const call = provider[`${args.path}`][`${args.method}`];
|
|
279
310
|
return call(...args.params);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
+
This file is part of the alephium project.
|
|
5
|
+
|
|
6
|
+
The library is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
The library is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.disableDebugMode = exports.enableDebugMode = exports.isDebugModeEnabled = void 0;
|
|
21
|
+
let debugModeEnabled = false;
|
|
22
|
+
function isDebugModeEnabled() {
|
|
23
|
+
return debugModeEnabled;
|
|
24
|
+
}
|
|
25
|
+
exports.isDebugModeEnabled = isDebugModeEnabled;
|
|
26
|
+
function enableDebugMode() {
|
|
27
|
+
debugModeEnabled = true;
|
|
28
|
+
}
|
|
29
|
+
exports.enableDebugMode = enableDebugMode;
|
|
30
|
+
function disableDebugMode() {
|
|
31
|
+
debugModeEnabled = false;
|
|
32
|
+
}
|
|
33
|
+
exports.disableDebugMode = disableDebugMode;
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"author": "Alephium dev <dev@alephium.org>",
|
|
29
29
|
"config": {
|
|
30
30
|
"alephium_version": "2.5.5",
|
|
31
|
-
"explorer_backend_version": "1.16.
|
|
31
|
+
"explorer_backend_version": "1.16.1"
|
|
32
32
|
},
|
|
33
33
|
"type": "commonjs",
|
|
34
34
|
"dependencies": {
|
package/src/api/api-explorer.ts
CHANGED
|
@@ -52,6 +52,10 @@ export interface AddressTokenBalance {
|
|
|
52
52
|
lockedBalance: string
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
export interface AmountHistory {
|
|
56
|
+
amountHistory?: TimedAmount[]
|
|
57
|
+
}
|
|
58
|
+
|
|
55
59
|
export interface AssetOutput {
|
|
56
60
|
/** @format int32 */
|
|
57
61
|
hint: number
|
|
@@ -171,7 +175,8 @@ export interface InternalServerError {
|
|
|
171
175
|
|
|
172
176
|
export enum IntervalType {
|
|
173
177
|
Daily = 'daily',
|
|
174
|
-
Hourly = 'hourly'
|
|
178
|
+
Hourly = 'hourly',
|
|
179
|
+
Weekly = 'weekly'
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
export interface ListBlocks {
|
|
@@ -295,6 +300,13 @@ export interface SubContracts {
|
|
|
295
300
|
subContracts?: string[]
|
|
296
301
|
}
|
|
297
302
|
|
|
303
|
+
export interface TimedAmount {
|
|
304
|
+
/** @format int64 */
|
|
305
|
+
timestamp: number
|
|
306
|
+
/** @format bigint */
|
|
307
|
+
amount: string
|
|
308
|
+
}
|
|
309
|
+
|
|
298
310
|
export interface TimedCount {
|
|
299
311
|
/** @format int64 */
|
|
300
312
|
timestamp: number
|
|
@@ -302,6 +314,11 @@ export interface TimedCount {
|
|
|
302
314
|
totalCountAllChains: number
|
|
303
315
|
}
|
|
304
316
|
|
|
317
|
+
export interface TimedPrices {
|
|
318
|
+
timestamps?: number[]
|
|
319
|
+
prices?: number[]
|
|
320
|
+
}
|
|
321
|
+
|
|
305
322
|
export interface Token {
|
|
306
323
|
/** @format 32-byte-hash */
|
|
307
324
|
id: string
|
|
@@ -1049,6 +1066,39 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1049
1066
|
...params
|
|
1050
1067
|
}).then(convertHttpResponse),
|
|
1051
1068
|
|
|
1069
|
+
/**
|
|
1070
|
+
* No description
|
|
1071
|
+
*
|
|
1072
|
+
* @tags Addresses
|
|
1073
|
+
* @name GetAddressesAddressAmountHistoryDeprecated
|
|
1074
|
+
* @request GET:/addresses/{address}/amount-history-DEPRECATED
|
|
1075
|
+
* @deprecated
|
|
1076
|
+
*/
|
|
1077
|
+
getAddressesAddressAmountHistoryDeprecated: (
|
|
1078
|
+
address: string,
|
|
1079
|
+
query: {
|
|
1080
|
+
/**
|
|
1081
|
+
* @format int64
|
|
1082
|
+
* @min 0
|
|
1083
|
+
*/
|
|
1084
|
+
fromTs: number
|
|
1085
|
+
/**
|
|
1086
|
+
* @format int64
|
|
1087
|
+
* @min 0
|
|
1088
|
+
*/
|
|
1089
|
+
toTs: number
|
|
1090
|
+
'interval-type': IntervalType
|
|
1091
|
+
},
|
|
1092
|
+
params: RequestParams = {}
|
|
1093
|
+
) =>
|
|
1094
|
+
this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1095
|
+
path: `/addresses/${address}/amount-history-DEPRECATED`,
|
|
1096
|
+
method: 'GET',
|
|
1097
|
+
query: query,
|
|
1098
|
+
format: 'json',
|
|
1099
|
+
...params
|
|
1100
|
+
}).then(convertHttpResponse),
|
|
1101
|
+
|
|
1052
1102
|
/**
|
|
1053
1103
|
* No description
|
|
1054
1104
|
*
|
|
@@ -1073,7 +1123,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1073
1123
|
},
|
|
1074
1124
|
params: RequestParams = {}
|
|
1075
1125
|
) =>
|
|
1076
|
-
this.request<
|
|
1126
|
+
this.request<AmountHistory, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1077
1127
|
path: `/addresses/${address}/amount-history`,
|
|
1078
1128
|
method: 'GET',
|
|
1079
1129
|
query: query,
|
|
@@ -1635,6 +1685,53 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1635
1685
|
...params
|
|
1636
1686
|
}).then(convertHttpResponse)
|
|
1637
1687
|
}
|
|
1688
|
+
market = {
|
|
1689
|
+
/**
|
|
1690
|
+
* No description
|
|
1691
|
+
*
|
|
1692
|
+
* @tags Market
|
|
1693
|
+
* @name PostMarketPrices
|
|
1694
|
+
* @request POST:/market/prices
|
|
1695
|
+
*/
|
|
1696
|
+
postMarketPrices: (
|
|
1697
|
+
query: {
|
|
1698
|
+
currency: string
|
|
1699
|
+
},
|
|
1700
|
+
data?: string[],
|
|
1701
|
+
params: RequestParams = {}
|
|
1702
|
+
) =>
|
|
1703
|
+
this.request<number[], BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1704
|
+
path: `/market/prices`,
|
|
1705
|
+
method: 'POST',
|
|
1706
|
+
query: query,
|
|
1707
|
+
body: data,
|
|
1708
|
+
type: ContentType.Json,
|
|
1709
|
+
format: 'json',
|
|
1710
|
+
...params
|
|
1711
|
+
}).then(convertHttpResponse),
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* No description
|
|
1715
|
+
*
|
|
1716
|
+
* @tags Market
|
|
1717
|
+
* @name GetMarketPricesSymbolCharts
|
|
1718
|
+
* @request GET:/market/prices/{symbol}/charts
|
|
1719
|
+
*/
|
|
1720
|
+
getMarketPricesSymbolCharts: (
|
|
1721
|
+
symbol: string,
|
|
1722
|
+
query: {
|
|
1723
|
+
currency: string
|
|
1724
|
+
},
|
|
1725
|
+
params: RequestParams = {}
|
|
1726
|
+
) =>
|
|
1727
|
+
this.request<TimedPrices, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1728
|
+
path: `/market/prices/${symbol}/charts`,
|
|
1729
|
+
method: 'GET',
|
|
1730
|
+
query: query,
|
|
1731
|
+
format: 'json',
|
|
1732
|
+
...params
|
|
1733
|
+
}).then(convertHttpResponse)
|
|
1734
|
+
}
|
|
1638
1735
|
utils = {
|
|
1639
1736
|
/**
|
|
1640
1737
|
* @description Perform a sanity check
|
|
@@ -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/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