Skip to content

Commit eb7f10f

Browse files
authored
feat(core): adaptation related to Polkadot updates (#615)
* feat(core): adaptation related to Polkadot updates * feat(core): add Tron vote and message signing V2 support 1. optimize display for tron energy rental transactions 2. fix side button issue when BLE is connected 3. adjust response timing during device initialization * chore: bump version to 4.12.0
1 parent 204425e commit eb7f10f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+631
-148
lines changed

common/protob/check.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@
1515
for fn in sorted(glob(os.path.join(MYDIR, "messages-*.proto"))):
1616
with open(fn, "rt") as f:
1717
prefix = EXPECTED_PREFIX_RE.search(fn).group(1).capitalize()
18-
if prefix in ("Bitcoin", "Bootloader", "Common", "Crypto", "Management", "Ton"):
18+
if prefix in (
19+
"Bitcoin",
20+
"Bootloader",
21+
"Common",
22+
"Crypto",
23+
"Management",
24+
"Ton",
25+
"Tron",
26+
):
1927
continue
2028
if prefix == "Nem":
2129
prefix = "NEM"

common/protob/messages-polkadot.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ message PolkadotSignTx {
3636
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
3737
required bytes raw_tx = 2; // serialized raw transaction
3838
required string network = 3; // Network name
39+
optional uint32 prefix = 4; // SS58 address-type
3940
}
4041

4142
/**

common/protob/messages-tron.proto

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ message TronSignTx {
3535
required bytes ref_block_bytes = 2; // Reference block number
3636
required bytes ref_block_hash = 3; // Reference block hash
3737
required uint64 expiration = 4; // Transaction expiration
38-
optional string data = 5; // Extra transaction info
38+
optional bytes data = 5; // Extra transaction info
3939
required TronContract contract = 6; // Contract messages
4040
required uint64 timestamp = 7; // UTC timestamp
4141
optional uint64 fee_limit = 8; // Fee limit for smartcontracts
@@ -63,6 +63,7 @@ message TronSignTx {
6363
enum TronResourceCode {
6464
BANDWIDTH = 0x00;
6565
ENERGY = 0x01;
66+
TRON_POWER = 0x02;
6667
}
6768

6869
// Freeze TRX balance
@@ -98,14 +99,26 @@ message TronSignTx {
9899
optional uint64 balance = 3;
99100
optional string receiver_address = 4;
100101
optional bool lock = 5;
102+
optional uint64 lock_period = 6;
101103
}
102104
message TronUnDelegateResourceContract {
103105
optional TronResourceCode resource = 2;
104106
optional uint64 balance = 3;
105107
optional string receiver_address = 4;
106108
}
107-
109+
message TronCancelAllUnfreezeV2Contract {
110+
}
111+
// Vote Witness Contract
112+
message TronVoteWitnessContract {
113+
message Vote {
114+
required string vote_address = 1;
115+
required uint32 vote_count = 2;
116+
}
117+
repeated Vote votes = 2;
118+
optional bool support = 3;
119+
}
108120
optional TronTransferContract transfer_contract = 2;
121+
optional TronVoteWitnessContract vote_witness_contract = 4;
109122
optional TronFreezeBalanceContract freeze_balance_contract = 11;
110123
optional TronUnfreezeBalanceContract unfreeze_balance_contract = 12;
111124
optional TronWithdrawBalanceContract withdraw_balance_contract = 13;
@@ -115,6 +128,10 @@ message TronSignTx {
115128
optional TronWithdrawExpireUnfreezeContract withdraw_expire_unfreeze_contract = 56;
116129
optional TronDelegateResourceContract delegate_resource_contract = 57;
117130
optional TronUnDelegateResourceContract undelegate_resource_contract = 58;
131+
optional TronCancelAllUnfreezeV2Contract cancel_all_unfreeze_v2_contract = 59;
132+
optional bytes provider = 3;
133+
optional bytes contract_name = 5;
134+
optional uint32 permission_id = 6;
118135
}
119136
}
120137

@@ -127,14 +144,20 @@ message TronSignedTx {
127144
optional bytes serialized_tx = 2; // Serialized transaction
128145
}
129146

147+
enum TronMessageType {
148+
V1 = 1 [deprecated=true];
149+
V2 = 2;
150+
}
151+
130152
/**
131153
* Request: Ask device to sign message
132154
* @next TronMessageSignature
133155
* @next Failure
134156
*/
135157
message TronSignMessage {
136-
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
137-
required bytes message = 2; // message to be signed
158+
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
159+
required bytes message = 2; // message to be signed
160+
optional TronMessageType message_type = 3[default = V1]; // message type
138161
}
139162

140163
/**

core/embed/firmware/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#define FIX_VERSION_BUILD 99
1010

1111
#define ONEKEY_VERSION_MAJOR 4
12-
#define ONEKEY_VERSION_MINOR 11
12+
#define ONEKEY_VERSION_MINOR 12
1313
#define ONEKEY_VERSION_PATCH 0
1414
#define ONEKEY_VERSION_BUILD 0
1515

16-
#define ONEKEY_VERSION "4.11.0"
16+
#define ONEKEY_VERSION "4.12.0"

core/src/all_modules.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@
137137
import trezor.enums.TonWalletVersion
138138
trezor.enums.TonWorkChain
139139
import trezor.enums.TonWorkChain
140+
trezor.enums.TronMessageType
141+
import trezor.enums.TronMessageType
140142
trezor.enums.TronResourceCode
141143
import trezor.enums.TronResourceCode
142144
trezor.enums.WordRequestType
@@ -885,6 +887,8 @@
885887
import apps.tron.get_address
886888
apps.tron.layout
887889
import apps.tron.layout
890+
apps.tron.providers
891+
import apps.tron.providers
888892
apps.tron.serialize
889893
import apps.tron.serialize
890894
apps.tron.sign_message

core/src/apps/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,8 @@ async def handle_CancelAuthorization(
346346

347347
def set_homescreen() -> None:
348348
import lvgl as lv # type: ignore[Import "lvgl" could not be resolved]
349-
from trezor import uart
350349

351350
ble_name = storage.device.get_ble_name()
352-
uart.get_ble_con_status()
353351
if storage.device.is_initialized():
354352
dev_state = get_state()
355353
device_name = storage.device.get_label()

core/src/apps/management/recovery_device/homescreen.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from trezor.messages import Success
1212
from trezor.ui.layouts import show_onekey_app_guide, show_popup, show_success
1313

14-
from apps.base import set_homescreen
1514
from apps.common import mnemonic
1615
from apps.homescreen.homescreen import homescreen
1716

@@ -158,11 +157,11 @@ async def _finish_recovery(
158157
header=_(i18n_keys.TITLE__WALLET_IS_READY),
159158
button=_(i18n_keys.BUTTON__CONTINUE),
160159
)
161-
if isinstance(ctx, wire.DummyContext):
162-
utils.make_show_app_guide()
163-
else:
164-
await show_onekey_app_guide()
165-
set_homescreen()
160+
# if isinstance(ctx, wire.DummyContext):
161+
# utils.make_show_app_guide()
162+
# else:
163+
await show_onekey_app_guide()
164+
# set_homescreen()
166165
return Success(message="Device recovered")
167166

168167

core/src/apps/management/reset_device/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ async def reset_device(ctx: wire.Context, msg: ResetDevice) -> Success:
122122
if not __debug__:
123123
await show_bip39_dotmap(ctx, secret)
124124
await layout.show_backup_success(ctx)
125-
if isinstance(ctx, wire.DummyContext):
126-
utils.make_show_app_guide()
127-
else:
128-
await show_onekey_app_guide()
125+
# if isinstance(ctx, wire.DummyContext):
126+
# utils.make_show_app_guide()
127+
# else:
128+
await show_onekey_app_guide()
129129
except BaseException as e:
130130
raise e
131131
else:

core/src/apps/polkadot/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
CURVE = "secp256k1"
44
SLIP44_ID = 354
55
PATTERN = PATTERN_BIP44
6-
PRIMARY_COLOR = 0xE6007A
7-
PRIMARY_COLOR_KSM = 0xFFFFFF
6+
PRIMARY_COLOR = 0x00FF33
7+
PRIMARY_COLOR_KSM = 0x00FF33
88
PRIMARY_COLOR_WESTEND = 0x969696
99
PRIMARY_COLOR_ASTAR = 0x04E2FE
1010
PRIMARY_COLOR_JOY = 0x4038FF
1111
PRIMARY_COLOR_MAMTA = 0x26C8BF
12+
PRIMARY_COLOR_HYDRATION = 0x00FF33
13+
PRIMARY_COLOR_BIFROST = 0x00FF33
14+
PRIMARY_COLOR_BIFROST_KSMC = 0x00FF33
1215
ICON = "A:/res/chain-dot.png"
1316
ICON_KSM = "A:/res/chain-kusama.png"
1417
ICON_WESTEND = "A:/res/chain-westend.png"
1518
ICON_ASTAR = "A:/res/chain-astar.png"
1619
ICON_JOY = "A:/res/chain-joystream.png"
1720
ICON_MANTA = "A:/res/chain-manta.png"
21+
ICON_HYDRATION = "A:/res/chain-hydration.png"
22+
ICON_BIFROST = "A:/res/chain-bifrost.png"
23+
ICON_BIFROST_KSM = "A:/res/chain-bifrost-ksm.png"

core/src/apps/polkadot/helper.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
from . import (
88
ICON,
99
ICON_ASTAR,
10+
ICON_BIFROST,
11+
ICON_BIFROST_KSM,
12+
ICON_HYDRATION,
1013
ICON_JOY,
1114
ICON_KSM,
1215
ICON_MANTA,
1316
ICON_WESTEND,
1417
PRIMARY_COLOR,
1518
PRIMARY_COLOR_ASTAR,
19+
PRIMARY_COLOR_BIFROST,
20+
PRIMARY_COLOR_BIFROST_KSMC,
21+
PRIMARY_COLOR_HYDRATION,
1622
PRIMARY_COLOR_JOY,
1723
PRIMARY_COLOR_KSM,
1824
PRIMARY_COLOR_MAMTA,
@@ -30,6 +36,9 @@
3036
["astar", 5],
3137
["joystream", 126],
3238
["manta", 77],
39+
["hydration", 0],
40+
["bifrost", 0],
41+
["bifrost-ksm", 0],
3342
]
3443

3544
COIN_AMOUNT_DECIMAL_PLACES = 10
@@ -41,6 +50,8 @@
4150
ASTAR_COIN_TICKER = "ASTR"
4251
JOY_COIN_TICKER = "JOY"
4352
MANTA_COIN_TICKER = "MANTA"
53+
HYDRATION_COIN_TICKER = "HDX"
54+
BIFROST_COIN_TICKER = "BNC"
4455

4556

4657
def ss58_encode(address: bytes, ss58_format: int = 42) -> str:
@@ -118,6 +129,30 @@ def update_chain_res(ctx: Context, network: str) -> tuple[str, str, int]:
118129
chain_name = "Manta"
119130
symbol = MANTA_COIN_TICKER
120131
decimal = COIN_AMOUNT_DECIMAL_PLACES_18
132+
elif network == "hydration":
133+
ctx.primary_color, ctx.icon_path = (
134+
lv.color_hex(PRIMARY_COLOR_HYDRATION),
135+
ICON_HYDRATION,
136+
)
137+
chain_name = "Hydration"
138+
symbol = HYDRATION_COIN_TICKER
139+
decimal = COIN_AMOUNT_DECIMAL_PLACES_12
140+
elif network == "bifrost":
141+
ctx.primary_color, ctx.icon_path = (
142+
lv.color_hex(PRIMARY_COLOR_BIFROST),
143+
ICON_BIFROST,
144+
)
145+
chain_name = "Bifrost"
146+
symbol = BIFROST_COIN_TICKER
147+
decimal = COIN_AMOUNT_DECIMAL_PLACES_12
148+
elif network == "bifrost-ksm":
149+
ctx.primary_color, ctx.icon_path = (
150+
lv.color_hex(PRIMARY_COLOR_BIFROST_KSMC),
151+
ICON_BIFROST_KSM,
152+
)
153+
chain_name = "Bifrost-KSM"
154+
symbol = BIFROST_COIN_TICKER
155+
decimal = COIN_AMOUNT_DECIMAL_PLACES_12
121156
else:
122157
ctx.primary_color, ctx.icon_path = lv.color_hex(PRIMARY_COLOR), ICON
123158
chain_name = "UNKN Chain"
@@ -126,10 +161,10 @@ def update_chain_res(ctx: Context, network: str) -> tuple[str, str, int]:
126161
return chain_name, symbol, decimal
127162

128163

129-
def get_address_type(network: str) -> int:
130-
address_type = 42
164+
def get_address_type(network: str, preset_prefix: int | None = None) -> int:
165+
address_type = preset_prefix if preset_prefix is not None else 42
131166
for element in POLKADOT_ADDRESS_TYPES:
132167
if network == element[0]:
133168
address_type = element[1]
134-
169+
break
135170
return address_type

0 commit comments

Comments
 (0)