only add public enums to the IDL (#2310)

Co-authored-by: henrye <henry@notanemail>
This commit is contained in:
Henry-E 2022-12-12 16:10:47 +00:00 committed by GitHub
parent 7527033c7b
commit 03eff348db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -46,6 +46,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- lang: Prevent the payer account from being initialized as a program account ([#2284](https://github.com/coral-xyz/anchor/pull/2284)).
- ts: Fixing breaking change where null or undefined wallet throws an error ([#2303](https://github.com/coral-xyz/anchor/pull/2303)).
- ts: Fixed `.fetchNullable()` to be robust towards accounts only holding a balance ([#2301](https://github.com/coral-xyz/anchor/pull/2301)).
- lang: Only add public enums to the IDL ([#2309](https://github.com/coral-xyz/anchor/pull/2309)).
### Breaking

View File

@ -484,7 +484,12 @@ fn parse_ty_defs(ctx: &CrateContext, no_docs: bool) -> Result<Vec<IdlTypeDefinit
ty: IdlTypeDefinitionTy::Struct { fields },
}))
})
.chain(ctx.enums().map(|enm| {
.chain(ctx.enums().filter_map(|enm| {
// Only take public types
match &enm.vis {
syn::Visibility::Public(_) => (),
_ => return None,
}
let name = enm.ident.to_string();
let doc = if !no_docs {
docs::parse(&enm.attrs)
@ -531,11 +536,11 @@ fn parse_ty_defs(ctx: &CrateContext, no_docs: bool) -> Result<Vec<IdlTypeDefinit
IdlEnumVariant { name, fields }
})
.collect::<Vec<IdlEnumVariant>>();
Ok(IdlTypeDefinition {
Some(Ok(IdlTypeDefinition {
name,
docs: doc,
ty: IdlTypeDefinitionTy::Enum { variants },
})
}))
}))
.collect()
}