Skip to content

Commit

Permalink
feat(solana): add nullable tag
Browse files Browse the repository at this point in the history
  • Loading branch information
RostarMarek committed May 7, 2024
1 parent 12725d9 commit 767484b
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 4 deletions.
3 changes: 2 additions & 1 deletion common/defs/solana/programs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,8 @@
{
"name": "new_authority",
"type": "authority",
"optional": true
"optional": false,
"nullable": true
}
],
"references": [
Expand Down
42 changes: 42 additions & 0 deletions common/tests/fixtures/solana/sign_tx.token_program.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,48 @@
"expected_signature": "7a96fb6cc283a10e26c9d330e8f2b2892d23698e008c959c29eb124a9c835fc0125865af4ee2ee267fe5ed03e51029f4244b05a592fd5c7969f5a9890ceef902"
}
},
{
"description": "Set Authority - null authority",
"parameters": {
"address": "m/44'/501'/0'/0'",
"construct": {
"version": null,
"header": {
"signers": 1,
"readonly_signers": 0,
"readonly_non_signers": 1
},
"accounts": [
"14CCvQzQzHCVgZM3j9soPnXuJXh1RmCfwLVUcdfbZVBS",
"FUqrjRRtF1LiptdFqaFxipE8R3YfCE4k56xwm5n1piqX",
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
],
"blockhash": "2p4rYZAaFfV5Uk5ugdG5KPNty9Uda9B3b4gWB8qnNqak",
"instructions": [
{
"program_index": 2,
"accounts": {
"mint_account": 1,
"current_authority": 0,
"multisig_signers": []
},
"data": {
"instruction_id": 6,
"authority_type": 1,
"new_authority": {
"is_included": false,
"value": null
}
}
}
],
"luts": []
}
},
"result": {
"expected_signature": "f983c4f3ac794bf02e67d3320c91e515c3de649b377c61c25546699fe6f551ffc8c022853823eb81cf785e71a5bbb78f5cbcfd49eb38480629bdc906c5c50202"
}
},
{
"description": "Set Authority - Multisig",
"parameters": {
Expand Down
13 changes: 11 additions & 2 deletions core/src/apps/solana/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,24 @@ async def confirm_instruction(
continue

if ui_property.default_value_to_hide == value:
continue
# currently we can define a default value to hide,
# but it needs to be of the type that the property is of (such as public key for new_authority)
# and for nullable values(such as new_authority) we want to display it to the user
if not property_template.is_nullable or value is not None:
continue

display_text = (
"Not set"
if value is None
else property_template.format(instruction, value)
)
await confirm_properties(
"confirm_instruction",
f"{instruction_index}/{instructions_count}: {instruction.ui_name}",
(
(
ui_property.display_name,
property_template.format(instruction, value),
display_text,
),
),
)
Expand Down
15 changes: 15 additions & 0 deletions core/src/apps/solana/transaction/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,24 @@ def parse_instruction_data(
parsed_data = {}
for property_template in property_templates:
is_included = True
# Property cannot be both optional and nullable as if there are multiple such properties in 1 instruction
# it could lead to non-deterministic parsing
# it is validated by mako template as well
if property_template.is_nullable and property_template.is_optional:
raise DataError("Parameter is nullable and optional")

if property_template.is_optional:
is_included = True if reader.get() == 1 else False

if property_template.is_nullable:
is_included = True if reader.get() == 1 else False
if not is_included:
# A default (null) value is included in the parsed message for nullable properties
# (e.g. new_authority in Set Authority instruction) even if the is_included flag is not set.
# We can safely discard this value.
if reader.remaining_count() != 0:
property_template.parse(reader)

parsed_data[property_template.name] = (
property_template.parse(reader) if is_included else None
)
Expand Down
Loading

0 comments on commit 767484b

Please sign in to comment.