Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Fix wait_for_commitments reference bug
Browse files Browse the repository at this point in the history
Fix bug when nick's crypto box is not set
Read utxos for commitments directly from wallet in add-utxo.py, not store private keys in a file.
  • Loading branch information
AdamISZ committed Aug 16, 2016
1 parent 077d3ed commit 82f09da
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 31 deletions.
54 changes: 50 additions & 4 deletions cmttools/add-utxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from optparse import OptionParser
import bitcoin as btc
from joinmarket import load_program_config, jm_single, get_p2pk_vbyte
from joinmarket import Wallet
from commitment_utils import get_utxo_info, validate_utxo_data, quit

def add_external_commitments(utxo_datas):
Expand Down Expand Up @@ -64,8 +65,9 @@ def main():

"'Utxo' means unspent transaction output, it must not "
"already be spent. "

"If you enter a utxo without the -r option, you will be "
"The options -w, -r and -R offer ways to load these utxos "
"from a file or wallet. "
"If you enter a single utxo without these options, you will be "
"prompted to enter the private key here - it must be in "
"WIF compressed format. "

Expand All @@ -92,6 +94,32 @@ def main():
help='name of json formatted file containing utxos with private keys, as '
'output from "python wallet-tool.py -u -p walletname showutxos"'
)
parser.add_option(
'-w',
'--load-wallet',
action='store',
type='str',
dest='loadwallet',
help='name of wallet from which to load utxos and use as commitments.'
)
parser.add_option(
'-g',
'--gap-limit',
action='store',
type='int',
dest='gaplimit',
default = 6,
help='Only to be used with -w; gap limit for Joinmarket wallet, default 6.'
)
parser.add_option(
'-M',
'--max-mixdepth',
action='store',
type='int',
dest='maxmixdepth',
default=5,
help='Only to be used with -w; number of mixdepths for wallet, default 5.'
)
parser.add_option(
'-d',
'--delete-external',
Expand Down Expand Up @@ -120,7 +148,7 @@ def main():
load_program_config()
utxo_data = []
if options.delete_ext:
other = options.in_file or options.in_json
other = options.in_file or options.in_json or options.loadwallet
if len(args) > 0 or other:
if raw_input("You have chosen to delete commitments, other arguments "
"will be ignored; continue? (y/n)") != 'y':
Expand All @@ -136,7 +164,25 @@ def main():
print "Commitments deleted."
sys.exit(0)

if options.in_file:
#Three options (-w, -r, -R) for loading utxo and privkey pairs from a wallet,
#csv file or json file.
if options.loadwallet:
os.chdir('..') #yuck (see earlier comment about package)
wallet = Wallet(options.loadwallet,
options.maxmixdepth,
options.gaplimit)
os.chdir(os.path.join(os.getcwd(), 'cmttools'))
jm_single().bc_interface.sync_wallet(wallet)
unsp = {}
for u, av in wallet.unspent.iteritems():
addr = av['address']
key = wallet.get_key_from_addr(addr)
wifkey = btc.wif_compressed_privkey(key, vbyte=get_p2pk_vbyte())
unsp[u] = {'address': av['address'],
'value': av['value'], 'privkey': wifkey}
for u, pva in unsp.iteritems():
utxo_data.append((u, pva['privkey']))
elif options.in_file:
with open(options.in_file, "rb") as f:
utxo_info = f.readlines()
for ul in utxo_info:
Expand Down
2 changes: 2 additions & 0 deletions joinmarket/maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def get_crypto_box_from_nick(self, nick):
'wrong ordering of protocol events, no crypto object, nick=' +
nick)
return None
elif not self.active_orders[nick]:
return None
else:
return self.active_orders[nick].crypto_box

Expand Down
5 changes: 2 additions & 3 deletions joinmarket/taker.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def get_commitment(self, utxos, amount):
while True:
self.commitment, self.reveal_commitment = self.commitment_creator(
self.wallet, utxos, amount)
if (self.commitment) or (jm_single().config.getint(
"POLICY", "wait_for_commitments") == 0):
if (self.commitment) or (jm_single().wait_for_commitments == 0):
break
log.debug("Failed to source commitments, waiting 3 minutes")
time.sleep(3 * 60)
Expand Down Expand Up @@ -603,7 +602,7 @@ def __init__(self, msgchan):
# that some other guy doesnt send you confusing stuff

def get_crypto_box_from_nick(self, nick):
if nick in self.cjtx.crypto_boxes:
if nick in self.cjtx.crypto_boxes and self.cjtx.crypto_boxes[nick] != None:
return self.cjtx.crypto_boxes[nick][
1] # libsodium encryption object
else:
Expand Down
2 changes: 1 addition & 1 deletion tumbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def main():
wallet = Wallet(wallet_file,
max_mix_depth=options['mixdepthsrc'] + options['mixdepthcount'])
jm_single().bc_interface.sync_wallet(wallet)
jm_single().config.set("POLICY", "wait_for_commitments", "1")
jm_single().wait_for_commitments = 1
log.debug('starting tumbler')
mcs = [IRCMessageChannel(c) for c in get_irc_mchannels()]
mcc = MessageChannelCollection(mcs)
Expand Down
24 changes: 1 addition & 23 deletions wallet-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@
dest='mixdepth',
help='mixing depth to import private key into',
default=0)
parser.add_option('-u',
'--utxo-file-output',
action='store_true',
dest='utxos2file',
default=False,
help='when using showutxos method, write json data to file'
)
parser.add_option('--csv',
action='store_true',
dest='csv',
Expand Down Expand Up @@ -124,22 +117,7 @@
'value': av['value'], 'privkey': wifkey}
else:
unsp = wallet.unspent
outdata = json.dumps(unsp, indent=4)
if options.utxos2file:
utxofilename = seed + '.utxos' #will be .json.utxos for "real"/file wallet
utxolocation = os.path.join('wallets', utxofilename)
if os.path.isfile(utxolocation):
if raw_input('File: ' + utxolocation + \
' already exists; overwrite? (y/n): ') != 'y':
print('Quitting')
sys.exit(0)
with open(utxolocation, 'wb') as f:
f.write(outdata)
print(outdata)
if options.utxos2file:
print("The above data was written to: " + utxolocation)
if options.showprivkey:
print("Remember, this file contains private keys!")
print(json.dumps(unsp, indent=4))
sys.exit(0)

if method == 'display' or method == 'displayall' or method == 'summary':
Expand Down

0 comments on commit 82f09da

Please sign in to comment.