@@ -93,13 +93,30 @@ def sort_key(t):
9393 except AttributeError :
9494 txid_hex = str (txid_obj )
9595 last_seen_dict [txid_hex ] = height
96+ first_seen_dict : Dict [str , int ] = {}
97+ for txid_obj , height in sorted (tx_graph .first_seen .items (), key = sort_key ):
98+ try :
99+ txid_hex = txid_obj .serialize ().hex ()
100+ except AttributeError :
101+ txid_hex = str (txid_obj )
102+ first_seen_dict [txid_hex ] = height
103+
104+ last_evicted_dict : Dict [str , int ] = {}
105+ for txid_obj , height in sorted (tx_graph .last_evicted .items (), key = sort_key ):
106+ try :
107+ txid_hex = txid_obj .serialize ().hex ()
108+ except AttributeError :
109+ txid_hex = str (txid_obj )
110+ last_evicted_dict [txid_hex ] = height
96111
97112 return {
98- "txs" : txs_list ,
99- "txouts" : txouts_dict ,
100- "anchors" : anchors_list ,
101- "last_seen" : last_seen_dict ,
102- }
113+ "txs" : txs_list ,
114+ "txouts" : txouts_dict ,
115+ "anchors" : anchors_list ,
116+ "last_seen" : last_seen_dict ,
117+ "first_seen" : first_seen_dict ,
118+ "last_evicted" : last_evicted_dict ,
119+ }
103120
104121 def _serialize_indexer (indexer : bdk .IndexerChangeSet ) -> Dict [str , Any ]:
105122 lr : Dict [str , int ] = {}
@@ -220,9 +237,29 @@ def _deserialize_tx_graph(data: Dict[str, Any]) -> bdk.TxGraphChangeSet:
220237 txid_obj = bdk .Txid (txid_hex )
221238 last_seen_dict [txid_obj ] = height
222239
240+ # Deserialize first_seen and last_evicted
241+ first_seen_data = data .get ("first_seen" , {})
242+ first_seen_dict : Dict [bdk .Txid , int ] = {}
243+ for txid_hex , timestamp in sorted (first_seen_data .items ()):
244+ try :
245+ txid_obj = bdk .Txid .from_bytes (binascii .unhexlify (txid_hex ))
246+ except Exception :
247+ txid_obj = bdk .Txid (txid_hex )
248+ first_seen_dict [txid_obj ] = timestamp
249+
250+ last_evicted_data = data .get ("last_evicted" , {})
251+ last_evicted_dict : Dict [bdk .Txid , int ] = {}
252+ for txid_hex , timestamp in sorted (last_evicted_data .items ()):
253+ try :
254+ txid_obj = bdk .Txid .from_bytes (binascii .unhexlify (txid_hex ))
255+ except Exception :
256+ txid_obj = bdk .Txid (txid_hex )
257+ last_evicted_dict [txid_obj ] = timestamp
258+
259+
223260 return bdk .TxGraphChangeSet (
224- txs = tx_objs , txouts = txouts_dict , anchors = anchors_list , last_seen = last_seen_dict
225- )
261+ txs = tx_objs , txouts = txouts_dict , anchors = anchors_list , last_seen = last_seen_dict , first_seen = first_seen_dict , last_evicted = last_evicted_dict
262+ )
226263
227264 def _deserialize_indexer (data : Dict [str , Any ]) -> bdk .IndexerChangeSet :
228265 lr_data = data .get ("last_revealed" , {})
0 commit comments