@alephium/web3 0.5.0-rc.15 → 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.
@@ -1,3 +1,19 @@
1
+ export interface AcceptedTransaction {
2
+ /** @format 32-byte-hash */
3
+ hash: string;
4
+ /** @format block-hash */
5
+ blockHash: string;
6
+ /** @format int64 */
7
+ timestamp: number;
8
+ inputs?: Input[];
9
+ outputs?: Output[];
10
+ /** @format int32 */
11
+ gasAmount: number;
12
+ /** @format uint256 */
13
+ gasPrice: string;
14
+ coinbase: boolean;
15
+ type: string;
16
+ }
1
17
  export interface AddressBalance {
2
18
  /** @format uint256 */
3
19
  balance: string;
@@ -19,6 +35,7 @@ export interface AssetOutput {
19
35
  key: string;
20
36
  /** @format uint256 */
21
37
  attoAlphAmount: string;
38
+ /** @format address */
22
39
  address: string;
23
40
  tokens?: Token[];
24
41
  /** @format int64 */
@@ -49,22 +66,6 @@ export interface BlockEntryLite {
49
66
  /** @format bigint */
50
67
  hashRate: string;
51
68
  }
52
- export interface ConfirmedTransaction {
53
- /** @format 32-byte-hash */
54
- hash: string;
55
- /** @format block-hash */
56
- blockHash: string;
57
- /** @format int64 */
58
- timestamp: number;
59
- inputs?: Input[];
60
- outputs?: Output[];
61
- /** @format int32 */
62
- gasAmount: number;
63
- /** @format uint256 */
64
- gasPrice: string;
65
- coinbase: boolean;
66
- type: string;
67
- }
68
69
  export interface ContractOutput {
69
70
  /** @format int32 */
70
71
  hint: number;
@@ -72,6 +73,7 @@ export interface ContractOutput {
72
73
  key: string;
73
74
  /** @format uint256 */
74
75
  attoAlphAmount: string;
76
+ /** @format address */
75
77
  address: string;
76
78
  tokens?: Token[];
77
79
  /** @format 32-byte-hash */
@@ -83,7 +85,9 @@ export interface Event {
83
85
  blockHash: string;
84
86
  /** @format 32-byte-hash */
85
87
  txHash: string;
88
+ /** @format address */
86
89
  contractAddress: string;
90
+ /** @format address */
87
91
  inputAddress?: string;
88
92
  /** @format int32 */
89
93
  eventIndex: number;
@@ -105,6 +109,7 @@ export interface Input {
105
109
  unlockScript?: string;
106
110
  /** @format 32-byte-hash */
107
111
  txHashRef?: string;
112
+ /** @format address */
108
113
  address?: string;
109
114
  /** @format uint256 */
110
115
  attoAlphAmount?: string;
@@ -126,6 +131,22 @@ export interface LogbackValue {
126
131
  name: string;
127
132
  level: string;
128
133
  }
134
+ export interface MempoolTransaction {
135
+ /** @format 32-byte-hash */
136
+ hash: string;
137
+ /** @format int32 */
138
+ chainFrom: number;
139
+ /** @format int32 */
140
+ chainTo: number;
141
+ inputs?: Input[];
142
+ outputs?: Output[];
143
+ /** @format int32 */
144
+ gasAmount: number;
145
+ /** @format uint256 */
146
+ gasPrice: string;
147
+ /** @format int64 */
148
+ lastSeen: number;
149
+ }
129
150
  export interface NotFound {
130
151
  detail: string;
131
152
  resource: string;
@@ -137,6 +158,23 @@ export interface OutputRef {
137
158
  /** @format 32-byte-hash */
138
159
  key: string;
139
160
  }
161
+ export interface PendingTransaction {
162
+ /** @format 32-byte-hash */
163
+ hash: string;
164
+ /** @format int32 */
165
+ chainFrom: number;
166
+ /** @format int32 */
167
+ chainTo: number;
168
+ inputs?: Input[];
169
+ outputs?: Output[];
170
+ /** @format int32 */
171
+ gasAmount: number;
172
+ /** @format uint256 */
173
+ gasPrice: string;
174
+ /** @format int64 */
175
+ lastSeen: number;
176
+ type: string;
177
+ }
140
178
  export interface PerChainCount {
141
179
  /** @format int32 */
142
180
  chainFrom: number;
@@ -214,27 +252,10 @@ export interface Transaction {
214
252
  gasPrice: string;
215
253
  coinbase: boolean;
216
254
  }
217
- export declare type TransactionLike = ConfirmedTransaction | UnconfirmedTransaction;
255
+ export declare type TransactionLike = AcceptedTransaction | PendingTransaction;
218
256
  export interface Unauthorized {
219
257
  detail: string;
220
258
  }
221
- export interface UnconfirmedTransaction {
222
- /** @format 32-byte-hash */
223
- hash: string;
224
- /** @format int32 */
225
- chainFrom: number;
226
- /** @format int32 */
227
- chainTo: number;
228
- inputs?: Input[];
229
- outputs?: Output[];
230
- /** @format int32 */
231
- gasAmount: number;
232
- /** @format uint256 */
233
- gasPrice: string;
234
- /** @format int64 */
235
- lastSeen: number;
236
- type: string;
237
- }
238
259
  export declare type Val = ValAddress | ValArray | ValBool | ValByteVec | ValI256 | ValU256;
239
260
  export interface ValAddress {
240
261
  /** @format address */
@@ -388,7 +409,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
388
409
  * @name GetTransactionsTransactionHash
389
410
  * @request GET:/transactions/{transaction_hash}
390
411
  */
391
- getTransactionsTransactionHash: (transactionHash: string, params?: RequestParams) => Promise<ConfirmedTransaction | UnconfirmedTransaction>;
412
+ getTransactionsTransactionHash: (transactionHash: string, params?: RequestParams) => Promise<AcceptedTransaction | PendingTransaction>;
392
413
  };
393
414
  addresses: {
394
415
  /**
@@ -481,13 +502,13 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
481
502
  */
482
503
  getAddressesAddressTotalTransactions: (address: string, params?: RequestParams) => Promise<number>;
483
504
  /**
484
- * @description List unconfirmed transactions of a given address
505
+ * @description List mempool transactions of a given address
485
506
  *
486
507
  * @tags Addresses
487
- * @name GetAddressesAddressUnconfirmedTransactions
488
- * @request GET:/addresses/{address}/unconfirmed-transactions
508
+ * @name GetAddressesAddressMempoolTransactions
509
+ * @request GET:/addresses/{address}/mempool/transactions
489
510
  */
490
- getAddressesAddressUnconfirmedTransactions: (address: string, params?: RequestParams) => Promise<TransactionLike[]>;
511
+ getAddressesAddressMempoolTransactions: (address: string, params?: RequestParams) => Promise<MempoolTransaction[]>;
491
512
  /**
492
513
  * @description Get address balance
493
514
  *
@@ -648,15 +669,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
648
669
  */
649
670
  getInfosAverageBlockTimes: (params?: RequestParams) => Promise<PerChainDuration[]>;
650
671
  };
651
- unconfirmedTransactions: {
672
+ mempool: {
652
673
  /**
653
- * @description list unconfirmed transactions
674
+ * @description list mempool transactions
654
675
  *
655
- * @tags Transactions
656
- * @name GetUnconfirmedTransactions
657
- * @request GET:/unconfirmed-transactions
676
+ * @tags Mempool
677
+ * @name GetMempoolTransactions
678
+ * @request GET:/mempool/transactions
658
679
  */
659
- getUnconfirmedTransactions: (query?: {
680
+ getMempoolTransactions: (query?: {
660
681
  /**
661
682
  * Page number
662
683
  * @format int32
@@ -669,7 +690,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
669
690
  limit?: number;
670
691
  /** Reverse pagination */
671
692
  reverse?: boolean;
672
- }, params?: RequestParams) => Promise<TransactionLike[]>;
693
+ }, params?: RequestParams) => Promise<MempoolTransaction[]>;
673
694
  };
674
695
  tokens: {
675
696
  /**
@@ -291,14 +291,14 @@ class Api extends HttpClient {
291
291
  ...params
292
292
  }).then(utils_1.convertHttpResponse),
293
293
  /**
294
- * @description List unconfirmed transactions of a given address
294
+ * @description List mempool transactions of a given address
295
295
  *
296
296
  * @tags Addresses
297
- * @name GetAddressesAddressUnconfirmedTransactions
298
- * @request GET:/addresses/{address}/unconfirmed-transactions
297
+ * @name GetAddressesAddressMempoolTransactions
298
+ * @request GET:/addresses/{address}/mempool/transactions
299
299
  */
300
- getAddressesAddressUnconfirmedTransactions: (address, params = {}) => this.request({
301
- path: `/addresses/${address}/unconfirmed-transactions`,
300
+ getAddressesAddressMempoolTransactions: (address, params = {}) => this.request({
301
+ path: `/addresses/${address}/mempool/transactions`,
302
302
  method: 'GET',
303
303
  format: 'json',
304
304
  ...params
@@ -500,16 +500,16 @@ class Api extends HttpClient {
500
500
  ...params
501
501
  }).then(utils_1.convertHttpResponse)
502
502
  };
503
- this.unconfirmedTransactions = {
503
+ this.mempool = {
504
504
  /**
505
- * @description list unconfirmed transactions
505
+ * @description list mempool transactions
506
506
  *
507
- * @tags Transactions
508
- * @name GetUnconfirmedTransactions
509
- * @request GET:/unconfirmed-transactions
507
+ * @tags Mempool
508
+ * @name GetMempoolTransactions
509
+ * @request GET:/mempool/transactions
510
510
  */
511
- getUnconfirmedTransactions: (query, params = {}) => this.request({
512
- path: `/unconfirmed-transactions`,
511
+ getMempoolTransactions: (query, params = {}) => this.request({
512
+ path: `/mempool/transactions`,
513
513
  method: 'GET',
514
514
  query: query,
515
515
  format: 'json',
@@ -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 unconfirmedTransactions: 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.unconfirmedTransactions = api_explorer_1.Api['unconfirmedTransactions'];
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.unconfirmedTransactions = { ...explorerApi.unconfirmedTransactions };
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);