Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
# - restore_dependency_cache
- run: | # TODO figure out how to make this only run on a cache miss in restore_dependency_cache
nvm use default
npm install
npm ci
- save_cache:
key: node_modules-{{ checksum "package-lock.json" }}-{{ checksum "combined-package-lock.txt" }}
paths:
Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
# - restore_dependency_cache
- run: | # TODO figure out how to make this only run on a cache miss in restore_dependency_cache
nvm use default
npm install
npm ci
- persist_to_workspace:
root: ~/bitcore/packages/crypto-rpc # only persist crypto-rpc package
paths:
Expand Down
57 changes: 46 additions & 11 deletions packages/bitcore-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions packages/bitcore-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"tss",
"wallet"
],
"engines":{
"node": "^22"
},
"repository": {
"type": "git",
"url": "https://github.com/bitpay/bitcore/tree/master/packages/bitcore-cli"
Expand All @@ -29,8 +32,8 @@
"bitcore-cli": "./bin/bitcore-cli"
},
"scripts": {
"test": "npm run compile && node copyTestWallets && mocha --exit 'build/test/**/*.js'",
"coverage": "npm run compile && node copyTestWallets && nyc mocha --exit 'build/test/**/*.js'",
"test": "npm run compile && node copyTestWallets && mocha --exit -n enable-source-maps 'build/test/**/*.js'",
"coverage": "npm run compile && node copyTestWallets && nyc mocha --exit -n enable-source-maps 'build/test/**/*.js'",
"build": "tsc",
"build:prod": "tsc -p tsconfig.prod.json",
"postbuild": "node createBin -v",
Expand All @@ -47,7 +50,7 @@
"@bitpay-labs/bitcore-mnemonic": "^11.9.0",
"@bitpay-labs/bitcore-wallet-client": "^11.10.2",
"@bitpay-labs/crypto-wallet-core": "^11.10.0",
"@clack/prompts": "1.0.0-alpha.6",
"@clack/prompts": "1.5.1",
"commander": "14.0.0",
"external-editor": "3.1.0",
"usb": "2.15.0"
Expand Down
1 change: 1 addition & 0 deletions packages/bitcore-cli/src/cli-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function getCommands(args: { wallet: IWallet; opts?: ICliOptions }) {
{ label: 'Derive', value: 'derive', hint: 'Derive a key along a path you will specify' },
{ label: 'Export', value: 'export', hint: 'Export the wallet to a file' },
{ label: 'Scan', value: 'scan', hint: 'Scan the wallet for funds' },
{ label: 'Flags', value: 'flags', hint: 'Manage XRP wallet flags', show: () => wallet.isXrp() },
{ label: 'Register', value: 'register', hint: 'Register the wallet with the Bitcore Wallet Service' },
{ label: 'Clear Cache', value: 'clearcache', hint: 'Clear the wallet cache' }
]
Expand Down
7 changes: 7 additions & 0 deletions packages/bitcore-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ if (require.main === module) {
prompt.intro(`Status for ${Utils.colorTextByChain(wallet.chain, walletName)}`);
const status = await commands.status.walletStatus({ wallet, opts });
cmdParams.status = status;
if (wallet.isMultiSig() && !wallet.isComplete()) {
prompt.outro(Utils.boldText('This multisig wallet is not fully set up yet. You need to wait for all copayers to join.'));
return;
}
prompt.outro(Utils.boldText('Welcome to the Bitcore CLI!'));
}

Expand Down Expand Up @@ -258,6 +262,9 @@ if (require.main === module) {
case 'scan':
await commands.scan.scanWallet(cmdParams);
break;
case 'flags':
({ action } = await commands.flags.getOrSetFlags(cmdParams));
break;
case 'register':
await commands.register.registerWallet(cmdParams);
break;
Expand Down
73 changes: 73 additions & 0 deletions packages/bitcore-cli/src/commands/flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Utils as CWCUtils, xrpl } from '@bitpay-labs/crypto-wallet-core';
import * as prompt from '@clack/prompts';
import { promptXrpFlag } from '../prompts';
import { Utils } from '../utils';
import { type ITransactionArgs, createTransaction, command as txCommand } from './transaction';
import type { CommonArgs } from '../../types/cli';

function flagsDisplay() {
const flags = Object.keys(xrpl.AccountSetTfFlags).filter(k => isNaN(parseInt(k))); // filter out numeric keys
return 'Possible flags are: ' + flags.join(', ');
}

export function command(args: CommonArgs<ITransactionArgs>) {
const { program } = args;
program
.description('View and manage XRP wallet flags')
.usage('<walletName> --command flags [options]')
.optionsGroup('Flags Options')
.option('--flags <flags>', 'Comma-delimited list of account transaction flag(s) to set. If provided, see Transaction Options below for additional options to provide for the setting transaction. ' + flagsDisplay());

const opts = txCommand({
...args,
opts: {
...args.opts,
extensionOpts: {
excludedOptions: new Set(['--to', '--amount']),
parse: (opts) => {
if (opts.flags) {
const flags = opts.flags.split(',').map(f => CWCUtils.normalizeXrpFlag(f.trim()));
if (flags.some(f => !f)) {
throw new Error('Invalid flag(s) specified. ' + flagsDisplay());
}
opts.flags = flags.join(',');
}
}
}
}
});

return opts;
}

export async function getOrSetFlags(args: CommonArgs<ITransactionArgs>) {
const { wallet, opts } = args;
if (opts.command) {
Object.assign(opts, command(args));
}

if (!wallet.isXrp()) {
// This code should only be reachable if using --command, so we should die.
Utils.die('Flags management is only available for XRP wallets');
}

const existingFlags = await wallet.getAccountFlags();
prompt.note(
Object.entries(existingFlags)
.map(([key, value]) => `${key}: ${value ? Utils.colorText('ON', 'green') : Utils.colorText('OFF', 'red')}`)
.join('\n'),
'Current XRP Account Flags'
);

const flags = opts.command ? opts.flags : await promptXrpFlag(existingFlags);

if (flags) {
opts.flags = flags;
opts.to = (await wallet.client.getMainAddresses())[0].address;
opts.amount = '0';
opts.txType = 'AccountSet';
await createTransaction(args);
}

return { action: 'menu' };
};
3 changes: 2 additions & 1 deletion packages/bitcore-cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export * as preferences from './preferences';
export * as sign from './sign';
export * as token from './token';
export * as register from './register';
export * as clearcache from './clearcache';
export * as clearcache from './clearcache';
export * as flags from './flags';
Loading