From e1fb918588986baecbcd476f046cd743058dbf51 Mon Sep 17 00:00:00 2001 From: MMGen Date: Sat, 16 Dec 2017 09:17:55 +0300 Subject: [PATCH] mmgen-split: code cleanups --- mmgen/main_split.py | 6 +----- mmgen/protocol.py | 2 +- mmgen/tx.py | 38 ++++++++++++++------------------------ 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/mmgen/main_split.py b/mmgen/main_split.py index 1353e3aa..c3b6556a 100755 --- a/mmgen/main_split.py +++ b/mmgen/main_split.py @@ -99,8 +99,7 @@ from mmgen.tx import MMGenSplitTX from mmgen.protocol import CoinProtocol if opt.tx_fees: - g_coin_save = g.coin - for idx,g_coin in ((1,opt.other_coin),(0,g_coin_save)): + for idx,g_coin in ((1,opt.other_coin),(0,g.coin)): g.coin = g_coin g.proto = CoinProtocol(g.coin,g.testnet) opt.tx_fee = opt.tx_fees.split(',')[idx] @@ -120,9 +119,6 @@ tx1.create_fn() gmsg("\nCreating transaction for short chain ({})".format(opt.other_coin)) -if opt.rpc_host2: g.rpc_host = opt.rpc_host2 -if opt.tx_fees: opt.tx_fee = opt.tx_fees.split(',')[1] - from mmgen.protocol import CoinProtocol g.coin = opt.other_coin g.proto = CoinProtocol(g.coin,g.testnet) diff --git a/mmgen/protocol.py b/mmgen/protocol.py index e3b18880..56222675 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -186,7 +186,7 @@ class B2XProtocol(BitcoinProtocol): coin_amt = B2XAmt max_tx_fee = B2XAmt('0.1') forks = [ - (None,'','btc',True) + (None,'','btc',True) # activation: 494784 ] class B2XTestnetProtocol(B2XProtocol): diff --git a/mmgen/tx.py b/mmgen/tx.py index 3ae8079b..a3f87647 100755 --- a/mmgen/tx.py +++ b/mmgen/tx.py @@ -1229,33 +1229,11 @@ class MMGenBumpTX(MMGenTX): class MMGenSplitTX(MMGenTX): - def __init__(self): - super(type(self),self).__init__() - - def get_fee_from_user(self,have_estimate_fail=[],split_tx=False): - - if split_tx: - try: - rpc_init(reinit=True) - except: - ymsg('Connect to {} daemon failed. Network fee estimation unavailable'.format(g.coin)) - desc = 'User-selected' - try: - # TODO: check in opts.py - start_fee = opt.tx_fees.split(',')[split_tx] - except: - start_fee = None - return self.get_usr_fee_interactive(start_fee,desc=desc) - - return super(type(self),self).get_fee_from_user(have_estimate_fail=have_estimate_fail) - - def get_outputs_from_cmdline(self,mmid): + def get_outputs_from_cmdline(self,mmid): # TODO: check that addr is empty from mmgen.addr import AddrData ad_w = AddrData(source='tw') - # TODO: check that addr is empty - if is_mmgen_id(mmid): coin_addr = mmaddr2coinaddr(mmid,ad_w,None) if is_mmgen_id(mmid) else CoinAddr(mmid) self.add_output(coin_addr,g.proto.coin_amt('0'),is_chg=True) @@ -1268,13 +1246,25 @@ class MMGenSplitTX(MMGenTX): fs = '{} Segwit address requested on the command line, but Segwit is not active on this chain' rdie(2,fs.format(g.proj_name)) + def get_split_fee_from_user(self): + if opt.rpc_host2: + g.rpc_host = opt.rpc_host2 + if opt.tx_fees: + opt.tx_fee = opt.tx_fees.split(',')[1] + try: + rpc_init(reinit=True) + except: + ymsg('Connect to {} daemon failed. Network fee estimation unavailable'.format(g.coin)) + return self.get_usr_fee_interactive(opt.tx_fee,'User-selected') + return super(type(self),self).get_fee_from_user() + def create_split(self,mmid): self.outputs = self.MMGenTxOutputList() self.get_outputs_from_cmdline(mmid) while True: - change_amt = self.sum_inputs() - self.get_fee_from_user(split_tx=True) + change_amt = self.sum_inputs() - self.get_split_fee_from_user() if change_amt >= 0: p = 'Transaction produces {} {} in change'.format(change_amt.hl(),g.coin) if opt.yes or keypress_confirm(p+'. OK?',default_yes=True):