@@ -16,6 +16,7 @@ import {
1616 Balance ,
1717 CID ,
1818 MixDescriptor ,
19+ Network ,
1920 Node ,
2021 TreasuryId ,
2122 client ,
@@ -130,6 +131,7 @@ console.log("opts", opts);
130131await client . start ( ) ;
131132const admin = client . runtime . resolve ( "Admin" ) ;
132133const faucet = client . runtime . resolve ( "Faucet" ) ;
134+ const networks = client . runtime . resolve ( "Networks" ) ;
133135const nodes = client . runtime . resolve ( "Nodes" ) ;
134136const pki = client . runtime . resolve ( "Pki" ) ;
135137const token = client . runtime . resolve ( "Token" ) ;
@@ -303,6 +305,61 @@ const executeCommand = async (
303305 } ) ;
304306 }
305307
308+ const commandNetworks = program
309+ . command ( "networks" )
310+ . description ( "networks commands" ) ;
311+ commandNetworks
312+ . command ( "register <identifier>" )
313+ . description ( "register a network <parameters := payload>" )
314+ . action ( async ( identifier : string ) => {
315+ if ( ! ipfsNode ) return callback ( responses . IPFS_NOT_STARTED ) ;
316+ if ( ! payload ) return callback ( responses . PAYLOAD_UNDEFINED ) ;
317+
318+ const parametersCID = await ipfsNode . putBytes ( payload ) ;
319+
320+ const r = await txer ( async ( ) => {
321+ await networks . register (
322+ new Network ( {
323+ identifier : CircuitString . fromString ( identifier ) ,
324+ parametersCID : CID . fromString ( parametersCID ) ,
325+ } ) ,
326+ ) ;
327+ } ) ;
328+
329+ const debug = { identifier, cid : parametersCID , tx : r . tx } ;
330+ callback ( { id, ...r } , debug ) ;
331+ } ) ;
332+ commandNetworks
333+ . command ( "getNetwork <identifier>" )
334+ . description ( "get network by identifier" )
335+ . action ( async ( identifier : string ) => {
336+ if ( ! ipfsNode ) return callback ( responses . IPFS_NOT_STARTED ) ;
337+ const networkID = Network . getID ( CircuitString . fromString ( identifier ) ) ;
338+ const network = ( await client . query . runtime . Networks . networks . get (
339+ networkID ,
340+ ) ) as Network | undefined ;
341+ if ( ! network ) return callback ( responses . RECORD_NOT_FOUND ) ;
342+
343+ const cid = network . parametersCID . toString ( ) ;
344+ const parameters = await ipfsNode . getBytes ( cid ) ;
345+
346+ const { parametersCID, ...rest } = Network . toObject ( network ) ;
347+ const data = {
348+ parameters,
349+ ...rest ,
350+ } ;
351+
352+ const debug = { identifier, cid, network : rest } ;
353+ callback (
354+ {
355+ id,
356+ status : SUCCESS ,
357+ data : opts . socketFormat === "cbor" ? cbor . encode ( data ) : data ,
358+ } ,
359+ debug ,
360+ ) ;
361+ } ) ;
362+
306363 const commandNodes = program . command ( "nodes" ) . description ( "nodes commands" ) ;
307364 commandNodes
308365 . command ( "isRegistrationOpen" )
0 commit comments