Browse Source

TwView: improve sort keys for deterministic output

The MMGen Project 1 year ago
parent
commit
54d68ab33f
4 changed files with 14 additions and 5 deletions
  1. 1 0
      mmgen/proto/btc/tw/txhistory.py
  2. 8 0
      mmgen/proto/eth/tw/view.py
  3. 1 1
      mmgen/tw/txhistory.py
  4. 4 4
      mmgen/tw/view.py

+ 1 - 0
mmgen/proto/btc/tw/txhistory.py

@@ -120,6 +120,7 @@ class BitcoinTwTransaction:
 		# unconfirmed transactions, e.g. replaced transactions, and the 'blocktime' field is missing
 		# for these, so use 'time' as a fallback.
 		self.time = self.tx.get('blocktime') or self.tx['time']
+		self.time_received = self.tx.get('timereceived')
 
 	def blockheight_disp(self,color):
 		return (

+ 8 - 0
mmgen/proto/eth/tw/view.py

@@ -16,6 +16,14 @@ from ....tw.view import TwView
 
 class EthereumTwView(TwView):
 
+	sort_funcs = {
+		'addr':   lambda i: i.addr,
+		'age':    lambda i: 0 - i.confs,
+		'amt':    lambda i: i.amt,
+		'txid':   lambda i: f'{i.txid} {i.vout:04}',
+		'twmmid': lambda i: i.twmmid.sort_key
+	}
+
 	def age_disp(self,o,age_fmt): # TODO
 		pass
 

+ 1 - 1
mmgen/tw/txhistory.py

@@ -167,7 +167,7 @@ class TwTxHistory(TwView):
 	}
 
 	sort_funcs = {
-		'age':         lambda i: i.time,
+		'age':         lambda i: '{:010}.{:010}'.format(0xffffffff - abs(i.confirmations), i.time_received or 0),
 		'blockheight': lambda i: 0 - abs(i.confirmations), # old/altcoin daemons return no 'blockheight' field
 		'amt':         lambda i: i.wallet_outputs_total,
 		'total_amt':   lambda i: i.outputs_total,

+ 4 - 4
mmgen/tw/view.py

@@ -232,11 +232,11 @@ class TwView(MMGenObject,metaclass=AsyncInit):
 	}
 
 	sort_funcs = {
-		'addr':   lambda i: i.addr,
-		'age':    lambda i: 0 - i.confs,
-		'amt':    lambda i: i.amt,
+		'addr':   lambda i: '{} {:010} {:024.12f}'.format(i.addr, 0xffffffff - abs(i.confs), i.amt),
+		'age':    lambda i: '{:010} {:024.12f}'.format(0xffffffff - abs(i.confs), i.amt),
+		'amt':    lambda i: '{:024.12f} {:010} {}'.format(i.amt, 0xffffffff - abs(i.confs), i.addr),
 		'txid':   lambda i: f'{i.txid} {i.vout:04}',
-		'twmmid': lambda i: i.twmmid.sort_key
+		'twmmid': lambda i: '{} {:010} {:024.12f}'.format(i.twmmid.sort_key, 0xffffffff - abs(i.confs), i.amt)
 	}
 
 	def sort_info(self,include_group=True):