From b80bfdb941b4ed22d2902f612198f37b1240007f Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:44:40 -0600 Subject: [PATCH] chore: add rfoxDir flag for custom storage path --- cli/MultiSig.md | 22 +++++++++++----------- cli/package.json | 1 + cli/src/constants.ts | 4 ---- cli/src/file.ts | 2 +- cli/src/index.ts | 14 +++++++++++++- cli/src/mnemonic.ts | 2 +- cli/src/wallet.ts | 2 +- cli/yarn.lock | 5 +++++ 8 files changed, 33 insertions(+), 19 deletions(-) diff --git a/cli/MultiSig.md b/cli/MultiSig.md index 4f7a029..ea1ff03 100644 --- a/cli/MultiSig.md +++ b/cli/MultiSig.md @@ -21,50 +21,50 @@ TAG=mainnet,cgo,ledger make install - Add your key: ```bash - ./thornode keys add {person1} --ledger + thornode keys add {person1} --ledger ``` - Export pubkey: ```bash - ./thornode keys show {person1} --pubkey + thornode keys show {person1} --pubkey ``` - Import signer pubkeys (ex. `'{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"someKeyValue}'`): ```bash - ./thornode keys add {person2} --pubkey '{person2_pubkey}' - ./thornode keys add {person3} --pubkey '{person3_pubkey}' + thornode keys add {person2} --pubkey '{person2_pubkey}' + thornode keys add {person3} --pubkey '{person3_pubkey}' ``` - View keys: ```bash - ./thornode keys list + thornode keys list ``` - Add multisig key: ```bash - ./thornode keys add multisig --multisig {person1},{person2},{person3} --multisig-threshold 2 + thornode keys add multisig --multisig {person1},{person2},{person3} --multisig-threshold 2 ``` - Validate multisig address: ```bash - ./thornode keys show multisig --address + thornode keys show multisig --address ``` ## Sign Transaction - Person 1 signs: ```bash - ./thornode tx sign --from {person1} --multisig multisig ~/rfox/unsignedTx_epoch-{N}.json --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc --ledger --sign-mode amino-json > ~/rfox/signedTx_epoch-{N}_{person1}.json + thornode tx sign --from {person1} --multisig multisig ~/rfox/unsignedTx_epoch-{N}.json --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc --ledger --sign-mode amino-json > ~/rfox/signedTx_epoch-{N}_{person1}.json ``` - Person 2 signs: ```bash - ./thornode tx sign --from {person2} --multisig multisig ~/rfox/unsignedTx_epoch-{N}.json --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc --ledger --sign-mode amino-json > ~/rfox/signedTx_epoch-{N}_{person2}.json + thornode tx sign --from {person2} --multisig multisig ~/rfox/unsignedTx_epoch-{N}.json --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc --ledger --sign-mode amino-json > ~/rfox/signedTx_epoch-{N}_{person2}.json ``` - Multisign: ```bash - ./thornode tx multisign ~/rfox/unsignedTx_epoch-{N}.json multisig ~/rfox/signedTx_epoch-{N}_{person1}.json ~/rfox/signedTx_epoch-{N}_{person2}.json --from multisig --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc > ~/rfox/signedTx_epoch-{N}_multisig.json + thornode tx multisign ~/rfox/unsignedTx_epoch-{N}.json multisig ~/rfox/signedTx_epoch-{N}_{person1}.json ~/rfox/signedTx_epoch-{N}_{person2}.json --from multisig --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc > ~/rfox/signedTx_epoch-{N}_multisig.json ``` ## Send Transaction - Broadcast transaction: ```bash - ./thornode tx broadcast ~/rfox/signedTx_epoch-{N}_multisig.json --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc --gas auto > tx.json + thornode tx broadcast ~/rfox/signedTx_epoch-{N}_multisig.json --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc --gas auto > tx.json ``` At this point, the cli should pick up the funding transaction and continue running the distribution from the hot wallet. diff --git a/cli/package.json b/cli/package.json index 033c2f7..40cff13 100644 --- a/cli/package.json +++ b/cli/package.json @@ -22,6 +22,7 @@ "bignumber.js": "^9.1.2", "bip39": "^3.1.0", "chalk": "^5.3.0", + "commander": "^12.1.0", "dotenv": "^16.4.5", "hash-wasm": "^4.11.0", "log-symbols": "^6.0.0", diff --git a/cli/src/constants.ts b/cli/src/constants.ts index fc678b1..3f585f7 100644 --- a/cli/src/constants.ts +++ b/cli/src/constants.ts @@ -1,7 +1,3 @@ -import os from 'node:os' -import path from 'node:path' - -export const RFOX_DIR = path.join(os.homedir(), 'rfox') export const RFOX_REWARD_RATE = 1n * 10n ** 27n export const MONTHS = [ diff --git a/cli/src/file.ts b/cli/src/file.ts index c763698..310a3b9 100644 --- a/cli/src/file.ts +++ b/cli/src/file.ts @@ -1,6 +1,6 @@ import fs from 'node:fs' -import { RFOX_DIR } from './constants' import { error, info, warn } from './logging' +import { RFOX_DIR } from '.' const deleteIfExists = (file: string) => { try { diff --git a/cli/src/index.ts b/cli/src/index.ts index 50200ae..f8d4bd9 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -2,16 +2,28 @@ import 'dotenv/config' import * as prompts from '@inquirer/prompts' import BigNumber from 'bignumber.js' import fs from 'node:fs' +import os from 'node:os' import path from 'node:path' import ora from 'ora' import { Client } from './client' -import { MONTHS, RFOX_DIR } from './constants' +import { MONTHS } from './constants' import { isEpochDistributionStarted } from './file' import { IPFS } from './ipfs' import { error, info, success, warn } from './logging' import { create, recoverKeystore } from './mnemonic' import { Epoch, RFOXMetadata } from './types' import { Wallet } from './wallet' +import { Command } from 'commander' + +const program = new Command() + +program.name('rFOX CLI') +program.description('Here to help you do all things rFOX') +program.option('--rfoxDir ', 'path to rfox directory', '~/rfox') +program.parse(process.argv) + +const options = program.opts() +export const RFOX_DIR = options.rfoxDir.replace(/^~(?=$|\/|\\)/, os.homedir()) const processEpoch = async () => { const ipfs = await IPFS.new() diff --git a/cli/src/mnemonic.ts b/cli/src/mnemonic.ts index d8fcdb1..b4fb2f7 100644 --- a/cli/src/mnemonic.ts +++ b/cli/src/mnemonic.ts @@ -2,9 +2,9 @@ import * as prompts from '@inquirer/prompts' import { generateMnemonic, validateMnemonic } from 'bip39' import crypto from 'node:crypto' import path from 'node:path' -import { RFOX_DIR } from './constants' import { read, write } from './file' import { error, info, success, warn } from './logging' +import { RFOX_DIR } from '.' const recoveryChoices = [ { diff --git a/cli/src/wallet.ts b/cli/src/wallet.ts index 0469166..0db5b71 100644 --- a/cli/src/wallet.ts +++ b/cli/src/wallet.ts @@ -5,10 +5,10 @@ import chalk from 'chalk' import symbols from 'log-symbols' import path from 'node:path' import ora, { Ora } from 'ora' -import { RFOX_DIR } from './constants' import { read, write } from './file' import { error, info, success } from './logging' import { Epoch } from './types' +import { RFOX_DIR } from '.' const BIP32_PATH = `m/44'/931'/0'/0/0` const SHAPESHIFT_MULTISIG_ADDRESS = 'thor1xmaggkcln5m5fnha2780xrdrulmplvfrz6wj3l' diff --git a/cli/yarn.lock b/cli/yarn.lock index 58abfb0..5e30c9e 100644 --- a/cli/yarn.lock +++ b/cli/yarn.lock @@ -1928,6 +1928,11 @@ commander@2.9.0: dependencies: graceful-readlink ">= 1.0.0" +commander@^12.1.0: + version "12.1.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3" + integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA== + component-type@1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/component-type/-/component-type-1.2.1.tgz#8a47901700238e4fc32269771230226f24b415a9"