2018-05-24 13:33:03 +00:00
|
|
|
from micropython import const
|
2021-12-08 09:10:58 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2018-05-24 13:33:03 +00:00
|
|
|
|
2021-03-23 12:35:27 +00:00
|
|
|
from trezor.enums import MessageType
|
2018-07-10 14:39:17 +00:00
|
|
|
|
2021-12-08 09:10:58 +00:00
|
|
|
if TYPE_CHECKING:
|
2021-07-20 10:59:03 +00:00
|
|
|
from trezor import protobuf
|
|
|
|
from trezor.messages import (
|
|
|
|
StellarAccountMergeOp,
|
|
|
|
StellarAllowTrustOp,
|
|
|
|
StellarBumpSequenceOp,
|
|
|
|
StellarChangeTrustOp,
|
2023-11-30 23:47:41 +00:00
|
|
|
StellarClaimClaimableBalanceOp,
|
2021-07-20 10:59:03 +00:00
|
|
|
StellarCreateAccountOp,
|
2021-10-07 23:33:09 +00:00
|
|
|
StellarCreatePassiveSellOfferOp,
|
2021-10-07 03:48:45 +00:00
|
|
|
StellarManageBuyOfferOp,
|
2023-08-15 15:56:09 +00:00
|
|
|
StellarManageDataOp,
|
2021-10-07 01:58:52 +00:00
|
|
|
StellarManageSellOfferOp,
|
|
|
|
StellarPathPaymentStrictReceiveOp,
|
2021-10-07 14:06:08 +00:00
|
|
|
StellarPathPaymentStrictSendOp,
|
2021-07-20 10:59:03 +00:00
|
|
|
StellarPaymentOp,
|
|
|
|
StellarSetOptionsOp,
|
|
|
|
)
|
|
|
|
|
2022-01-07 14:13:54 +00:00
|
|
|
StellarMessageType = (
|
|
|
|
StellarAccountMergeOp
|
|
|
|
| StellarAllowTrustOp
|
|
|
|
| StellarBumpSequenceOp
|
|
|
|
| StellarChangeTrustOp
|
|
|
|
| StellarCreateAccountOp
|
|
|
|
| StellarCreatePassiveSellOfferOp
|
|
|
|
| StellarManageDataOp
|
|
|
|
| StellarManageBuyOfferOp
|
|
|
|
| StellarManageSellOfferOp
|
|
|
|
| StellarPathPaymentStrictReceiveOp
|
|
|
|
| StellarPathPaymentStrictSendOp
|
|
|
|
| StellarPaymentOp
|
|
|
|
| StellarSetOptionsOp
|
2023-11-30 23:47:41 +00:00
|
|
|
| StellarClaimClaimableBalanceOp
|
2022-01-07 14:13:54 +00:00
|
|
|
)
|
2021-07-20 10:59:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
TX_TYPE = b"\x00\x00\x00\x02"
|
2018-06-05 14:29:49 +00:00
|
|
|
|
2021-10-07 03:48:45 +00:00
|
|
|
# source: https://github.com/stellar/go/blob/a1db2a6b1f/xdr/Stellar-transaction.x#L35
|
2018-06-05 14:29:49 +00:00
|
|
|
# Inflation not supported see https://github.com/trezor/trezor-core/issues/202#issuecomment-393342089
|
2021-07-20 10:59:03 +00:00
|
|
|
op_codes: dict[int, int] = {
|
2021-03-23 12:35:27 +00:00
|
|
|
MessageType.StellarAccountMergeOp: 8,
|
|
|
|
MessageType.StellarAllowTrustOp: 7,
|
|
|
|
MessageType.StellarBumpSequenceOp: 11,
|
|
|
|
MessageType.StellarChangeTrustOp: 6,
|
|
|
|
MessageType.StellarCreateAccountOp: 0,
|
2021-10-07 23:33:09 +00:00
|
|
|
MessageType.StellarCreatePassiveSellOfferOp: 4,
|
2021-03-23 12:35:27 +00:00
|
|
|
MessageType.StellarManageDataOp: 10,
|
2021-10-07 03:48:45 +00:00
|
|
|
MessageType.StellarManageBuyOfferOp: 12,
|
2021-10-07 01:58:52 +00:00
|
|
|
MessageType.StellarManageSellOfferOp: 3,
|
|
|
|
MessageType.StellarPathPaymentStrictReceiveOp: 2,
|
2021-10-07 14:06:08 +00:00
|
|
|
MessageType.StellarPathPaymentStrictSendOp: 13,
|
2021-03-23 12:35:27 +00:00
|
|
|
MessageType.StellarPaymentOp: 1,
|
|
|
|
MessageType.StellarSetOptionsOp: 5,
|
2023-11-30 23:47:41 +00:00
|
|
|
MessageType.StellarClaimClaimableBalanceOp: 15,
|
2018-05-24 13:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-29 10:16:28 +00:00
|
|
|
# https://www.stellar.org/developers/guides/concepts/accounts.html#balance
|
2018-06-05 14:29:49 +00:00
|
|
|
# https://github.com/stellar/go/blob/3d2c1defe73dbfed00146ebe0e8d7e07ce4bb1b6/amount/main.go#L23
|
2019-12-09 16:43:30 +00:00
|
|
|
AMOUNT_DECIMALS = const(7)
|
2018-05-29 10:16:28 +00:00
|
|
|
|
|
|
|
# https://github.com/stellar/go/blob/master/network/main.go
|
2018-07-10 14:39:17 +00:00
|
|
|
NETWORK_PASSPHRASE_PUBLIC = "Public Global Stellar Network ; September 2015"
|
|
|
|
NETWORK_PASSPHRASE_TESTNET = "Test SDF Network ; September 2015"
|
2018-05-29 10:16:28 +00:00
|
|
|
|
2018-06-05 14:29:49 +00:00
|
|
|
# https://www.stellar.org/developers/guides/concepts/accounts.html#flags
|
|
|
|
FLAG_AUTH_REQUIRED = const(1)
|
|
|
|
FLAG_AUTH_REVOCABLE = const(2)
|
|
|
|
FLAG_AUTH_IMMUTABLE = const(4)
|
2018-06-18 13:41:59 +00:00
|
|
|
FLAGS_MAX_SIZE = const(7)
|
2018-06-05 14:29:49 +00:00
|
|
|
|
2018-05-24 13:33:03 +00:00
|
|
|
|
2021-07-20 10:59:03 +00:00
|
|
|
def get_op_code(msg: protobuf.MessageType) -> int:
|
2021-03-23 12:35:27 +00:00
|
|
|
wire = msg.MESSAGE_WIRE_TYPE
|
|
|
|
if wire not in op_codes:
|
2018-07-10 14:39:17 +00:00
|
|
|
raise ValueError("Stellar: op code unknown")
|
2021-12-08 09:10:58 +00:00
|
|
|
assert isinstance(wire, int)
|
2021-03-23 12:35:27 +00:00
|
|
|
return op_codes[wire]
|