@@ -71,14 +71,31 @@ const device = (ctx: Context, prefix: string | undefined) => {
7171 }
7272
7373 // get device node information including the assigned stake and, if running, the Docker container
74- const node = async ( ) => {
75- const address = await ctx . wallet ( ) . address ( )
76- const deviceWallet = await ( await volume ( ) ) . read ( )
74+ const node = async ( stakeId ?: string ) => {
75+ const stake = await ( async ( ) => {
76+ if ( stakeId ) {
77+ const deviceWallet = await ( await volume ( ) ) . read ( )
78+ log . debug ( 'finding stake via index' , { stake : stakeId , deviceAddress : deviceWallet . address , network : deviceWallet . network } )
79+ try {
80+ const stake = await ctx . xeClient ( ) . stakeViaIndex ( stakeId )
81+ return stake
82+ }
83+ catch {
84+ throw new Error ( 'Stake not found on the index. It might take several minutes until your stake appears.' )
85+ }
86+ }
87+ else {
88+ const address = await ctx . wallet ( ) . address ( )
89+ const deviceWallet = await ( await volume ( ) ) . read ( )
7790
78- log . debug ( 'finding node' , { address, deviceAddress : deviceWallet . address , network : deviceWallet . network } )
91+ log . debug ( 'finding stake via local wallet' , { address, deviceAddress : deviceWallet . address , network : deviceWallet . network } )
92+
93+ const stake = Object . values ( await ctx . xeClient ( ) . stakes ( address ) ) . find ( s => s . device === deviceWallet . address )
94+ if ( stake === undefined ) throw new Error ( 'device is not assigned to a stake' )
95+ return stake
96+ }
97+ } ) ( )
7998
80- const stake = Object . values ( await ctx . xeClient ( ) . stakes ( address ) ) . find ( s => s . device === deviceWallet . address )
81- if ( stake === undefined ) throw new Error ( 'device is not assigned to a stake' )
8299
83100 const image = ctx . network . registry . imageName ( stake . type , arch ( ) )
84101 const name = toUpperCaseFirst ( stake . type )
0 commit comments