commit afec848151fedf7ac2363f65161ed21ce0ad3744
parent 9a6d98f899c112ceb88e5543163fcf552e82df09
Author: ThomasV <electrumdev@gmail.com>
Date: Sun, 18 Jan 2015 17:12:25 +0100
Merge pull request #982 from dabura667/customoutput
Add arbitrary non-standard outputs
Diffstat:
2 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/gui/qt/paytoedit.py b/gui/qt/paytoedit.py
@@ -66,13 +66,13 @@ class PayToEdit(ScanQRTextEdit):
self.setStyleSheet("QWidget { background-color:#ffcccc;}")
def parse_address_and_amount(self, line):
- m = re.match('^OP_RETURN\s+([0-9a-fA-F]+)$', line.strip())
- if m:
- _type = 'op_return'
- address = m.group(1).decode('hex')
- amount = 0
+ x, y = line.split(',')
+ n = re.match('^SCRIPT\s+([0-9a-fA-F]+)$', x.strip())
+ if n:
+ _type = 'script'
+ address = n.group(1).decode('hex')
+ amount = self.parse_amount(y)
else:
- x, y = line.split(',')
_type = 'address'
address = self.parse_address(x)
amount = self.parse_amount(y)
diff --git 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 'script', bytes
@@ -564,20 +564,20 @@ class Transaction:
@classmethod
def pay_script(self, output_type, addr):
- if output_type == 'op_return':
- h = addr.encode('hex')
- return '6a' + push_script(h)
- 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
+ if output_type == 'script':
+ return addr.encode('hex')
+ 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:
raise
return script
@@ -756,10 +756,8 @@ class Transaction:
addr = x
elif type == 'pubkey':
addr = public_key_to_bc_address(x.decode('hex'))
- elif type == 'op_return':
- addr = 'OP_RETURN ' + x.encode('hex')
else:
- addr = "(None)"
+ addr = 'SCRIPT ' + x.encode('hex')
o.append((addr,v)) # consider using yield (addr, v)
return o