kevinheavey / solders

A high-performance Python toolkit for Solana, written in Rust
https://kevinheavey.github.io/solders/
Apache License 2.0
205 stars 23 forks source link

How to decompile a serialized VersionedTransaction fully into the original state, i.e. have CompiledInstructions be fully modifiable normal Instructions again? #99

Closed ff781 closed 3 weeks ago

kevinheavey commented 2 months ago

Here's what solana-py uses, though be warned I suspect there could be some edge case where this is incorrect:

def _decompile_instructions(msg: SoldersMessage) -> List[Instruction]:
    account_keys = msg.account_keys
    decompiled_instructions: List[Instruction] = []
    for compiled_ix in msg.instructions:
        program_id = account_keys[compiled_ix.program_id_index]
        account_metas = [
            AccountMeta(
                account_keys[idx],
                is_signer=msg.is_signer(idx),
                is_writable=msg.is_writable(idx),
            )
            for idx in compiled_ix.accounts
        ]
        decompiled_instructions.append(Instruction(program_id, compiled_ix.data, account_metas))
    return decompiled_instructions