1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

core: move decred writers to decred.py

This commit is contained in:
Tomas Susanka 2020-05-17 13:47:17 +00:00
parent 3084ee1eed
commit aa115b6320
2 changed files with 18 additions and 29 deletions

View File

@ -123,9 +123,7 @@ class Decred(Bitcoin):
# serialize input with correct signature # serialize input with correct signature
gc.collect() gc.collect()
script_sig = self.input_derive_script(txi_sign, key_sign_pub, signature) script_sig = self.input_derive_script(txi_sign, key_sign_pub, signature)
writers.write_tx_input_decred_witness( self.write_tx_input_witness(self.serialized_tx, txi_sign, script_sig)
self.serialized_tx, txi_sign, script_sig
)
self.set_serialized_signature(i_sign, signature) self.set_serialized_signature(i_sign, signature)
async def step5_serialize_outputs(self) -> None: async def step5_serialize_outputs(self) -> None:
@ -142,15 +140,18 @@ class Decred(Bitcoin):
raise wire.ProcessError("Cannot use utxo that has script_version != 0") raise wire.ProcessError("Cannot use utxo that has script_version != 0")
def hash143_add_input(self, txi: TxInputType) -> None: def hash143_add_input(self, txi: TxInputType) -> None:
writers.write_tx_input_decred(self.h_prefix, txi) self.write_tx_input(self.h_prefix, txi, bytes())
def hash143_add_output(self, txo: TxOutputType, script_pubkey: bytes) -> None: def hash143_add_output(self, txo: TxOutputType, script_pubkey: bytes) -> None:
writers.write_tx_output_decred(self.h_prefix, txo, script_pubkey) self.write_tx_output(self.h_prefix, txo, script_pubkey)
def write_tx_input( def write_tx_input(
self, w: writers.Writer, txi: TxInputType, script: bytes self, w: writers.Writer, txi: TxInputType, script: bytes
) -> None: ) -> None:
writers.write_tx_input_decred(w, txi) writers.write_bytes_reversed(w, txi.prev_hash, writers.TX_HASH_SIZE)
writers.write_uint32(w, txi.prev_index or 0)
writers.write_uint8(w, txi.decred_tree or 0)
writers.write_uint32(w, txi.sequence)
def write_tx_output( def write_tx_output(
self, self,
@ -158,7 +159,9 @@ class Decred(Bitcoin):
txo: Union[TxOutputType, TxOutputBinType], txo: Union[TxOutputType, TxOutputBinType],
script_pubkey: bytes, script_pubkey: bytes,
) -> None: ) -> None:
writers.write_tx_output_decred(w, txo, script_pubkey) writers.write_uint64(w, txo.amount)
writers.write_uint16(w, txo.decred_script_version)
writers.write_bytes_prefixed(w, script_pubkey)
def write_tx_header( def write_tx_header(
self, self,
@ -180,3 +183,11 @@ class Decred(Bitcoin):
) -> None: ) -> None:
writers.write_uint32(w, tx.lock_time) writers.write_uint32(w, tx.lock_time)
writers.write_uint32(w, tx.expiry) writers.write_uint32(w, tx.expiry)
def write_tx_input_witness(
self, w: writers.Writer, i: TxInputType, script_sig: bytes
) -> None:
writers.write_uint64(w, i.amount or 0)
writers.write_uint32(w, 0) # block height fraud proof
writers.write_uint32(w, 0xFFFFFFFF) # block index fraud proof
writers.write_bytes_prefixed(w, script_sig)

View File

@ -53,20 +53,6 @@ def write_tx_input_check(w: Writer, i: TxInputType) -> None:
write_uint64(w, i.amount or 0) write_uint64(w, i.amount or 0)
def write_tx_input_decred(w: Writer, i: TxInputType) -> None:
write_bytes_reversed(w, i.prev_hash, TX_HASH_SIZE)
write_uint32(w, i.prev_index or 0)
write_uint8(w, i.decred_tree or 0)
write_uint32(w, i.sequence)
def write_tx_input_decred_witness(w: Writer, i: TxInputType, script_sig: bytes) -> None:
write_uint64(w, i.amount or 0)
write_uint32(w, 0) # block height fraud proof
write_uint32(w, 0xFFFFFFFF) # block index fraud proof
write_bytes_prefixed(w, script_sig)
def write_tx_output( def write_tx_output(
w: Writer, o: Union[TxOutputType, TxOutputBinType], script_pubkey: bytes w: Writer, o: Union[TxOutputType, TxOutputBinType], script_pubkey: bytes
) -> None: ) -> None:
@ -74,14 +60,6 @@ def write_tx_output(
write_bytes_prefixed(w, script_pubkey) write_bytes_prefixed(w, script_pubkey)
def write_tx_output_decred(
w: Writer, o: Union[TxOutputType, TxOutputBinType], script_pubkey: bytes
) -> None:
write_uint64(w, o.amount)
write_uint16(w, o.decred_script_version)
write_bytes_prefixed(w, script_pubkey)
def write_op_push(w: Writer, n: int) -> None: def write_op_push(w: Writer, n: int) -> None:
ensure(n >= 0 and n <= 0xFFFFFFFF) ensure(n >= 0 and n <= 0xFFFFFFFF)
if n < 0x4C: if n < 0x4C: