1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +00:00

core/sign_tx: In write_tx_header() rename has_segwit parameter to witness_marker and clarify usage.

This commit is contained in:
Andrew Kozlik 2020-05-05 16:06:48 +02:00 committed by Andrew Kozlik
parent 846116a666
commit 3de565c33c
4 changed files with 24 additions and 13 deletions

View File

@ -291,7 +291,7 @@ class Bitcoin:
# should come out the same as h_confirmed, checked before signing the digest
h_check = self.create_hash_writer()
self.write_tx_header(h_sign, self.tx, has_segwit=False)
self.write_tx_header(h_sign, self.tx, witness_marker=False)
writers.write_varint(h_sign, self.tx.inputs_count)
for i in range(self.tx.inputs_count):
@ -374,8 +374,8 @@ class Bitcoin:
txh = self.create_hash_writer()
# TODO set has_segwit correctly
self.write_tx_header(txh, tx, has_segwit=False)
# witnesses are not included in txid hash
self.write_tx_header(txh, tx, witness_marker=False)
writers.write_varint(txh, tx.inputs_cnt)
for i in range(tx.inputs_cnt):
@ -431,10 +431,13 @@ class Bitcoin:
writers.write_tx_output(w, txo, script_pubkey)
def write_tx_header(
self, w: writers.Writer, tx: Union[SignTx, TransactionType], has_segwit: bool
self,
w: writers.Writer,
tx: Union[SignTx, TransactionType],
witness_marker: bool,
) -> None:
writers.write_uint32(w, tx.version) # nVersion
if has_segwit:
if witness_marker:
writers.write_varint(w, 0x00) # segwit witness marker
writers.write_varint(w, 0x01) # segwit witness flag

View File

@ -65,12 +65,15 @@ class Bitcoinlike(Bitcoin):
return hashtype
def write_tx_header(
self, w: writers.Writer, tx: Union[SignTx, TransactionType], has_segwit: bool
self,
w: writers.Writer,
tx: Union[SignTx, TransactionType],
witness_marker: bool,
) -> None:
writers.write_uint32(w, tx.version) # nVersion
if self.coin.timestamp:
writers.write_uint32(w, tx.timestamp)
if has_segwit:
if witness_marker:
writers.write_varint(w, 0x00) # segwit witness marker
writers.write_varint(w, 0x01) # segwit witness flag

View File

@ -32,7 +32,7 @@ class Decred(Bitcoin):
ensure(coin.decred)
super().__init__(tx, keychain, coin)
self.write_tx_header(self.serialized_tx, self.tx, has_segwit=False)
self.write_tx_header(self.serialized_tx, self.tx, witness_marker=True)
writers.write_varint(self.serialized_tx, self.tx.inputs_count)
def init_hash143(self) -> None:
@ -163,12 +163,17 @@ class Decred(Bitcoin):
writers.write_tx_output_decred(w, txo, script_pubkey)
def write_tx_header(
self, w: writers.Writer, tx: Union[SignTx, TransactionType], has_segwit: bool
self,
w: writers.Writer,
tx: Union[SignTx, TransactionType],
witness_marker: bool,
) -> None:
if isinstance(tx, TransactionType):
version = tx.version | DECRED_SERIALIZE_NO_WITNESS
else:
# The upper 16 bits of the transaction version specify the serialization
# format and the lower 16 bits specify the version number.
if witness_marker:
version = tx.version | DECRED_SERIALIZE_FULL
else:
version = tx.version | DECRED_SERIALIZE_NO_WITNESS
writers.write_uint32(w, version)

View File

@ -77,7 +77,7 @@ class Overwintered(Bitcoinlike):
await self.sign_nonsegwit_bip143_input(i_sign)
def write_tx_header(
self, w: Writer, tx: Union[SignTx, TransactionType], has_segwit: bool
self, w: Writer, tx: Union[SignTx, TransactionType], witness_marker: bool
) -> None:
# nVersion | fOverwintered
write_uint32(w, tx.version | OVERWINTERED)