public inbox for bitcoindev@googlegroups.com
 help / color / mirror / Atom feed
* [Bitcoin-development] [PATCH] bitcoind: whitelist nodes, to prevent them from being banned
@ 2013-11-22 20:46 Jeff Garzik
  2013-11-22 23:11 ` Michael Hendricks
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff Garzik @ 2013-11-22 20:46 UTC (permalink / raw)
  To: Bitcoin Dev

[-- Attachment #1: Type: text/plain, Size: 313 bytes --]

Trying something new... a [simple] patch sent to the list, for
discussion.  Seems unlikely to be controversial.  github access is
temporarily disabled, so this is the best pull request avenue for the
moment.

-- 
Jeff Garzik
Bitcoin core developer and open source evangelist
BitPay, Inc.      https://bitpay.com/

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 4130 bytes --]

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<outs.length; i++) {
+    var txout = outs[i];
+    var script = txout.getScript();
+    var type = script.getOutType();
+    var amount = (txout.getValue() / 1e8).round(8);
+    if(type == 'Address') {
+      outDescriptions.push({
+        type: type,
+        amount: amount,
+        address: Util.pubKeyHashToAddress(script.simpleOutHash())
+      });
+    } else {
+      outDescriptions.push({
+        type: type,
+        amount: amount
+      });
+    }
+  }
+  return {
+    txid: Util.formatHashFull(tx.getHash()),
+    outs: outDescriptions
+  }
+};
+
+function CmdShow(tx) {
+	console.log(inspect(transactionDesc(tx), false, 10));
+}
+
+function CmdSign(tx) {
+	var txHex = Util.encodeHex(tx.serialize());
+	var retHex = bitcoinRPC.signRawTransaction(txHex);
+	console.log(retHex);
+}
+
+function CmdSend(tx) {
+	var txHex = Util.encodeHex(tx.serialize());
+	bitcoinRPC.sendRawTransaction(txHex);
+}
+
+function ExecCmdData(tx, cmdData) {
+	for (var i = 0; i < cmdData.length; i++) {
+		var obj = cmdData[i];
+		if (obj.cmd == "show") {
+			CmdShow(tx);
+		}
+		else if (obj.cmd == "sign") {
+			CmdSign(tx);
+		}
+		else if (obj.cmd == "send") {
+			CmdSend(tx);
+		}
+	}
+}
+
+if (argv.host) {
+	setupRPC(host, port, user, pass);
+}
+var tx = argv.txid ? loadTxRPC(argv.txid) :
+		     loadTxFile(argv.file);
+var cmdData = loadCmdFile(argv.cmd);
+ExecCmdData(tx, cmdData);
+

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Bitcoin-development] [PATCH] bitcoind: whitelist nodes, to prevent them from being banned
  2013-11-22 20:46 [Bitcoin-development] [PATCH] bitcoind: whitelist nodes, to prevent them from being banned Jeff Garzik
@ 2013-11-22 23:11 ` Michael Hendricks
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Hendricks @ 2013-11-22 23:11 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Bitcoin Dev

[-- Attachment #1: Type: text/plain, Size: 1135 bytes --]

Wrong patch?  This looks like node.js code for something called txtool.


-- 
Michael


On Fri, Nov 22, 2013 at 1:46 PM, Jeff Garzik <jgarzik@bitpay•com> wrote:

> Trying something new... a [simple] patch sent to the list, for
> discussion.  Seems unlikely to be controversial.  github access is
> temporarily disabled, so this is the best pull request avenue for the
> moment.
>
> --
> Jeff Garzik
> Bitcoin core developer and open source evangelist
> BitPay, Inc.      https://bitpay.com/
>
>
> ------------------------------------------------------------------------------
> Shape the Mobile Experience: Free Subscription
> Software experts and developers: Be at the forefront of tech innovation.
> Intel(R) Software Adrenaline delivers strategic insight and game-changing
> conversations that shape the rapidly evolving mobile landscape. Sign up
> now.
> http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
> _______________________________________________
> Bitcoin-development mailing list
> Bitcoin-development@lists•sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bitcoin-development
>
>

[-- Attachment #2: Type: text/html, Size: 1926 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-22 23:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-22 20:46 [Bitcoin-development] [PATCH] bitcoind: whitelist nodes, to prevent them from being banned Jeff Garzik
2013-11-22 23:11 ` Michael Hendricks

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox