From 54d68ab33f152bfc25ac7223af187e54039410b6 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 8 Mar 2024 14:13:22 +0000 Subject: [PATCH] TwView: improve sort keys for deterministic output --- mmgen/proto/btc/tw/txhistory.py | 1 + mmgen/proto/eth/tw/view.py | 8 ++++++++ mmgen/tw/txhistory.py | 2 +- mmgen/tw/view.py | 8 ++++---- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mmgen/proto/btc/tw/txhistory.py b/mmgen/proto/btc/tw/txhistory.py index 1c0b5c03..6ecac25a 100755 --- a/mmgen/proto/btc/tw/txhistory.py +++ b/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 ( diff --git a/mmgen/proto/eth/tw/view.py b/mmgen/proto/eth/tw/view.py index 0a988ef0..7734e66d 100755 --- a/mmgen/proto/eth/tw/view.py +++ b/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 diff --git a/mmgen/tw/txhistory.py b/mmgen/tw/txhistory.py index bc49b0e7..d7d70a29 100755 --- a/mmgen/tw/txhistory.py +++ b/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, diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index bc3f9663..3af9eeed 100755 --- a/mmgen/tw/view.py +++ b/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):