@@ -469,16 +469,89 @@ async def respond_to_offer(self, file_path: Path) -> bool:
469469
470470 cs_aud = create_spend_for_auditor (auditor , auditor )
471471 coinsols .append (cs_aud )
472+ colour_spend = SpendBundle ([cs , cs_eph , cs_aud ], aggsig )
473+ wallet = wallets [colour ]
472474
473475 spend_bundle = SpendBundle (coinsols , aggsig )
474-
475- if chia_spend_bundle is not None :
476- spend_bundle = SpendBundle .aggregate ([spend_bundle , chia_spend_bundle ])
476+ my_tx_records = []
477477
478478 if zero_spend_list is not None :
479479 zero_spend_list .append (spend_bundle )
480480 spend_bundle = SpendBundle .aggregate (zero_spend_list )
481481
482+ # Add transaction history hor this trade
483+ if chia_spend_bundle is not None :
484+ spend_bundle = SpendBundle .aggregate ([spend_bundle , chia_spend_bundle ])
485+ if chia_discrepancy < 0 :
486+ tx_record = TransactionRecord (
487+ confirmed_at_index = uint32 (0 ),
488+ created_at_time = uint64 (int (time .time ())),
489+ to_puzzle_hash = token_bytes (),
490+ amount = uint64 (abs (chia_discrepancy )),
491+ fee_amount = uint64 (0 ),
492+ incoming = False ,
493+ confirmed = False ,
494+ sent = uint32 (10 ),
495+ spend_bundle = chia_spend_bundle ,
496+ additions = chia_spend_bundle .additions (),
497+ removals = chia_spend_bundle .removals (),
498+ wallet_id = uint32 (1 ),
499+ sent_to = [],
500+ )
501+ else :
502+ tx_record = TransactionRecord (
503+ confirmed_at_index = uint32 (0 ),
504+ created_at_time = uint64 (int (time .time ())),
505+ to_puzzle_hash = token_bytes (),
506+ amount = uint64 (abs (chia_discrepancy )),
507+ fee_amount = uint64 (0 ),
508+ incoming = True ,
509+ confirmed = False ,
510+ sent = uint32 (10 ),
511+ spend_bundle = chia_spend_bundle ,
512+ additions = chia_spend_bundle .additions (),
513+ removals = chia_spend_bundle .removals (),
514+ wallet_id = uint32 (1 ),
515+ sent_to = [],
516+ )
517+ my_tx_records .append (tx_record )
518+
519+ for colour , amount in cc_discrepancies .items ():
520+ wallet = wallets [colour ]
521+ if chia_discrepancy > 0 :
522+ tx_record = TransactionRecord (
523+ confirmed_at_index = uint32 (0 ),
524+ created_at_time = uint64 (int (time .time ())),
525+ to_puzzle_hash = token_bytes (),
526+ amount = uint64 (abs (amount )),
527+ fee_amount = uint64 (0 ),
528+ incoming = False ,
529+ confirmed = False ,
530+ sent = uint32 (10 ),
531+ spend_bundle = chia_spend_bundle ,
532+ additions = chia_spend_bundle .additions (),
533+ removals = chia_spend_bundle .removals (),
534+ wallet_id = wallet .wallet_info .id ,
535+ sent_to = [],
536+ )
537+ else :
538+ tx_record = TransactionRecord (
539+ confirmed_at_index = uint32 (0 ),
540+ created_at_time = uint64 (int (time .time ())),
541+ to_puzzle_hash = token_bytes (),
542+ amount = uint64 (abs (amount )),
543+ fee_amount = uint64 (0 ),
544+ incoming = True ,
545+ confirmed = False ,
546+ sent = uint32 (10 ),
547+ spend_bundle = chia_spend_bundle ,
548+ additions = chia_spend_bundle .additions (),
549+ removals = chia_spend_bundle .removals (),
550+ wallet_id = wallet .wallet_info .id ,
551+ sent_to = [],
552+ )
553+ my_tx_records .append (tx_record )
554+
482555 tx_record = TransactionRecord (
483556 confirmed_at_index = uint32 (0 ),
484557 created_at_time = uint64 (int (time .time ())),
@@ -491,10 +564,12 @@ async def respond_to_offer(self, file_path: Path) -> bool:
491564 spend_bundle = spend_bundle ,
492565 additions = spend_bundle .additions (),
493566 removals = spend_bundle .removals (),
494- wallet_id = uint32 (1 ),
567+ wallet_id = uint32 (0 ),
495568 sent_to = [],
496569 )
497570
498571 await self .wallet_state_manager .add_pending_transaction (tx_record )
572+ for tx in my_tx_records :
573+ await self .wallet_state_manager .add_transaction (tx )
499574
500575 return True
0 commit comments