Last active
February 24, 2019 23:49
-
-
Save brianddk/e57a4ef04e2a7fc24da29a4baf91b343 to your computer and use it in GitHub Desktop.
A very simple one-to-one TXN for python trezor v0.11.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# [rights] Copyright Dan B. (brianddk) 2018 https://github.com/brianddk | |
# [license] Licensed under Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0 | |
# [repo] https://gist.github.com/brianddk/e57a4ef04e2a7fc24da29a4baf91b343 | |
# [tipjar] LTC: LQjSwZLigtgqHA3rE14yeRNbNNY2r3tXcA | |
# | |
from trezorlib import btc, coins, messages as proto, tools, ui | |
from trezorlib.client import TrezorClient | |
from trezorlib.transport import get_transport | |
# self.setup_mnemonic_allallall() # see trezorlib///test_msg_signtx.py | |
# User Provided Fields; These are pulled from test scripts | |
# CHANGE THESE!!! | |
coin = "Testnet" | |
in1_prev_hash = "e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd" | |
in1_prev_index = 0 | |
in1_addr_path = "44'/1'/0'/0/0" | |
in1_amount = 31000000 | |
out1_address = "msj42CCGruhRsFrGATiUuh25dtxYtnpbTx" | |
out1_amount = 30090000 | |
# Defaults | |
sequence = 4294967293 | |
# Code | |
prev_hash = bytes.fromhex(in1_prev_hash) | |
device = get_transport() | |
client = TrezorClient(transport=device, ui=ui.ClickUI()) | |
in1 = proto.TxInputType( | |
address_n=tools.parse_path(in1_addr_path), | |
prev_hash=prev_hash, | |
prev_index=in1_prev_index, | |
amount=in1_amount, | |
script_type=proto.InputScriptType.SPENDADDRESS, | |
sequence=sequence | |
) | |
out1 = proto.TxOutputType( | |
address=out1_address, | |
amount=out1_amount, | |
script_type=proto.OutputScriptType.PAYTOADDRESS | |
) | |
_, serialized_tx = btc.sign_tx(client, coin, [in1], [out1], prev_txes=coins.tx_api[coin]) | |
client.close() | |
print('"txn_hex": {', serialized_tx.hex(), '}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@matejcik , Very clever! I see now, passing in a TxApi object into
prev_txes
allows use of the__getitem__
overload avoided the later exception onSPENDADDRESS
. Also see the defaulting ofdetails
... Thx again!BTW... really great job on v0.11. I really like the new TxApi.