MMGenTX: new 'send_amt' property, replacing update_send_amt()
This commit is contained in:
parent
00f978ef7c
commit
7181c33ddc
4 changed files with 19 additions and 19 deletions
|
|
@ -186,10 +186,6 @@ class EthereumMMGenTX:
|
|||
if self.outputs and self.outputs[0].is_chg:
|
||||
self.update_output_amt(0,ETHAmt(funds_left))
|
||||
|
||||
def update_send_amt(self):
|
||||
if self.outputs:
|
||||
self.send_amt = self.outputs[0].amt
|
||||
|
||||
async def get_cmdline_input_addrs(self):
|
||||
ret = []
|
||||
if opt.inputs:
|
||||
|
|
@ -229,6 +225,10 @@ class EthereumMMGenTX:
|
|||
""")
|
||||
fmt_keys = ('from','to','amt','nonce')
|
||||
|
||||
@property
|
||||
def send_amt(self):
|
||||
return self.outputs[0].amt if self.outputs else self.proto.coin_amt('0')
|
||||
|
||||
@property
|
||||
def fee(self):
|
||||
return self.fee_gasPrice2abs(self.txobj['gasPrice'].toWei())
|
||||
|
|
|
|||
|
|
@ -152,7 +152,6 @@ async def main():
|
|||
tx.usr_fee = tx.get_usr_fee_interactive(tx_fee=opt.tx_fee,desc='User-selected')
|
||||
|
||||
tx.bump_fee(output_idx,tx.usr_fee)
|
||||
tx.update_send_amt()
|
||||
|
||||
assert tx.fee <= tx.proto.max_tx_fee
|
||||
|
||||
|
|
|
|||
25
mmgen/tx.py
25
mmgen/tx.py
|
|
@ -371,6 +371,13 @@ class MMGenTX:
|
|||
return self.proto.coin_amt('0')
|
||||
return self.proto.coin_amt(sum(e.amt for e in olist))
|
||||
|
||||
def get_chg_output_idx(self):
|
||||
ch_ops = [x.is_chg for x in self.outputs]
|
||||
try:
|
||||
return ch_ops.index(True)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
def has_segwit_inputs(self):
|
||||
return any(i.mmid and i.mmid.mmtype in ('S','B') for i in self.inputs)
|
||||
|
||||
|
|
@ -520,13 +527,6 @@ class MMGenTX:
|
|||
self.proto = proto
|
||||
self.tw = tw
|
||||
|
||||
def get_chg_output_idx(self):
|
||||
ch_ops = [x.is_chg for x in self.outputs]
|
||||
try:
|
||||
return ch_ops.index(True)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
def del_output(self,idx):
|
||||
self.outputs.pop(idx)
|
||||
|
||||
|
|
@ -835,11 +835,6 @@ class MMGenTX:
|
|||
else:
|
||||
self.update_output_amt(chg_idx,self.proto.coin_amt(funds_left))
|
||||
|
||||
def update_send_amt(self):
|
||||
self.send_amt = self.sum_outputs(exclude =
|
||||
None if len(self.outputs) == 1 else self.get_chg_output_idx()
|
||||
)
|
||||
|
||||
def check_fee(self):
|
||||
fee = self.sum_inputs() - self.sum_outputs()
|
||||
if fee > self.proto.max_tx_fee:
|
||||
|
|
@ -1079,6 +1074,12 @@ class MMGenTX:
|
|||
+ ''.join(format_io('inputs'))
|
||||
+ ''.join(format_io('outputs')) )
|
||||
|
||||
@property
|
||||
def send_amt(self):
|
||||
return self.sum_outputs(
|
||||
exclude = None if len(self.outputs) == 1 else self.get_chg_output_idx()
|
||||
)
|
||||
|
||||
@property
|
||||
def fee(self):
|
||||
return self.sum_inputs() - self.sum_outputs()
|
||||
|
|
|
|||
|
|
@ -114,8 +114,6 @@ class MMGenTxFile:
|
|||
|
||||
desc = 'TxID in metadata'
|
||||
tx.txid = MMGenTxID(txid)
|
||||
desc = 'send amount in metadata'
|
||||
tx.send_amt = tx.proto.coin_amt(send_amt)
|
||||
desc = 'block count in metadata'
|
||||
tx.blockcount = int(blockcount)
|
||||
|
||||
|
|
@ -130,6 +128,8 @@ class MMGenTxFile:
|
|||
tx.inputs = eval_io_data(inputs_data,'inputs')
|
||||
desc = 'outputs data'
|
||||
tx.outputs = eval_io_data(outputs_data,'outputs')
|
||||
desc = 'send amount in metadata'
|
||||
assert Decimal(send_amt) == tx.send_amt, f'{send_amt} != {tx.send_amt}'
|
||||
except Exception as e:
|
||||
die(2,f'Invalid {desc} in transaction file: {e!s}')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue