Skip to content

Commit 4445e9c

Browse files
Code cleanup.
1 parent 83998b4 commit 4445e9c

12 files changed

Lines changed: 47 additions & 146 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,4 @@ You can also simply open an issue with the tag `enhancement`.
259259
4. Push to the Branch (`git push origin feature/my-feature`)
260260
5. Open a Pull Request
261261

262-
Please try to follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
262+
Please try to follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).

proto_gen.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ cat > value.options << 'EOF'
6464
* anonymous_oneof:true
6565
# Handle recursive Value fields with pointers to break cycles
6666
com.daml.ledger.api.v2.RecordField.value type:FT_POINTER
67-
com.daml.ledger.api.v2.List.elements type:FT_POINTER
67+
com.daml.ledger.api.v2.List.elements type:FT_POINTER
6868
com.daml.ledger.api.v2.Optional.value type:FT_POINTER
6969
com.daml.ledger.api.v2.Variant.value type:FT_POINTER
7070
com.daml.ledger.api.v2.TextMap.Entry.value type:FT_POINTER
@@ -111,7 +111,7 @@ cat > interactive_submission_service.options << 'EOF'
111111
* anonymous_oneof:true
112112
com.daml.ledger.api.v2.interactive.PrepareSubmissionResponse.prepared_transaction_hash max_size: 32
113113
com.daml.ledger.api.v2.interactive.PrepareSubmissionResponse.hashing_details type:FT_POINTER
114-
com.daml.ledger.api.v2.interactive.DamlTransaction.NodeSeed.node_id type:FT_STATIC
114+
com.daml.ledger.api.v2.interactive.DamlTransaction.NodeSeed.node_id type:FT_STATIC
115115
com.daml.ledger.api.v2.interactive.DamlTransaction.version type:FT_POINTER
116116
com.daml.ledger.api.v2.interactive.DamlTransaction.roots type:FT_POINTER
117117
com.daml.ledger.api.v2.interactive.DamlTransaction.roots type:FT_POINTER
@@ -140,29 +140,29 @@ generate_nanopb_code() {
140140
# Extract the base name for the options file
141141
local base_name=$(basename "$proto_file" .proto)
142142
local options_file="${base_name}.options"
143-
143+
144144
# Check if specific options file exists, otherwise use value.options for Value-related protos
145145
if [ ! -f "$options_file" ] && [[ "$proto_file" == *"value.proto"* ]]; then
146146
options_file="value.options"
147147
fi
148148

149149
# Build the protoc command
150150
local protoc_cmd="$PROTOC --nanopb_out=$OUTPUT_DIR"
151-
151+
152152
# Add options file if it exists
153153
if [ -f "$options_file" ]; then
154154
protoc_cmd="$protoc_cmd --nanopb_opt=-f$options_file"
155155
fi
156-
156+
157157
# Add common options to handle recursion and static allocation
158158
protoc_cmd="$protoc_cmd --nanopb_opt=-T"
159159
protoc_cmd="$protoc_cmd --nanopb_opt=-s\"max_size:1024\""
160-
160+
161161
# Add extra options if provided
162162
if [ -n "$extra_opts" ]; then
163163
protoc_cmd="$protoc_cmd $extra_opts"
164164
fi
165-
165+
166166
# Add include paths
167167
protoc_cmd="$protoc_cmd -I$include_paths -I. --plugin=protoc-gen-nanopb=$NANOPB_GENERATOR $proto_file"
168168
py_protoc_cmd="$PROTOC -I$include_paths -I. --python_out=tests --pyi_out=tests $proto_file"

src/handler/sign_tx.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,7 @@ int handler_sign_tx(buffer_t *cdata, uint8_t chunk, bool more) {
108108

109109
PRINTF("Hash: %.*H\n", sizeof(G_context.tx_info.m_hash), G_context.tx_info.m_hash);
110110

111-
return io_send_sw(SW_OK);
112-
// Example to trig a blind-sign flow
113-
// if (strcmp((char *) G_context.tx_info.transaction.memo, "Blind-sign") == 0) {
114-
// return ui_display_blind_signed_transaction();
115-
// } else {
116-
// return ui_display_transaction();
117-
// }
111+
return ui_display_blind_signed_transaction();
118112
}
119113
}
120114
return 0;

src/transaction/hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ static void hash_transaction(const DamlTransaction *tx, uint8_t out[32]) {
593593
static void encode_input_contract(ByteWriter *bw, const InputContract *c) {
594594
encode_int64(bw, c->created_at);
595595

596-
// Encode contract create node in seprate buffer and calculate its hash
596+
// Encode contract create node in separate buffer and calculate its hash
597597
uint8_t *scratch = app_mem_alloc(MAX_ENCODED_NODE_LEN);
598598
LEDGER_ASSERT(scratch != NULL, "Failed to allocate scratch buf for node id");
599599

src/transaction/hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ typedef com_daml_ledger_api_v2_interactive_PreparedTransaction PreparedTransacti
77

88
int prepared_transaction_hash(const PreparedTransaction *pt, uint8_t out[32]);
99

10-
#endif // HASH_H
10+
#endif // HASH_H

src/ui/menu.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,3 @@
44
* Show main menu (ready screen, version, about, quit).
55
*/
66
void ui_menu_main(void);
7-
8-
/**
9-
* Show about submenu (copyright, date).
10-
*/
11-
void ui_menu_about(void);

src/ui/menu_nbgl.c

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -40,116 +40,19 @@ void app_quit(void) {
4040
static const char* const INFO_TYPES[SETTING_INFO_NB] = {"Version", "Developer"};
4141
static const char* const INFO_CONTENTS[SETTING_INFO_NB] = {APPVERSION, "Ledger"};
4242

43-
// settings switches definitions
44-
enum { DUMMY_SWITCH_1_TOKEN = FIRST_USER_TOKEN, DUMMY_SWITCH_2_TOKEN };
45-
enum { DUMMY_SWITCH_1_ID = 0, DUMMY_SWITCH_2_ID, SETTINGS_SWITCHES_NB };
46-
47-
static nbgl_contentSwitch_t switches[SETTINGS_SWITCHES_NB] = {0};
48-
4943
static const nbgl_contentInfoList_t infoList = {
5044
.nbInfos = SETTING_INFO_NB,
5145
.infoTypes = INFO_TYPES,
5246
.infoContents = INFO_CONTENTS,
5347
};
5448

55-
static uint8_t initSettingPage;
56-
static void review_warning_choice(bool confirm);
57-
static void controls_callback(int token, uint8_t index, int page);
58-
59-
// settings menu definition
60-
#define SETTING_CONTENTS_NB 1
61-
static const nbgl_content_t contents[SETTING_CONTENTS_NB] = {
62-
{.type = SWITCHES_LIST,
63-
.content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB,
64-
.content.switchesList.switches = switches,
65-
.contentActionCallback = controls_callback}};
66-
67-
static const nbgl_genericContents_t settingContents = {.callbackCallNeeded = false,
68-
.contentsList = contents,
69-
.nbContents = SETTING_CONTENTS_NB};
70-
71-
// callback for setting warning choice
72-
static void review_warning_choice(bool confirm) {
73-
uint8_t switch_value;
74-
if (confirm) {
75-
// toggle the switch value
76-
switch_value = !N_storage.dummy2_allowed;
77-
switches[DUMMY_SWITCH_2_ID].initState = (nbgl_state_t) switch_value;
78-
// store the new setting value in NVM
79-
nvm_write((void*) &N_storage.dummy2_allowed, &switch_value, 1);
80-
}
81-
82-
// Reset setting menu to the right page
83-
nbgl_useCaseHomeAndSettings(APPNAME,
84-
&ICON_APP_HOME,
85-
NULL,
86-
initSettingPage,
87-
&settingContents,
88-
&infoList,
89-
NULL,
90-
app_quit);
91-
}
92-
93-
static void controls_callback(int token, uint8_t index, int page) {
94-
UNUSED(index);
95-
96-
initSettingPage = page;
97-
98-
uint8_t switch_value;
99-
if (token == DUMMY_SWITCH_1_TOKEN) {
100-
// Dummy 1 switch touched
101-
// toggle the switch value
102-
switch_value = !N_storage.dummy1_allowed;
103-
switches[DUMMY_SWITCH_1_ID].initState = (nbgl_state_t) switch_value;
104-
// store the new setting value in NVM
105-
nvm_write((void*) &N_storage.dummy1_allowed, &switch_value, 1);
106-
} else if (token == DUMMY_SWITCH_2_TOKEN) {
107-
// Dummy 2 switch touched
108-
109-
// in this example we display a warning when the user wants
110-
// to activate the dummy 2 setting
111-
if (!N_storage.dummy2_allowed) {
112-
// Display the warning message and ask the user to confirm
113-
nbgl_useCaseChoice(&ICON_APP_WARNING,
114-
"Dummy 2",
115-
"Are you sure to\nallow dummy 2\nin transactions?",
116-
"I understand, confirm",
117-
"Cancel",
118-
review_warning_choice);
119-
} else {
120-
// toggle the switch value
121-
switch_value = !N_storage.dummy2_allowed;
122-
switches[DUMMY_SWITCH_2_ID].initState = (nbgl_state_t) switch_value;
123-
// store the new setting value in NVM
124-
nvm_write((void*) &N_storage.dummy2_allowed, &switch_value, 1);
125-
}
126-
}
127-
}
128-
12949
// home page definition
13050
void ui_menu_main(void) {
131-
// Initialize switches data
132-
switches[DUMMY_SWITCH_1_ID].initState = (nbgl_state_t) N_storage.dummy1_allowed;
133-
switches[DUMMY_SWITCH_1_ID].text = "Dummy 1";
134-
switches[DUMMY_SWITCH_1_ID].subText = "Allow dummy 1\nin transactions";
135-
switches[DUMMY_SWITCH_1_ID].token = DUMMY_SWITCH_1_TOKEN;
136-
#ifdef HAVE_PIEZO_SOUND
137-
switches[DUMMY_SWITCH_1_ID].tuneId = TUNE_TAP_CASUAL;
138-
#endif
139-
140-
switches[DUMMY_SWITCH_2_ID].initState = (nbgl_state_t) N_storage.dummy2_allowed;
141-
switches[DUMMY_SWITCH_2_ID].text = "Dummy 2";
142-
switches[DUMMY_SWITCH_2_ID].subText = "Allow dummy 2\nin transactions";
143-
switches[DUMMY_SWITCH_2_ID].token = DUMMY_SWITCH_2_TOKEN;
144-
#ifdef HAVE_PIEZO_SOUND
145-
switches[DUMMY_SWITCH_2_ID].tuneId = TUNE_TAP_CASUAL;
146-
#endif
147-
14851
nbgl_useCaseHomeAndSettings(APPNAME,
14952
&ICON_APP_HOME,
15053
NULL,
15154
INIT_HOME_PAGE,
152-
&settingContents,
55+
NULL,
15356
&infoList,
15457
NULL,
15558
app_quit);

tests/application_client/boilerplate_command_sender.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def sign_tx(self, path: str, transaction: bytes) -> Generator[None, None, None]:
108108
data=pack_derivation_path(path))
109109
messages = split_message(transaction, MAX_APDU_LEN)
110110
idx: int = P1.P1_START + 1
111-
111+
112112
print(f"Sending {len(messages)} chunks of transaction data")
113113

114114
for msg in messages[:-1]:

tests/application_client/boilerplate_transaction.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
from io import BytesIO
33
from typing import Union
44

5-
from .boilerplate_utils import read, read_uint, read_varint, write_varint, UINT64_MAX
65
from google.protobuf.json_format import Parse
7-
from com.daml.ledger.api.v2.interactive import interactive_submission_service_pb2
6+
# pylint: disable=no-name-in-module, import-error
7+
from com.daml.ledger.api.v2.interactive.interactive_submission_service_pb2 import PrepareSubmissionResponse # type: ignore
8+
9+
from .boilerplate_utils import read, read_uint, read_varint, write_varint, UINT64_MAX
810

911
# from proto.message_pb2 import SimpleInt
1012

@@ -54,12 +56,11 @@ def from_bytes(cls, hexa: Union[bytes, BytesIO]):
5456
return cls(nonce=nonce, to=to, value=value, memo=memo)
5557

5658
@classmethod
57-
def serialize_from_json(self, json_file: str) -> bytes:
58-
with open(json_file, "r") as file:
59+
def serialize_from_json(cls, json_file: str) -> bytes:
60+
with open(json_file, "r", encoding="utf-8") as file:
5961
data = json.load(file)
60-
61-
prepared_tx = interactive_submission_service_pb2.PrepareSubmissionResponse()
62+
63+
prepared_tx = PrepareSubmissionResponse()
6264
Parse(json.dumps(data), prepared_tx)
63-
64-
return prepared_tx.SerializeToString()
6565

66+
return prepared_tx.SerializeToString()

tests/test_sign_cmd.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
1-
import pytest
21
from ragger.backend.interface import BackendInterface
3-
from ragger.error import ExceptionRAPDU
4-
from ragger.navigator.navigation_scenario import NavigateWithScenario
2+
# from ragger.error import ExceptionRAPDU
3+
# from ragger.navigator.navigation_scenario import NavigateWithScenario
54

65
from application_client.boilerplate_transaction import Transaction
7-
from application_client.boilerplate_command_sender import BoilerplateCommandSender, Errors
8-
from application_client.boilerplate_response_unpacker import unpack_get_public_key_response, unpack_sign_tx_response
9-
from utils import check_signature_validity
6+
from application_client.boilerplate_command_sender import (
7+
BoilerplateCommandSender,
8+
# Errors,
9+
)
10+
# from application_client.boilerplate_response_unpacker import (
11+
# unpack_get_public_key_response,
12+
# unpack_sign_tx_response,
13+
# )
14+
# from utils import check_signature_validity
15+
1016

1117
# In this test se send to the device a transaction to sign and validate it on screen
1218
# This test is mostly the same as the previous one but with different values.
1319
# In particular the long memo will force the transaction to be sent in multiple chunks
14-
def test_sign_tx_long_tx(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None:
20+
def test_sign_tx_long_tx(
21+
backend: BackendInterface, # , scenario_navigator: NavigateWithScenario
22+
) -> None:
1523
# Use the app interface instead of raw interface
1624
client = BoilerplateCommandSender(backend)
1725
path: str = "m/44'/1'/0'/0/0"
1826

1927
# rapdu = client.get_public_key(path=path)
2028
# _, public_key, _, _ = unpack_get_public_key_response(rapdu.data)
21-
22-
serialized_tx = Transaction.serialize_from_json("tests/tx_examples/external_sign_ping.json")
23-
29+
30+
serialized_tx = Transaction.serialize_from_json(
31+
"tests/tx_examples/external_sign_ping.json"
32+
)
33+
2434
print(f"Serialized transaction length: {len(serialized_tx)} bytes")
25-
35+
2636
# client.sign_tx(path=path, transaction=serialized_tx)
2737

28-
with client.sign_tx(path=path, transaction=serialized_tx) as response:
38+
with client.sign_tx(path=path, transaction=serialized_tx):
2939
print("Transaction sent")
30-
# if response.status != 0x9000:
31-
# raise ExceptionRAPDU(f"Unexpected status code: {response.status}")
32-
# # scenario_navigator.review_approve()
40+
# scenario_navigator.review_approve()
3341

3442
# response = client.get_async_response().data
3543
# _, der_sig, _ = unpack_sign_tx_response(response)

0 commit comments

Comments
 (0)