Skip to content

Commit f71951a

Browse files
authored
Merge pull request #142 from edge/develop
v1.8.7
2 parents 27e0620 + 7b5deff commit f71951a

File tree

12 files changed

+92
-41
lines changed

12 files changed

+92
-41
lines changed

.ci/docker/build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ ARG NODE=node16
1919
ENV PKG_CACHE_PATH=/pkg-cache
2020

2121
# Pre-fetch Node base binaries to avoid build time issues
22-
RUN npm install -g pkg-fetch
22+
# https://github.com/vercel/pkg-fetch/releases/tag/v3.4
23+
RUN npm install -g [email protected]
2324
RUN pkg-fetch -n ${NODE} -p linux -a $ARCH
2425
RUN pkg-fetch -n ${NODE} -p macos -a $ARCH
2526
RUN pkg-fetch -n ${NODE} -p win -a $ARCH

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@edge/cli",
3-
"version": "1.8.5",
3+
"version": "1.8.7",
44
"description": "Command line interface for the Edge network",
55
"private": true,
66
"author": "Edge Network <[email protected]>",
@@ -38,7 +38,7 @@
3838
"typescript": "^4.9.4"
3939
},
4040
"dependencies": {
41-
"@edge/index-utils": "^0.3.5",
41+
"@edge/index-utils": "^0.7.2",
4242
"@edge/log": "^1.3.0",
4343
"@edge/stargate-utils": "^0.5.0",
4444
"@edge/wallet-utils": "^0.14.2",

src/api/xe.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a GNU GPL-style license
33
// that can be found in the LICENSE.md file. All rights reserved.
44

5+
import * as index from '@edge/index-utils'
56
import * as xe from '@edge/xe-utils'
67
import { Context } from '../main'
78
import { SuperAgentRequest } from 'superagent'
@@ -34,6 +35,13 @@ const client = (ctx: Context) => {
3435
return data
3536
}
3637

38+
const stakeViaIndex = async (stake: string) => {
39+
log.debug('stake query via index', { host, address: stake })
40+
const data = await index.stake.stake(ctx.network.index.host, stake, cb)
41+
log.debug('stake response', { data })
42+
return data
43+
}
44+
3745
const stakes = async (address: string) => {
3846
log.debug('stakes', { host, address })
3947
const data = await xe.stake.stakes(host, address, cb)
@@ -65,6 +73,7 @@ const client = (ctx: Context) => {
6573
return {
6674
createTransaction,
6775
pendingTransactions,
76+
stakeViaIndex,
6877
stakes,
6978
wallet,
7079
walletWithNextNonce,

src/device/cli/restart.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ import { errorHandler } from '../../cli'
1616
*/
1717
export const action = (ctx: Context) => async (): Promise<void> => {
1818
const opts = {
19-
...cli.docker.readPrefix(ctx.cmd)
19+
...cli.docker.readPrefix(ctx.cmd),
20+
...cli.stake.read(ctx.cmd)
2021
}
2122

2223
const device = ctx.device(opts.prefix)
2324
const docker = device.docker()
24-
const node = await device.node()
25+
const node = await device.node(opts.stake)
2526

2627
const info = await node.container()
2728
if (info === undefined) {
@@ -36,6 +37,7 @@ export const action = (ctx: Context) => async (): Promise<void> => {
3637
export const command = (ctx: Context): Command => {
3738
const cmd = new Command('restart').description('restart node').addHelpText('after', help)
3839
cli.docker.configurePrefix(cmd)
40+
cli.stake.configure(cmd)
3941
cmd.action(errorHandler(ctx, checkVersionHandler(ctx, action({ ...ctx, cmd }))))
4042
return cmd
4143
}

src/device/cli/start.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ export const action = (ctx: Context) => async (): Promise<void> => {
2323
...cli.docker.readAllEnv(ctx.cmd),
2424
...cli.docker.readAllExtraHosts(ctx.cmd, ctx.network),
2525
...cli.docker.readNetworks(ctx.cmd),
26-
...cli.docker.readPrefix(ctx.cmd)
26+
...cli.docker.readPrefix(ctx.cmd),
27+
...cli.stake.read(ctx.cmd)
2728
}
2829

2930
const log = ctx.log()
3031
const device = ctx.device(opts.prefix)
3132
const docker = device.docker()
32-
const node = await device.node()
33+
const node = await device.node(opts.stake)
3334

3435
let info = await node.container()
3536
if (info !== undefined) {
@@ -69,6 +70,7 @@ export const command = (ctx: Context): Command => {
6970
cli.docker.configurePrefix(cmd)
7071
cli.docker.configureStargate(cmd)
7172
cli.docker.configureTarget(cmd)
73+
cli.stake.configure(cmd)
7274
cmd.action(errorHandler(ctx, checkVersionHandler(ctx, action({ ...ctx, cmd }))))
7375
return cmd
7476
}

src/device/cli/status.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ import { errorHandler } from '../../cli'
1717
*/
1818
export const action = (ctx: Context) => async (): Promise<void> => {
1919
const opts = {
20-
...cli.docker.readPrefix(ctx.cmd)
20+
...cli.docker.readPrefix(ctx.cmd),
21+
...cli.stake.read(ctx.cmd)
2122
}
2223

2324
const device = ctx.device(opts.prefix)
24-
const node = await device.node()
25+
const node = await device.node(opts.stake)
2526
const info = await node.container()
2627
if (info === undefined) repl.echo(`${node.name} is not running`)
2728
else repl.echo(`${node.name} is running`)
@@ -30,6 +31,7 @@ export const action = (ctx: Context) => async (): Promise<void> => {
3031
export const command = (ctx: Context): Command => {
3132
const cmd = new Command('status').description('display node status').addHelpText('after', help)
3233
cli.docker.configurePrefix(cmd)
34+
cli.stake.configure(cmd)
3335
cmd.action(errorHandler(ctx, checkVersionHandler(ctx, action({ ...ctx, cmd }))))
3436
return cmd
3537
}

src/device/cli/stop.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import { errorHandler } from '../../cli'
1616
*/
1717
export const action = (ctx: Context) => async (): Promise<void> => {
1818
const opts = {
19-
...cli.docker.readPrefix(ctx.cmd)
19+
...cli.docker.readPrefix(ctx.cmd),
20+
...cli.stake.read(ctx.cmd)
2021
}
2122

2223
const log = ctx.log()
2324
const device = ctx.device(opts.prefix)
2425
const docker = device.docker()
25-
const node = await device.node()
26+
const node = await device.node(opts.stake)
2627

2728
const info = await node.container()
2829
if (info === undefined) {
@@ -41,6 +42,7 @@ export const action = (ctx: Context) => async (): Promise<void> => {
4142
export const command = (ctx: Context): Command => {
4243
const cmd = new Command('stop').description('stop node').addHelpText('after', help)
4344
cli.docker.configurePrefix(cmd)
45+
cli.stake.configure(cmd)
4446
cmd.action(errorHandler(ctx, checkVersionHandler(ctx, action({ ...ctx, cmd }))))
4547
return cmd
4648
}

src/device/cli/update.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import { EndpointsConfig, ImageInspectInfo } from 'dockerode'
1919
*/
2020
export const action = (ctx: Context) => async (): Promise<void> => {
2121
const opts = {
22-
...cli.docker.readPrefix(ctx.cmd)
22+
...cli.docker.readPrefix(ctx.cmd),
23+
...cli.stake.read(ctx.cmd)
2324
}
2425

2526
const log = ctx.log()
2627
const device = ctx.device(opts.prefix)
2728
const docker = device.docker()
28-
const node = await device.node()
29+
const node = await device.node(opts.stake)
2930

3031
repl.echo(`Checking ${node.name} version...`)
3132
const { target } = await cli.docker.readTarget(ctx, node.stake.type)
@@ -100,6 +101,7 @@ export const command = (ctx: Context): Command => {
100101
cli.docker.configureTarget(cmd)
101102
cli.docker.configurePrefix(cmd)
102103
cli.docker.configureAuth(cmd)
104+
cli.stake.configure(cmd)
103105
cmd.action(errorHandler(ctx, checkVersionHandler(ctx, action({ ...ctx, cmd }))))
104106
return cmd
105107
}

src/device/index.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/update/cli/update.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import * as cli from '../../cli'
66
import * as repl from '../../repl'
77
import { Command } from 'commander'
8+
import { arch } from 'os'
89
import { errorHandler } from '../../cli'
10+
import { normalizedPlatform } from '../../helpers'
911
import path from 'path'
1012
import { Context, Network } from '../../main'
1113
import { chmodSync, copyFileSync, renameSync, unlinkSync } from 'fs'
12-
import { currentVersion, download, latestVersion } from '..'
14+
import { currentVersion, download, ext, latestVersion } from '..'
1315

1416
/** Update CLI. */
1517
export const action = (ctx: Context, argv: string[]) => async (): Promise<void> => {
@@ -30,21 +32,33 @@ export const action = (ctx: Context, argv: string[]) => async (): Promise<void>
3032

3133
if (/node$/.test(selfPath)) throw new Error('path to binary appears to be node path')
3234

33-
repl.echo(`Downloading v${lv}`)
34-
const { file } = await download(ctx)
35-
const tmpFilename = `${path.dirname(file)}/tmp-${Date.now}`
35+
let tmpFilename = ''
36+
try {
37+
repl.echo(`Downloading v${lv}`)
38+
const { file } = await download(ctx)
39+
tmpFilename = `${path.dirname(file)}/tmp-${Date.now()}`
3640

37-
// After downloading the file, we move the current binary to a temporary
38-
// location, move the new file to the current binary location, and then
39-
// attempt to remove the previous binary. This may fail on Windows.
40-
repl.echo(`Updating from v${cv} to v${lv}`)
41-
chmodSync(file, 0o755)
42-
renameSync(selfPath, tmpFilename)
43-
copyFileSync(file, selfPath)
41+
// After downloading the file, we move the current binary to a temporary
42+
// location, move the new file to the current binary location, and then
43+
// attempt to remove the previous binary. This may fail on Windows.
44+
repl.echo(`Updating from v${cv} to v${lv}`)
45+
chmodSync(file, 0o755)
46+
renameSync(selfPath, tmpFilename)
47+
copyFileSync(file, selfPath)
48+
}
49+
catch (err) {
50+
log.error(`Failed to download Edge CLI v${cv}`, { err })
51+
const buildURL = ctx.network.files.latestBuildURL(normalizedPlatform(), arch(), ext())
52+
repl.nl()
53+
repl.echo('If you have difficulty updating Edge CLI via this method, you can download it manually from the following URL:')
54+
repl.nl()
55+
repl.echo(buildURL)
56+
return
57+
}
4458

4559
// Try to remove file but ignore any errors.
4660
try {
47-
unlinkSync(tmpFilename)
61+
if (tmpFilename) unlinkSync(tmpFilename)
4862
}
4963
catch (err) {
5064
if (opts.debug) log.error('Unable to remove download', { err })

src/update/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const download = async ({ network, ...ctx }: Context): Promise<DownloadIn
118118
}
119119
}
120120

121-
const ext = (): string => normalizedPlatform() === 'windows' ? '.exe' : ''
121+
export const ext = (): string => normalizedPlatform() === 'windows' ? '.exe' : ''
122122

123123
export const latestVersion = async ({ network, ...ctx }: Context): Promise<SemVer> => {
124124
const log = ctx.log('update.version.get')

0 commit comments

Comments
 (0)