Skip to content

Commit

Permalink
✨ Group together instruction calls within transaction macro
Browse files Browse the repository at this point in the history
  • Loading branch information
lukacan committed Feb 24, 2025
1 parent 80812b4 commit 828d320
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions crates/syn/src/codegen/trident_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ impl ToTokens for TridentTransactionStruct {
None => quote! { stringify!(#name).to_string() },
};

// Generate instruction blocks for each field
let instruction_blocks = self.fields.iter().map(|f| {
let field_ident = &f.ident;
quote! {
{
self.#field_ident.resolve_accounts(client, fuzz_accounts);
self.#field_ident.set_accounts(client, fuzz_accounts);
self.#field_ident.set_remaining_accounts(client, fuzz_accounts);
}
}
});

let expanded = quote! {
impl TransactionMethods for #name {
type IxAccounts = FuzzAccounts;
Expand Down Expand Up @@ -50,9 +62,7 @@ impl ToTokens for TridentTransactionStruct {
client: &mut impl FuzzClient,
fuzz_accounts: &mut FuzzAccounts,
) -> Vec<Vec<AccountMeta>> {
#(self.#field_idents.resolve_accounts(client, fuzz_accounts);)*
#(self.#field_idents.set_accounts(client, fuzz_accounts);)*
#(self.#field_idents.set_remaining_accounts(client, fuzz_accounts);)*
#(#instruction_blocks)*
vec![
#(self.#field_idents.to_account_metas()),*
]
Expand Down

0 comments on commit 828d320

Please sign in to comment.