Skip to content

Commit dbc90a2

Browse files
committed
Add anchorTraits option
1 parent d98b51a commit dbc90a2

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

packages/renderers-rust/public/templates/accountsPage.njk

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,35 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for {{ account.
128128
}
129129
}
130130

131-
#[cfg(feature = "anchor")]
132-
impl anchor_lang::AccountDeserialize for {{ account.name | pascalCase }} {
133-
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
134-
Ok(Self::deserialize(buf)?)
135-
}
136-
}
131+
{% if anchorTraits %}
132+
#[cfg(feature = "anchor")]
133+
impl anchor_lang::AccountDeserialize for {{ account.name | pascalCase }} {
134+
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
135+
Ok(Self::deserialize(buf)?)
136+
}
137+
}
137138

138-
#[cfg(feature = "anchor")]
139-
impl anchor_lang::AccountSerialize for {{ account.name | pascalCase }} {}
139+
#[cfg(feature = "anchor")]
140+
impl anchor_lang::AccountSerialize for {{ account.name | pascalCase }} {}
140141

141-
#[cfg(feature = "anchor")]
142-
impl anchor_lang::Owner for {{ account.name | pascalCase }} {
143-
fn owner() -> Pubkey {
144-
crate::{{ program.name | snakeCase | upper }}_ID
145-
}
146-
}
142+
#[cfg(feature = "anchor")]
143+
impl anchor_lang::Owner for {{ account.name | pascalCase }} {
144+
fn owner() -> Pubkey {
145+
crate::{{ program.name | snakeCase | upper }}_ID
146+
}
147+
}
147148

148-
#[cfg(feature = "anchor-idl-build")]
149-
impl anchor_lang::IdlBuild for {{ account.name | pascalCase }} {}
149+
#[cfg(feature = "anchor-idl-build")]
150+
impl anchor_lang::IdlBuild for {{ account.name | pascalCase }} {}
150151

151-
{#
152-
This is not used for the IDL generation since default `IdlBuild` impl doesn't include
153-
the type in the IDL but it stil needs to be added in order to make compilation work.
154-
#}
155-
#[cfg(feature = "anchor-idl-build")]
156-
impl anchor_lang::Discriminator for {{ account.name | pascalCase }} {
157-
const DISCRIMINATOR: [u8; 8] = [0; 8];
158-
}
152+
{#
153+
This is not used for the IDL generation since default `IdlBuild` impl doesn't include
154+
the type in the IDL but it stil needs to be added in order to make compilation work.
155+
#}
156+
#[cfg(feature = "anchor-idl-build")]
157+
impl anchor_lang::Discriminator for {{ account.name | pascalCase }} {
158+
const DISCRIMINATOR: [u8; 8] = [0; 8];
159+
}
160+
{% endif %}
159161

160162
{% endblock %}

packages/renderers-rust/src/getRenderMapVisitor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export type GetRenderMapOptions = {
3535
linkOverrides?: LinkOverrides;
3636
renderParentInstructions?: boolean;
3737
traitOptions?: TraitOptions;
38+
anchorTraits?: boolean;
3839
};
3940

4041
export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {
@@ -46,6 +47,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {
4647
const getImportFrom = getImportFromFactory(options.linkOverrides ?? {});
4748
const getTraitsFromNode = getTraitsFromNodeFactory(options.traitOptions);
4849
const typeManifestVisitor = getTypeManifestVisitor({ getImportFrom, getTraitsFromNode });
50+
const anchorTraits = options.anchorTraits ?? true;
4951

5052
return pipe(
5153
staticVisitor(
@@ -101,6 +103,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {
101103
program,
102104
seeds,
103105
typeManifest,
106+
anchorTraits,
104107
}),
105108
);
106109
},

0 commit comments

Comments
 (0)