Browse Source

Merge pull request #982 from dabura667/customoutput

Add arbitrary non-standard outputs
283
ThomasV 10 years ago
parent
commit
afec848151
  1. 12
      gui/qt/paytoedit.py
  2. 34
      lib/transaction.py

12
gui/qt/paytoedit.py

@ -66,13 +66,13 @@ class PayToEdit(ScanQRTextEdit):
self.setStyleSheet("QWidget { background-color:#ffcccc;}") self.setStyleSheet("QWidget { background-color:#ffcccc;}")
def parse_address_and_amount(self, line): def parse_address_and_amount(self, line):
m = re.match('^OP_RETURN\s+([0-9a-fA-F]+)$', line.strip()) x, y = line.split(',')
if m: n = re.match('^SCRIPT\s+([0-9a-fA-F]+)$', x.strip())
_type = 'op_return' if n:
address = m.group(1).decode('hex') _type = 'script'
amount = 0 address = n.group(1).decode('hex')
amount = self.parse_amount(y)
else: else:
x, y = line.split(',')
_type = 'address' _type = 'address'
address = self.parse_address(x) address = self.parse_address(x)
amount = self.parse_amount(y) amount = self.parse_amount(y)

34
lib/transaction.py

@ -424,7 +424,7 @@ def get_address_from_output_script(bytes):
if match_decoded(decoded, match): if match_decoded(decoded, match):
return 'op_return', decoded[1][1] return 'op_return', decoded[1][1]
return "(None)", "(None)" return 'script', bytes
@ -564,20 +564,20 @@ class Transaction:
@classmethod @classmethod
def pay_script(self, output_type, addr): def pay_script(self, output_type, addr):
if output_type == 'op_return': if output_type == 'script':
h = addr.encode('hex') return addr.encode('hex')
return '6a' + push_script(h) elif output_type == 'address':
else: addrtype, hash_160 = bc_address_to_hash_160(addr)
assert output_type == 'address' if addrtype == 0:
addrtype, hash_160 = bc_address_to_hash_160(addr) script = '76a9' # op_dup, op_hash_160
if addrtype == 0: script += push_script(hash_160.encode('hex'))
script = '76a9' # op_dup, op_hash_160 script += '88ac' # op_equalverify, op_checksig
script += push_script(hash_160.encode('hex')) elif addrtype == 5:
script += '88ac' # op_equalverify, op_checksig script = 'a9' # op_hash_160
elif addrtype == 5: script += push_script(hash_160.encode('hex'))
script = 'a9' # op_hash_160 script += '87' # op_equal
script += push_script(hash_160.encode('hex')) else:
script += '87' # op_equal raise
else: else:
raise raise
return script return script
@ -756,10 +756,8 @@ class Transaction:
addr = x addr = x
elif type == 'pubkey': elif type == 'pubkey':
addr = public_key_to_bc_address(x.decode('hex')) addr = public_key_to_bc_address(x.decode('hex'))
elif type == 'op_return':
addr = 'OP_RETURN ' + x.encode('hex')
else: else:
addr = "(None)" addr = 'SCRIPT ' + x.encode('hex')
o.append((addr,v)) # consider using yield (addr, v) o.append((addr,v)) # consider using yield (addr, v)
return o return o

Loading…
Cancel
Save