23
23
from chia_rs .sized_ints import uint32 , uint64
24
24
from typing_extensions import Self
25
25
26
- from chia ._tests .util .coin_store import add_coin_records_to_db
27
26
from chia .consensus .block_rewards import calculate_base_farmer_reward , calculate_pool_reward
28
27
from chia .consensus .coinbase import create_farmer_coin , create_pool_coin
29
28
from chia .consensus .default_constants import DEFAULT_CONSTANTS
@@ -243,22 +242,20 @@ async def farm_block(self, puzzle_hash: bytes32 = bytes32(b"0" * 32)) -> tuple[l
243
242
244
243
# Rewards get created
245
244
next_block_height : uint32 = uint32 (self .block_height + 1 ) if len (self .block_records ) > 0 else self .block_height
246
- pool_coin : Coin = create_pool_coin (
247
- next_block_height ,
248
- puzzle_hash ,
249
- calculate_pool_reward (next_block_height ),
250
- self .defaults .GENESIS_CHALLENGE ,
251
- )
252
- farmer_coin : Coin = create_farmer_coin (
253
- next_block_height ,
254
- puzzle_hash ,
255
- uint64 (calculate_base_farmer_reward (next_block_height ) + fees ),
256
- self .defaults .GENESIS_CHALLENGE ,
257
- )
258
- await add_coin_records_to_db (
259
- self .coin_store .db_wrapper , [self .new_coin_record (pool_coin , True ), self .new_coin_record (farmer_coin , True )]
260
- )
261
-
245
+ included_reward_coins = [
246
+ create_pool_coin (
247
+ next_block_height ,
248
+ puzzle_hash ,
249
+ calculate_pool_reward (next_block_height ),
250
+ self .defaults .GENESIS_CHALLENGE ,
251
+ ),
252
+ create_farmer_coin (
253
+ next_block_height ,
254
+ puzzle_hash ,
255
+ uint64 (calculate_base_farmer_reward (next_block_height ) + fees ),
256
+ self .defaults .GENESIS_CHALLENGE ,
257
+ ),
258
+ ]
262
259
# Coin store gets updated
263
260
generator_bundle : Optional [SpendBundle ] = None
264
261
return_additions : list [Coin ] = []
@@ -282,20 +279,16 @@ async def farm_block(self, puzzle_hash: bytes32 = bytes32(b"0" * 32)) -> tuple[l
282
279
return_additions = additions
283
280
return_removals = bundle .removals ()
284
281
spent_coins_ids = [r .name () for r in return_removals ]
285
- await add_coin_records_to_db (
286
- self .coin_store .db_wrapper , [self .new_coin_record (addition ) for addition in additions ]
287
- )
288
- await self .coin_store ._set_spent (spent_coins_ids , uint32 (self .block_height + 1 ))
289
-
282
+ await self .coin_store .new_block (
283
+ height = uint32 (self .block_height + 1 ),
284
+ timestamp = self .timestamp ,
285
+ included_reward_coins = included_reward_coins ,
286
+ tx_additions = return_additions ,
287
+ tx_removals = spent_coins_ids if spent_coins_ids is not None else [],
288
+ )
290
289
# SimBlockRecord is created
291
290
generator : Optional [BlockGenerator ] = await self .generate_transaction_generator (generator_bundle )
292
- self .block_records .append (
293
- SimBlockRecord .create (
294
- [pool_coin , farmer_coin ],
295
- next_block_height ,
296
- self .timestamp ,
297
- )
298
- )
291
+ self .block_records .append (SimBlockRecord .create (included_reward_coins , next_block_height , self .timestamp ))
299
292
self .blocks .append (SimFullBlock (generator , next_block_height ))
300
293
301
294
# block_height is incremented
0 commit comments