From 7b0b1cfcbbc8c7b2860302451e6e23c4e076b62e Mon Sep 17 00:00:00 2001 From: philemon Date: Mon, 27 Jun 2016 21:30:13 +0300 Subject: [PATCH] txcreate: cmdline tx fee adjustment factor. test.py: fix for txcreate on empty blockchains. --- mmgen/globalvars.py | 3 ++- mmgen/main_txcreate.py | 31 +++++++++++++++++-------------- test/test.py | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/mmgen/globalvars.py b/mmgen/globalvars.py index d41a90ab..5b23d560 100755 --- a/mmgen/globalvars.py +++ b/mmgen/globalvars.py @@ -38,6 +38,7 @@ disable_hold_protect = os.getenv('MMGEN_DISABLE_HOLD_PROTECT') from decimal import Decimal tx_fee = Decimal('0.0003') max_tx_fee = Decimal('0.01') +tx_fee_adj = Decimal('1.0') tx_confs = 3 seed_len = 256 @@ -88,7 +89,7 @@ default_wordlist = 'electrum' #default_wordlist = 'tirosh' # Global value sets user opt -dfl_vars = 'seed_len','hash_preset','usr_randchars','debug','tx_fee','tx_confs' +dfl_vars = 'seed_len','hash_preset','usr_randchars','debug','tx_fee','tx_confs','tx_fee_adj' seed_lens = 128,192,256 mn_lens = [i / 32 * 3 for i in seed_lens] diff --git a/mmgen/main_txcreate.py b/mmgen/main_txcreate.py index 99b84c3c..cb76255e 100755 --- a/mmgen/main_txcreate.py +++ b/mmgen/main_txcreate.py @@ -34,14 +34,14 @@ opts_data = { 'usage': '[opts] ... [change addr] [addr file] ...', 'options': """ -h, --help Print this help message +-a, --tx-fee-adj= f Adjust transaction fee by factor 'f' (see below) -c, --comment-file= f Source the transaction's comment from file 'f' --C, --tx-confs= c Estimated confirmations (default: {g.tx_confs}) +-C, --tx-confs= c Desired number of confirmations (default: {g.tx_confs}) -d, --outdir= d Specify an alternate directory 'd' for output -e, --echo-passphrase Print passphrase to screen when typing it -f, --tx-fee= f Transaction fee (default: {g.tx_fee} BTC (but see below)) -i, --info Display unspent outputs and exit --q, --quiet Suppress warnings; overwrite files without - prompting +-q, --quiet Suppress warnings; overwrite files without prompting -v, --verbose Produce more verbose output """.format(g=g), 'notes': """ @@ -49,19 +49,21 @@ opts_data = { Transaction inputs are chosen from a list of the user's unpent outputs via an interactive menu. -If not specified by the user, transaction fees are calculated using -bitcoind's "estimatefee" function for the default (or user-specified) -number of confirmations. Only if "estimatefee" fails is the default fee -of {g.tx_fee} BTC used. +If the transaction fee is not specified by the user, it will be calculated +using bitcoind's "estimatefee" function for the default (or user-specified) +number of confirmations. If "estimatefee" fails, the global default fee of +{g.tx_fee} BTC will be used. -Ages of transactions are approximate based on an average block creation +Dynamic fees will be multiplied by the value of '--tx-fee-adj', if specified. + +Ages of transactions are approximate based on an average block discovery interval of {g.mins_per_block} minutes. -Addresses on the command line can be Bitcoin addresses or {pnm} addresses -of the form :. +All addresses on the command line can be either Bitcoin addresses or {pnm} +addresses of the form :. -To send all inputs (minus TX fee) to a single output, specify one address -with no amount on the command line. +To send the value of all inputs (minus TX fee) to a single output, specify +one address with no amount on the command line. """.format(g=g,pnm=pnm) } @@ -348,7 +350,7 @@ Accept the global default fee of {f} BTC? def get_tx_size_and_fee(inputs,outputs): tx_size = len(inputs)*180 + len(outputs)*34 + 10 if fee_estimate: - ftype,fee = 'Calculated','{:.8f}'.format(fee_estimate * tx_size / 1024) + ftype,fee = 'Calculated','{:.8f}'.format(fee_estimate*opt.tx_fee_adj*tx_size / 1024) else: ftype,fee = 'User-selected',opt.tx_fee if not keypress_confirm('{} TX fee: {} BTC. OK?'.format(ftype,fee),default_yes=True): @@ -362,7 +364,8 @@ def get_tx_size_and_fee(inputs,outputs): break vmsg('Inputs:{} Outputs:{} TX size:{}'.format(len(sel_unspent),len(tx_out),tx_size)) vmsg('Fee estimate: {} (1024 bytes, {} confs)'.format(fee_estimate,opt.tx_confs)) - vmsg('TX fee: {}'.format(fee)) + m = ('',' (after %sx adjustment)' % opt.tx_fee_adj)[opt.tx_fee_adj != 1] + vmsg('TX fee: {}{}'.format(fee,m)) return tx_size,normalize_btc_amt(fee) # main(): execution begins here diff --git a/test/test.py b/test/test.py index 9c319568..03be5735 100755 --- a/test/test.py +++ b/test/test.py @@ -1116,7 +1116,7 @@ class MMGenTestSuite(object): m = '\nAnswer the interactive prompts as follows:\n' + \ " 'y', 'y', 'q', '1-8', ENTER, ENTER, ENTER, 'y'" msg(grnbg(m)) - t = MMGenExpect(name,'mmgen-txcreate',add_args + cmd_args) + t = MMGenExpect(name,'mmgen-txcreate',['-f','0.0001'] + add_args + cmd_args) if ni: return t.license() for num in tx_data: