Skip to content

Commit d733b50

Browse files
committed
feat: add commands: networks (get|set)Active
1 parent 0814a2c commit d733b50

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,21 @@ const executeCommand = async (
345345
const debug = { identifier, cid: parametersCID, tx: r.tx };
346346
callback({ id, ...r }, debug);
347347
});
348+
commandNetworks
349+
.command("getActive")
350+
.description("get the identifier of the active network(s)")
351+
.action(async () => {
352+
const nid = (await client.query.runtime.Networks.activeNetwork.get()) as
353+
| Field
354+
| undefined;
355+
if (!nid) return callback(responses.RECORD_NOT_FOUND);
356+
357+
// retrieve the string form of the network identifier
358+
const n = await client.query.runtime.Networks.networks.get(nid);
359+
if (!n) return callback(responses.RECORD_NOT_FOUND);
360+
361+
callback({ id, status: SUCCESS, data: n.identifier.toString() });
362+
});
348363
commandNetworks
349364
.command("getNetwork <identifier> [file://]")
350365
.description("get network by identifier; optionally save params to file")
@@ -376,6 +391,16 @@ const executeCommand = async (
376391
debug,
377392
);
378393
});
394+
commandNetworks
395+
.command("setActive <identifier>")
396+
.description("set the active network")
397+
.action(async (identifier: string) => {
398+
const networkID = Network.getID(CircuitString.fromString(identifier));
399+
const r = await txer(async () => {
400+
await networks.setActiveNetwork(networkID);
401+
});
402+
callback({ id, ...r });
403+
});
379404

380405
const commandNodes = program.command("nodes").description("nodes commands");
381406
commandNodes

0 commit comments

Comments
 (0)