Skip to content

Commit 2cc6161

Browse files
committed
Fixed calculating transaction params.
1 parent 3cd2cbc commit 2cc6161

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

zcash_test_vectors/transaction.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,17 @@ def __bytes__(self):
419419
class TransactionV5(object):
420420
def __init__(self, rand, consensus_branch_id):
421421
# 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
423426

424427
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()
428433

429434
def init_header(self, consensus_branch_id, rand):
430435
# Common Transaction Fields
@@ -433,10 +438,8 @@ def init_header(self, consensus_branch_id, rand):
433438
self.nLockTime = rand.u32()
434439
self.nExpiryHeight = rand.u32() % TX_EXPIRY_HEIGHT_THRESHOLD
435440

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
440443

441444
# Transparent Transaction Fields
442445
self.vin = []
@@ -453,10 +456,8 @@ def init_transparent(self, rand, flip_coins):
453456
for _ in range((rand.u8() % 3) + 1):
454457
self.vout.append(TxOut(rand))
455458

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
460461

461462
# Sapling Transaction Fields
462463
self.vSpendsSapling = []
@@ -477,10 +478,8 @@ def init_sapling(self, rand, flip_coins):
477478
# v^balanceSapling is defined to be 0.
478479
self.valueBalanceSapling = 0
479480

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
484483

485484
# Orchard Transaction Fields
486485
self.vActionsOrchard = []
@@ -500,8 +499,6 @@ def init_orchard(self, rand, flip_coins):
500499
# v^balanceOrchard is defined to be 0.
501500
self.valueBalanceOrchard = 0
502501

503-
assert is_coinbase == self.is_coinbase()
504-
505502
def version_bytes(self):
506503
return NU5_TX_VERSION | (1 << 31)
507504

0 commit comments

Comments
 (0)