mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-29 19:08:12 +00:00
apps.common: add op_return to signtx
This commit is contained in:
parent
357a081b53
commit
ea12087de7
@ -144,9 +144,10 @@ async def sign_tx(tx: SignTx, root):
|
|||||||
'Only one change output is valid')
|
'Only one change output is valid')
|
||||||
change_out = txo.amount
|
change_out = txo.amount
|
||||||
else:
|
else:
|
||||||
if not await confirm_output(txo, coin):
|
if txo.script_type != OutputScriptType.PAYTOOPRETURN:
|
||||||
raise SigningError(FailureType.ActionCancelled,
|
if not await confirm_output(txo, coin):
|
||||||
'Output cancelled')
|
raise SigningError(FailureType.ActionCancelled,
|
||||||
|
'Output cancelled')
|
||||||
txo_bin.amount = txo.amount
|
txo_bin.amount = txo.amount
|
||||||
txo_bin.script_pubkey = output_derive_script(txo, coin, root)
|
txo_bin.script_pubkey = output_derive_script(txo, coin, root)
|
||||||
write_tx_output(h_first, txo_bin)
|
write_tx_output(h_first, txo_bin)
|
||||||
@ -319,6 +320,12 @@ def output_derive_script(o: TxOutputType, coin: CoinType, root) -> bytes:
|
|||||||
elif o.script_type == OutputScriptType.PAYTOSCRIPTHASH:
|
elif o.script_type == OutputScriptType.PAYTOSCRIPTHASH:
|
||||||
ra = output_paytoaddress_extract_raw_address(o, coin, root, p2sh=True)
|
ra = output_paytoaddress_extract_raw_address(o, coin, root, p2sh=True)
|
||||||
return script_paytoscripthash_new(ra[1:])
|
return script_paytoscripthash_new(ra[1:])
|
||||||
|
elif o.script_type == OutputScriptType.PAYTOOPRETURN:
|
||||||
|
if o.amount == 0:
|
||||||
|
return script_paytoopreturn_new(o.op_return_data)
|
||||||
|
else:
|
||||||
|
raise SigningError(FailureType.SyntaxError,
|
||||||
|
'OP_RETURN output with non-zero amount')
|
||||||
else:
|
else:
|
||||||
raise SigningError(FailureType.SyntaxError,
|
raise SigningError(FailureType.SyntaxError,
|
||||||
'Invalid output script type')
|
'Invalid output script type')
|
||||||
@ -421,6 +428,13 @@ def script_paytoscripthash_new(scripthash: bytes) -> bytearray:
|
|||||||
s[22] = 0x87 # OP_EQUAL
|
s[22] = 0x87 # OP_EQUAL
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
def script_paytoopreturn_new(data: bytes) -> bytearray:
|
||||||
|
w = bytearray()
|
||||||
|
w.append(0x6A) # OP_RETURN
|
||||||
|
write_op_push(w, len(data))
|
||||||
|
w.extend(data)
|
||||||
|
return w
|
||||||
|
|
||||||
def script_spendaddress_new(pubkey: bytes, signature: bytes) -> bytearray:
|
def script_spendaddress_new(pubkey: bytes, signature: bytes) -> bytearray:
|
||||||
w = bytearray()
|
w = bytearray()
|
||||||
write_op_push(w, len(signature) + 1)
|
write_op_push(w, len(signature) + 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user