1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-05 22:18:16 +00:00
trezor-firmware/core/src/apps/stellar/consts.py

86 lines
2.8 KiB
Python
Raw Normal View History

2018-05-24 13:33:03 +00:00
from micropython import const
from typing import TYPE_CHECKING
2018-05-24 13:33:03 +00:00
from trezor.enums import MessageType
2018-07-10 14:39:17 +00:00
if TYPE_CHECKING:
from trezor import protobuf
from trezor.messages import (
StellarAccountMergeOp,
StellarAllowTrustOp,
StellarBumpSequenceOp,
StellarChangeTrustOp,
StellarClaimClaimableBalanceOp,
StellarCreateAccountOp,
StellarCreatePassiveSellOfferOp,
StellarManageBuyOfferOp,
StellarManageDataOp,
StellarManageSellOfferOp,
StellarPathPaymentStrictReceiveOp,
StellarPathPaymentStrictSendOp,
StellarPaymentOp,
StellarSetOptionsOp,
)
StellarMessageType = (
StellarAccountMergeOp
| StellarAllowTrustOp
| StellarBumpSequenceOp
| StellarChangeTrustOp
| StellarCreateAccountOp
| StellarCreatePassiveSellOfferOp
| StellarManageDataOp
| StellarManageBuyOfferOp
| StellarManageSellOfferOp
| StellarPathPaymentStrictReceiveOp
| StellarPathPaymentStrictSendOp
| StellarPaymentOp
| StellarSetOptionsOp
| StellarClaimClaimableBalanceOp
)
TX_TYPE = b"\x00\x00\x00\x02"
2018-06-05 14:29:49 +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
op_codes: dict[int, int] = {
MessageType.StellarAccountMergeOp: 8,
MessageType.StellarAllowTrustOp: 7,
MessageType.StellarBumpSequenceOp: 11,
MessageType.StellarChangeTrustOp: 6,
MessageType.StellarCreateAccountOp: 0,
MessageType.StellarCreatePassiveSellOfferOp: 4,
MessageType.StellarManageDataOp: 10,
MessageType.StellarManageBuyOfferOp: 12,
MessageType.StellarManageSellOfferOp: 3,
MessageType.StellarPathPaymentStrictReceiveOp: 2,
MessageType.StellarPathPaymentStrictSendOp: 13,
MessageType.StellarPaymentOp: 1,
MessageType.StellarSetOptionsOp: 5,
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
def get_op_code(msg: protobuf.MessageType) -> int:
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")
assert isinstance(wire, int)
return op_codes[wire]