From b3673c9a2ef9dd92e5c46f9af1cb862de3d863d7 Mon Sep 17 00:00:00 2001 From: Pod Date: Fri, 9 Jun 2023 22:18:23 +0200 Subject: [PATCH 1/6] chore: update index-utils --- package-lock.json | 14 +++++++------- package.json | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7ec72bb..d30576f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.8.5", "license": "SEE LICENSE IN LICENSE.md", "dependencies": { - "@edge/index-utils": "^0.3.5", + "@edge/index-utils": "^0.7.2", "@edge/log": "^1.3.0", "@edge/stargate-utils": "^0.5.0", "@edge/wallet-utils": "^0.14.2", @@ -208,9 +208,9 @@ } }, "node_modules/@edge/index-utils": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@edge/index-utils/-/index-utils-0.3.5.tgz", - "integrity": "sha512-H4mQ1hZp8xC80HVEHvk6AmTMTpn1x8Dac+HxufC0/ZiOMoKFVRm7rkOlphA9mGC8f2gauuGkbknvHRuhzxM36A==", + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/@edge/index-utils/-/index-utils-0.7.2.tgz", + "integrity": "sha512-OGi/xCFrYaBl/ddMNFodgSXVuD/EtJWGOqhe4/Qe3mkqAotcvihYI/VIckfueEMt2IZgt+awGbQHAh7fQFaLoA==", "dependencies": { "superagent": "^6.1.0 || ^7.0.0" } @@ -3628,9 +3628,9 @@ "requires": {} }, "@edge/index-utils": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@edge/index-utils/-/index-utils-0.3.5.tgz", - "integrity": "sha512-H4mQ1hZp8xC80HVEHvk6AmTMTpn1x8Dac+HxufC0/ZiOMoKFVRm7rkOlphA9mGC8f2gauuGkbknvHRuhzxM36A==", + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/@edge/index-utils/-/index-utils-0.7.2.tgz", + "integrity": "sha512-OGi/xCFrYaBl/ddMNFodgSXVuD/EtJWGOqhe4/Qe3mkqAotcvihYI/VIckfueEMt2IZgt+awGbQHAh7fQFaLoA==", "requires": { "superagent": "^6.1.0 || ^7.0.0" }, diff --git a/package.json b/package.json index c916bd1..de8c03d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "typescript": "^4.9.4" }, "dependencies": { - "@edge/index-utils": "^0.3.5", + "@edge/index-utils": "^0.7.2", "@edge/log": "^1.3.0", "@edge/stargate-utils": "^0.5.0", "@edge/wallet-utils": "^0.14.2", @@ -55,4 +55,4 @@ "optionalDependencies": { "pkg": "^5.8.0" } -} +} \ No newline at end of file From 24500be9866ca407337a7b51b1b716c1abb426bc Mon Sep 17 00:00:00 2001 From: Pod Date: Fri, 9 Jun 2023 22:33:46 +0200 Subject: [PATCH 2/6] feat: add stake option to device --- src/api/xe.ts | 9 +++++++++ src/device/cli/restart.ts | 6 ++++-- src/device/cli/start.ts | 6 ++++-- src/device/cli/status.ts | 6 ++++-- src/device/cli/stop.ts | 6 ++++-- src/device/cli/update.ts | 6 ++++-- src/device/index.ts | 29 +++++++++++++++++++++++------ 7 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/api/xe.ts b/src/api/xe.ts index 277683f..b207117 100644 --- a/src/api/xe.ts +++ b/src/api/xe.ts @@ -2,6 +2,7 @@ // Use of this source code is governed by a GNU GPL-style license // that can be found in the LICENSE.md file. All rights reserved. +import * as index from '@edge/index-utils' import * as xe from '@edge/xe-utils' import { Context } from '../main' import { SuperAgentRequest } from 'superagent' @@ -34,6 +35,13 @@ const client = (ctx: Context) => { return data } + const stakeViaIndex = async (stake: string) => { + log.debug('stake query via index', { host, address: stake }) + const data = await index.stake.stake(ctx.network.index.host, stake, cb) + log.debug('stake response', { data }) + return data + } + const stakes = async (address: string) => { log.debug('stakes', { host, address }) const data = await xe.stake.stakes(host, address, cb) @@ -65,6 +73,7 @@ const client = (ctx: Context) => { return { createTransaction, pendingTransactions, + stakeViaIndex, stakes, wallet, walletWithNextNonce, diff --git a/src/device/cli/restart.ts b/src/device/cli/restart.ts index 25535a0..bda9dd8 100644 --- a/src/device/cli/restart.ts +++ b/src/device/cli/restart.ts @@ -16,12 +16,13 @@ import { errorHandler } from '../../cli' */ export const action = (ctx: Context) => async (): Promise => { const opts = { - ...cli.docker.readPrefix(ctx.cmd) + ...cli.docker.readPrefix(ctx.cmd), + ...cli.stake.read(ctx.cmd) } const device = ctx.device(opts.prefix) const docker = device.docker() - const node = await device.node() + const node = await device.node(opts.stake) const info = await node.container() if (info === undefined) { @@ -36,6 +37,7 @@ export const action = (ctx: Context) => async (): Promise => { export const command = (ctx: Context): Command => { const cmd = new Command('restart').description('restart node').addHelpText('after', help) cli.docker.configurePrefix(cmd) + cli.stake.configure(cmd) cmd.action(errorHandler(ctx, checkVersionHandler(ctx, action({ ...ctx, cmd })))) return cmd } diff --git a/src/device/cli/start.ts b/src/device/cli/start.ts index c6faad7..36efec2 100644 --- a/src/device/cli/start.ts +++ b/src/device/cli/start.ts @@ -23,13 +23,14 @@ export const action = (ctx: Context) => async (): Promise => { ...cli.docker.readAllEnv(ctx.cmd), ...cli.docker.readAllExtraHosts(ctx.cmd, ctx.network), ...cli.docker.readNetworks(ctx.cmd), - ...cli.docker.readPrefix(ctx.cmd) + ...cli.docker.readPrefix(ctx.cmd), + ...cli.stake.read(ctx.cmd) } const log = ctx.log() const device = ctx.device(opts.prefix) const docker = device.docker() - const node = await device.node() + const node = await device.node(opts.stake) let info = await node.container() if (info !== undefined) { @@ -69,6 +70,7 @@ export const command = (ctx: Context): Command => { cli.docker.configurePrefix(cmd) cli.docker.configureStargate(cmd) cli.docker.configureTarget(cmd) + cli.stake.configure(cmd) cmd.action(errorHandler(ctx, checkVersionHandler(ctx, action({ ...ctx, cmd })))) return cmd } diff --git a/src/device/cli/status.ts b/src/device/cli/status.ts index 69f51bc..a767c2d 100644 --- a/src/device/cli/status.ts +++ b/src/device/cli/status.ts @@ -17,11 +17,12 @@ import { errorHandler } from '../../cli' */ export const action = (ctx: Context) => async (): Promise => { const opts = { - ...cli.docker.readPrefix(ctx.cmd) + ...cli.docker.readPrefix(ctx.cmd), + ...cli.stake.read(ctx.cmd) } const device = ctx.device(opts.prefix) - const node = await device.node() + const node = await device.node(opts.stake) const info = await node.container() if (info === undefined) repl.echo(`${node.name} is not running`) else repl.echo(`${node.name} is running`) @@ -30,6 +31,7 @@ export const action = (ctx: Context) => async (): Promise => { export const command = (ctx: Context): Command => { const cmd = new Command('status').description('display node status').addHelpText('after', help) cli.docker.configurePrefix(cmd) + cli.stake.configure(cmd) cmd.action(errorHandler(ctx, checkVersionHandler(ctx, action({ ...ctx, cmd })))) return cmd } diff --git a/src/device/cli/stop.ts b/src/device/cli/stop.ts index c7d0904..ebeb97b 100644 --- a/src/device/cli/stop.ts +++ b/src/device/cli/stop.ts @@ -16,13 +16,14 @@ import { errorHandler } from '../../cli' */ export const action = (ctx: Context) => async (): Promise => { const opts = { - ...cli.docker.readPrefix(ctx.cmd) + ...cli.docker.readPrefix(ctx.cmd), + ...cli.stake.read(ctx.cmd) } const log = ctx.log() const device = ctx.device(opts.prefix) const docker = device.docker() - const node = await device.node() + const node = await device.node(opts.stake) const info = await node.container() if (info === undefined) { @@ -41,6 +42,7 @@ export const action = (ctx: Context) => async (): Promise => { export const command = (ctx: Context): Command => { const cmd = new Command('stop').description('stop node').addHelpText('after', help) cli.docker.configurePrefix(cmd) + cli.stake.configure(cmd) cmd.action(errorHandler(ctx, checkVersionHandler(ctx, action({ ...ctx, cmd })))) return cmd } diff --git a/src/device/cli/update.ts b/src/device/cli/update.ts index 9ca7394..872b7a9 100644 --- a/src/device/cli/update.ts +++ b/src/device/cli/update.ts @@ -19,13 +19,14 @@ import { EndpointsConfig, ImageInspectInfo } from 'dockerode' */ export const action = (ctx: Context) => async (): Promise => { const opts = { - ...cli.docker.readPrefix(ctx.cmd) + ...cli.docker.readPrefix(ctx.cmd), + ...cli.stake.read(ctx.cmd) } const log = ctx.log() const device = ctx.device(opts.prefix) const docker = device.docker() - const node = await device.node() + const node = await device.node(opts.stake) repl.echo(`Checking ${node.name} version...`) const { target } = await cli.docker.readTarget(ctx, node.stake.type) @@ -100,6 +101,7 @@ export const command = (ctx: Context): Command => { cli.docker.configureTarget(cmd) cli.docker.configurePrefix(cmd) cli.docker.configureAuth(cmd) + cli.stake.configure(cmd) cmd.action(errorHandler(ctx, checkVersionHandler(ctx, action({ ...ctx, cmd })))) return cmd } diff --git a/src/device/index.ts b/src/device/index.ts index b2a3912..06c3a0e 100644 --- a/src/device/index.ts +++ b/src/device/index.ts @@ -71,14 +71,31 @@ const device = (ctx: Context, prefix: string | undefined) => { } // get device node information including the assigned stake and, if running, the Docker container - const node = async () => { - const address = await ctx.wallet().address() - const deviceWallet = await (await volume()).read() + const node = async (stakeId?: string) => { + const stake = await (async () => { + if (stakeId) { + const deviceWallet = await (await volume()).read() + log.debug('finding stake via index', { stake: stakeId, deviceAddress: deviceWallet.address, network: deviceWallet.network }) + try { + const stake = await ctx.xeClient().stakeViaIndex(stakeId) + return stake + } + catch { + throw new Error('Stake not found on the index. It might take several minutes until your stake appears.') + } + } + else { + const address = await ctx.wallet().address() + const deviceWallet = await (await volume()).read() - log.debug('finding node', { address, deviceAddress: deviceWallet.address, network: deviceWallet.network }) + log.debug('finding stake via local wallet', { address, deviceAddress: deviceWallet.address, network: deviceWallet.network }) + + const stake = Object.values(await ctx.xeClient().stakes(address)).find(s => s.device === deviceWallet.address) + if (stake === undefined) throw new Error('device is not assigned to a stake') + return stake + } + })() - const stake = Object.values(await ctx.xeClient().stakes(address)).find(s => s.device === deviceWallet.address) - if (stake === undefined) throw new Error('device is not assigned to a stake') const image = ctx.network.registry.imageName(stake.type, arch()) const name = toUpperCaseFirst(stake.type) From 80847028c0c02f36df624d2df63106be69f9bb51 Mon Sep 17 00:00:00 2001 From: Aneurin Barker Snook Date: Tue, 15 Aug 2023 09:01:46 +0100 Subject: [PATCH 3/6] chore: bump version to 1.8.6 --- package-lock.json | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index d30576f..c6401a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@edge/cli", - "version": "1.8.5", + "version": "1.8.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@edge/cli", - "version": "1.8.5", + "version": "1.8.6", "license": "SEE LICENSE IN LICENSE.md", "dependencies": { "@edge/index-utils": "^0.7.2", diff --git a/package.json b/package.json index de8c03d..83ac511 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@edge/cli", - "version": "1.8.5", + "version": "1.8.6", "description": "Command line interface for the Edge network", "private": true, "author": "Edge Network ", @@ -55,4 +55,4 @@ "optionalDependencies": { "pkg": "^5.8.0" } -} \ No newline at end of file +} From 0a9c25ba58da9dfb896f0d97e04c412330f83d84 Mon Sep 17 00:00:00 2001 From: Aneurin Barker Snook Date: Tue, 15 Aug 2023 10:20:26 +0100 Subject: [PATCH 4/6] fix: lock pkg-fetch version --- .ci/docker/build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.ci/docker/build b/.ci/docker/build index 3b391da..440d9c3 100644 --- a/.ci/docker/build +++ b/.ci/docker/build @@ -19,7 +19,8 @@ ARG NODE=node16 ENV PKG_CACHE_PATH=/pkg-cache # Pre-fetch Node base binaries to avoid build time issues -RUN npm install -g pkg-fetch +# https://github.com/vercel/pkg-fetch/releases/tag/v3.4 +RUN npm install -g pkg-fetch@3.4.2 RUN pkg-fetch -n ${NODE} -p linux -a $ARCH RUN pkg-fetch -n ${NODE} -p macos -a $ARCH RUN pkg-fetch -n ${NODE} -p win -a $ARCH From 2b07e6fc2fa995d2f8b2fbd044b9685d21ce4171 Mon Sep 17 00:00:00 2001 From: Aneurin Barker Snook Date: Tue, 15 Aug 2023 13:33:12 +0100 Subject: [PATCH 5/6] fix: update bug also add improved advice on manual download in event of error --- src/update/cli/update.ts | 38 ++++++++++++++++++++++++++------------ src/update/index.ts | 2 +- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/update/cli/update.ts b/src/update/cli/update.ts index 8de0522..16b1cf5 100644 --- a/src/update/cli/update.ts +++ b/src/update/cli/update.ts @@ -5,11 +5,13 @@ import * as cli from '../../cli' import * as repl from '../../repl' import { Command } from 'commander' +import { arch } from 'os' import { errorHandler } from '../../cli' +import { normalizedPlatform } from '../../helpers' import path from 'path' import { Context, Network } from '../../main' import { chmodSync, copyFileSync, renameSync, unlinkSync } from 'fs' -import { currentVersion, download, latestVersion } from '..' +import { currentVersion, download, ext, latestVersion } from '..' /** Update CLI. */ export const action = (ctx: Context, argv: string[]) => async (): Promise => { @@ -30,21 +32,33 @@ export const action = (ctx: Context, argv: string[]) => async (): Promise if (/node$/.test(selfPath)) throw new Error('path to binary appears to be node path') - repl.echo(`Downloading v${lv}`) - const { file } = await download(ctx) - const tmpFilename = `${path.dirname(file)}/tmp-${Date.now}` + let tmpFilename = '' + try { + repl.echo(`Downloading v${lv}`) + const { file } = await download(ctx) + tmpFilename = `${path.dirname(file)}/tmp-${Date.now()}` - // After downloading the file, we move the current binary to a temporary - // location, move the new file to the current binary location, and then - // attempt to remove the previous binary. This may fail on Windows. - repl.echo(`Updating from v${cv} to v${lv}`) - chmodSync(file, 0o755) - renameSync(selfPath, tmpFilename) - copyFileSync(file, selfPath) + // After downloading the file, we move the current binary to a temporary + // location, move the new file to the current binary location, and then + // attempt to remove the previous binary. This may fail on Windows. + repl.echo(`Updating from v${cv} to v${lv}`) + chmodSync(file, 0o755) + renameSync(selfPath, tmpFilename) + copyFileSync(file, selfPath) + } + catch (err) { + log.error(`Failed to download Edge CLI v${cv}`, { err }) + const buildURL = ctx.network.files.latestBuildURL(normalizedPlatform(), arch(), ext()) + repl.nl() + repl.echo('If you have difficulty updating Edge CLI via this method, you can download it manually from the following URL:') + repl.nl() + repl.echo(buildURL) + return + } // Try to remove file but ignore any errors. try { - unlinkSync(tmpFilename) + if (tmpFilename) unlinkSync(tmpFilename) } catch (err) { if (opts.debug) log.error('Unable to remove download', { err }) diff --git a/src/update/index.ts b/src/update/index.ts index 9c90e1c..4d0ffb5 100644 --- a/src/update/index.ts +++ b/src/update/index.ts @@ -118,7 +118,7 @@ export const download = async ({ network, ...ctx }: Context): Promise normalizedPlatform() === 'windows' ? '.exe' : '' +export const ext = (): string => normalizedPlatform() === 'windows' ? '.exe' : '' export const latestVersion = async ({ network, ...ctx }: Context): Promise => { const log = ctx.log('update.version.get') From 7b5deff104208ec245c0f056ae81595d49bc288b Mon Sep 17 00:00:00 2001 From: Aneurin Barker Snook Date: Tue, 15 Aug 2023 13:33:33 +0100 Subject: [PATCH 6/6] chore: bump version to 1.8.7 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index c6401a6..bb5ae46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@edge/cli", - "version": "1.8.6", + "version": "1.8.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@edge/cli", - "version": "1.8.6", + "version": "1.8.7", "license": "SEE LICENSE IN LICENSE.md", "dependencies": { "@edge/index-utils": "^0.7.2", diff --git a/package.json b/package.json index 83ac511..3de7fb6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@edge/cli", - "version": "1.8.6", + "version": "1.8.7", "description": "Command line interface for the Edge network", "private": true, "author": "Edge Network ",