mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-11 18:58:59 +03:00
Fix TX amount calculation in trade manager (#16934)
This commit is contained in:
parent
186ce3ab31
commit
68afc8c31c
@ -706,10 +706,22 @@ class TradeManager:
|
||||
removal_tree_hash = Program.to([coin_as_list(rem) for rem in grouped_removals]).get_tree_hash()
|
||||
# We also need to calculate the sent amount
|
||||
removed: int = sum(c.amount for c in grouped_removals)
|
||||
removed_ids: List[bytes32] = [c.name() for c in grouped_removals]
|
||||
all_additions_from_grouped_removals: List[Coin] = [
|
||||
c for c in all_additions if c.parent_coin_info in removed_ids
|
||||
]
|
||||
potential_change_coins: List[Coin] = addition_dict[wid] if wid in addition_dict else []
|
||||
change_coins: List[Coin] = [c for c in potential_change_coins if c.parent_coin_info in all_removals]
|
||||
change_amount: int = sum(c.amount for c in change_coins)
|
||||
sent_amount: int = removed - change_amount
|
||||
sent_amount: int = (
|
||||
removed
|
||||
- change_amount
|
||||
- (
|
||||
removed - sum(c.amount for c in all_additions_from_grouped_removals) # removals - additions == fees
|
||||
if wallet == self.wallet_state_manager.main_wallet
|
||||
else 0
|
||||
)
|
||||
)
|
||||
txs.append(
|
||||
TransactionRecord(
|
||||
confirmed_at_height=uint32(0),
|
||||
|
@ -660,10 +660,16 @@ async def test_cat_trades(
|
||||
Offer.from_bytes(trade_make.offer),
|
||||
peer,
|
||||
wallet_environments.tx_config,
|
||||
fee=uint64(1),
|
||||
)
|
||||
assert trade_take is not None
|
||||
assert tx_records is not None
|
||||
|
||||
# Testing a precious display bug real quick
|
||||
xch_tx: TransactionRecord = next(tx for tx in tx_records if tx.wallet_id == 1)
|
||||
assert xch_tx.amount == 3
|
||||
assert xch_tx.fee_amount == 1
|
||||
|
||||
await wallet_environments.process_pending_states(
|
||||
[
|
||||
WalletStateTransition(
|
||||
@ -696,9 +702,9 @@ async def test_cat_trades(
|
||||
WalletStateTransition(
|
||||
pre_block_balance_updates={
|
||||
"xch": {
|
||||
"unconfirmed_wallet_balance": -3,
|
||||
"<=#spendable_balance": -3,
|
||||
"<=#max_send_amount": -3,
|
||||
"unconfirmed_wallet_balance": -4, # -3 for offer, -1 for fee
|
||||
"<=#spendable_balance": -4,
|
||||
"<=#max_send_amount": -4,
|
||||
"pending_coin_removal_count": 1,
|
||||
},
|
||||
"cat": {
|
||||
@ -723,7 +729,7 @@ async def test_cat_trades(
|
||||
},
|
||||
post_block_balance_updates={
|
||||
"xch": {
|
||||
"confirmed_wallet_balance": -3,
|
||||
"confirmed_wallet_balance": -4,
|
||||
">#spendable_balance": 0,
|
||||
">#max_send_amount": 0,
|
||||
"pending_coin_removal_count": -1,
|
||||
|
Loading…
Reference in New Issue
Block a user