mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-07 17:39:03 +00:00
fix(core/solana): avoid looking at not-exposed instruction ids
This commit is contained in:
parent
e4e6d60e64
commit
dd5a3365a9
@ -309,39 +309,19 @@ class Transaction:
|
||||
SOLANA_TOKEN_ACCOUNT_SIZE,
|
||||
)
|
||||
from ..transaction.instructions import (
|
||||
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID,
|
||||
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE,
|
||||
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT,
|
||||
_SYSTEM_PROGRAM_ID,
|
||||
_SYSTEM_PROGRAM_ID_INS_ALLOCATE,
|
||||
_SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED,
|
||||
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT,
|
||||
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED,
|
||||
is_system_program_account_creation,
|
||||
is_atap_account_creation,
|
||||
_TOKEN_2022_PROGRAM_ID,
|
||||
_TOKEN_PROGRAM_ID,
|
||||
)
|
||||
|
||||
allocation = 0
|
||||
for instruction in self.instructions:
|
||||
if instruction.program_id == _SYSTEM_PROGRAM_ID and (
|
||||
instruction.instruction_id
|
||||
in (
|
||||
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT,
|
||||
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED,
|
||||
_SYSTEM_PROGRAM_ID_INS_ALLOCATE,
|
||||
_SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED,
|
||||
)
|
||||
):
|
||||
if is_system_program_account_creation(instruction):
|
||||
allocation += (
|
||||
instruction.parsed_data["space"] + SOLANA_ACCOUNT_OVERHEAD_SIZE
|
||||
)
|
||||
elif instruction.program_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID and (
|
||||
instruction.instruction_id
|
||||
in (
|
||||
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE,
|
||||
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT,
|
||||
)
|
||||
):
|
||||
elif is_atap_account_creation(instruction):
|
||||
spl_token_account = self.get_account_address(
|
||||
instruction.parsed_accounts["spl_token"]
|
||||
)
|
||||
|
@ -117,6 +117,30 @@ COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE = (
|
||||
)
|
||||
|
||||
|
||||
def is_system_program_account_creation(instruction: Instruction) -> bool:
|
||||
return (
|
||||
instruction.program_id == _SYSTEM_PROGRAM_ID
|
||||
and instruction.instruction_id
|
||||
in (
|
||||
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT,
|
||||
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED,
|
||||
_SYSTEM_PROGRAM_ID_INS_ALLOCATE,
|
||||
_SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def is_atap_account_creation(instruction: Instruction) -> bool:
|
||||
return (
|
||||
instruction.program_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID
|
||||
and instruction.instruction_id
|
||||
in (
|
||||
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE,
|
||||
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Type[Instruction]:
|
||||
def get_id(name: str) -> tuple[str, InstructionId]:
|
||||
if name == "SystemProgramCreateAccountInstruction":
|
||||
|
@ -83,6 +83,29 @@ COMPUTE_BUDGET_PROGRAM_ID = _COMPUTE_BUDGET_PROGRAM_ID
|
||||
COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_LIMIT = _COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_LIMIT
|
||||
COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE = _COMPUTE_BUDGET_PROGRAM_ID_INS_SET_COMPUTE_UNIT_PRICE
|
||||
|
||||
|
||||
def is_system_program_account_creation(instruction: Instruction) -> bool:
|
||||
return (
|
||||
instruction.program_id == _SYSTEM_PROGRAM_ID
|
||||
and instruction.instruction_id in (
|
||||
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT,
|
||||
_SYSTEM_PROGRAM_ID_INS_CREATE_ACCOUNT_WITH_SEED,
|
||||
_SYSTEM_PROGRAM_ID_INS_ALLOCATE,
|
||||
_SYSTEM_PROGRAM_ID_INS_ALLOCATE_WITH_SEED,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def is_atap_account_creation(instruction: Instruction) -> bool:
|
||||
return (
|
||||
instruction.program_id == _ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID
|
||||
and instruction.instruction_id in (
|
||||
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE,
|
||||
_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID_INS_CREATE_IDEMPOTENT,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Type[Instruction]:
|
||||
def get_id(name: str) -> tuple[str, InstructionId]:
|
||||
%for program in programs["programs"]:
|
||||
|
Loading…
Reference in New Issue
Block a user