diff --git a/node_modules/bitpay/bitcoinRPC.js b/node_modules/bitpay/bitcoinRPC.js index bd410ac..e6edf81 100644 --- a/node_modules/bitpay/bitcoinRPC.js +++ b/node_modules/bitpay/bitcoinRPC.js @@ -68,6 +68,18 @@ function spec(b) { RPC.call(this, 'gettransaction', [txid], callback); }; + BitcoinRPC.prototype.getRawTransaction = function(txid, callback) { + RPC.call(this, 'getrawtransaction', [txid], callback); + }; + + BitcoinRPC.prototype.signRawTransaction = function(hexstr, callback) { + RPC.call(this, 'signrawtransaction', [hexstr], callback); + }; + + BitcoinRPC.prototype.sendRawTransaction = function(hexstr, callback) { + RPC.call(this, 'sendrawtransaction', [hexstr], callback); + }; + BitcoinRPC.prototype.sendToAddress = function(address, amount, callback) { RPC.call(this, 'sendtoaddress', [address, amount], callback); }; diff --git a/node_modules/txtool/txtool b/node_modules/txtool/txtool new file mode 100755 index 0000000..b50dc77 --- /dev/null +++ b/node_modules/txtool/txtool @@ -0,0 +1,124 @@ +#!/usr/bin/env node + +var fs = require('fs'); +var Util = require('bitcoin/lib/ext/util'); +var BitcoinRPC = require('bitpay/bitcoinRPC').default(); +var bitcoinRPC = undefined; +var Transaction = required('bitcoin/lib/model/transaction').class(); + +var argv = require('optimist') + .usage('Transaction tool.\nUsage: $0 [options]') + .demand(['c']) + .alias('f', 'file') + .describe('f', 'Transaction source file (raw, serialized, hex encoded)') + .alias('x', 'txid') + .describe('x', 'Transaction id (switches TX source to RPC)') + .alias('c', 'cmd') + .describe('c', 'JSON command file') + .alias('h', 'host') + .describe('h', 'bitcoind RPC hostname or IP address') + .alias('p', 'port') + .describe('p', 'bitcoind RPC port') + .alias('U', 'user') + .describe('U', 'bitcoind RPC username') + .alias('P', 'pass') + .describe('P', 'bitcoind RPC password') + .argv +; + +function setupRPC(host, port, user, pass) { + var opts = {}; + opts.host = host; + opts.port = port; + opts.user = user; + opts.pass = pass; + bitcoinRPC = new BitcoinRPC(opts); +} + +function loadTxRPC(txid) { + var hexstr = bitcoinRPC.getRawTransaction(txid); + + var data = new Buffer(hexstr, 'hex'); + var tx = new Transaction(data); + return tx; +} + +function loadTxfile(filename) { + var hexfile = fs.readFilesync(filename, 'utf8'); + + var data = new Buffer(hexfile.trim(), 'hex'); + var tx = new Transaction(data); + return tx; +} + +function loadCmdFile(filename) { + var data = JSON.parse(fs.readFileSync(filename)).result; + return data; +} + +// how many copies of this can one codebase bear? +function transactionDesc(tx) { + var outDescriptions = []; + var outs = tx.outs; + for(var i=0; i