From b741dd89caa39628ce4e2943b5c46474c32dc2b7 Mon Sep 17 00:00:00 2001 From: dabura667 Date: Sun, 18 Jan 2015 02:37:44 +0900 Subject: [PATCH] Added arbitrary outputs write your own output scripts should you be so inclined. --- gui/qt/paytoedit.py | 12 +++++++++--- lib/transaction.py | 29 +++++++++++++++-------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/gui/qt/paytoedit.py b/gui/qt/paytoedit.py index a01156ef..2493f7c0 100644 --- a/gui/qt/paytoedit.py +++ b/gui/qt/paytoedit.py @@ -73,9 +73,15 @@ class PayToEdit(ScanQRTextEdit): amount = 0 else: x, y = line.split(',') - _type = 'address' - address = self.parse_address(x) - amount = self.parse_amount(y) + n = re.match('^CUSTOM_OUT\s+([0-9a-fA-F]+)$', x.strip()) + if n: + _type = 'custom' + address = n.group(1).decode('hex') + amount = self.parse_amount(y) + else: + _type = 'address' + address = self.parse_address(x) + amount = self.parse_amount(y) return _type, address, amount diff --git a/lib/transaction.py b/lib/transaction.py index 1a049d80..ea1f15af 100644 --- a/lib/transaction.py +++ b/lib/transaction.py @@ -424,7 +424,7 @@ def get_address_from_output_script(bytes): if match_decoded(decoded, match): return 'op_return', decoded[1][1] - return "(None)", "(None)" + return 'custom', bytes @@ -567,19 +567,20 @@ class Transaction: if output_type == 'op_return': h = addr.encode('hex') return '6a' + push_script(h) + elif output_type == 'address': + addrtype, hash_160 = bc_address_to_hash_160(addr) + if addrtype == 0: + script = '76a9' # op_dup, op_hash_160 + script += push_script(hash_160.encode('hex')) + script += '88ac' # op_equalverify, op_checksig + elif addrtype == 5: + script = 'a9' # op_hash_160 + script += push_script(hash_160.encode('hex')) + script += '87' # op_equal + else: + raise else: - assert output_type == 'address' - addrtype, hash_160 = bc_address_to_hash_160(addr) - if addrtype == 0: - script = '76a9' # op_dup, op_hash_160 - script += push_script(hash_160.encode('hex')) - script += '88ac' # op_equalverify, op_checksig - elif addrtype == 5: - script = 'a9' # op_hash_160 - script += push_script(hash_160.encode('hex')) - script += '87' # op_equal - else: - raise + script = addr.encode('hex') return script def input_script(self, txin, i, for_sig): @@ -759,7 +760,7 @@ class Transaction: elif type == 'op_return': addr = 'OP_RETURN ' + x.encode('hex') else: - addr = "(None)" + addr = 'CUSTOM ' + x.encode('hex') o.append((addr,v)) # consider using yield (addr, v) return o