@@ -419,12 +419,17 @@ def __bytes__(self):
419
419
class TransactionV5 (object ):
420
420
def __init__ (self , rand , consensus_branch_id ):
421
421
# Decide which transaction parts will be generated.
422
- flip_coins = rand .u8 ()
422
+ flip_coins_result = rand .u8 ()
423
+
424
+ have_transparent_in = (flip_coins_result >> 0 ) % 2
425
+ is_coinbase = (not have_transparent_in ) and (flip_coins_result >> 4 ) % 2
423
426
424
427
self .init_header (consensus_branch_id , rand )
425
- self .init_transparent (rand , flip_coins )
426
- self .init_sapling (rand , flip_coins )
427
- self .init_orchard (rand , flip_coins )
428
+ self .init_transparent (rand , flip_coins_result , have_transparent_in , is_coinbase )
429
+ self .init_sapling (rand , flip_coins_result , is_coinbase )
430
+ self .init_orchard (rand , flip_coins_result , is_coinbase )
431
+
432
+ assert is_coinbase == self .is_coinbase ()
428
433
429
434
def init_header (self , consensus_branch_id , rand ):
430
435
# Common Transaction Fields
@@ -433,10 +438,8 @@ def init_header(self, consensus_branch_id, rand):
433
438
self .nLockTime = rand .u32 ()
434
439
self .nExpiryHeight = rand .u32 () % TX_EXPIRY_HEIGHT_THRESHOLD
435
440
436
- def init_transparent (self , rand , flip_coins ):
437
- have_transparent_in = (flip_coins >> 0 ) % 2
438
- have_transparent_out = (flip_coins >> 1 ) % 2
439
- is_coinbase = (not have_transparent_in ) and (flip_coins >> 4 ) % 2
441
+ def init_transparent (self , rand , flip_coins_result , have_transparent_in , is_coinbase ):
442
+ have_transparent_out = (flip_coins_result >> 1 ) % 2
440
443
441
444
# Transparent Transaction Fields
442
445
self .vin = []
@@ -453,10 +456,8 @@ def init_transparent(self, rand, flip_coins):
453
456
for _ in range ((rand .u8 () % 3 ) + 1 ):
454
457
self .vout .append (TxOut (rand ))
455
458
456
- def init_sapling (self , rand , flip_coins ):
457
- have_transparent_in = (flip_coins >> 0 ) % 2
458
- have_sapling = (flip_coins >> 2 ) % 2
459
- is_coinbase = (not have_transparent_in ) and (flip_coins >> 4 ) % 2
459
+ def init_sapling (self , rand , flip_coins_result , is_coinbase ):
460
+ have_sapling = (flip_coins_result >> 2 ) % 2
460
461
461
462
# Sapling Transaction Fields
462
463
self .vSpendsSapling = []
@@ -477,10 +478,8 @@ def init_sapling(self, rand, flip_coins):
477
478
# v^balanceSapling is defined to be 0.
478
479
self .valueBalanceSapling = 0
479
480
480
- def init_orchard (self , rand , flip_coins ):
481
- have_transparent_in = (flip_coins >> 0 ) % 2
482
- have_orchard = (flip_coins >> 3 ) % 2
483
- is_coinbase = (not have_transparent_in ) and (flip_coins >> 4 ) % 2
481
+ def init_orchard (self , rand , flip_coins_result , is_coinbase ):
482
+ have_orchard = (flip_coins_result >> 3 ) % 2
484
483
485
484
# Orchard Transaction Fields
486
485
self .vActionsOrchard = []
@@ -500,8 +499,6 @@ def init_orchard(self, rand, flip_coins):
500
499
# v^balanceOrchard is defined to be 0.
501
500
self .valueBalanceOrchard = 0
502
501
503
- assert is_coinbase == self .is_coinbase ()
504
-
505
502
def version_bytes (self ):
506
503
return NU5_TX_VERSION | (1 << 31 )
507
504
0 commit comments