Skip to content

Commit e6a8da0

Browse files
committed
feat: get active network info by "_" identifier
1 parent 0dbe35d commit e6a8da0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,24 @@ const executeCommand = async (
362362
});
363363
commandNetworks
364364
.command("getNetwork <identifier> [file://]")
365-
.description("get network by identifier; optionally save params to file")
365+
.description(
366+
'get network by id; "_" for active, optionally save params to file',
367+
)
366368
.action(async (identifier: string, file?: string) => {
367369
if (!ipfsNode) return callback(responses.IPFS_NOT_STARTED);
368-
const networkID = Network.getID(CircuitString.fromString(identifier));
370+
371+
var networkID: Field;
372+
if (identifier === "_") {
373+
const nid =
374+
(await client.query.runtime.Networks.activeNetwork.get()) as
375+
| Field
376+
| undefined;
377+
if (!nid) return callback(responses.RECORD_NOT_FOUND);
378+
networkID = nid;
379+
} else {
380+
networkID = Network.getID(CircuitString.fromString(identifier));
381+
}
382+
369383
const network = (await client.query.runtime.Networks.networks.get(
370384
networkID,
371385
)) as Network | undefined;

0 commit comments

Comments
 (0)