@alephium/web3 0.5.0-rc.16 → 0.5.0-rc.18
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/explorer-provider.d.ts +18 -0
- package/dist/src/api/explorer-provider.js +65 -0
- package/dist/src/api/index.d.ts +2 -42
- package/dist/src/api/index.js +6 -117
- package/dist/src/api/node-provider.d.ts +21 -0
- package/dist/src/api/node-provider.js +68 -0
- package/dist/src/api/types.d.ts +8 -0
- package/dist/src/api/types.js +17 -1
- package/dist/src/contract/contract.js +6 -6
- package/dist/src/index.js +0 -3
- package/dist/src/signer/signer.js +1 -1
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/number.d.ts +8 -4
- package/dist/src/utils/number.fixture.d.ts +5 -0
- package/dist/src/utils/number.fixture.js +28 -1
- package/dist/src/utils/number.js +44 -2
- package/package.json +1 -1
- package/src/api/explorer-provider.ts +78 -0
- package/src/api/index.ts +2 -148
- package/src/api/node-provider.ts +84 -0
- package/src/api/types.ts +23 -0
- package/src/contract/contract.ts +9 -7
- package/src/index.ts +0 -4
- package/src/signer/signer.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/number.fixture.ts +28 -0
- package/src/utils/number.ts +52 -5
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ApiRequestArguments, ApiRequestHandler } from './types';
|
|
2
|
+
import { Api as ExplorerApi } from './api-explorer';
|
|
3
|
+
export declare class ExplorerProvider {
|
|
4
|
+
readonly blocks: ExplorerApi<string>['blocks'];
|
|
5
|
+
readonly transactions: ExplorerApi<string>['transactions'];
|
|
6
|
+
readonly addresses: ExplorerApi<string>['addresses'];
|
|
7
|
+
readonly infos: ExplorerApi<string>['infos'];
|
|
8
|
+
readonly mempool: ExplorerApi<string>['mempool'];
|
|
9
|
+
readonly tokens: ExplorerApi<string>['tokens'];
|
|
10
|
+
readonly charts: ExplorerApi<string>['charts'];
|
|
11
|
+
readonly utils: ExplorerApi<string>['utils'];
|
|
12
|
+
constructor(baseUrl: string, apiKey?: string);
|
|
13
|
+
constructor(provider: ExplorerProvider);
|
|
14
|
+
constructor(handler: ApiRequestHandler);
|
|
15
|
+
request: (args: ApiRequestArguments) => Promise<any>;
|
|
16
|
+
static Proxy(explorerProvider: ExplorerProvider): ExplorerProvider;
|
|
17
|
+
static Remote(handler: ApiRequestHandler): ExplorerProvider;
|
|
18
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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.ExplorerProvider = void 0;
|
|
21
|
+
const types_1 = require("./types");
|
|
22
|
+
const api_explorer_1 = require("./api-explorer");
|
|
23
|
+
function initializeExplorerApi(baseUrl, apiKey) {
|
|
24
|
+
const explorerApi = new api_explorer_1.Api({
|
|
25
|
+
baseUrl: baseUrl,
|
|
26
|
+
baseApiParams: { secure: true },
|
|
27
|
+
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
28
|
+
});
|
|
29
|
+
explorerApi.setSecurityData(apiKey ?? null);
|
|
30
|
+
return explorerApi;
|
|
31
|
+
}
|
|
32
|
+
class ExplorerProvider {
|
|
33
|
+
constructor(param0, apiKey) {
|
|
34
|
+
this.request = (args) => {
|
|
35
|
+
return (0, types_1.request)(this, args);
|
|
36
|
+
};
|
|
37
|
+
let explorerApi;
|
|
38
|
+
if (typeof param0 === 'string') {
|
|
39
|
+
explorerApi = initializeExplorerApi(param0, apiKey);
|
|
40
|
+
}
|
|
41
|
+
else if (typeof param0 === 'function') {
|
|
42
|
+
explorerApi = new ExplorerProvider('https://1.2.3.4:0');
|
|
43
|
+
(0, types_1.forwardRequests)(explorerApi, param0);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
explorerApi = param0;
|
|
47
|
+
}
|
|
48
|
+
this.blocks = { ...explorerApi.blocks };
|
|
49
|
+
this.transactions = { ...explorerApi.transactions };
|
|
50
|
+
this.addresses = { ...explorerApi.addresses };
|
|
51
|
+
this.infos = { ...explorerApi.infos };
|
|
52
|
+
this.mempool = { ...explorerApi.mempool };
|
|
53
|
+
this.tokens = { ...explorerApi.tokens };
|
|
54
|
+
this.charts = { ...explorerApi.charts };
|
|
55
|
+
this.utils = { ...explorerApi.utils };
|
|
56
|
+
}
|
|
57
|
+
// This can prevent the proxied explorer provider from being modified
|
|
58
|
+
static Proxy(explorerProvider) {
|
|
59
|
+
return new ExplorerProvider(explorerProvider);
|
|
60
|
+
}
|
|
61
|
+
static Remote(handler) {
|
|
62
|
+
return new ExplorerProvider(handler);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.ExplorerProvider = ExplorerProvider;
|
package/dist/src/api/index.d.ts
CHANGED
|
@@ -1,45 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
path: string;
|
|
4
|
-
method: string;
|
|
5
|
-
params: any[];
|
|
6
|
-
}
|
|
7
|
-
export declare type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
|
|
8
|
-
export declare class NodeProvider {
|
|
9
|
-
readonly wallets: NodeApi<string>['wallets'];
|
|
10
|
-
readonly infos: NodeApi<string>['infos'];
|
|
11
|
-
readonly blockflow: NodeApi<string>['blockflow'];
|
|
12
|
-
readonly addresses: NodeApi<string>['addresses'];
|
|
13
|
-
readonly transactions: NodeApi<string>['transactions'];
|
|
14
|
-
readonly mempool: NodeApi<string>['mempool'];
|
|
15
|
-
readonly contracts: NodeApi<string>['contracts'];
|
|
16
|
-
readonly multisig: NodeApi<string>['multisig'];
|
|
17
|
-
readonly utils: NodeApi<string>['utils'];
|
|
18
|
-
readonly miners: NodeApi<string>['miners'];
|
|
19
|
-
readonly events: NodeApi<string>['events'];
|
|
20
|
-
constructor(baseUrl: string, apiKey?: string);
|
|
21
|
-
constructor(provider: NodeProvider);
|
|
22
|
-
constructor(handler: ApiRequestHandler);
|
|
23
|
-
request: (args: ApiRequestArguments) => Promise<any>;
|
|
24
|
-
static Proxy(nodeProvider: NodeProvider): NodeProvider;
|
|
25
|
-
static Remote(handler: ApiRequestHandler): NodeProvider;
|
|
26
|
-
}
|
|
27
|
-
export declare class ExplorerProvider {
|
|
28
|
-
readonly blocks: any;
|
|
29
|
-
readonly transactions: any;
|
|
30
|
-
readonly addresses: any;
|
|
31
|
-
readonly infos: any;
|
|
32
|
-
readonly mempool: any;
|
|
33
|
-
readonly tokens: any;
|
|
34
|
-
readonly charts: any;
|
|
35
|
-
readonly utils: any;
|
|
36
|
-
constructor(baseUrl: string, apiKey?: string);
|
|
37
|
-
constructor(provider: ExplorerProvider);
|
|
38
|
-
constructor(handler: ApiRequestHandler);
|
|
39
|
-
request: (args: ApiRequestArguments) => Promise<any>;
|
|
40
|
-
static Proxy(explorerProvider: ExplorerProvider): ExplorerProvider;
|
|
41
|
-
static Remote(handler: ApiRequestHandler): ExplorerProvider;
|
|
42
|
-
}
|
|
1
|
+
export * from './node-provider';
|
|
2
|
+
export * from './explorer-provider';
|
|
43
3
|
export * as node from './api-alephium';
|
|
44
4
|
export * as explorer from './api-explorer';
|
|
45
5
|
export * from './types';
|
package/dist/src/api/index.js
CHANGED
|
@@ -32,6 +32,9 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
32
32
|
}) : function(o, v) {
|
|
33
33
|
o["default"] = v;
|
|
34
34
|
});
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
35
38
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
36
39
|
if (mod && mod.__esModule) return mod;
|
|
37
40
|
var result = {};
|
|
@@ -39,124 +42,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
39
42
|
__setModuleDefault(result, mod);
|
|
40
43
|
return result;
|
|
41
44
|
};
|
|
42
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
43
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
44
|
-
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.explorer = exports.node =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function forwardRequests(api, handler) {
|
|
50
|
-
// Update class properties to forward requests
|
|
51
|
-
for (const [path, pathObject] of Object.entries(api)) {
|
|
52
|
-
for (const method of Object.keys(pathObject)) {
|
|
53
|
-
pathObject[`${method}`] = async (...params) => {
|
|
54
|
-
return handler({ path, method, params });
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async function request(provider, args) {
|
|
60
|
-
const call = provider[`${args.path}`][`${args.method}`];
|
|
61
|
-
return call(...args.params);
|
|
62
|
-
}
|
|
63
|
-
function initializeNodeApi(baseUrl, apiKey) {
|
|
64
|
-
const nodeApi = new api_alephium_1.Api({
|
|
65
|
-
baseUrl: baseUrl,
|
|
66
|
-
baseApiParams: { secure: true },
|
|
67
|
-
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
68
|
-
});
|
|
69
|
-
nodeApi.setSecurityData(apiKey ?? null);
|
|
70
|
-
return nodeApi;
|
|
71
|
-
}
|
|
72
|
-
class NodeProvider {
|
|
73
|
-
constructor(param0, apiKey) {
|
|
74
|
-
this.request = (args) => {
|
|
75
|
-
return request(this, args);
|
|
76
|
-
};
|
|
77
|
-
let nodeApi;
|
|
78
|
-
if (typeof param0 === 'string') {
|
|
79
|
-
nodeApi = initializeNodeApi(param0, apiKey);
|
|
80
|
-
}
|
|
81
|
-
else if (typeof param0 === 'function') {
|
|
82
|
-
nodeApi = new NodeProvider('https://1.2.3.4:0');
|
|
83
|
-
forwardRequests(nodeApi, param0);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
nodeApi = param0;
|
|
87
|
-
}
|
|
88
|
-
this.wallets = { ...nodeApi.wallets };
|
|
89
|
-
this.infos = { ...nodeApi.infos };
|
|
90
|
-
this.blockflow = { ...nodeApi.blockflow };
|
|
91
|
-
this.addresses = { ...nodeApi.addresses };
|
|
92
|
-
this.transactions = { ...nodeApi.transactions };
|
|
93
|
-
this.mempool = { ...nodeApi.mempool };
|
|
94
|
-
this.contracts = { ...nodeApi.contracts };
|
|
95
|
-
this.multisig = { ...nodeApi.multisig };
|
|
96
|
-
this.utils = { ...nodeApi.utils };
|
|
97
|
-
this.miners = { ...nodeApi.miners };
|
|
98
|
-
this.events = { ...nodeApi.events };
|
|
99
|
-
}
|
|
100
|
-
// This can prevent the proxied node provider from being modified
|
|
101
|
-
static Proxy(nodeProvider) {
|
|
102
|
-
return new NodeProvider(nodeProvider);
|
|
103
|
-
}
|
|
104
|
-
static Remote(handler) {
|
|
105
|
-
return new NodeProvider(handler);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.NodeProvider = NodeProvider;
|
|
109
|
-
function initializeExplorerApi(baseUrl, apiKey) {
|
|
110
|
-
const explorerApi = new api_explorer_1.Api({
|
|
111
|
-
baseUrl: baseUrl,
|
|
112
|
-
baseApiParams: { secure: true },
|
|
113
|
-
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
114
|
-
});
|
|
115
|
-
explorerApi.setSecurityData(apiKey ?? null);
|
|
116
|
-
return explorerApi;
|
|
117
|
-
}
|
|
118
|
-
class ExplorerProvider {
|
|
119
|
-
constructor(param0, apiKey) {
|
|
120
|
-
this.blocks = api_explorer_1.Api['blocks'];
|
|
121
|
-
this.transactions = api_explorer_1.Api['transactions'];
|
|
122
|
-
this.addresses = api_explorer_1.Api['addresses'];
|
|
123
|
-
this.infos = api_explorer_1.Api['infos'];
|
|
124
|
-
this.mempool = api_explorer_1.Api['mempool'];
|
|
125
|
-
this.tokens = api_explorer_1.Api['tokens'];
|
|
126
|
-
this.charts = api_explorer_1.Api['charts'];
|
|
127
|
-
this.utils = api_explorer_1.Api['utils'];
|
|
128
|
-
this.request = (args) => {
|
|
129
|
-
return request(this, args);
|
|
130
|
-
};
|
|
131
|
-
let explorerApi;
|
|
132
|
-
if (typeof param0 === 'string') {
|
|
133
|
-
explorerApi = initializeExplorerApi(param0, apiKey);
|
|
134
|
-
}
|
|
135
|
-
else if (typeof param0 === 'function') {
|
|
136
|
-
explorerApi = new ExplorerProvider('https://1.2.3.4:0');
|
|
137
|
-
forwardRequests(explorerApi, param0);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
explorerApi = param0;
|
|
141
|
-
}
|
|
142
|
-
this.blocks = { ...explorerApi.blocks };
|
|
143
|
-
this.transactions = { ...explorerApi.transactions };
|
|
144
|
-
this.addresses = { ...explorerApi.addresses };
|
|
145
|
-
this.infos = { ...explorerApi.infos };
|
|
146
|
-
this.mempool = { ...explorerApi.mempool };
|
|
147
|
-
this.tokens = { ...explorerApi.tokens };
|
|
148
|
-
this.charts = { ...explorerApi.charts };
|
|
149
|
-
this.utils = { ...explorerApi.utils };
|
|
150
|
-
}
|
|
151
|
-
// This can prevent the proxied explorer provider from being modified
|
|
152
|
-
static Proxy(explorerProvider) {
|
|
153
|
-
return new ExplorerProvider(explorerProvider);
|
|
154
|
-
}
|
|
155
|
-
static Remote(handler) {
|
|
156
|
-
return new ExplorerProvider(handler);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
exports.ExplorerProvider = ExplorerProvider;
|
|
46
|
+
exports.explorer = exports.node = void 0;
|
|
47
|
+
__exportStar(require("./node-provider"), exports);
|
|
48
|
+
__exportStar(require("./explorer-provider"), exports);
|
|
160
49
|
exports.node = __importStar(require("./api-alephium"));
|
|
161
50
|
exports.explorer = __importStar(require("./api-explorer"));
|
|
162
51
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ApiRequestArguments, ApiRequestHandler } from './types';
|
|
2
|
+
import { Api as NodeApi } from './api-alephium';
|
|
3
|
+
export declare class NodeProvider {
|
|
4
|
+
readonly wallets: NodeApi<string>['wallets'];
|
|
5
|
+
readonly infos: NodeApi<string>['infos'];
|
|
6
|
+
readonly blockflow: NodeApi<string>['blockflow'];
|
|
7
|
+
readonly addresses: NodeApi<string>['addresses'];
|
|
8
|
+
readonly transactions: NodeApi<string>['transactions'];
|
|
9
|
+
readonly mempool: NodeApi<string>['mempool'];
|
|
10
|
+
readonly contracts: NodeApi<string>['contracts'];
|
|
11
|
+
readonly multisig: NodeApi<string>['multisig'];
|
|
12
|
+
readonly utils: NodeApi<string>['utils'];
|
|
13
|
+
readonly miners: NodeApi<string>['miners'];
|
|
14
|
+
readonly events: NodeApi<string>['events'];
|
|
15
|
+
constructor(baseUrl: string, apiKey?: string);
|
|
16
|
+
constructor(provider: NodeProvider);
|
|
17
|
+
constructor(handler: ApiRequestHandler);
|
|
18
|
+
request: (args: ApiRequestArguments) => Promise<any>;
|
|
19
|
+
static Proxy(nodeProvider: NodeProvider): NodeProvider;
|
|
20
|
+
static Remote(handler: ApiRequestHandler): NodeProvider;
|
|
21
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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.NodeProvider = void 0;
|
|
21
|
+
const types_1 = require("./types");
|
|
22
|
+
const api_alephium_1 = require("./api-alephium");
|
|
23
|
+
function initializeNodeApi(baseUrl, apiKey) {
|
|
24
|
+
const nodeApi = new api_alephium_1.Api({
|
|
25
|
+
baseUrl: baseUrl,
|
|
26
|
+
baseApiParams: { secure: true },
|
|
27
|
+
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
28
|
+
});
|
|
29
|
+
nodeApi.setSecurityData(apiKey ?? null);
|
|
30
|
+
return nodeApi;
|
|
31
|
+
}
|
|
32
|
+
class NodeProvider {
|
|
33
|
+
constructor(param0, apiKey) {
|
|
34
|
+
this.request = (args) => {
|
|
35
|
+
return (0, types_1.request)(this, args);
|
|
36
|
+
};
|
|
37
|
+
let nodeApi;
|
|
38
|
+
if (typeof param0 === 'string') {
|
|
39
|
+
nodeApi = initializeNodeApi(param0, apiKey);
|
|
40
|
+
}
|
|
41
|
+
else if (typeof param0 === 'function') {
|
|
42
|
+
nodeApi = new NodeProvider('https://1.2.3.4:0');
|
|
43
|
+
(0, types_1.forwardRequests)(nodeApi, param0);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
nodeApi = param0;
|
|
47
|
+
}
|
|
48
|
+
this.wallets = { ...nodeApi.wallets };
|
|
49
|
+
this.infos = { ...nodeApi.infos };
|
|
50
|
+
this.blockflow = { ...nodeApi.blockflow };
|
|
51
|
+
this.addresses = { ...nodeApi.addresses };
|
|
52
|
+
this.transactions = { ...nodeApi.transactions };
|
|
53
|
+
this.mempool = { ...nodeApi.mempool };
|
|
54
|
+
this.contracts = { ...nodeApi.contracts };
|
|
55
|
+
this.multisig = { ...nodeApi.multisig };
|
|
56
|
+
this.utils = { ...nodeApi.utils };
|
|
57
|
+
this.miners = { ...nodeApi.miners };
|
|
58
|
+
this.events = { ...nodeApi.events };
|
|
59
|
+
}
|
|
60
|
+
// This can prevent the proxied node provider from being modified
|
|
61
|
+
static Proxy(nodeProvider) {
|
|
62
|
+
return new NodeProvider(nodeProvider);
|
|
63
|
+
}
|
|
64
|
+
static Remote(handler) {
|
|
65
|
+
return new NodeProvider(handler);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.NodeProvider = NodeProvider;
|
package/dist/src/api/types.d.ts
CHANGED
|
@@ -22,3 +22,11 @@ export declare function fromApiVals(vals: node.Val[], names: string[], types: st
|
|
|
22
22
|
export declare function fromApiArray(vals: node.Val[], types: string[]): Val[];
|
|
23
23
|
export declare function fromApiVal(v: node.Val, tpe: string): Val;
|
|
24
24
|
export declare function typeLength(tpe: string): number;
|
|
25
|
+
export interface ApiRequestArguments {
|
|
26
|
+
path: string;
|
|
27
|
+
method: string;
|
|
28
|
+
params: any[];
|
|
29
|
+
}
|
|
30
|
+
export declare type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
|
|
31
|
+
export declare function forwardRequests(api: Record<string, any>, handler: ApiRequestHandler): void;
|
|
32
|
+
export declare function request(provider: Record<string, any>, args: ApiRequestArguments): Promise<any>;
|
package/dist/src/api/types.js
CHANGED
|
@@ -17,7 +17,7 @@ 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.typeLength = 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.request = exports.forwardRequests = exports.typeLength = 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 utils_1 = require("../utils");
|
|
22
22
|
utils_1.assertType;
|
|
23
23
|
function toApiToken(token) {
|
|
@@ -245,3 +245,19 @@ function typeLength(tpe) {
|
|
|
245
245
|
return dims.reduce((a, b) => a * b);
|
|
246
246
|
}
|
|
247
247
|
exports.typeLength = typeLength;
|
|
248
|
+
function forwardRequests(api, handler) {
|
|
249
|
+
// Update class properties to forward requests
|
|
250
|
+
for (const [path, pathObject] of Object.entries(api)) {
|
|
251
|
+
for (const method of Object.keys(pathObject)) {
|
|
252
|
+
pathObject[`${method}`] = async (...params) => {
|
|
253
|
+
return handler({ path, method, params });
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.forwardRequests = forwardRequests;
|
|
259
|
+
async function request(provider, args) {
|
|
260
|
+
const call = provider[`${args.path}`][`${args.method}`];
|
|
261
|
+
return call(...args.params);
|
|
262
|
+
}
|
|
263
|
+
exports.request = request;
|
|
@@ -140,7 +140,7 @@ class ProjectArtifact {
|
|
|
140
140
|
compilerOptionsUsed: this.compilerOptionsUsed,
|
|
141
141
|
infos: Object.fromEntries(new Map([...this.infos].sort()))
|
|
142
142
|
};
|
|
143
|
-
const content =
|
|
143
|
+
const content = (0, utils_1.stringifyJsonWithBigint)(artifact, 2);
|
|
144
144
|
return fs_2.promises.writeFile(filepath, content);
|
|
145
145
|
}
|
|
146
146
|
needToReCompile(compilerOptions, sourceInfos) {
|
|
@@ -169,7 +169,7 @@ class ProjectArtifact {
|
|
|
169
169
|
return undefined;
|
|
170
170
|
}
|
|
171
171
|
const content = await fs_2.promises.readFile(filepath);
|
|
172
|
-
const json =
|
|
172
|
+
const json = (0, utils_1.parseJsonWithBigint)(content.toString());
|
|
173
173
|
const compilerOptionsUsed = json.compilerOptionsUsed;
|
|
174
174
|
const files = new Map(Object.entries(json.infos));
|
|
175
175
|
return new ProjectArtifact(compilerOptionsUsed, files);
|
|
@@ -480,7 +480,7 @@ class Contract extends Artifact {
|
|
|
480
480
|
// support both 'code.ral' and 'code.ral.json'
|
|
481
481
|
static async fromArtifactFile(path, bytecodeDebugPatch, codeHashDebug) {
|
|
482
482
|
const content = await fs_2.promises.readFile(path);
|
|
483
|
-
const artifact =
|
|
483
|
+
const artifact = (0, utils_1.parseJsonWithBigint)(content.toString());
|
|
484
484
|
return Contract.fromJson(artifact, bytecodeDebugPatch, codeHashDebug);
|
|
485
485
|
}
|
|
486
486
|
toString() {
|
|
@@ -493,7 +493,7 @@ class Contract extends Artifact {
|
|
|
493
493
|
eventsSig: this.eventsSig,
|
|
494
494
|
functions: this.functions
|
|
495
495
|
};
|
|
496
|
-
return
|
|
496
|
+
return (0, utils_1.stringifyJsonWithBigint)(object, 2);
|
|
497
497
|
}
|
|
498
498
|
toState(fields, asset, address) {
|
|
499
499
|
const addressDef = typeof address !== 'undefined' ? address : Contract.randomAddress();
|
|
@@ -718,7 +718,7 @@ class Script extends Artifact {
|
|
|
718
718
|
}
|
|
719
719
|
static async fromArtifactFile(path, bytecodeDebugPatch) {
|
|
720
720
|
const content = await fs_2.promises.readFile(path);
|
|
721
|
-
const artifact =
|
|
721
|
+
const artifact = (0, utils_1.parseJsonWithBigint)(content.toString());
|
|
722
722
|
return this.fromJson(artifact, bytecodeDebugPatch);
|
|
723
723
|
}
|
|
724
724
|
toString() {
|
|
@@ -729,7 +729,7 @@ class Script extends Artifact {
|
|
|
729
729
|
fieldsSig: this.fieldsSig,
|
|
730
730
|
functions: this.functions
|
|
731
731
|
};
|
|
732
|
-
return
|
|
732
|
+
return (0, utils_1.stringifyJsonWithBigint)(object, 2);
|
|
733
733
|
}
|
|
734
734
|
async txParamsForExecution(signer, params) {
|
|
735
735
|
const selectedAccount = await signer.getSelectedAccount();
|
package/dist/src/index.js
CHANGED
|
@@ -44,9 +44,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.utils = exports.web3 = void 0;
|
|
47
|
-
BigInt.prototype['toJSON'] = function () {
|
|
48
|
-
return this.toString();
|
|
49
|
-
};
|
|
50
47
|
__exportStar(require("./api"), exports);
|
|
51
48
|
__exportStar(require("./contract"), exports);
|
|
52
49
|
__exportStar(require("./signer"), exports);
|
|
@@ -61,7 +61,7 @@ class SignerProvider {
|
|
|
61
61
|
const derivedAddress = (0, utils_1.addressFromPublicKey)(account.publicKey, account.keyType);
|
|
62
62
|
const derivedGroup = (0, utils_1.groupOfAddress)(derivedAddress);
|
|
63
63
|
if (derivedAddress !== account.address || derivedGroup !== account.group) {
|
|
64
|
-
throw Error(`Invalid
|
|
64
|
+
throw Error(`Invalid account data: ${JSON.stringify(account)}`);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
package/dist/src/utils/index.js
CHANGED
|
@@ -8,7 +8,11 @@ export interface IPrettifyNumberConfig {
|
|
|
8
8
|
decimalPlacesWhenZero: number;
|
|
9
9
|
}
|
|
10
10
|
export declare const prettifyNumberConfig: Record<string, IPrettifyNumberConfig>;
|
|
11
|
-
export declare function prettifyAttoAlphAmount(amount: bigint): string |
|
|
12
|
-
export declare function prettifyTokenAmount(amount: bigint, decimals: number): string |
|
|
13
|
-
export declare function prettifyExactAmount(amount: bigint, decimals: number): string |
|
|
14
|
-
export declare function prettifyNumber(amount: bigint, decimals: number, config: IPrettifyNumberConfig): string |
|
|
11
|
+
export declare function prettifyAttoAlphAmount(amount: bigint): string | undefined;
|
|
12
|
+
export declare function prettifyTokenAmount(amount: bigint, decimals: number): string | undefined;
|
|
13
|
+
export declare function prettifyExactAmount(amount: bigint, decimals: number): string | undefined;
|
|
14
|
+
export declare function prettifyNumber(amount: bigint, decimals: number, config: IPrettifyNumberConfig): string | undefined;
|
|
15
|
+
export declare function convertAmountWithDecimals(amount: string | number, decimals: number): bigint | undefined;
|
|
16
|
+
export declare function convertAlphAmount(amount: string | number): bigint | undefined;
|
|
17
|
+
export declare function stringifyJsonWithBigint(obj: any, space?: string | number): string;
|
|
18
|
+
export declare function parseJsonWithBigint(text: string): any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tests = void 0;
|
|
3
|
+
exports.tests1 = exports.tests = void 0;
|
|
4
4
|
/*
|
|
5
5
|
Copyright 2018 - 2022 The Alephium Authors
|
|
6
6
|
This file is part of the alephium project.
|
|
@@ -160,3 +160,30 @@ exports.tests = [
|
|
|
160
160
|
tokenFormat: '0.0'
|
|
161
161
|
}
|
|
162
162
|
];
|
|
163
|
+
exports.tests1 = [
|
|
164
|
+
{
|
|
165
|
+
raw: '0',
|
|
166
|
+
decimals: 18,
|
|
167
|
+
amount: 0n
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
raw: '1.23',
|
|
171
|
+
decimals: 2,
|
|
172
|
+
amount: 123n
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
raw: '1',
|
|
176
|
+
decimals: 5,
|
|
177
|
+
amount: 100000n
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
raw: '1',
|
|
181
|
+
decimals: 18,
|
|
182
|
+
amount: 1000000000000000000n
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
raw: '1.23456789',
|
|
186
|
+
decimals: 18,
|
|
187
|
+
amount: 1234567890000000000n
|
|
188
|
+
}
|
|
189
|
+
];
|
package/dist/src/utils/number.js
CHANGED
|
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.prettifyNumber = exports.prettifyExactAmount = exports.prettifyTokenAmount = exports.prettifyAttoAlphAmount = exports.prettifyNumberConfig = exports.isNumeric = void 0;
|
|
23
|
+
exports.parseJsonWithBigint = exports.stringifyJsonWithBigint = exports.convertAlphAmount = exports.convertAmountWithDecimals = exports.prettifyNumber = exports.prettifyExactAmount = exports.prettifyTokenAmount = exports.prettifyAttoAlphAmount = exports.prettifyNumberConfig = exports.isNumeric = void 0;
|
|
24
24
|
// Credits:
|
|
25
25
|
// 1. https://github.com/argentlabs/argent-x/blob/e63affa7f28b27333dca4081a3dcd375bb2da40b/packages/extension/src/shared/utils/number.ts
|
|
26
26
|
// 2. https://github.com/ethers-io/ethers.js/blob/724881f34d428406488a1c9f9dbebe54b6edecda/src.ts/utils/fixednumber.ts
|
|
@@ -62,7 +62,7 @@ exports.prettifyExactAmount = prettifyExactAmount;
|
|
|
62
62
|
function prettifyNumber(amount, decimals, config) {
|
|
63
63
|
const number = toFixedNumber(amount, decimals);
|
|
64
64
|
if (!(0, exports.isNumeric)(number)) {
|
|
65
|
-
return
|
|
65
|
+
return undefined;
|
|
66
66
|
}
|
|
67
67
|
const numberBN = new bignumber_js_1.default(number);
|
|
68
68
|
let untrimmed;
|
|
@@ -128,3 +128,45 @@ function toFixedNumber(val, decimals) {
|
|
|
128
128
|
}
|
|
129
129
|
return negative + str;
|
|
130
130
|
}
|
|
131
|
+
function convertAmountWithDecimals(amount, decimals) {
|
|
132
|
+
try {
|
|
133
|
+
const result = new bignumber_js_1.default(amount).multipliedBy(Math.pow(10, decimals));
|
|
134
|
+
return BigInt(result.toFormat(0, { groupSeparator: '' }));
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.convertAmountWithDecimals = convertAmountWithDecimals;
|
|
141
|
+
function convertAlphAmount(amount) {
|
|
142
|
+
return convertAmountWithDecimals(amount, 18);
|
|
143
|
+
}
|
|
144
|
+
exports.convertAlphAmount = convertAlphAmount;
|
|
145
|
+
function replacer(key, value) {
|
|
146
|
+
if (typeof value === 'bigint') {
|
|
147
|
+
return { __bigintval__: value.toString() };
|
|
148
|
+
}
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
function reviver(key, value) {
|
|
152
|
+
if (value != null && typeof value === 'object' && '__bigintval__' in value) {
|
|
153
|
+
return BigInt(value['__bigintval__']);
|
|
154
|
+
}
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
function stringifyJsonWithBigint(obj, space) {
|
|
158
|
+
const bigintToString = BigInt.prototype['toJSON'];
|
|
159
|
+
BigInt.prototype['toJSON'] = undefined;
|
|
160
|
+
const result = JSON.stringify(obj, replacer, space);
|
|
161
|
+
BigInt.prototype['toJSON'] = bigintToString;
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
exports.stringifyJsonWithBigint = stringifyJsonWithBigint;
|
|
165
|
+
function parseJsonWithBigint(text) {
|
|
166
|
+
const bigintToString = BigInt.prototype['toJSON'];
|
|
167
|
+
BigInt.prototype['toJSON'] = undefined;
|
|
168
|
+
const result = JSON.parse(text, reviver);
|
|
169
|
+
BigInt.prototype['toJSON'] = bigintToString;
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
exports.parseJsonWithBigint = parseJsonWithBigint;
|