lang: Fix using defined types in instruction parameters with `declare_program!` (#2959)
This commit is contained in:
parent
d8d007eb89
commit
460a16171a
|
@ -25,6 +25,7 @@ The minor version will be incremented upon a breaking change and the patch versi
|
|||
- cli: add filename to 'Unable to read keypair file' errors ([#2932](https://github.com/coral-xyz/anchor/pull/2932)).
|
||||
- idl: Fix path resolution of the `Cargo.lock` of the project when generating idls for external types ([#2946](https://github.com/coral-xyz/anchor/pull/2946)).
|
||||
- idl: Fix potential panic on external type resolution ([#2954](https://github.com/coral-xyz/anchor/pull/2954)).
|
||||
- lang: Fix using defined types in instruction parameters with `declare_program!` ([#2959](https://github.com/coral-xyz/anchor/pull/2959)).
|
||||
|
||||
### Breaking
|
||||
|
||||
|
|
|
@ -73,6 +73,9 @@ fn gen_program(idl: &Idl, name: &syn::Ident) -> proc_macro2::TokenStream {
|
|||
#docs
|
||||
pub mod #name {
|
||||
use anchor_lang::prelude::*;
|
||||
use accounts::*;
|
||||
use events::*;
|
||||
use types::*;
|
||||
|
||||
#id
|
||||
#program_mod
|
||||
|
|
|
@ -110,7 +110,7 @@ pub fn gen_accounts_mod(idl: &Idl) -> proc_macro2::TokenStream {
|
|||
quote! {
|
||||
/// Program account type definitions.
|
||||
pub mod accounts {
|
||||
use super::{*, types::*};
|
||||
use super::*;
|
||||
|
||||
#(#accounts)*
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ pub fn gen_events_mod(idl: &Idl) -> proc_macro2::TokenStream {
|
|||
quote! {
|
||||
/// Program event type definitions.
|
||||
pub mod events {
|
||||
use super::{*, types::*};
|
||||
use super::*;
|
||||
|
||||
#(#events)*
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ fn gen_event(idl: &Idl) -> proc_macro2::TokenStream {
|
|||
});
|
||||
|
||||
quote! {
|
||||
use super::{*, events::*};
|
||||
use super::*;
|
||||
|
||||
/// An enum that includes all events of the declared program as a tuple variant.
|
||||
///
|
||||
|
|
|
@ -81,6 +81,47 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "update_all",
|
||||
"discriminator": [
|
||||
205,
|
||||
139,
|
||||
239,
|
||||
66,
|
||||
134,
|
||||
131,
|
||||
110,
|
||||
182
|
||||
],
|
||||
"accounts": [
|
||||
{
|
||||
"name": "authority",
|
||||
"signer": true
|
||||
},
|
||||
{
|
||||
"name": "my_account",
|
||||
"writable": true,
|
||||
"pda": {
|
||||
"seeds": [
|
||||
{
|
||||
"kind": "account",
|
||||
"path": "authority"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "my_account",
|
||||
"type": {
|
||||
"defined": {
|
||||
"name": "MyAccount"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "update_composite",
|
||||
"discriminator": [
|
||||
|
|
|
@ -19,6 +19,12 @@ pub mod external {
|
|||
ctx.accounts.update.my_account.field = value;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Compilation test for whether a defined type (an account in this case) can be used in `cpi` client.
|
||||
pub fn update_all(ctx: Context<Update>, my_account: MyAccount) -> Result<()> {
|
||||
*ctx.accounts.my_account = my_account;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Accounts)]
|
||||
|
|
Loading…
Reference in New Issue