Browse Source

tx.new: add `is_swap` attribute

The MMGen Project 3 weeks ago
parent
commit
0f7e51e499
6 changed files with 12 additions and 5 deletions
  1. 3 2
      mmgen/proto/btc/tx/new.py
  2. 1 0
      mmgen/tx/base.py
  3. 1 0
      mmgen/tx/file.py
  4. 3 0
      mmgen/tx/info.py
  5. 3 3
      mmgen/tx/new.py
  6. 1 0
      mmgen/tx/new_swap.py

+ 3 - 2
mmgen/proto/btc/tx/new.py

@@ -135,7 +135,7 @@ class New(Base, TxNew):
 
 	async def create_serialized(self, locktime=None, bump=None):
 
-		if not bump:
+		if not (bump or self.is_swap):
 			self.inputs.sort_bip69()
 			# Set all sequence numbers to the same value, in conformity with the behavior of most modern wallets:
 			do_rbf = self.proto.cap('rbf') and not self.cfg.no_rbf
@@ -143,7 +143,8 @@ class New(Base, TxNew):
 			for i in self.inputs:
 				i.sequence = seqnum_val
 
-		self.outputs.sort_bip69()
+		if not self.is_swap:
+			self.outputs.sort_bip69()
 
 		inputs_list = [{
 				'txid':     e.txid,

+ 1 - 0
mmgen/tx/base.py

@@ -79,6 +79,7 @@ class Base(MMGenObject):
 	locktime     = None
 	chain        = None
 	signed       = False
+	is_swap      = False
 	file_format  = 'json'
 	non_mmgen_inputs_msg = f"""
 		This transaction includes inputs with non-{gc.proj_name} addresses.  When

+ 1 - 0
mmgen/tx/file.py

@@ -71,6 +71,7 @@ class MMGenTxFile(MMGenObject):
 		'comment': MMGenTxComment,
 		'coin_txid': CoinTxID,
 		'sent_timestamp': None,
+		'is_swap': False,
 	}
 
 	def __init__(self, tx):

+ 3 - 0
mmgen/tx/info.py

@@ -29,6 +29,9 @@ class TxInfo:
 
 		tx = self.tx
 
+		if tx.is_swap:
+			sort = 'raw'
+
 		if tx.proto.base_proto == 'Ethereum':
 			blockcount = None
 		else:

+ 3 - 3
mmgen/tx/new.py

@@ -83,7 +83,7 @@ class New(Base):
 	_funds_available = namedtuple('funds_available', ['is_positive', 'amt'])
 
 	def __init__(self, *args, target=None, **kwargs):
-		self.target = target
+		self.is_swap = target == 'swaptx'
 		super().__init__(*args, **kwargs)
 
 	def warn_insufficient_funds(self, amt, coin):
@@ -266,7 +266,7 @@ class New(Base):
 			edesc = 'argument',
 		)
 		cmd_args = tuple(a for a in cmd_args if a not in addrfile_args)
-		if self.target == 'tx':
+		if not self.is_swap:
 			cmd_args = remove_dups(cmd_args, desc='command line', edesc='argument')
 		return cmd_args, addrfile_args
 
@@ -415,7 +415,7 @@ class New(Base):
 
 		if not do_info:
 			cmd_args, addrfile_args = self.get_addrfiles_from_cmdline(cmd_args)
-			if self.target == 'swaptx':
+			if self.is_swap:
 				# updates self.proto!
 				self.proto, cmd_args = await self.process_swap_cmdline_args(cmd_args, addrfile_args)
 			from ..rpc import rpc_init

+ 1 - 0
mmgen/tx/new_swap.py

@@ -16,6 +16,7 @@ from .new import New
 
 class NewSwap(New):
 	desc = 'swap transaction'
+	is_swap = True
 
 	async def process_swap_cmdline_args(self, cmd_args):
 		raise NotImplementedError(f'Swap not implemented for protocol {self.proto.__name__}')