@hiero-ledger/sdk 2.71.0-beta.0 → 2.71.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.
Files changed (62) hide show
  1. package/dist/umd.js +142 -40
  2. package/dist/umd.min.js +2 -2
  3. package/lib/LedgerId.cjs +4 -4
  4. package/lib/LedgerId.js +1 -1
  5. package/lib/LedgerId.js.map +1 -1
  6. package/lib/channel/NativeChannel.cjs +3 -2
  7. package/lib/channel/NativeChannel.js +1 -1
  8. package/lib/channel/NativeChannel.js.map +1 -1
  9. package/lib/channel/NodeMirrorChannel.cjs +0 -2
  10. package/lib/channel/NodeMirrorChannel.js +1 -1
  11. package/lib/channel/NodeMirrorChannel.js.map +1 -1
  12. package/lib/client/Client.cjs +3 -2
  13. package/lib/client/Client.d.ts +2 -2
  14. package/lib/client/Client.js +1 -1
  15. package/lib/client/Client.js.map +1 -1
  16. package/lib/client/NativeClient.cjs +141 -44
  17. package/lib/client/NativeClient.d.ts +48 -16
  18. package/lib/client/NativeClient.js +1 -1
  19. package/lib/client/NativeClient.js.map +1 -1
  20. package/lib/client/NodeClient.cjs +63 -2
  21. package/lib/client/NodeClient.d.ts +42 -0
  22. package/lib/client/NodeClient.js +1 -1
  23. package/lib/client/NodeClient.js.map +1 -1
  24. package/lib/client/WebClient.cjs +64 -34
  25. package/lib/client/WebClient.d.ts +35 -15
  26. package/lib/client/WebClient.js +1 -1
  27. package/lib/client/WebClient.js.map +1 -1
  28. package/lib/constants/ClientConstants.cjs +22 -7
  29. package/lib/constants/ClientConstants.d.ts +12 -6
  30. package/lib/constants/ClientConstants.js +1 -1
  31. package/lib/constants/ClientConstants.js.map +1 -1
  32. package/lib/contract/ContractCreateTransaction.cjs +5 -0
  33. package/lib/contract/ContractCreateTransaction.js +1 -1
  34. package/lib/contract/ContractCreateTransaction.js.map +1 -1
  35. package/lib/contract/ContractDeleteTransaction.cjs +35 -2
  36. package/lib/contract/ContractDeleteTransaction.d.ts +18 -0
  37. package/lib/contract/ContractDeleteTransaction.js +1 -1
  38. package/lib/contract/ContractDeleteTransaction.js.map +1 -1
  39. package/lib/contract/ContractUpdateTransaction.cjs +2 -1
  40. package/lib/contract/ContractUpdateTransaction.js +1 -1
  41. package/lib/contract/ContractUpdateTransaction.js.map +1 -1
  42. package/lib/encoding/hex.cjs +11 -0
  43. package/lib/encoding/hex.js +1 -1
  44. package/lib/encoding/hex.js.map +1 -1
  45. package/lib/native.cjs +2 -2
  46. package/lib/native.d.ts +1 -1
  47. package/lib/native.js +1 -1
  48. package/lib/version.js +1 -1
  49. package/package.json +2 -2
  50. package/src/LedgerId.js +4 -4
  51. package/src/channel/NativeChannel.js +9 -1
  52. package/src/channel/NodeMirrorChannel.js +0 -2
  53. package/src/client/Client.js +4 -2
  54. package/src/client/NativeClient.js +151 -47
  55. package/src/client/NodeClient.js +56 -3
  56. package/src/client/WebClient.js +63 -44
  57. package/src/constants/ClientConstants.js +26 -8
  58. package/src/contract/ContractCreateTransaction.js +5 -3
  59. package/src/contract/ContractDeleteTransaction.js +34 -0
  60. package/src/contract/ContractUpdateTransaction.js +4 -1
  61. package/src/encoding/hex.js +20 -0
  62. package/src/native.js +1 -1
@@ -3,12 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.Network = void 0;
6
+ exports.default = void 0;
7
7
  var _Client = _interopRequireDefault(require("./Client.cjs"));
8
8
  var _NativeChannel = _interopRequireDefault(require("../channel/NativeChannel.cjs"));
9
9
  var _AccountId = _interopRequireDefault(require("../account/AccountId.cjs"));
10
10
  var _LedgerId = _interopRequireDefault(require("../LedgerId.cjs"));
11
11
  var _ClientConstants = require("../constants/ClientConstants.cjs");
12
+ var _AddressBookQueryWeb = _interopRequireDefault(require("../network/AddressBookQueryWeb.cjs"));
13
+ var _FileId = _interopRequireDefault(require("../file/FileId.cjs"));
12
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
15
  // SPDX-License-Identifier: Apache-2.0
14
16
 
@@ -17,27 +19,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
17
19
  /**
18
20
  * @typedef {import("./Client.js").ClientConfiguration} ClientConfiguration
19
21
  */
20
- const Network = exports.Network = {
21
- /**
22
- * @param {string} name
23
- * @returns {{[key: string]: (string | AccountId)}}
24
- */
25
- fromName(name) {
26
- switch (name) {
27
- case "mainnet":
28
- return Network.MAINNET;
29
- case "testnet":
30
- return Network.TESTNET;
31
- case "previewnet":
32
- return Network.PREVIEWNET;
33
- default:
34
- throw new Error(`unknown network name: ${name}`);
35
- }
36
- },
37
- MAINNET: _ClientConstants.MAINNET,
38
- TESTNET: _ClientConstants.NATIVE_TESTNET,
39
- PREVIEWNET: _ClientConstants.NATIVE_PREVIEWNET
40
- };
41
22
 
42
23
  /**
43
24
  * @augments {Client<NativeChannel, *>}
@@ -52,16 +33,19 @@ class NativeClient extends _Client.default {
52
33
  if (typeof props.network === "string") {
53
34
  switch (props.network) {
54
35
  case "mainnet":
55
- this.setNetwork(Network.MAINNET);
36
+ this.setNetwork(_ClientConstants.WebNetwork.MAINNET);
56
37
  this.setLedgerId(_LedgerId.default.MAINNET);
38
+ this.setMirrorNetwork(_ClientConstants.MirrorNetwork.MAINNET);
57
39
  break;
58
40
  case "testnet":
59
- this.setNetwork(Network.TESTNET);
41
+ this.setNetwork(_ClientConstants.WebNetwork.TESTNET);
60
42
  this.setLedgerId(_LedgerId.default.TESTNET);
43
+ this.setMirrorNetwork(_ClientConstants.MirrorNetwork.TESTNET);
61
44
  break;
62
45
  case "previewnet":
63
- this.setNetwork(Network.PREVIEWNET);
46
+ this.setNetwork(_ClientConstants.WebNetwork.PREVIEWNET);
64
47
  this.setLedgerId(_LedgerId.default.PREVIEWNET);
48
+ this.setMirrorNetwork(_ClientConstants.MirrorNetwork.PREVIEWNET);
65
49
  break;
66
50
  default:
67
51
  throw new Error(
@@ -108,8 +92,7 @@ class NativeClient extends _Client.default {
108
92
  */
109
93
  static forNetwork(network) {
110
94
  return new NativeClient({
111
- network,
112
- scheduleNetworkUpdate: false
95
+ network
113
96
  });
114
97
  }
115
98
 
@@ -119,8 +102,7 @@ class NativeClient extends _Client.default {
119
102
  */
120
103
  static forName(network) {
121
104
  return new NativeClient({
122
- network,
123
- scheduleNetworkUpdate: false
105
+ network
124
106
  });
125
107
  }
126
108
 
@@ -131,8 +113,7 @@ class NativeClient extends _Client.default {
131
113
  */
132
114
  static forMainnet() {
133
115
  return new NativeClient({
134
- network: "mainnet",
135
- scheduleNetworkUpdate: false
116
+ network: "mainnet"
136
117
  });
137
118
  }
138
119
 
@@ -143,8 +124,7 @@ class NativeClient extends _Client.default {
143
124
  */
144
125
  static forTestnet() {
145
126
  return new NativeClient({
146
- network: "testnet",
147
- scheduleNetworkUpdate: false
127
+ network: "testnet"
148
128
  });
149
129
  }
150
130
 
@@ -155,11 +135,75 @@ class NativeClient extends _Client.default {
155
135
  */
156
136
  static forPreviewnet() {
157
137
  return new NativeClient({
158
- network: "previewnet",
159
- scheduleNetworkUpdate: false
138
+ network: "previewnet"
160
139
  });
161
140
  }
162
141
 
142
+ /**
143
+ * Construct a Hedera client pre-configured for Mainnet access with network update.
144
+ *
145
+ * @returns {Promise<NativeClient>}
146
+ */
147
+ static async forMainnetAsync() {
148
+ return new NativeClient({
149
+ network: "mainnet"
150
+ }).updateNetwork();
151
+ }
152
+
153
+ /**
154
+ * Construct a Hedera client pre-configured for Testnet access with network update.
155
+ *
156
+ * @returns {Promise<NativeClient>}
157
+ */
158
+ static async forTestnetAsync() {
159
+ return new NativeClient({
160
+ network: "testnet"
161
+ }).updateNetwork();
162
+ }
163
+
164
+ /**
165
+ * Construct a Hedera client pre-configured for Previewnet access with network update.
166
+ *
167
+ * @returns {Promise<NativeClient>}
168
+ */
169
+ static async forPreviewnetAsync() {
170
+ return new NativeClient({
171
+ network: "previewnet"
172
+ }).updateNetwork();
173
+ }
174
+
175
+ /**
176
+ * Construct a client for a specific network with optional network update.
177
+ * Updates network only if the network is not "local-node".
178
+ *
179
+ * @param {string} network
180
+ * @returns {Promise<NativeClient>}
181
+ */
182
+ static async forNameAsync(network) {
183
+ const client = new NativeClient({
184
+ network
185
+ });
186
+ if (network !== "local-node") {
187
+ await client.updateNetwork();
188
+ }
189
+ return client;
190
+ }
191
+
192
+ /**
193
+ * Construct a client configured to use mirror nodes.
194
+ * This will query the address book to get the network nodes.
195
+ *
196
+ * @param {string[] | string} mirrorNetwork
197
+ * @returns {Promise<NativeClient>}
198
+ */
199
+ static async forMirrorNetwork(mirrorNetwork) {
200
+ const client = new NativeClient({
201
+ mirrorNetwork
202
+ });
203
+ await client.updateNetwork();
204
+ return client;
205
+ }
206
+
163
207
  /**
164
208
  * @param {{[key: string]: (string | AccountId)} | string} network
165
209
  * @returns {void}
@@ -168,13 +212,13 @@ class NativeClient extends _Client.default {
168
212
  if (typeof network === "string") {
169
213
  switch (network) {
170
214
  case "previewnet":
171
- this._network.setNetwork(Network.PREVIEWNET);
215
+ this._network.setNetwork(_ClientConstants.WebNetwork.PREVIEWNET);
172
216
  break;
173
217
  case "testnet":
174
- this._network.setNetwork(Network.TESTNET);
218
+ this._network.setNetwork(_ClientConstants.WebNetwork.TESTNET);
175
219
  break;
176
220
  case "mainnet":
177
- this._network.setNetwork(Network.MAINNET);
221
+ this._network.setNetwork(_ClientConstants.WebNetwork.MAINNET);
178
222
  }
179
223
  } else {
180
224
  this._network.setNetwork(network);
@@ -183,11 +227,63 @@ class NativeClient extends _Client.default {
183
227
 
184
228
  /**
185
229
  * @param {string[] | string} mirrorNetwork
186
- * @returns {void}
230
+ * @returns {this}
187
231
  */
188
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
189
232
  setMirrorNetwork(mirrorNetwork) {
190
- // Do nothing as this is not currently supported
233
+ if (typeof mirrorNetwork === "string") {
234
+ switch (mirrorNetwork) {
235
+ case "local-node":
236
+ this._mirrorNetwork.setNetwork(_ClientConstants.MirrorNetwork.LOCAL_NODE);
237
+ break;
238
+ case "previewnet":
239
+ this._mirrorNetwork.setNetwork(_ClientConstants.MirrorNetwork.PREVIEWNET);
240
+ break;
241
+ case "testnet":
242
+ this._mirrorNetwork.setNetwork(_ClientConstants.MirrorNetwork.TESTNET);
243
+ break;
244
+ case "mainnet":
245
+ this._mirrorNetwork.setNetwork(_ClientConstants.MirrorNetwork.MAINNET);
246
+ break;
247
+ default:
248
+ this._mirrorNetwork.setNetwork([mirrorNetwork]);
249
+ }
250
+ } else {
251
+ this._mirrorNetwork.setNetwork(mirrorNetwork);
252
+ }
253
+ return this;
254
+ }
255
+
256
+ /**
257
+ * @override
258
+ * @returns {Promise<this>}
259
+ */
260
+ async updateNetwork() {
261
+ if (this._isUpdatingNetwork) {
262
+ return this;
263
+ }
264
+ this._isUpdatingNetwork = true;
265
+ try {
266
+ const addressBook = await new _AddressBookQueryWeb.default().setFileId(_FileId.default.getAddressBookFileIdFor(this.shard, this.realm)).execute(this);
267
+
268
+ /** @type {Record<string, AccountId>} */
269
+ const network = {};
270
+ for (const nodeAddress of addressBook.nodeAddresses) {
271
+ for (const endpoint of nodeAddress.addresses) {
272
+ if (nodeAddress.accountId != null) {
273
+ network[endpoint.toString()] = nodeAddress.accountId;
274
+ }
275
+ }
276
+ }
277
+ this.setNetwork(network);
278
+ } catch (/** @type {unknown} */error) {
279
+ if (this._logger) {
280
+ const errorMessage = error instanceof Error ? error.message : String(error);
281
+ this._logger.trace(`failed to update client address book: ${errorMessage}`);
282
+ }
283
+ } finally {
284
+ this._isUpdatingNetwork = false;
285
+ }
286
+ return this;
191
287
  }
192
288
 
193
289
  /**
@@ -199,12 +295,13 @@ class NativeClient extends _Client.default {
199
295
  }
200
296
 
201
297
  /**
202
- * @abstract
298
+ * @override
203
299
  * @returns {(address: string) => *}
204
300
  */
205
301
  _createMirrorNetworkChannel() {
206
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
207
- return address => null;
302
+ return () => {
303
+ throw new Error("mirror support is not supported in native");
304
+ };
208
305
  }
209
306
  }
210
307
  exports.default = NativeClient;
@@ -1,15 +1,6 @@
1
- export namespace Network {
2
- /**
3
- * @param {string} name
4
- * @returns {{[key: string]: (string | AccountId)}}
5
- */
6
- export function fromName(name: string): {
7
- [key: string]: (string | AccountId);
8
- };
9
- export { MAINNET };
10
- export { NATIVE_TESTNET as TESTNET };
11
- export { NATIVE_PREVIEWNET as PREVIEWNET };
12
- }
1
+ /**
2
+ * @typedef {import("./Client.js").ClientConfiguration} ClientConfiguration
3
+ */
13
4
  /**
14
5
  * @augments {Client<NativeChannel, *>}
15
6
  */
@@ -58,15 +49,56 @@ export default class NativeClient extends Client<NativeChannel, any> {
58
49
  * @returns {NativeClient}
59
50
  */
60
51
  static forPreviewnet(): NativeClient;
52
+ /**
53
+ * Construct a Hedera client pre-configured for Mainnet access with network update.
54
+ *
55
+ * @returns {Promise<NativeClient>}
56
+ */
57
+ static forMainnetAsync(): Promise<NativeClient>;
58
+ /**
59
+ * Construct a Hedera client pre-configured for Testnet access with network update.
60
+ *
61
+ * @returns {Promise<NativeClient>}
62
+ */
63
+ static forTestnetAsync(): Promise<NativeClient>;
64
+ /**
65
+ * Construct a Hedera client pre-configured for Previewnet access with network update.
66
+ *
67
+ * @returns {Promise<NativeClient>}
68
+ */
69
+ static forPreviewnetAsync(): Promise<NativeClient>;
70
+ /**
71
+ * Construct a client for a specific network with optional network update.
72
+ * Updates network only if the network is not "local-node".
73
+ *
74
+ * @param {string} network
75
+ * @returns {Promise<NativeClient>}
76
+ */
77
+ static forNameAsync(network: string): Promise<NativeClient>;
78
+ /**
79
+ * Construct a client configured to use mirror nodes.
80
+ * This will query the address book to get the network nodes.
81
+ *
82
+ * @param {string[] | string} mirrorNetwork
83
+ * @returns {Promise<NativeClient>}
84
+ */
85
+ static forMirrorNetwork(mirrorNetwork: string[] | string): Promise<NativeClient>;
61
86
  /**
62
87
  * @param {ClientConfiguration} [props]
63
88
  */
64
89
  constructor(props?: ClientConfiguration);
90
+ /**
91
+ * @param {string[] | string} mirrorNetwork
92
+ * @returns {this}
93
+ */
94
+ setMirrorNetwork(mirrorNetwork: string[] | string): this;
95
+ /**
96
+ * @override
97
+ * @returns {Promise<this>}
98
+ */
99
+ override updateNetwork(): Promise<this>;
65
100
  }
66
101
  export type ClientConfiguration = import("./Client.js").ClientConfiguration;
67
- import AccountId from "../account/AccountId.js";
68
- import { MAINNET } from "../constants/ClientConstants.js";
69
- import { NATIVE_TESTNET } from "../constants/ClientConstants.js";
70
- import { NATIVE_PREVIEWNET } from "../constants/ClientConstants.js";
71
102
  import NativeChannel from "../channel/NativeChannel.js";
72
103
  import Client from "./Client.js";
104
+ import AccountId from "../account/AccountId.js";
@@ -1,2 +1,2 @@
1
- import e from"./Client.js";import t from"../channel/NativeChannel.js";import"../account/AccountId.js";import r from"../LedgerId.js";import{NATIVE_PREVIEWNET as n,NATIVE_TESTNET as s,MAINNET as o}from"../constants/ClientConstants.js";const w={MAINNET:o,TESTNET:s,PREVIEWNET:n};class a extends e{constructor(t){if(super(t),null!=t)if("string"==typeof t.network)switch(t.network){case"mainnet":this.setNetwork(w.MAINNET),this.setLedgerId(r.MAINNET);break;case"testnet":this.setNetwork(w.TESTNET),this.setLedgerId(r.TESTNET);break;case"previewnet":this.setNetwork(w.PREVIEWNET),this.setLedgerId(r.PREVIEWNET);break;default:throw new Error(`unknown network: ${t.network}`)}else if(null!=t.network){e._validateNetworkConsistency(t.network);const{shard:r,realm:n}=e._extractShardRealm(t.network);this._shard=r,this._realm=n,this.setNetwork(t.network)}}static fromConfig(e){return new a("string"==typeof e?JSON.parse(e):e)}static forNetwork(e){return new a({network:e,scheduleNetworkUpdate:!1})}static forName(e){return new a({network:e,scheduleNetworkUpdate:!1})}static forMainnet(){return new a({network:"mainnet",scheduleNetworkUpdate:!1})}static forTestnet(){return new a({network:"testnet",scheduleNetworkUpdate:!1})}static forPreviewnet(){return new a({network:"previewnet",scheduleNetworkUpdate:!1})}setNetwork(e){if("string"==typeof e)switch(e){case"previewnet":this._network.setNetwork(w.PREVIEWNET);break;case"testnet":this._network.setNetwork(w.TESTNET);break;case"mainnet":this._network.setNetwork(w.MAINNET)}else this._network.setNetwork(e)}setMirrorNetwork(e){}_createNetworkChannel(){return e=>new t(e)}_createMirrorNetworkChannel(){return e=>null}}export{w as Network,a as default};
1
+ import t from"./Client.js";import e from"../channel/NativeChannel.js";import"../account/AccountId.js";import r from"../LedgerId.js";import{WebNetwork as s,MirrorNetwork as o}from"../constants/ClientConstants.js";import n from"../network/AddressBookQueryWeb.js";import i from"../file/FileId.js";class a extends t{constructor(e){if(super(e),null!=e)if("string"==typeof e.network)switch(e.network){case"mainnet":this.setNetwork(s.MAINNET),this.setLedgerId(r.MAINNET),this.setMirrorNetwork(o.MAINNET);break;case"testnet":this.setNetwork(s.TESTNET),this.setLedgerId(r.TESTNET),this.setMirrorNetwork(o.TESTNET);break;case"previewnet":this.setNetwork(s.PREVIEWNET),this.setLedgerId(r.PREVIEWNET),this.setMirrorNetwork(o.PREVIEWNET);break;default:throw new Error(`unknown network: ${e.network}`)}else if(null!=e.network){t._validateNetworkConsistency(e.network);const{shard:r,realm:s}=t._extractShardRealm(e.network);this._shard=r,this._realm=s,this.setNetwork(e.network)}}static fromConfig(t){return new a("string"==typeof t?JSON.parse(t):t)}static forNetwork(t){return new a({network:t})}static forName(t){return new a({network:t})}static forMainnet(){return new a({network:"mainnet"})}static forTestnet(){return new a({network:"testnet"})}static forPreviewnet(){return new a({network:"previewnet"})}static async forMainnetAsync(){return new a({network:"mainnet"}).updateNetwork()}static async forTestnetAsync(){return new a({network:"testnet"}).updateNetwork()}static async forPreviewnetAsync(){return new a({network:"previewnet"}).updateNetwork()}static async forNameAsync(t){const e=new a({network:t});return"local-node"!==t&&await e.updateNetwork(),e}static async forMirrorNetwork(t){const e=new a({mirrorNetwork:t});return await e.updateNetwork(),e}setNetwork(t){if("string"==typeof t)switch(t){case"previewnet":this._network.setNetwork(s.PREVIEWNET);break;case"testnet":this._network.setNetwork(s.TESTNET);break;case"mainnet":this._network.setNetwork(s.MAINNET)}else this._network.setNetwork(t)}setMirrorNetwork(t){if("string"==typeof t)switch(t){case"local-node":this._mirrorNetwork.setNetwork(o.LOCAL_NODE);break;case"previewnet":this._mirrorNetwork.setNetwork(o.PREVIEWNET);break;case"testnet":this._mirrorNetwork.setNetwork(o.TESTNET);break;case"mainnet":this._mirrorNetwork.setNetwork(o.MAINNET);break;default:this._mirrorNetwork.setNetwork([t])}else this._mirrorNetwork.setNetwork(t);return this}async updateNetwork(){if(this._isUpdatingNetwork)return this;this._isUpdatingNetwork=!0;try{const t=await(new n).setFileId(i.getAddressBookFileIdFor(this.shard,this.realm)).execute(this),e={};for(const r of t.nodeAddresses)for(const t of r.addresses)null!=r.accountId&&(e[t.toString()]=r.accountId);this.setNetwork(e)}catch(t){if(this._logger){const e=t instanceof Error?t.message:String(t);this._logger.trace(`failed to update client address book: ${e}`)}}finally{this._isUpdatingNetwork=!1}return this}_createNetworkChannel(){return t=>new e(t)}_createMirrorNetworkChannel(){return()=>{throw new Error("mirror support is not supported in native")}}}export{a as default};
2
2
  //# sourceMappingURL=NativeClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NativeClient.js","sources":["../../src/client/NativeClient.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Client from \"./Client.js\";\nimport NativeChannel from \"../channel/NativeChannel.js\";\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport AccountId from \"../account/AccountId.js\";\nimport LedgerId from \"../LedgerId.js\";\nimport {\n MAINNET,\n NATIVE_TESTNET,\n NATIVE_PREVIEWNET,\n} from \"../constants/ClientConstants.js\";\n\n/**\n * @typedef {import(\"./Client.js\").ClientConfiguration} ClientConfiguration\n */\nexport const Network = {\n /**\n * @param {string} name\n * @returns {{[key: string]: (string | AccountId)}}\n */\n fromName(name) {\n switch (name) {\n case \"mainnet\":\n return Network.MAINNET;\n\n case \"testnet\":\n return Network.TESTNET;\n\n case \"previewnet\":\n return Network.PREVIEWNET;\n\n default:\n throw new Error(`unknown network name: ${name}`);\n }\n },\n\n MAINNET: MAINNET,\n TESTNET: NATIVE_TESTNET,\n PREVIEWNET: NATIVE_PREVIEWNET,\n};\n\n/**\n * @augments {Client<NativeChannel, *>}\n */\nexport default class NativeClient extends Client {\n /**\n * @param {ClientConfiguration} [props]\n */\n constructor(props) {\n super(props);\n\n if (props != null) {\n if (typeof props.network === \"string\") {\n switch (props.network) {\n case \"mainnet\":\n this.setNetwork(Network.MAINNET);\n this.setLedgerId(LedgerId.MAINNET);\n break;\n\n case \"testnet\":\n this.setNetwork(Network.TESTNET);\n this.setLedgerId(LedgerId.TESTNET);\n break;\n\n case \"previewnet\":\n this.setNetwork(Network.PREVIEWNET);\n this.setLedgerId(LedgerId.PREVIEWNET);\n break;\n\n default:\n throw new Error(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `unknown network: ${props.network}`,\n );\n }\n } else if (props.network != null) {\n Client._validateNetworkConsistency(props.network);\n\n const { shard, realm } = Client._extractShardRealm(\n props.network,\n );\n\n // Shard and realm are inferred from the network, so we need to set them here\n // to ensure that the client is properly configured.\n this._shard = shard;\n this._realm = realm;\n\n this.setNetwork(props.network);\n }\n }\n }\n\n /**\n * @param {string | ClientConfiguration} data\n * @returns {NativeClient}\n */\n static fromConfig(data) {\n return new NativeClient(\n typeof data === \"string\"\n ? /** @type {ClientConfiguration | undefined} */ (\n JSON.parse(data)\n )\n : data,\n );\n }\n\n /**\n * Construct a client for a specific network.\n *\n * It is the responsibility of the caller to ensure that all nodes in the map are part of the\n * same Hedera network. Failure to do so will result in undefined behavior.\n *\n * The client will load balance all requests to Hedera using a simple round-robin scheme to\n * chose nodes to send transactions to. For one transaction, at most 1/3 of the nodes will be\n * tried.\n *\n * @param {{[key: string]: (string | AccountId)} | string} network\n * @returns {NativeClient}\n */\n static forNetwork(network) {\n return new NativeClient({\n network,\n scheduleNetworkUpdate: false,\n });\n }\n\n /**\n * @param {string} network\n * @returns {NativeClient}\n */\n static forName(network) {\n return new NativeClient({ network, scheduleNetworkUpdate: false });\n }\n\n /**\n * Construct a Hedera client pre-configured for Mainnet access.\n *\n * @returns {NativeClient}\n */\n static forMainnet() {\n return new NativeClient({\n network: \"mainnet\",\n scheduleNetworkUpdate: false,\n });\n }\n\n /**\n * Construct a Hedera client pre-configured for Testnet access.\n *\n * @returns {NativeClient}\n */\n static forTestnet() {\n return new NativeClient({\n network: \"testnet\",\n scheduleNetworkUpdate: false,\n });\n }\n\n /**\n * Construct a Hedera client pre-configured for Previewnet access.\n *\n * @returns {NativeClient}\n */\n static forPreviewnet() {\n return new NativeClient({\n network: \"previewnet\",\n scheduleNetworkUpdate: false,\n });\n }\n\n /**\n * @param {{[key: string]: (string | AccountId)} | string} network\n * @returns {void}\n */\n setNetwork(network) {\n if (typeof network === \"string\") {\n switch (network) {\n case \"previewnet\":\n this._network.setNetwork(Network.PREVIEWNET);\n break;\n case \"testnet\":\n this._network.setNetwork(Network.TESTNET);\n break;\n case \"mainnet\":\n this._network.setNetwork(Network.MAINNET);\n }\n } else {\n this._network.setNetwork(network);\n }\n }\n\n /**\n * @param {string[] | string} mirrorNetwork\n * @returns {void}\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n setMirrorNetwork(mirrorNetwork) {\n // Do nothing as this is not currently supported\n }\n\n /**\n * @override\n * @returns {(address: string) => NativeChannel}\n */\n _createNetworkChannel() {\n return (address) => new NativeChannel(address);\n }\n\n /**\n * @abstract\n * @returns {(address: string) => *}\n */\n _createMirrorNetworkChannel() {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n return (address) => null;\n }\n}\n"],"names":["Network","MAINNET","TESTNET","NATIVE_TESTNET","PREVIEWNET","NATIVE_PREVIEWNET","NativeClient","Client","constructor","props","super","network","this","setNetwork","setLedgerId","LedgerId","Error","_validateNetworkConsistency","shard","realm","_extractShardRealm","_shard","_realm","fromConfig","data","JSON","parse","forNetwork","scheduleNetworkUpdate","forName","forMainnet","forTestnet","forPreviewnet","_network","setMirrorNetwork","mirrorNetwork","_createNetworkChannel","address","NativeChannel","_createMirrorNetworkChannel"],"mappings":"yOAgBY,MAACA,EAAU,CAqBnBC,QAASA,EACTC,QAASC,EACTC,WAAYC,GAMD,MAAMC,UAAqBC,EAItC,WAAAC,CAAYC,GAGR,GAFAC,MAAMD,GAEO,MAATA,EACA,GAA6B,iBAAlBA,EAAME,QACb,OAAQF,EAAME,SACV,IAAK,UACDC,KAAKC,WAAWb,EAAQC,SACxBW,KAAKE,YAAYC,EAASd,SAC1B,MAEJ,IAAK,UACDW,KAAKC,WAAWb,EAAQE,SACxBU,KAAKE,YAAYC,EAASb,SAC1B,MAEJ,IAAK,aACDU,KAAKC,WAAWb,EAAQI,YACxBQ,KAAKE,YAAYC,EAASX,YAC1B,MAEJ,QACI,MAAM,IAAIY,MAEN,oBAAoBP,EAAME,gBAGnC,GAAqB,MAAjBF,EAAME,QAAiB,CAC9BJ,EAAOU,4BAA4BR,EAAME,SAEzC,MAAMO,MAAEA,EAAKC,MAAEA,GAAUZ,EAAOa,mBAC5BX,EAAME,SAKVC,KAAKS,OAASH,EACdN,KAAKU,OAASH,EAEdP,KAAKC,WAAWJ,EAAME,QACtC,CAEA,CAMI,iBAAOY,CAAWC,GACd,OAAO,IAAIlB,EACS,iBAATkB,EAEGC,KAAKC,MAAMF,GAEfA,EAElB,CAeI,iBAAOG,CAAWhB,GACd,OAAO,IAAIL,EAAa,CACpBK,UACAiB,uBAAuB,GAEnC,CAMI,cAAOC,CAAQlB,GACX,OAAO,IAAIL,EAAa,CAAEK,UAASiB,uBAAuB,GAClE,CAOI,iBAAOE,GACH,OAAO,IAAIxB,EAAa,CACpBK,QAAS,UACTiB,uBAAuB,GAEnC,CAOI,iBAAOG,GACH,OAAO,IAAIzB,EAAa,CACpBK,QAAS,UACTiB,uBAAuB,GAEnC,CAOI,oBAAOI,GACH,OAAO,IAAI1B,EAAa,CACpBK,QAAS,aACTiB,uBAAuB,GAEnC,CAMI,UAAAf,CAAWF,GACP,GAAuB,iBAAZA,EACP,OAAQA,GACJ,IAAK,aACDC,KAAKqB,SAASpB,WAAWb,EAAQI,YACjC,MACJ,IAAK,UACDQ,KAAKqB,SAASpB,WAAWb,EAAQE,SACjC,MACJ,IAAK,UACDU,KAAKqB,SAASpB,WAAWb,EAAQC,cAGzCW,KAAKqB,SAASpB,WAAWF,EAErC,CAOI,gBAAAuB,CAAiBC,GAErB,CAMI,qBAAAC,GACI,OAAQC,GAAY,IAAIC,EAAcD,EAC9C,CAMI,2BAAAE,GAEI,OAAQF,GAAY,IAC5B"}
1
+ {"version":3,"file":"NativeClient.js","sources":["../../src/client/NativeClient.js"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport Client from \"./Client.js\";\nimport NativeChannel from \"../channel/NativeChannel.js\";\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport AccountId from \"../account/AccountId.js\";\nimport LedgerId from \"../LedgerId.js\";\nimport { MirrorNetwork, WebNetwork } from \"../constants/ClientConstants.js\";\nimport AddressBookQuery from \"../network/AddressBookQueryWeb.js\";\nimport FileId from \"../file/FileId.js\";\n\n/**\n * @typedef {import(\"./Client.js\").ClientConfiguration} ClientConfiguration\n */\n\n/**\n * @augments {Client<NativeChannel, *>}\n */\nexport default class NativeClient extends Client {\n /**\n * @param {ClientConfiguration} [props]\n */\n constructor(props) {\n super(props);\n\n if (props != null) {\n if (typeof props.network === \"string\") {\n switch (props.network) {\n case \"mainnet\":\n this.setNetwork(WebNetwork.MAINNET);\n this.setLedgerId(LedgerId.MAINNET);\n this.setMirrorNetwork(MirrorNetwork.MAINNET);\n break;\n\n case \"testnet\":\n this.setNetwork(WebNetwork.TESTNET);\n this.setLedgerId(LedgerId.TESTNET);\n this.setMirrorNetwork(MirrorNetwork.TESTNET);\n break;\n\n case \"previewnet\":\n this.setNetwork(WebNetwork.PREVIEWNET);\n this.setLedgerId(LedgerId.PREVIEWNET);\n this.setMirrorNetwork(MirrorNetwork.PREVIEWNET);\n break;\n\n default:\n throw new Error(\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `unknown network: ${props.network}`,\n );\n }\n } else if (props.network != null) {\n Client._validateNetworkConsistency(props.network);\n\n const { shard, realm } = Client._extractShardRealm(\n props.network,\n );\n\n // Shard and realm are inferred from the network, so we need to set them here\n // to ensure that the client is properly configured.\n this._shard = shard;\n this._realm = realm;\n\n this.setNetwork(props.network);\n }\n }\n }\n\n /**\n * @param {string | ClientConfiguration} data\n * @returns {NativeClient}\n */\n static fromConfig(data) {\n return new NativeClient(\n typeof data === \"string\"\n ? /** @type {ClientConfiguration | undefined} */ (\n JSON.parse(data)\n )\n : data,\n );\n }\n\n /**\n * Construct a client for a specific network.\n *\n * It is the responsibility of the caller to ensure that all nodes in the map are part of the\n * same Hedera network. Failure to do so will result in undefined behavior.\n *\n * The client will load balance all requests to Hedera using a simple round-robin scheme to\n * chose nodes to send transactions to. For one transaction, at most 1/3 of the nodes will be\n * tried.\n *\n * @param {{[key: string]: (string | AccountId)} | string} network\n * @returns {NativeClient}\n */\n static forNetwork(network) {\n return new NativeClient({\n network,\n });\n }\n\n /**\n * @param {string} network\n * @returns {NativeClient}\n */\n static forName(network) {\n return new NativeClient({ network });\n }\n\n /**\n * Construct a Hedera client pre-configured for Mainnet access.\n *\n * @returns {NativeClient}\n */\n static forMainnet() {\n return new NativeClient({\n network: \"mainnet\",\n });\n }\n\n /**\n * Construct a Hedera client pre-configured for Testnet access.\n *\n * @returns {NativeClient}\n */\n static forTestnet() {\n return new NativeClient({\n network: \"testnet\",\n });\n }\n\n /**\n * Construct a Hedera client pre-configured for Previewnet access.\n *\n * @returns {NativeClient}\n */\n static forPreviewnet() {\n return new NativeClient({\n network: \"previewnet\",\n });\n }\n\n /**\n * Construct a Hedera client pre-configured for Mainnet access with network update.\n *\n * @returns {Promise<NativeClient>}\n */\n static async forMainnetAsync() {\n return new NativeClient({\n network: \"mainnet\",\n }).updateNetwork();\n }\n\n /**\n * Construct a Hedera client pre-configured for Testnet access with network update.\n *\n * @returns {Promise<NativeClient>}\n */\n static async forTestnetAsync() {\n return new NativeClient({\n network: \"testnet\",\n }).updateNetwork();\n }\n\n /**\n * Construct a Hedera client pre-configured for Previewnet access with network update.\n *\n * @returns {Promise<NativeClient>}\n */\n static async forPreviewnetAsync() {\n return new NativeClient({\n network: \"previewnet\",\n }).updateNetwork();\n }\n\n /**\n * Construct a client for a specific network with optional network update.\n * Updates network only if the network is not \"local-node\".\n *\n * @param {string} network\n * @returns {Promise<NativeClient>}\n */\n static async forNameAsync(network) {\n const client = new NativeClient({ network });\n\n if (network !== \"local-node\") {\n await client.updateNetwork();\n }\n\n return client;\n }\n\n /**\n * Construct a client configured to use mirror nodes.\n * This will query the address book to get the network nodes.\n *\n * @param {string[] | string} mirrorNetwork\n * @returns {Promise<NativeClient>}\n */\n static async forMirrorNetwork(mirrorNetwork) {\n const client = new NativeClient({\n mirrorNetwork,\n });\n\n await client.updateNetwork();\n\n return client;\n }\n\n /**\n * @param {{[key: string]: (string | AccountId)} | string} network\n * @returns {void}\n */\n setNetwork(network) {\n if (typeof network === \"string\") {\n switch (network) {\n case \"previewnet\":\n this._network.setNetwork(WebNetwork.PREVIEWNET);\n break;\n case \"testnet\":\n this._network.setNetwork(WebNetwork.TESTNET);\n break;\n case \"mainnet\":\n this._network.setNetwork(WebNetwork.MAINNET);\n }\n } else {\n this._network.setNetwork(network);\n }\n }\n\n /**\n * @param {string[] | string} mirrorNetwork\n * @returns {this}\n */\n setMirrorNetwork(mirrorNetwork) {\n if (typeof mirrorNetwork === \"string\") {\n switch (mirrorNetwork) {\n case \"local-node\":\n this._mirrorNetwork.setNetwork(MirrorNetwork.LOCAL_NODE);\n break;\n case \"previewnet\":\n this._mirrorNetwork.setNetwork(MirrorNetwork.PREVIEWNET);\n break;\n case \"testnet\":\n this._mirrorNetwork.setNetwork(MirrorNetwork.TESTNET);\n break;\n case \"mainnet\":\n this._mirrorNetwork.setNetwork(MirrorNetwork.MAINNET);\n break;\n default:\n this._mirrorNetwork.setNetwork([mirrorNetwork]);\n }\n } else {\n this._mirrorNetwork.setNetwork(mirrorNetwork);\n }\n\n return this;\n }\n\n /**\n * @override\n * @returns {Promise<this>}\n */\n async updateNetwork() {\n if (this._isUpdatingNetwork) {\n return this;\n }\n\n this._isUpdatingNetwork = true;\n\n try {\n const addressBook = await new AddressBookQuery()\n .setFileId(\n FileId.getAddressBookFileIdFor(this.shard, this.realm),\n )\n .execute(this);\n\n /** @type {Record<string, AccountId>} */\n const network = {};\n for (const nodeAddress of addressBook.nodeAddresses) {\n for (const endpoint of nodeAddress.addresses) {\n if (nodeAddress.accountId != null) {\n network[endpoint.toString()] = nodeAddress.accountId;\n }\n }\n }\n\n this.setNetwork(network);\n } catch (/** @type {unknown} */ error) {\n if (this._logger) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this._logger.trace(\n `failed to update client address book: ${errorMessage}`,\n );\n }\n } finally {\n this._isUpdatingNetwork = false;\n }\n\n return this;\n }\n\n /**\n * @override\n * @returns {(address: string) => NativeChannel}\n */\n _createNetworkChannel() {\n return (address) => new NativeChannel(address);\n }\n\n /**\n * @override\n * @returns {(address: string) => *}\n */\n _createMirrorNetworkChannel() {\n return () => {\n throw new Error(\"mirror support is not supported in native\");\n };\n }\n}\n"],"names":["NativeClient","Client","constructor","props","super","network","this","setNetwork","WebNetwork","MAINNET","setLedgerId","LedgerId","setMirrorNetwork","MirrorNetwork","TESTNET","PREVIEWNET","Error","_validateNetworkConsistency","shard","realm","_extractShardRealm","_shard","_realm","fromConfig","data","JSON","parse","forNetwork","forName","forMainnet","forTestnet","forPreviewnet","forMainnetAsync","updateNetwork","forTestnetAsync","forPreviewnetAsync","forNameAsync","client","forMirrorNetwork","mirrorNetwork","_network","_mirrorNetwork","LOCAL_NODE","_isUpdatingNetwork","addressBook","AddressBookQuery","setFileId","FileId","getAddressBookFileIdFor","execute","nodeAddress","nodeAddresses","endpoint","addresses","accountId","toString","error","_logger","errorMessage","message","String","trace","_createNetworkChannel","address","NativeChannel","_createMirrorNetworkChannel"],"mappings":"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"}
@@ -171,12 +171,11 @@ class NodeClient extends _Client.default {
171
171
  * @returns {Promise<NodeClient>}
172
172
  */
173
173
  static async forMirrorNetwork(mirrorNetwork, shard, realm) {
174
- const INITIAL_UPDATE_PERIOD = 10_000;
175
174
  const client = new NodeClient({
176
175
  mirrorNetwork,
177
176
  shard,
178
177
  realm
179
- }).setNetworkUpdatePeriod(INITIAL_UPDATE_PERIOD);
178
+ });
180
179
  await client.updateNetwork();
181
180
  return client;
182
181
  }
@@ -211,6 +210,68 @@ class NodeClient extends _Client.default {
211
210
  });
212
211
  }
213
212
 
213
+ /**
214
+ * Construct a Hedera client pre-configured for Mainnet access with network update.
215
+ *
216
+ * @param {object} [props]
217
+ * @param {boolean} [props.scheduleNetworkUpdate]
218
+ * @returns {Promise<NodeClient>}
219
+ */
220
+ static async forMainnetAsync(props = {}) {
221
+ return new NodeClient({
222
+ network: "mainnet",
223
+ ...props
224
+ }).updateNetwork();
225
+ }
226
+
227
+ /**
228
+ * Construct a Hedera client pre-configured for Testnet access with network update.
229
+ *
230
+ * @param {object} [props]
231
+ * @param {boolean} [props.scheduleNetworkUpdate]
232
+ * @returns {Promise<NodeClient>}
233
+ */
234
+ static async forTestnetAsync(props = {}) {
235
+ return new NodeClient({
236
+ network: "testnet",
237
+ ...props
238
+ }).updateNetwork();
239
+ }
240
+
241
+ /**
242
+ * Construct a Hedera client pre-configured for Previewnet access with network update.
243
+ *
244
+ * @param {object} [props]
245
+ * @param {boolean} [props.scheduleNetworkUpdate]
246
+ * @returns {Promise<NodeClient>}
247
+ */
248
+ static async forPreviewnetAsync(props = {}) {
249
+ return new NodeClient({
250
+ network: "previewnet",
251
+ ...props
252
+ }).updateNetwork();
253
+ }
254
+
255
+ /**
256
+ * Construct a client for a specific network with optional network update.
257
+ * Updates network only if the network is not "local-node".
258
+ *
259
+ * @param {string} network
260
+ * @param {object} [props]
261
+ * @param {boolean} [props.scheduleNetworkUpdate]
262
+ * @returns {Promise<NodeClient>}
263
+ */
264
+ static async forNameAsync(network, props = {}) {
265
+ const client = new NodeClient({
266
+ network,
267
+ ...props
268
+ });
269
+ if (network !== "local-node") {
270
+ await client.updateNetwork();
271
+ }
272
+ return client;
273
+ }
274
+
214
275
  /**
215
276
  * @param {{[key: string]: (string | AccountId)} | string} network
216
277
  * @returns {void}
@@ -92,6 +92,48 @@ export default class NodeClient extends Client<NodeChannel, NodeMirrorChannel> {
92
92
  static forLocalNode(props?: {
93
93
  scheduleNetworkUpdate?: boolean | undefined;
94
94
  }): NodeClient;
95
+ /**
96
+ * Construct a Hedera client pre-configured for Mainnet access with network update.
97
+ *
98
+ * @param {object} [props]
99
+ * @param {boolean} [props.scheduleNetworkUpdate]
100
+ * @returns {Promise<NodeClient>}
101
+ */
102
+ static forMainnetAsync(props?: {
103
+ scheduleNetworkUpdate?: boolean | undefined;
104
+ }): Promise<NodeClient>;
105
+ /**
106
+ * Construct a Hedera client pre-configured for Testnet access with network update.
107
+ *
108
+ * @param {object} [props]
109
+ * @param {boolean} [props.scheduleNetworkUpdate]
110
+ * @returns {Promise<NodeClient>}
111
+ */
112
+ static forTestnetAsync(props?: {
113
+ scheduleNetworkUpdate?: boolean | undefined;
114
+ }): Promise<NodeClient>;
115
+ /**
116
+ * Construct a Hedera client pre-configured for Previewnet access with network update.
117
+ *
118
+ * @param {object} [props]
119
+ * @param {boolean} [props.scheduleNetworkUpdate]
120
+ * @returns {Promise<NodeClient>}
121
+ */
122
+ static forPreviewnetAsync(props?: {
123
+ scheduleNetworkUpdate?: boolean | undefined;
124
+ }): Promise<NodeClient>;
125
+ /**
126
+ * Construct a client for a specific network with optional network update.
127
+ * Updates network only if the network is not "local-node".
128
+ *
129
+ * @param {string} network
130
+ * @param {object} [props]
131
+ * @param {boolean} [props.scheduleNetworkUpdate]
132
+ * @returns {Promise<NodeClient>}
133
+ */
134
+ static forNameAsync(network: string, props?: {
135
+ scheduleNetworkUpdate?: boolean | undefined;
136
+ }): Promise<NodeClient>;
95
137
  /**
96
138
  * @param {ClientConfiguration} [props]
97
139
  */
@@ -1,2 +1,2 @@
1
- import e from"fs";import r from"util";import t from"./Client.js";import o from"../channel/NodeChannel.js";import s from"../channel/NodeMirrorChannel.js";import i from"../LedgerId.js";import n from"../account/AccountId.js";import a from"../address_book/NodeAddressBook.js";import{addressBook as w}from"./addressbooks/mainnet.js";import{addressBook as k}from"./addressbooks/testnet.js";import{addressBook as N}from"./addressbooks/previewnet.js";import{decode as m}from"../encoding/hex.js";import{MirrorNetwork as d}from"../constants/ClientConstants.js";const c=r.promisify(e.readFile),h={LOCAL_NODE:{"127.0.0.1:50211":new n(3)}};class f extends t{constructor(e){if(super(e),this._maxExecutionTime=1e4,null!=e){if("string"==typeof e.network)this._setNetworkFromName(e.network);else if(null!=e.network){t._validateNetworkConsistency(e.network);const{shard:r,realm:o}=t._extractShardRealm(e.network);this._shard=r,this._realm=o,this.setNetwork(e.network)}if("string"==typeof e.mirrorNetwork)switch(e.mirrorNetwork){case"mainnet":this.setMirrorNetwork(d.MAINNET);break;case"testnet":this.setMirrorNetwork(d.TESTNET);break;case"previewnet":this.setMirrorNetwork(d.PREVIEWNET);break;default:this.setMirrorNetwork([e.mirrorNetwork])}else null!=e.mirrorNetwork&&this.setMirrorNetwork(e.mirrorNetwork)}}static fromConfig(e){return new f("string"==typeof e?JSON.parse(e):e)}static async fromConfigFile(e){return f.fromConfig(await c(e,"utf8"))}static forNetwork(e,r){return new f({network:e,...r})}static forName(e,r={}){return new f({network:e,...r})}static forMainnet(e={}){return new f({network:"mainnet",...e})}static forTestnet(e={}){return new f({network:"testnet",...e})}static async forMirrorNetwork(e,r,t){const o=new f({mirrorNetwork:e,shard:r,realm:t}).setNetworkUpdatePeriod(1e4);return await o.updateNetwork(),o}static forPreviewnet(e={}){return new f({network:"previewnet",...e})}static forLocalNode(e={scheduleNetworkUpdate:!1}){return new f({network:"local-node",...e})}setNetwork(e){"string"==typeof e?this._setNetworkFromName(e):this._network.setNetwork(e)}setMaxExecutionTime(e){return this._maxExecutionTime=e,this}_setNetworkFromName(e){switch(e){case"mainnet":this.setNetworkFromAddressBook(a.fromBytes(m(w))),this.setMirrorNetwork(d.MAINNET),this.setLedgerId(i.MAINNET);break;case"testnet":this.setNetworkFromAddressBook(a.fromBytes(m(k))),this.setMirrorNetwork(d.TESTNET),this.setLedgerId(i.TESTNET);break;case"previewnet":this.setNetworkFromAddressBook(a.fromBytes(m(N))),this.setMirrorNetwork(d.PREVIEWNET),this.setLedgerId(i.PREVIEWNET);break;case"local-node":this.setNetwork(h.LOCAL_NODE),this.setMirrorNetwork(d.LOCAL_NODE),this.setLedgerId(i.LOCAL_NODE);break;default:throw new Error(`unknown network: ${e}`)}return this}setMirrorNetwork(e){if("string"==typeof e)switch(e){case"local-node":this._mirrorNetwork.setNetwork(d.LOCAL_NODE);break;case"previewnet":this._mirrorNetwork.setNetwork(d.PREVIEWNET);break;case"testnet":this._mirrorNetwork.setNetwork(d.TESTNET);break;case"mainnet":this._mirrorNetwork.setNetwork(d.MAINNET);break;default:this._mirrorNetwork.setNetwork([e])}else this._mirrorNetwork.setNetwork(e);return this}_createNetworkChannel(){return e=>new o(e,this._maxExecutionTime)}_createMirrorNetworkChannel(){return e=>new s(e)}}export{h as Network,f as default};
1
+ import e from"fs";import r from"util";import t from"./Client.js";import o from"../channel/NodeChannel.js";import s from"../channel/NodeMirrorChannel.js";import n from"../LedgerId.js";import i from"../account/AccountId.js";import a from"../address_book/NodeAddressBook.js";import{addressBook as w}from"./addressbooks/mainnet.js";import{addressBook as k}from"./addressbooks/testnet.js";import{addressBook as N}from"./addressbooks/previewnet.js";import{decode as m}from"../encoding/hex.js";import{MirrorNetwork as c}from"../constants/ClientConstants.js";const d=r.promisify(e.readFile),h={LOCAL_NODE:{"127.0.0.1:50211":new i(3)}};class f extends t{constructor(e){if(super(e),this._maxExecutionTime=1e4,null!=e){if("string"==typeof e.network)this._setNetworkFromName(e.network);else if(null!=e.network){t._validateNetworkConsistency(e.network);const{shard:r,realm:o}=t._extractShardRealm(e.network);this._shard=r,this._realm=o,this.setNetwork(e.network)}if("string"==typeof e.mirrorNetwork)switch(e.mirrorNetwork){case"mainnet":this.setMirrorNetwork(c.MAINNET);break;case"testnet":this.setMirrorNetwork(c.TESTNET);break;case"previewnet":this.setMirrorNetwork(c.PREVIEWNET);break;default:this.setMirrorNetwork([e.mirrorNetwork])}else null!=e.mirrorNetwork&&this.setMirrorNetwork(e.mirrorNetwork)}}static fromConfig(e){return new f("string"==typeof e?JSON.parse(e):e)}static async fromConfigFile(e){return f.fromConfig(await d(e,"utf8"))}static forNetwork(e,r){return new f({network:e,...r})}static forName(e,r={}){return new f({network:e,...r})}static forMainnet(e={}){return new f({network:"mainnet",...e})}static forTestnet(e={}){return new f({network:"testnet",...e})}static async forMirrorNetwork(e,r,t){const o=new f({mirrorNetwork:e,shard:r,realm:t});return await o.updateNetwork(),o}static forPreviewnet(e={}){return new f({network:"previewnet",...e})}static forLocalNode(e={scheduleNetworkUpdate:!1}){return new f({network:"local-node",...e})}static async forMainnetAsync(e={}){return new f({network:"mainnet",...e}).updateNetwork()}static async forTestnetAsync(e={}){return new f({network:"testnet",...e}).updateNetwork()}static async forPreviewnetAsync(e={}){return new f({network:"previewnet",...e}).updateNetwork()}static async forNameAsync(e,r={}){const t=new f({network:e,...r});return"local-node"!==e&&await t.updateNetwork(),t}setNetwork(e){"string"==typeof e?this._setNetworkFromName(e):this._network.setNetwork(e)}setMaxExecutionTime(e){return this._maxExecutionTime=e,this}_setNetworkFromName(e){switch(e){case"mainnet":this.setNetworkFromAddressBook(a.fromBytes(m(w))),this.setMirrorNetwork(c.MAINNET),this.setLedgerId(n.MAINNET);break;case"testnet":this.setNetworkFromAddressBook(a.fromBytes(m(k))),this.setMirrorNetwork(c.TESTNET),this.setLedgerId(n.TESTNET);break;case"previewnet":this.setNetworkFromAddressBook(a.fromBytes(m(N))),this.setMirrorNetwork(c.PREVIEWNET),this.setLedgerId(n.PREVIEWNET);break;case"local-node":this.setNetwork(h.LOCAL_NODE),this.setMirrorNetwork(c.LOCAL_NODE),this.setLedgerId(n.LOCAL_NODE);break;default:throw new Error(`unknown network: ${e}`)}return this}setMirrorNetwork(e){if("string"==typeof e)switch(e){case"local-node":this._mirrorNetwork.setNetwork(c.LOCAL_NODE);break;case"previewnet":this._mirrorNetwork.setNetwork(c.PREVIEWNET);break;case"testnet":this._mirrorNetwork.setNetwork(c.TESTNET);break;case"mainnet":this._mirrorNetwork.setNetwork(c.MAINNET);break;default:this._mirrorNetwork.setNetwork([e])}else this._mirrorNetwork.setNetwork(e);return this}_createNetworkChannel(){return e=>new o(e,this._maxExecutionTime)}_createMirrorNetworkChannel(){return e=>new s(e)}}export{h as Network,f as default};
2
2
  //# sourceMappingURL=NodeClient.js.map