Skip to content

Commit

Permalink
added support for sending to p2sh addresses by taker
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-belcher committed Sep 27, 2015
1 parent aa319fb commit f29707c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/blockchaininterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __init__(self, blockr_domain, txd, unconfirmfun, confirmfun):
self.confirmfun = confirmfun
self.tx_output_set = set([(sv['script'], sv['value']) for sv in txd['outs']])
self.output_addresses = [btc.script_to_address(scrval[0],
common.get_addr_vbyte()) for scrval in self.tx_output_set]
common.get_p2pk_vbyte()) for scrval in self.tx_output_set]
common.debug('txoutset=' + pprint.pformat(self.tx_output_set))
common.debug('outaddrs=' + ','.join(self.output_addresses))

Expand Down Expand Up @@ -526,7 +526,7 @@ def add_tx_notify(self, txd, unconfirmfun, confirmfun, notifyaddr):
self.notifythread.start()
one_addr_imported = False
for outs in txd['outs']:
addr = btc.script_to_address(outs['script'], common.get_addr_vbyte())
addr = btc.script_to_address(outs['script'], common.get_p2pk_vbyte())
if self.rpc('getaccount', [addr]) != '':
one_addr_imported = True
break
Expand Down
14 changes: 10 additions & 4 deletions lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ def get_network():
'''Returns network name'''
return config.get("BLOCKCHAIN","network")

def get_addr_vbyte():
def get_p2sh_vbyte():
if get_network() == 'testnet':
return 0xc4
else:
return 0x05

def get_p2pk_vbyte():
if get_network() == 'testnet':
return 0x6f
else:
Expand All @@ -159,7 +165,7 @@ def validate_address(addr):
ver = btc.get_version_byte(addr)
except AssertionError:
return False, 'Checksum wrong. Typo in address?'
if ver != get_addr_vbyte():
if ver != get_p2pk_vbyte() and ver != get_p2sh_vbyte():
return False, 'Wrong address version. Testnet/mainnet confused?'
return True, 'address validated'

Expand Down Expand Up @@ -358,7 +364,7 @@ def get_key(self, mixing_depth, forchange, i):
return btc.bip32_extract_key(btc.bip32_ckd(self.keys[mixing_depth][forchange], i))

def get_addr(self, mixing_depth, forchange, i):
return btc.privtoaddr(self.get_key(mixing_depth, forchange, i), get_addr_vbyte())
return btc.privtoaddr(self.get_key(mixing_depth, forchange, i), get_p2pk_vbyte())

def get_new_addr(self, mixing_depth, forchange):
index = self.index[mixing_depth]
Expand Down Expand Up @@ -395,7 +401,7 @@ def remove_old_utxos(self, tx):
def add_new_utxos(self, tx, txid):
added_utxos = {}
for index, outs in enumerate(tx['outs']):
addr = btc.script_to_address(outs['script'], get_addr_vbyte())
addr = btc.script_to_address(outs['script'], get_p2pk_vbyte())
if addr not in self.addr_cache:
continue
addrdict = {'address': addr, 'value': outs['value']}
Expand Down
6 changes: 3 additions & 3 deletions lib/maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def verify_unsigned_tx(self, txd):
if None in input_utxo_data:
return False, 'some utxos already spent or not confirmed yet'
input_addresses = [u['address'] for u in input_utxo_data]
if btc.pubtoaddr(self.i_utxo_pubkey, get_addr_vbyte())\
if btc.pubtoaddr(self.i_utxo_pubkey, get_p2pk_vbyte())\
not in input_addresses:
return False, "authenticating bitcoin address is not contained"
my_utxo_set = set(self.utxos.keys())
Expand All @@ -146,7 +146,7 @@ def verify_unsigned_tx(self, txd):
times_seen_cj_addr = 0
times_seen_change_addr = 0
for outs in txd['outs']:
addr = btc.script_to_address(outs['script'], get_addr_vbyte())
addr = btc.script_to_address(outs['script'], get_p2pk_vbyte())
if addr == self.cj_addr:
times_seen_cj_addr += 1
if outs['value'] != self.cj_amount:
Expand Down Expand Up @@ -314,7 +314,7 @@ def on_tx_unconfirmed(self, cjorder, txid, removed_utxos):
def on_tx_confirmed(self, cjorder, confirmations, txid):
to_announce = []
for i, out in enumerate(cjorder.tx['outs']):
addr = btc.script_to_address(out['script'], get_addr_vbyte())
addr = btc.script_to_address(out['script'], get_p2pk_vbyte())
if addr == cjorder.change_addr:
neworder = {'oid': self.get_next_oid(), 'ordertype': 'absorder', 'minsize': 12000,
'maxsize': out['value'], 'txfee': 10000, 'cjfee': 100000,
Expand Down
2 changes: 1 addition & 1 deletion lib/taker.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def recv_txio(self, nick, utxo_list, cj_pub, change_addr):
total_input - self.cj_amount - order['txfee'] + real_cjfee})
debug('fee breakdown for %s totalin=%d cjamount=%d txfee=%d realcjfee=%d' % (nick,
total_input, self.cj_amount, order['txfee'], real_cjfee))
cj_addr = btc.pubtoaddr(cj_pub, get_addr_vbyte())
cj_addr = btc.pubtoaddr(cj_pub, get_p2pk_vbyte())
self.outputs.append({'address': cj_addr, 'value': self.cj_amount})
self.cjfee_total += real_cjfee
self.nonrespondants.remove(nick)
Expand Down
4 changes: 2 additions & 2 deletions wallet-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
sys.path.insert(0, os.path.join(data_dir, 'lib'))

import bitcoin as btc
from common import Wallet, load_program_config, get_addr_vbyte
from common import Wallet, load_program_config, get_p2pk_vbyte
import common
import old_mnemonic, slowaes

Expand Down Expand Up @@ -70,7 +70,7 @@
balance_depth += balance
used = ('used' if k < wallet.index[m][forchange] else ' new')
privkey = btc.encode_privkey(wallet.get_key(m, forchange, k), 'wif_compressed',
get_addr_vbyte()) if options.showprivkey else ''
get_p2pk_vbyte()) if options.showprivkey else ''
if method == 'displayall' or balance > 0 or (used == ' new' and forchange==0):
print ' m/0/%d/%d/%03d %-35s%s %.8f btc %s' % (m, forchange, k, addr, used, balance/1e8, privkey)
print 'for mixdepth=%d balance=%.8fbtc' % (m, balance_depth/1e8)
Expand Down

0 comments on commit f29707c

Please sign in to comment.