From 66c6ef83159a7c5871da251f6fa0f80a31c80fe1 Mon Sep 17 00:00:00 2001 From: Olivier Lalonde Date: Fri, 28 Feb 2014 13:19:15 +0800 Subject: [PATCH] works when specifying addresses as argument --- cli.js | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/index.js | 0 package.json | 8 +++++ 3 files changed, 94 insertions(+) create mode 100755 cli.js create mode 100644 lib/index.js diff --git a/cli.js b/cli.js new file mode 100755 index 0000000..2133670 --- /dev/null +++ b/cli.js @@ -0,0 +1,86 @@ +#!/usr/bin/env node + +var program = require('commander'), + bitcoin = require('bitcoin'), + async = require('async'), + fs = require('fs'); + +program + .version(JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8')).version) + .usage('') + .option('-h, --host ', 'bitcoind RPC host', 'localhost') + .option('-p, --port ', 'bitcoind RPC port', parseInt, 8332) + .option('--user ', 'bitcoind RPC user') + .option('--pass ', 'bitcoind RPC pass') + .option('--human', 'Human readable output.'); + +function parse_list (str) { + var arr = str.split(','); + for (var i = 0; i < arr.length; i++) { + arr[i] = arr[i].trim(); + } + return arr; +} + +program + .command('signall ') + .description('Generates an asset proof file with all private keys in wallet.') + .option('--addresses ', 'Comma separated list of addresses to sign.', parse_list) + .action(function (id, opts) { + var client = new bitcoin.Client({ + host: program.host, + port: program.port, + user: program.user, + pass: program.pass + }); + + //client.getBalance('*', 6, function (err, balance) { + //if (err) return console.log(err); + //console.log('Balance:', balance); + //}); + + //@TODO: batch requests https://github.com/freewil/node-bitcoin#batch-multiple-rpc-calls-into-single-http-request + + var addresses = opts.addresses, + output = { + id: id, + signatures: [] + }; + + async.series([ + function (cb) { + if (addresses) return cb(); + + client.cmd('listreceivedbyaddress', 1, function (err, res){ + if (err) return cb(err); + cb(); + }); + }, + function (cb) { + async.each(addresses, function (addr, cb) { + client.cmd('signmessage', addr, id, function (err, res) { + if (err) return cb(err); + + output.signatures.push({ + address: addr, + signature: res + }); + + cb(); + }); + }, cb); + } + ], function (err) { + if (err) return console.error(err); + if (program.human) { + console.log(output); + } + else { + console.log(JSON.stringify(output)); + } + }); + + + }); + +program.parse(process.argv); diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index b6fe1ad..df246fc 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "0.0.1", "description": "Tool to prove how many bitcoins someone controls. Intended for use as part of the blind-solvency-proof scheme.", "main": "index.js", + "bin": { + "baproof": "./cli.js" + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, @@ -24,5 +27,10 @@ "gitHead": "c54a83d26bea69ebad03cd14ddf0da2ea39dcddb", "bugs": { "url": "https://github.com/olalonde/bitcoin-asset-proof/issues" + }, + "dependencies": { + "commander": "~2.1.0", + "bitcoin": "~2.0.1", + "async": "~0.2.10" } }