mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-14 17:31:04 +00:00
core/bitcoin: drop decred_script_version
This commit is contained in:
parent
ef9eb7b7a4
commit
9dfc08ca61
@ -213,7 +213,7 @@ message TxAck {
|
|||||||
optional MultisigRedeemScriptType multisig = 7; // Filled if input is going to spend multisig tx
|
optional MultisigRedeemScriptType multisig = 7; // Filled if input is going to spend multisig tx
|
||||||
optional uint64 amount = 8; // amount of previous transaction output (for segwit only)
|
optional uint64 amount = 8; // amount of previous transaction output (for segwit only)
|
||||||
optional uint32 decred_tree = 9; // only for Decred
|
optional uint32 decred_tree = 9; // only for Decred
|
||||||
optional uint32 decred_script_version = 10; // only for Decred
|
// optional uint32 decred_script_version = 10; // only for Decred // deprecated -> only 0 is supported
|
||||||
// optional bytes prev_block_hash_bip115 = 11; // BIP-115 support dropped
|
// optional bytes prev_block_hash_bip115 = 11; // BIP-115 support dropped
|
||||||
// optional uint32 prev_block_height_bip115 = 12; // BIP-115 support dropped
|
// optional uint32 prev_block_height_bip115 = 12; // BIP-115 support dropped
|
||||||
}
|
}
|
||||||
@ -235,7 +235,7 @@ message TxAck {
|
|||||||
required OutputScriptType script_type = 4; // output script type
|
required OutputScriptType script_type = 4; // output script type
|
||||||
optional MultisigRedeemScriptType multisig = 5; // defines multisig address; script_type must be PAYTOMULTISIG
|
optional MultisigRedeemScriptType multisig = 5; // defines multisig address; script_type must be PAYTOMULTISIG
|
||||||
optional bytes op_return_data = 6; // defines op_return data; script_type must be PAYTOOPRETURN, amount must be 0
|
optional bytes op_return_data = 6; // defines op_return data; script_type must be PAYTOOPRETURN, amount must be 0
|
||||||
optional uint32 decred_script_version = 7; // only for Decred
|
// optional uint32 decred_script_version = 7; // only for Decred // deprecated -> only 0 is supported
|
||||||
// optional bytes block_hash_bip115 = 8; // BIP-115 support dropped
|
// optional bytes block_hash_bip115 = 8; // BIP-115 support dropped
|
||||||
// optional uint32 block_height_bip115 = 9; // BIP-115 support dropped
|
// optional uint32 block_height_bip115 = 9; // BIP-115 support dropped
|
||||||
enum OutputScriptType {
|
enum OutputScriptType {
|
||||||
|
@ -22,6 +22,7 @@ from .bitcoin import Bitcoin
|
|||||||
DECRED_SERIALIZE_FULL = const(0 << 16)
|
DECRED_SERIALIZE_FULL = const(0 << 16)
|
||||||
DECRED_SERIALIZE_NO_WITNESS = const(1 << 16)
|
DECRED_SERIALIZE_NO_WITNESS = const(1 << 16)
|
||||||
DECRED_SERIALIZE_WITNESS_SIGNING = const(3 << 16)
|
DECRED_SERIALIZE_WITNESS_SIGNING = const(3 << 16)
|
||||||
|
DECRED_SCRIPT_VERSION = const(0)
|
||||||
|
|
||||||
DECRED_SIGHASH_ALL = const(1)
|
DECRED_SIGHASH_ALL = const(1)
|
||||||
|
|
||||||
@ -63,8 +64,6 @@ class Decred(Bitcoin):
|
|||||||
self.write_tx_input(self.serialized_tx, txi, bytes())
|
self.write_tx_input(self.serialized_tx, txi, bytes())
|
||||||
|
|
||||||
async def confirm_output(self, txo: TxOutputType, script_pubkey: bytes) -> None:
|
async def confirm_output(self, txo: TxOutputType, script_pubkey: bytes) -> None:
|
||||||
if txo.decred_script_version != 0:
|
|
||||||
raise wire.ActionCancelled("Cannot send to output with script version != 0")
|
|
||||||
await super().confirm_output(txo, script_pubkey)
|
await super().confirm_output(txo, script_pubkey)
|
||||||
self.write_tx_output(self.serialized_tx, txo, script_pubkey)
|
self.write_tx_output(self.serialized_tx, txo, script_pubkey)
|
||||||
|
|
||||||
@ -160,7 +159,10 @@ class Decred(Bitcoin):
|
|||||||
script_pubkey: bytes,
|
script_pubkey: bytes,
|
||||||
) -> None:
|
) -> None:
|
||||||
writers.write_uint64(w, txo.amount)
|
writers.write_uint64(w, txo.amount)
|
||||||
writers.write_uint16(w, txo.decred_script_version)
|
if isinstance(txo, TxOutputBinType):
|
||||||
|
writers.write_uint16(w, txo.decred_script_version)
|
||||||
|
else:
|
||||||
|
writers.write_uint16(w, DECRED_SCRIPT_VERSION)
|
||||||
writers.write_bytes_prefixed(w, script_pubkey)
|
writers.write_bytes_prefixed(w, script_pubkey)
|
||||||
|
|
||||||
def write_tx_header(
|
def write_tx_header(
|
||||||
|
@ -21,7 +21,7 @@ from apps.common.coininfo import CoinInfo
|
|||||||
from ..writers import TX_HASH_SIZE
|
from ..writers import TX_HASH_SIZE
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from typing import Any, Awaitable, Dict, Union
|
from typing import Any, Awaitable, Dict
|
||||||
from trezor.messages.TxInputType import EnumTypeInputScriptType
|
from trezor.messages.TxInputType import EnumTypeInputScriptType
|
||||||
from trezor.messages.TxOutputType import EnumTypeOutputScriptType
|
from trezor.messages.TxOutputType import EnumTypeOutputScriptType
|
||||||
|
|
||||||
@ -241,8 +241,6 @@ def sanitize_tx_input(tx: TransactionType, coin: CoinInfo) -> TxInputType:
|
|||||||
raise wire.DataError("Segwit not enabled on this coin")
|
raise wire.DataError("Segwit not enabled on this coin")
|
||||||
if txi.amount is None:
|
if txi.amount is None:
|
||||||
raise wire.DataError("Segwit input without amount")
|
raise wire.DataError("Segwit input without amount")
|
||||||
|
|
||||||
_sanitize_decred(txi, coin)
|
|
||||||
return txi
|
return txi
|
||||||
|
|
||||||
|
|
||||||
@ -267,26 +265,9 @@ def sanitize_tx_output(tx: TransactionType, coin: CoinInfo) -> TxOutputType:
|
|||||||
raise wire.DataError("Both address and address_n provided.")
|
raise wire.DataError("Both address and address_n provided.")
|
||||||
if not txo.address_n and not txo.address:
|
if not txo.address_n and not txo.address:
|
||||||
raise wire.DataError("Missing address")
|
raise wire.DataError("Missing address")
|
||||||
|
|
||||||
_sanitize_decred(txo, coin)
|
|
||||||
|
|
||||||
return txo
|
return txo
|
||||||
|
|
||||||
|
|
||||||
def sanitize_tx_binoutput(tx: TransactionType, coin: CoinInfo) -> TxOutputBinType:
|
def sanitize_tx_binoutput(tx: TransactionType, coin: CoinInfo) -> TxOutputBinType:
|
||||||
txo_bin = tx.bin_outputs[0]
|
txo_bin = tx.bin_outputs[0]
|
||||||
_sanitize_decred(txo_bin, coin)
|
|
||||||
return txo_bin
|
return txo_bin
|
||||||
|
|
||||||
|
|
||||||
def _sanitize_decred(
|
|
||||||
tx: Union[TxInputType, TxOutputType, TxOutputBinType], coin: CoinInfo
|
|
||||||
) -> None:
|
|
||||||
if coin.decred:
|
|
||||||
if tx.decred_script_version is None:
|
|
||||||
tx.decred_script_version = 0
|
|
||||||
else:
|
|
||||||
if tx.decred_script_version is not None:
|
|
||||||
raise wire.DataError(
|
|
||||||
"Decred details provided but Decred coin not specified."
|
|
||||||
)
|
|
||||||
|
@ -26,7 +26,6 @@ class TxInputType(p.MessageType):
|
|||||||
multisig: MultisigRedeemScriptType = None,
|
multisig: MultisigRedeemScriptType = None,
|
||||||
amount: int = None,
|
amount: int = None,
|
||||||
decred_tree: int = None,
|
decred_tree: int = None,
|
||||||
decred_script_version: int = None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self.address_n = address_n if address_n is not None else []
|
self.address_n = address_n if address_n is not None else []
|
||||||
self.prev_hash = prev_hash
|
self.prev_hash = prev_hash
|
||||||
@ -37,7 +36,6 @@ class TxInputType(p.MessageType):
|
|||||||
self.multisig = multisig
|
self.multisig = multisig
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
self.decred_tree = decred_tree
|
self.decred_tree = decred_tree
|
||||||
self.decred_script_version = decred_script_version
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fields(cls) -> Dict:
|
def get_fields(cls) -> Dict:
|
||||||
@ -51,5 +49,4 @@ class TxInputType(p.MessageType):
|
|||||||
7: ('multisig', MultisigRedeemScriptType, 0),
|
7: ('multisig', MultisigRedeemScriptType, 0),
|
||||||
8: ('amount', p.UVarintType, 0),
|
8: ('amount', p.UVarintType, 0),
|
||||||
9: ('decred_tree', p.UVarintType, 0),
|
9: ('decred_tree', p.UVarintType, 0),
|
||||||
10: ('decred_script_version', p.UVarintType, 0),
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ class TxOutputType(p.MessageType):
|
|||||||
script_type: EnumTypeOutputScriptType = None,
|
script_type: EnumTypeOutputScriptType = None,
|
||||||
multisig: MultisigRedeemScriptType = None,
|
multisig: MultisigRedeemScriptType = None,
|
||||||
op_return_data: bytes = None,
|
op_return_data: bytes = None,
|
||||||
decred_script_version: int = None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self.address = address
|
self.address = address
|
||||||
self.address_n = address_n if address_n is not None else []
|
self.address_n = address_n if address_n is not None else []
|
||||||
@ -31,7 +30,6 @@ class TxOutputType(p.MessageType):
|
|||||||
self.script_type = script_type
|
self.script_type = script_type
|
||||||
self.multisig = multisig
|
self.multisig = multisig
|
||||||
self.op_return_data = op_return_data
|
self.op_return_data = op_return_data
|
||||||
self.decred_script_version = decred_script_version
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fields(cls) -> Dict:
|
def get_fields(cls) -> Dict:
|
||||||
@ -42,5 +40,4 @@ class TxOutputType(p.MessageType):
|
|||||||
4: ('script_type', p.EnumType("OutputScriptType", (0, 1, 2, 3, 4, 5)), 0), # required
|
4: ('script_type', p.EnumType("OutputScriptType", (0, 1, 2, 3, 4, 5)), 0), # required
|
||||||
5: ('multisig', MultisigRedeemScriptType, 0),
|
5: ('multisig', MultisigRedeemScriptType, 0),
|
||||||
6: ('op_return_data', p.BytesType, 0),
|
6: ('op_return_data', p.BytesType, 0),
|
||||||
7: ('decred_script_version', p.UVarintType, 0),
|
|
||||||
}
|
}
|
||||||
|
@ -652,13 +652,6 @@ static bool signing_validate_input(const TxInputType *txinput) {
|
|||||||
signing_abort();
|
signing_abort();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!coin->decred && txinput->has_decred_script_version) {
|
|
||||||
fsm_sendFailure(
|
|
||||||
FailureType_Failure_DataError,
|
|
||||||
_("Decred details provided but Decred coin not specified."));
|
|
||||||
signing_abort();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !BITCOIN_ONLY
|
#if !BITCOIN_ONLY
|
||||||
if (coin->force_bip143 || coin->overwintered) {
|
if (coin->force_bip143 || coin->overwintered) {
|
||||||
@ -783,13 +776,6 @@ static bool signing_check_input(const TxInputType *txinput) {
|
|||||||
tx_sequence_hash(&hasher_sequence, txinput);
|
tx_sequence_hash(&hasher_sequence, txinput);
|
||||||
#if !BITCOIN_ONLY
|
#if !BITCOIN_ONLY
|
||||||
if (coin->decred) {
|
if (coin->decred) {
|
||||||
if (txinput->decred_script_version > 0) {
|
|
||||||
fsm_sendFailure(FailureType_Failure_DataError,
|
|
||||||
_("Decred v1+ scripts are not supported"));
|
|
||||||
signing_abort();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// serialize Decred prefix in Phase 1
|
// serialize Decred prefix in Phase 1
|
||||||
resp.has_serialized = true;
|
resp.has_serialized = true;
|
||||||
resp.serialized.has_serialized_tx = true;
|
resp.serialized.has_serialized_tx = true;
|
||||||
|
@ -61,6 +61,8 @@
|
|||||||
/* size of a Decred witness (without script): 8 amount, 4 block height, 4 block
|
/* size of a Decred witness (without script): 8 amount, 4 block height, 4 block
|
||||||
* index */
|
* index */
|
||||||
#define TXSIZE_DECRED_WITNESS 16
|
#define TXSIZE_DECRED_WITNESS 16
|
||||||
|
/* support version of Decred script_version */
|
||||||
|
#define DECRED_SCRIPT_VERSION 0
|
||||||
|
|
||||||
static const uint8_t segwit_header[2] = {0, 1};
|
static const uint8_t segwit_header[2] = {0, 1};
|
||||||
|
|
||||||
@ -193,7 +195,7 @@ int compile_output(const CoinInfo *coin, const HDNode *root, TxOutputType *in,
|
|||||||
TxOutputBinType *out, bool needs_confirm) {
|
TxOutputBinType *out, bool needs_confirm) {
|
||||||
memzero(out, sizeof(TxOutputBinType));
|
memzero(out, sizeof(TxOutputBinType));
|
||||||
out->amount = in->amount;
|
out->amount = in->amount;
|
||||||
out->decred_script_version = in->decred_script_version;
|
out->decred_script_version = DECRED_SCRIPT_VERSION;
|
||||||
uint8_t addr_raw[MAX_ADDR_RAW_SIZE] = {0};
|
uint8_t addr_raw[MAX_ADDR_RAW_SIZE] = {0};
|
||||||
size_t addr_raw_len = 0;
|
size_t addr_raw_len = 0;
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ class TxInputType(p.MessageType):
|
|||||||
multisig: MultisigRedeemScriptType = None,
|
multisig: MultisigRedeemScriptType = None,
|
||||||
amount: int = None,
|
amount: int = None,
|
||||||
decred_tree: int = None,
|
decred_tree: int = None,
|
||||||
decred_script_version: int = None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self.address_n = address_n if address_n is not None else []
|
self.address_n = address_n if address_n is not None else []
|
||||||
self.prev_hash = prev_hash
|
self.prev_hash = prev_hash
|
||||||
@ -37,7 +36,6 @@ class TxInputType(p.MessageType):
|
|||||||
self.multisig = multisig
|
self.multisig = multisig
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
self.decred_tree = decred_tree
|
self.decred_tree = decred_tree
|
||||||
self.decred_script_version = decred_script_version
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fields(cls) -> Dict:
|
def get_fields(cls) -> Dict:
|
||||||
@ -51,5 +49,4 @@ class TxInputType(p.MessageType):
|
|||||||
7: ('multisig', MultisigRedeemScriptType, 0),
|
7: ('multisig', MultisigRedeemScriptType, 0),
|
||||||
8: ('amount', p.UVarintType, 0),
|
8: ('amount', p.UVarintType, 0),
|
||||||
9: ('decred_tree', p.UVarintType, 0),
|
9: ('decred_tree', p.UVarintType, 0),
|
||||||
10: ('decred_script_version', p.UVarintType, 0),
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ class TxOutputType(p.MessageType):
|
|||||||
script_type: EnumTypeOutputScriptType = None,
|
script_type: EnumTypeOutputScriptType = None,
|
||||||
multisig: MultisigRedeemScriptType = None,
|
multisig: MultisigRedeemScriptType = None,
|
||||||
op_return_data: bytes = None,
|
op_return_data: bytes = None,
|
||||||
decred_script_version: int = None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self.address = address
|
self.address = address
|
||||||
self.address_n = address_n if address_n is not None else []
|
self.address_n = address_n if address_n is not None else []
|
||||||
@ -31,7 +30,6 @@ class TxOutputType(p.MessageType):
|
|||||||
self.script_type = script_type
|
self.script_type = script_type
|
||||||
self.multisig = multisig
|
self.multisig = multisig
|
||||||
self.op_return_data = op_return_data
|
self.op_return_data = op_return_data
|
||||||
self.decred_script_version = decred_script_version
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fields(cls) -> Dict:
|
def get_fields(cls) -> Dict:
|
||||||
@ -42,5 +40,4 @@ class TxOutputType(p.MessageType):
|
|||||||
4: ('script_type', p.EnumType("OutputScriptType", (0, 1, 2, 3, 4, 5)), 0), # required
|
4: ('script_type', p.EnumType("OutputScriptType", (0, 1, 2, 3, 4, 5)), 0), # required
|
||||||
5: ('multisig', MultisigRedeemScriptType, 0),
|
5: ('multisig', MultisigRedeemScriptType, 0),
|
||||||
6: ('op_return_data', p.BytesType, 0),
|
6: ('op_return_data', p.BytesType, 0),
|
||||||
7: ('decred_script_version', p.UVarintType, 0),
|
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,6 @@ class TestMsgSigntxDecred:
|
|||||||
address="TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz",
|
address="TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz",
|
||||||
amount=190000000,
|
amount=190000000,
|
||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
decred_script_version=0,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
@ -123,7 +122,6 @@ class TestMsgSigntxDecred:
|
|||||||
address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR",
|
address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR",
|
||||||
amount=489975000,
|
amount=489975000,
|
||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
decred_script_version=0,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
out2 = proto.TxOutputType(
|
out2 = proto.TxOutputType(
|
||||||
@ -131,7 +129,6 @@ class TestMsgSigntxDecred:
|
|||||||
address_n=parse_path("m/44'/1'/0'/1/0"),
|
address_n=parse_path("m/44'/1'/0'/1/0"),
|
||||||
amount=100000000,
|
amount=100000000,
|
||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
decred_script_version=0,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
@ -222,14 +219,12 @@ class TestMsgSigntxDecred:
|
|||||||
multisig=multisig,
|
multisig=multisig,
|
||||||
amount=99900000,
|
amount=99900000,
|
||||||
script_type=proto.OutputScriptType.PAYTOMULTISIG,
|
script_type=proto.OutputScriptType.PAYTOMULTISIG,
|
||||||
decred_script_version=0,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
out2 = proto.TxOutputType(
|
out2 = proto.TxOutputType(
|
||||||
address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR",
|
address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR",
|
||||||
amount=300000000,
|
amount=300000000,
|
||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
decred_script_version=0,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
|
Loading…
Reference in New Issue
Block a user