@alephium/web3 0.5.0-rc.16 → 0.5.0-rc.17

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.
@@ -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;
@@ -1,45 +1,5 @@
1
- import { Api as NodeApi } from './api-alephium';
2
- export interface ApiRequestArguments {
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';
@@ -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 = exports.ExplorerProvider = exports.NodeProvider = void 0;
47
- const api_alephium_1 = require("./api-alephium");
48
- const api_explorer_1 = require("./api-explorer");
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;
@@ -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>;
@@ -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;
@@ -4,3 +4,4 @@ export * from './djb2';
4
4
  export * from './utils';
5
5
  export * from './subscription';
6
6
  export * from './sign';
7
+ export * from './number';
@@ -37,3 +37,4 @@ __exportStar(require("./djb2"), exports);
37
37
  __exportStar(require("./utils"), exports);
38
38
  __exportStar(require("./subscription"), exports);
39
39
  __exportStar(require("./sign"), exports);
40
+ __exportStar(require("./number"), exports);
@@ -8,7 +8,9 @@ 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 | null;
12
- export declare function prettifyTokenAmount(amount: bigint, decimals: number): string | null;
13
- export declare function prettifyExactAmount(amount: bigint, decimals: number): string | null;
14
- export declare function prettifyNumber(amount: bigint, decimals: number, config: IPrettifyNumberConfig): string | null;
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;
@@ -5,3 +5,8 @@ export declare const tests: {
5
5
  alphFormat: string;
6
6
  tokenFormat: string;
7
7
  }[];
8
+ export declare const tests1: {
9
+ raw: string;
10
+ decimals: number;
11
+ amount: bigint;
12
+ }[];
@@ -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
+ ];
@@ -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.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 null;
65
+ return undefined;
66
66
  }
67
67
  const numberBN = new bignumber_js_1.default(number);
68
68
  let untrimmed;
@@ -128,3 +128,17 @@ 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.5.0-rc.16",
3
+ "version": "0.5.0-rc.17",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -0,0 +1,78 @@
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
+ import { ApiRequestArguments, ApiRequestHandler, forwardRequests, request } from './types'
20
+ import { Api as ExplorerApi } from './api-explorer'
21
+
22
+ function initializeExplorerApi(baseUrl: string, apiKey?: string): ExplorerApi<string> {
23
+ const explorerApi = new ExplorerApi<string>({
24
+ baseUrl: baseUrl,
25
+ baseApiParams: { secure: true },
26
+ securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
27
+ })
28
+ explorerApi.setSecurityData(apiKey ?? null)
29
+ return explorerApi
30
+ }
31
+
32
+ export class ExplorerProvider {
33
+ readonly blocks: ExplorerApi<string>['blocks']
34
+ readonly transactions: ExplorerApi<string>['transactions']
35
+ readonly addresses: ExplorerApi<string>['addresses']
36
+ readonly infos: ExplorerApi<string>['infos']
37
+ readonly mempool: ExplorerApi<string>['mempool']
38
+ readonly tokens: ExplorerApi<string>['tokens']
39
+ readonly charts: ExplorerApi<string>['charts']
40
+ readonly utils: ExplorerApi<string>['utils']
41
+
42
+ constructor(baseUrl: string, apiKey?: string)
43
+ constructor(provider: ExplorerProvider)
44
+ constructor(handler: ApiRequestHandler)
45
+ constructor(param0: string | ExplorerProvider | ApiRequestHandler, apiKey?: string) {
46
+ let explorerApi: ExplorerProvider
47
+ if (typeof param0 === 'string') {
48
+ explorerApi = initializeExplorerApi(param0, apiKey)
49
+ } else if (typeof param0 === 'function') {
50
+ explorerApi = new ExplorerProvider('https://1.2.3.4:0')
51
+ forwardRequests(explorerApi, param0 as ApiRequestHandler)
52
+ } else {
53
+ explorerApi = param0 as ExplorerProvider
54
+ }
55
+
56
+ this.blocks = { ...explorerApi.blocks }
57
+ this.transactions = { ...explorerApi.transactions }
58
+ this.addresses = { ...explorerApi.addresses }
59
+ this.infos = { ...explorerApi.infos }
60
+ this.mempool = { ...explorerApi.mempool }
61
+ this.tokens = { ...explorerApi.tokens }
62
+ this.charts = { ...explorerApi.charts }
63
+ this.utils = { ...explorerApi.utils }
64
+ }
65
+
66
+ request = (args: ApiRequestArguments): Promise<any> => {
67
+ return request(this, args)
68
+ }
69
+
70
+ // This can prevent the proxied explorer provider from being modified
71
+ static Proxy(explorerProvider: ExplorerProvider): ExplorerProvider {
72
+ return new ExplorerProvider(explorerProvider)
73
+ }
74
+
75
+ static Remote(handler: ApiRequestHandler): ExplorerProvider {
76
+ return new ExplorerProvider(handler)
77
+ }
78
+ }