diff --git a/packages/renderers-vixen-parser/e2e/anchor/src/generated/accounts_parser.rs b/packages/renderers-vixen-parser/e2e/anchor/src/generated/accounts_parser.rs index 0f1f29a7..7f45e94a 100644 --- a/packages/renderers-vixen-parser/e2e/anchor/src/generated/accounts_parser.rs +++ b/packages/renderers-vixen-parser/e2e/anchor/src/generated/accounts_parser.rs @@ -5,7 +5,7 @@ //! //! -use wen_transfer_guard_program_sdk::accounts::guardV1::Guardv1; +use wen_transfer_guard_program_sdk::accounts::guard_v1::GuardV1; use wen_transfer_guard_program_sdk::ID; /// WenTransferGuard Program State diff --git a/packages/renderers-vixen-parser/e2e/anchor/src/generated/instructions_parser.rs b/packages/renderers-vixen-parser/e2e/anchor/src/generated/instructions_parser.rs index bcdd04b1..25f9fb01 100644 --- a/packages/renderers-vixen-parser/e2e/anchor/src/generated/instructions_parser.rs +++ b/packages/renderers-vixen-parser/e2e/anchor/src/generated/instructions_parser.rs @@ -67,7 +67,6 @@ impl InstructionParser { let accounts_len = ix.accounts.len(); let ix_discriminator: [u8; 8] = ix.data[0..8].try_into()?; let mut ix_data = &ix.data[8..]; - match ix_discriminator { [251, 254, 17, 198, 219, 218, 154, 99] => { check_min_accounts_req(accounts_len, 8)?; diff --git a/packages/renderers-vixen-parser/e2e/dummy/src/generated/instructions_parser.rs b/packages/renderers-vixen-parser/e2e/dummy/src/generated/instructions_parser.rs index ceb8d615..7a6bf451 100644 --- a/packages/renderers-vixen-parser/e2e/dummy/src/generated/instructions_parser.rs +++ b/packages/renderers-vixen-parser/e2e/dummy/src/generated/instructions_parser.rs @@ -18,13 +18,13 @@ use dummy_program_sdk::ID; /// Dummy Instructions #[derive(Debug)] pub enum DummyProgramIx { - Instruction1(Instruction1IxAccounts, Instruction1IxData), - Instruction2(Instruction2IxAccounts, Instruction2IxData), + Instruction1(Instruction1IxAccounts), + Instruction2(Instruction2IxAccounts), Instruction3(Instruction3IxAccounts, Instruction3IxData), Instruction4(Instruction4IxAccounts, Instruction4IxData), Instruction5(Instruction5IxAccounts, Instruction5IxData), - Instruction6(Instruction6IxAccounts, Instruction6IxData), - Instruction7(Instruction7IxAccounts, Instruction7IxData), + Instruction6(Instruction6IxAccounts), + Instruction7(Instruction7IxAccounts), } #[derive(Debug, Copy, Clone)] @@ -71,7 +71,6 @@ impl InstructionParser { let accounts_len = ix.accounts.len(); let ix_discriminator: [u8; 1] = ix.data[0..1].try_into()?; let mut ix_data = &ix.data[1..]; - match ix_discriminator { [42] => { check_min_accounts_req(accounts_len, 0)?; diff --git a/packages/renderers-vixen-parser/e2e/memo/src/generated/instructions_parser.rs b/packages/renderers-vixen-parser/e2e/memo/src/generated/instructions_parser.rs index 770f4043..19a20734 100644 --- a/packages/renderers-vixen-parser/e2e/memo/src/generated/instructions_parser.rs +++ b/packages/renderers-vixen-parser/e2e/memo/src/generated/instructions_parser.rs @@ -61,12 +61,10 @@ impl InstructionParser { let accounts_len = ix.accounts.len(); let ix_discriminator: [u8; 1] = ix.data[0..1].try_into()?; let mut ix_data = &ix.data[1..]; - - match ix_discriminator { - _ => Err(yellowstone_vixen_core::ParseError::from( - "Invalid Instruction discriminator".to_owned(), - )), - } + check_min_accounts_req(accounts_len, 0)?; + let de_ix_data: AddMemoIxData = BorshDeserialize::deserialize(&mut ix_data)?; + let ix_accounts = AddMemoIxAccounts {}; + Ok(MemoProgramIx::AddMemo(ix_accounts, de_ix_data)) } } diff --git a/packages/renderers-vixen-parser/e2e/system/src/generated/instructions_parser.rs b/packages/renderers-vixen-parser/e2e/system/src/generated/instructions_parser.rs index 3d1e0e9d..bbb7d79a 100644 --- a/packages/renderers-vixen-parser/e2e/system/src/generated/instructions_parser.rs +++ b/packages/renderers-vixen-parser/e2e/system/src/generated/instructions_parser.rs @@ -96,7 +96,6 @@ impl InstructionParser { let accounts_len = ix.accounts.len(); let ix_discriminator: [u8; 1] = ix.data[0..1].try_into()?; let mut ix_data = &ix.data[1..]; - match ix_discriminator { [0] => { check_min_accounts_req(accounts_len, 2)?; diff --git a/packages/renderers-vixen-parser/public/templates/accountsParserPage.njk b/packages/renderers-vixen-parser/public/templates/accountsParserPage.njk index 62c70309..1f1a1821 100644 --- a/packages/renderers-vixen-parser/public/templates/accountsParserPage.njk +++ b/packages/renderers-vixen-parser/public/templates/accountsParserPage.njk @@ -11,7 +11,7 @@ #[derive(Debug)] pub enum {{ programName | pascalCase }}ProgramState { {% for account in accounts %} - {{ account.name | pascalCase }}({{ account.name | pascalCase }}), + {{ account.name | pascalCase }}({{ account.name | pascalCase }}), {% endfor %} } @@ -20,16 +20,14 @@ impl {{ programName | pascalCase }}ProgramState { let data_len = data_bytes.len(); match data_len { {% for account in accounts %} - {{ account.name | pascalCase }}::LEN => Ok( - {{ programName | pascalCase }}ProgramState::{{ account.name | pascalCase }}( - {{ account.name | pascalCase }}::from_bytes(data_bytes)? - ) - ), + {{ account.name | pascalCase }}::LEN => Ok( + {{ programName | pascalCase }}ProgramState::{{ account.name | pascalCase }}( + {{ account.name | pascalCase }}::from_bytes(data_bytes)? + ) + ), {% endfor %} _ => Err(yellowstone_vixen_core::ParseError::from("Invalid Account data length".to_owned())), } - - } } diff --git a/packages/renderers-vixen-parser/public/templates/instructionsParserPage.njk b/packages/renderers-vixen-parser/public/templates/instructionsParserPage.njk index b9aec9bf..aff5d878 100644 --- a/packages/renderers-vixen-parser/public/templates/instructionsParserPage.njk +++ b/packages/renderers-vixen-parser/public/templates/instructionsParserPage.njk @@ -9,7 +9,11 @@ #[derive(Debug)] pub enum {{ programName | pascalCase }}ProgramIx { {% for instruction in instructions %} - {{ instruction.name | pascalCase }}({{ instruction.name | pascalCase }}IxAccounts, {{ instruction.name | pascalCase }}IxData), + {% if instruction.hasArgs %} + {{ instruction.name | pascalCase }}({{ instruction.name | pascalCase }}IxAccounts, {{ instruction.name | pascalCase }}IxData), + {% else %} + {{ instruction.name | pascalCase }}({{ instruction.name | pascalCase }}IxAccounts), + {% endif %} {% endfor %} } @@ -52,27 +56,34 @@ impl InstructionParser { let accounts_len = ix.accounts.len(); let ix_discriminator:[u8; {{ IX_DATA_OFFSET }}] = ix.data[0..{{ IX_DATA_OFFSET }}].try_into()?; let mut ix_data = &ix.data[{{ IX_DATA_OFFSET }}..]; - - match ix_discriminator { - {% for instruction in instructions %} - {% if instruction.discriminator != null %} - {{ instruction.discriminator }} => { - check_min_accounts_req(accounts_len, {{ instruction.accounts | length }})?; - let de_ix_data:{{ instruction.name | pascalCase }}IxData = BorshDeserialize::deserialize(&mut ix_data)?; - let ix_accounts = {{ instruction.name | pascalCase }}IxAccounts{ - {% for account in instruction.accounts %} - {{ account.name | snakeCase }}: ix.accounts[{{ account.index }}], - {% endfor %} - }; - Ok({{ programName | pascalCase }}ProgramIx::{{ instruction.name | pascalCase }}(ix_accounts, de_ix_data)) - - - }, - {% endif %} - {% endfor %} - _ => Err(yellowstone_vixen_core::ParseError::from("Invalid Instruction discriminator".to_owned())), - } - + {% if hasDiscriminator %} + match ix_discriminator { + {% for instruction in instructions %} + {% if instruction.discriminator != null %} + {{ instruction.discriminator }} => { + check_min_accounts_req(accounts_len, {{ instruction.accounts | length }})?; + let de_ix_data:{{ instruction.name | pascalCase }}IxData = BorshDeserialize::deserialize(&mut ix_data)?; + let ix_accounts = {{ instruction.name | pascalCase }}IxAccounts{ + {% for account in instruction.accounts %} + {{ account.name | snakeCase }}: ix.accounts[{{ account.index }}], + {% endfor %} + }; + Ok({{ programName | pascalCase }}ProgramIx::{{ instruction.name | pascalCase }}(ix_accounts, de_ix_data)) + }, + {% endif %} + {% endfor %} + _ => Err(yellowstone_vixen_core::ParseError::from("Invalid Instruction discriminator".to_owned())), + } + {% else %} + check_min_accounts_req(accounts_len, {{ instructions[0].accounts | length }})?; + let de_ix_data:{{ instructions[0].name | pascalCase }}IxData = BorshDeserialize::deserialize(&mut ix_data)?; + let ix_accounts = {{ instructions[0].name | pascalCase }}IxAccounts{ + {% for account in instructions[0].accounts %} + {{ account.name | snakeCase }}: ix.accounts[{{ account.index }}], + {% endfor %} + }; + Ok({{ programName | pascalCase }}ProgramIx::{{ instructions[0].name | pascalCase }}(ix_accounts, de_ix_data)) + {% endif %} } } diff --git a/packages/renderers-vixen-parser/src/getRenderMapVisitor.ts b/packages/renderers-vixen-parser/src/getRenderMapVisitor.ts index 67907cf3..c456c954 100644 --- a/packages/renderers-vixen-parser/src/getRenderMapVisitor.ts +++ b/packages/renderers-vixen-parser/src/getRenderMapVisitor.ts @@ -115,7 +115,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { accounts.forEach(acc => { accountParserImports.add( - `${codamaSdkName}::accounts::{${acc.name}::${toPascalCase(acc.name)}}`, + `${codamaSdkName}::accounts::{${toSnakeCase(acc.name)}::${fromCamelToPascalCase(acc.name)}}`, ); }); @@ -151,6 +151,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { imports: instructionParserImports, programName, accounts, + hasDiscriminator: instructions.some(ix => ix.discriminator !== null), instructions, IX_DATA_OFFSET, };