Browse Source

default filter orders for CLI sendpayment, add answeryes option

master
Adam Gibson 10 years ago
parent
commit
e6b6a1aa7f
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 32
      jmclient/taker.py
  2. 26
      scripts/sendpayment.py

32
jmclient/taker.py

@ -27,6 +27,7 @@ class Taker(object):
def __init__(self,
wallet,
schedule,
answeryes,
order_chooser=weighted_order_choose,
sign_method=None,
callbacks=None):
@ -41,6 +42,7 @@ class Taker(object):
"""
self.wallet = wallet
self.schedule = schedule
self.answeryes = answeryes
self.order_chooser = order_chooser
self.ignored_makers = None
self.schedule_index = -1
@ -51,21 +53,39 @@ class Taker(object):
#sending info messages to client, and action on completion.
if callbacks:
self.filter_orders_callback = callbacks[0]
if not self.filter_orders_callback:
self.filter_orders_callback = self.default_filter_orders_callback
self.taker_info_callback = callbacks[1]
self.on_finished_callback = callbacks[2]
if not self.taker_info_callback:
self.taker_info_callback = self.default_taker_info_callback
self.on_finished_callback = callbacks[2]
if not self.on_finished_callback:
self.on_finished_callback = self.default_on_finished_callback
else:
#default settings; currently not possible, see default_on_finished
self.filter_orders_callback = None
self.taker_info_callback = self.default_taker_info_callback
self.on_finished_callback = self.default_on_finished_callback
def default_taker_info_callback(self, infotype, msg):
jlog.debug(infotype + ":" + msg)
def default_filter_orders_callback(self, orders_fees):
orders, total_cj_fee = orders_fees
jlog.info("Chose these orders: " +pprint.pformat(orders))
jlog.info('total cj fee = ' + str(total_cj_fee))
total_fee_pc = 1.0 * total_cj_fee / self.cjamount
jlog.info('total coinjoin fee = ' + str(float('%.3g' % (
100.0 * total_fee_pc))) + '%')
WARNING_THRESHOLD = 0.02 # 2%
if total_fee_pc > WARNING_THRESHOLD:
jlog.info('\n'.join(['=' * 60] * 3))
jlog.info('WARNING ' * 6)
jlog.info('\n'.join(['=' * 60] * 1))
jlog.info('OFFERED COINJOIN FEE IS UNUSUALLY HIGH. DOUBLE/TRIPLE CHECK.')
jlog.info('\n'.join(['=' * 60] * 1))
jlog.info('WARNING ' * 6)
jlog.info('\n'.join(['=' * 60] * 3))
if not self.answeryes:
if raw_input('send with these orders? (y/n):')[0] != 'y':
self.on_finished_callback(False)
return True
def default_on_finished_callback(self, result, fromtx=False):
"""Currently not possible without access to the client protocol factory"""
raise NotImplementedError

26
scripts/sendpayment.py

@ -58,20 +58,6 @@ from jmclient import (Taker, load_program_config,
from jmbase.support import get_log, debug_dump_object
log = get_log()
txcount = 1
wallet = None
def check_high_fee(total_fee_pc):
WARNING_THRESHOLD = 0.02 # 2%
if total_fee_pc > WARNING_THRESHOLD:
print('\n'.join(['=' * 60] * 3))
print('WARNING ' * 6)
print('\n'.join(['=' * 60] * 1))
print('OFFERED COINJOIN FEE IS UNUSUALLY HIGH. DOUBLE/TRIPLE CHECK.')
print('\n'.join(['=' * 60] * 1))
print('WARNING ' * 6)
print('\n'.join(['=' * 60] * 3))
def main():
parser = OptionParser(
@ -117,13 +103,6 @@ def main():
dest='daemonport',
help='port on which joinmarketd is running',
default='12345')
parser.add_option('-b',
'--txcount',
type='int',
dest='txcount',
help=('optionally do more than 1 transaction to the '
'same destination, of the same amount'),
default=1)
parser.add_option(
'-C',
'--choose-cheapest',
@ -229,7 +208,8 @@ def main():
else:
if not res:
log.info("Did not complete successfully, shutting down")
log.info("All transactions completed correctly")
else:
log.info("All transactions completed correctly")
reactor.stop()
#just a sample schedule; twice from same mixdepth
@ -240,12 +220,12 @@ def main():
jm_single().bc_interface.tick_forward_chain_interval = 10
taker = Taker(wallet,
schedule,
options.answeryes,
order_chooser=chooseOrdersFunc,
callbacks=(None, None, taker_finished))
clientfactory = JMTakerClientProtocolFactory(taker)
start_reactor("localhost", options.daemonport, clientfactory)
if __name__ == "__main__":
main()
print('done')

Loading…
Cancel
Save