Skip to content

Commit

Permalink
Added CLI arguments for providing numbr of accounts to generate, spec…
Browse files Browse the repository at this point in the history
…ifying mnemonic, and toggling debug logging
  • Loading branch information
rkalis committed Oct 30, 2018
1 parent 4c6c8f0 commit a3d1e60
Show file tree
Hide file tree
Showing 5 changed files with 505 additions and 116 deletions.
52 changes: 29 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ npm install --global pandacash-cli
## Usage
After installing `pandacash-cli`, it can be used as a command-line tool to quickly spin up a local development BCH blockchain with a single command. The local blockchain comes with ten pre-funded BCH addresses, which can be used in the local development process. `pandacash-cli` will also spin up a REST API to interface with the local blockchain that is fully compatible with [BITBOX](https://developer.bitcoin.com/bitbox/).

**Command Line**
```bash
pandacash-cli
$ pandacash-cli <options>
```

Options:
* `-a` or `--accounts`: Specify the number of accounts to generate at startup.
* `-m` or `--mnemonic`: bip39 mnemonic phrase for generating a PRNG seed, which is in turn used for hierarchical deterministic (HD) account generation.
* `--debug`: Show debug output from the bitcoin node.

```bash
____ _ ____ _
| _ \ __ _ _ __ __| | __ _ / ___| __ _ ___ | |__
Expand All @@ -39,37 +45,37 @@ Seeding accounts
Advancing blockchain to enable spending
Starting BITBOX API at port 3000
PandaCash CLI v0.0.1
PandaCash CLI v0.2.0
Available Accounts
==================
(0) bchreg:qr9mp5wlj0qey2es35j99kg0qn4lwj9jsqvwacyyfs
(1) bchreg:qq7e82yqmlwf94u085vc402ecv26rvl09srlpjkf09
(2) bchreg:qqpgxm3j008hlxqtjdxtxrpylvvasg7dpql2xrwhqz
(3) bchreg:qrkw3ytggq4g5ng3v0n9efrnw9q9zvdrjy5xwjnncs
(4) bchreg:qp9jzuvszclraqq7jh485pf3p2dn5cyw3gmpdnehzc
(5) bchreg:qrkgyqf04a8x55a9juwm9k6evdysmzq2zgjcl4y93e
(6) bchreg:qz540yauansl6lu32j0uhrlzzvyk4s2nlufw5jcrqz
(7) bchreg:qpy7us0e6chgej3lhwrpr6rlvtlym5hrh5rsp63g68
(8) bchreg:qpejwem46w6m4ah9lkr0v5gdaqy277dxdc7rgg4wl0
(9) bchreg:qzeekdn8jwn48kaufzru4zhwuphme79695ln2kpmpy
(0) bchreg:qpk8s58gaal6gwhvyulxszzecws539g27c50v0nk6t
(1) bchreg:qqm2nlulp8ulnnhxqpmmtkvvwmkr8usrhggh3z5uwl
(2) bchreg:qrl5aqss5e7av0606zl5ajnj2xurkf280gwyqff9v6
(3) bchreg:qqahjdfalxw9j2t57ajs5jctl9ayzp5yk553yvxwv3
(4) bchreg:qp3qhranmxzpr42rn0sl3rqmvdhrcty9l5nugh9ysp
(5) bchreg:qraulxcveneskyfayw78fyaxhvr6t8w3ssp7zclse8
(6) bchreg:qqahhkf755uz3dz8g48d3dzgvee0p4c79ynffxevqh
(7) bchreg:qr7tgfwz2gzcy424v7g34enhugs02e7qkukh96cfc7
(8) bchreg:qps5zg80jh4lden2crvzr5uzra8tesfs2vjp4l6z0t
(9) bchreg:qqc0pw9q5c7ssx6wxpug63w3y6vlw0zamqjjp3p5mr
Private Keys
==================
(0) cV59RxmDATEV3x66grEWGbWgvGHYCQoCu9uDwtF4uyQtxTm52Ptb
(1) cSnTygYBZdbH2fNzoPzk9kARJNc6zaAsUyvpWfUbztFmYctaAw4E
(2) cVEiVmNNs8W2nTqHkcM1Ghpga4SQijw3W86eEerBp5Ynxe8zWq8d
(3) cN35RxP1bhyuoSnMF6DZSa6ZiVddZ6Rm5MFVQUSt1qTDua35jVR6
(4) cV6ughqaPwG1DqqW8oWk7PC3PA9SUGCXfxxSyPe58pQivchVHR9i
(5) cQ4cBokvYvSL8TWLiWGZESS2YVQDxXXpoqh3QAUizU2sBfJnsHiJ
(6) cPbDNta1FNgvfKR44hS37aEQai6oS31LVDD6kpFZoGkuri64ULya
(7) cR38r4hUmgfuyTEqkiWtaxwUWZyc6LA8M6JAb9pmjereWUhBwGJp
(8) cW1HaJ2b5FrFA5ya5sHMciUC9WaQJQsZu5n5odWsSKJToXoGhMqr
(9) cQb4ycXBeecZga3cvq18KEUxwxH1qARhQQ38KJvyX8QxLgEj5Bqe
(0) cVABvrFC8MXZJHSCyULa99MXDsQdLeQwKHxjGXughgd6pXNtd558
(1) cPZ2RbJK6UYVjeMwpgtd8EvnzjfdZraegcsddz6jPmajE4Qe848d
(2) cSDUAHNne1ssgFsavbjp8mLBy7CEtqgYM874konLWiy4BVbf85PM
(3) cT3ApxBWsoX62jUZiJcpzsXQHbXB4sTgdH8PF2qDTdHSgaLurcJJ
(4) cV9tvwoc9iDpK2kWLLzxEdRFe68LNMTrZQ7xLiyhCuZGX8pQfpGH
(5) cMmQyLbXeX9jcucMwr4GFQKwWr7knCPqnS6GU7b7HD1D6R8xR755
(6) cQ2ULCzf2FwcUsV1rioHrEVUR1p4zUmjcpEVFHmBTdM6CJP7Si2H
(7) cNYwTL8nFm9ckqwRMDuRuTUd1NraSkTs2Np87TuBCCnvNn3enVy6
(8) cVY8RP3UXBrZksGPNhAR72qpGHkYmmLVu6ycgizSEAYWrhHvbhia
(9) cUHqwE6oXE5dDQrn8bXwkYmm71vViwzjGseGeSPCyUjThEXZHpXG
HD Wallet
==================
Mnemonic: unveil stadium curtain now network cabbage fun silly spider neither machine power
Mnemonic: candy maple cake sugar pudding cream honey rich smooth crumble sweet treat
Base HD Path: m/44'/145'/0'/0/{account_index}
Bitcoin Cash Listening on http://localhost:18332
Expand Down
56 changes: 56 additions & 0 deletions args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module.exports = exports = function(yargs, version) {
return yargs
.strict()
.option('a', {
group: 'Accounts:',
alias: 'accounts',
describe: 'Number of accounts to generate at startup',
type: 'number',
default: 10
})
// .option('e', {
// group: 'Accounts:',
// alias: 'defaultBalanceEther',
// describe: 'Amount of ether to assign each test account',
// type: 'number',
// default: 100.0
// })
.option('m', {
group: 'Chain:',
alias: 'mnemonic',
type: 'string',
describe: 'bip39 mnemonic phrase for generating a PRNG seed, which is in turn used for hierarchical deterministic (HD) account generation',
demandOption: false
})
// .option('b', {
// group: 'Chain:',
// alias: 'blockTime',
// type: 'number',
// describe: 'Block time in seconds for automatic mining. Will instantly mine a new block for every transaction if option omitted. Avoid using unless your test cases require a specific mining interval.',
// demandOption: false
// })
// .option('t', {
// group: 'Chain:',
// alias: 'time',
// describe: 'Date (ISO 8601) that the first block should start. Use this feature, along with the evm_increaseTime method to test time-dependent code.',
// type: 'string',
// coerce: (arg) => {
// let timestamp = Date.parse(arg);
// if (isNaN(timestamp)) {
// throw new Error('Invalid \'time\' format');
// }
// return new Date(timestamp);
// }
// })
.option('debug', {
group: 'Other:',
describe: 'Show debug output from the bitcoin node',
type: 'boolean',
default: false
})
.showHelpOnFail(false, 'Specify -? or --help for available options')
.help('help')
.alias('help', '?')
.wrap(Math.min(120, yargs.terminalWidth()))
.version(version)
}
45 changes: 31 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
#! /usr/bin/env node
const chalk = require('chalk');
const clear = require('clear');
const figlet = require('figlet');
const util = require('util');
const _exec = require('child_process').exec;
const exec = util.promisify(_exec);
const path = require('path');
const package = require('./package.json');
const chalk = require('chalk');
const clear = require('clear');
const figlet = require('figlet');
const util = require('util');
const _exec = require('child_process').exec;
const exec = util.promisify(_exec);
const path = require('path');
const pkg = require('./package.json');
const yargs = require('yargs');
const initArgs = require("./args")

var detailedVersion = `Pandacash CLI v${pkg.version}`;

var argv = initArgs(yargs, detailedVersion).argv;

var options = {
mnemonic: argv.m,
totalAccounts: argv.a,
// defaultBalance: argv.e,
// blockTime: argv.b,
debug: argv.debug,
// time: argv.t,
}

const BITBOXSDK = require('bitbox-sdk/lib/bitbox-sdk');
const BITBOX = new BITBOXSDK.default();
Expand All @@ -17,15 +32,15 @@ const BITCOIN_CLI = 'bitcoin-cli -regtest -rpcuser=regtest -rpcpassword=regtest'
const BITCOIN_DATA_DIR = '/opt/bitcoin/';
const REST_APP = path.dirname(require.resolve('rest.bitcoin.com/package.json')) + '/app.js';

const mnemonic = generateSeedMnemonic();
const keyPairs = generateSeedKeyPairs();
const mnemonic = options.mnemonic || generateSeedMnemonic();
const keyPairs = generateSeedKeyPairs(mnemonic, options.totalAccounts);

function generateSeedMnemonic() {
return BITBOX.Mnemonic.generate(128);
}

function generateSeedKeyPairs() {
return BITBOX.Mnemonic.toKeypairs(mnemonic, 10, true);
function generateSeedKeyPairs(mnemonic, totalAccounts) {
return BITBOX.Mnemonic.toKeypairs(mnemonic, totalAccounts, true);
}

async function startDocker() {
Expand Down Expand Up @@ -93,7 +108,7 @@ async function startBitboxApi() {

function printPandaMessage() {
process.stdout.write(`
PandaCash CLI v${package.version}
${detailedVersion}
Available Accounts
==================`);
Expand Down Expand Up @@ -141,7 +156,9 @@ function printPandaMessage() {

printPandaMessage();

enableLogging();
if (options.debug) {
enableLogging();
}
})();


Loading

0 comments on commit a3d1e60

Please sign in to comment.