Skip to content

Commit

Permalink
works when specifying addresses as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
olalonde committed Feb 28, 2014
1 parent f422936 commit 66c6ef8
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
86 changes: 86 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -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('<action>')
.option('-h, --host <host>', 'bitcoind RPC host', 'localhost')
.option('-p, --port <port>', 'bitcoind RPC port', parseInt, 8332)
.option('--user <user>', 'bitcoind RPC user')
.option('--pass <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 <id>')
.description('Generates an asset proof file with all private keys in wallet.')
.option('--addresses <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);
Empty file added lib/index.js
Empty file.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
}
}

0 comments on commit 66c6ef8

Please sign in to comment.