diff --git a/cli/src/main.rs b/cli/src/main.rs index 4b8440b3..a88e2fe8 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -921,12 +921,12 @@ fn test(skip_deploy: bool, skip_local_validator: bool, file: Option) -> } }; - let log_streams = stream_logs(&cfg.cluster.url())?; + // Setup log reader. + let log_streams = stream_logs(&cfg.cluster.url()); - let result: Result<_> = { + // Run the tests. + let test_result: Result<_> = { let ts_config_exist = Path::new("tsconfig.json").exists(); - - // Run the tests. let mut args = vec!["-t", "1000000"]; if let Some(ref file) = file { args.push(file); @@ -959,19 +959,18 @@ fn test(skip_deploy: bool, skip_local_validator: bool, file: Option) -> exit }; + // Check all errors and shut down. if let Some(mut child) = validator_handle { if let Err(err) = child.kill() { println!("Failed to kill subprocess {}: {}", child.id(), err); } } - - for mut child in log_streams { + for mut child in log_streams? { if let Err(err) = child.kill() { println!("Failed to kill subprocess {}: {}", child.id(), err); } } - - match result { + match test_result { Ok(exit) => { if !exit.status.success() { std::process::exit(exit.status.code().unwrap()); diff --git a/client/src/lib.rs b/client/src/lib.rs index 9f45a9fb..27b22875 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -120,7 +120,7 @@ impl Program { self.program_id } - pub fn on( + pub fn on( &self, f: impl Fn(&EventContext, T) -> () + Send + 'static, ) -> Result { @@ -187,7 +187,7 @@ impl Program { } } -fn handle_program_log( +fn handle_program_log( self_program_str: &str, l: &str, ) -> Result<(Option, Option, bool), ClientError> { diff --git a/lang/attribute/event/src/lib.rs b/lang/attribute/event/src/lib.rs index 59c6207f..e347d661 100644 --- a/lang/attribute/event/src/lib.rs +++ b/lang/attribute/event/src/lib.rs @@ -26,10 +26,10 @@ pub fn event( }; proc_macro::TokenStream::from(quote! { - #[derive(anchor_lang::EventIndex, AnchorSerialize, AnchorDeserialize)] + #[derive(anchor_lang::__private::EventIndex, AnchorSerialize, AnchorDeserialize)] #event_strct - impl anchor_lang::EventData for #event_name { + impl anchor_lang::Event for #event_name { fn data(&self) -> Vec { let mut d = #discriminator.to_vec(); d.append(&mut self.try_to_vec().unwrap()); @@ -45,16 +45,16 @@ pub fn event( }) } -/// Creates an event in an Anchor program, which can subsequently be subscribed -/// to by clients. Calling this method will internally borsh serialize the -/// [event](./attr.event.html), base64 encode the bytes, and then add a -/// [msg!](../solana_program/macro.msg.html) log to the transaction. +/// Creates an event that can be subscribed to by clients. Calling this method +/// will internally borsh serialize the [event](./attr.event.html), base64 +/// encode the bytes, and then add a [msg!](../solana_program/macro.msg.html) +/// log to the transaction. #[proc_macro] pub fn emit(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let data: proc_macro2::TokenStream = input.into(); proc_macro::TokenStream::from(quote! { { - let data = anchor_lang::EventData::data(&#data); + let data = anchor_lang::Event::data(&#data); let msg_str = &anchor_lang::__private::base64::encode(data); anchor_lang::solana_program::msg!(msg_str); } diff --git a/lang/src/context.rs b/lang/src/context.rs index 5000250b..44082045 100644 --- a/lang/src/context.rs +++ b/lang/src/context.rs @@ -9,6 +9,7 @@ pub struct Context<'a, 'b, 'c, 'info, T> { /// Deserialized accounts. pub accounts: &'b mut T, /// Remaining accounts given but not deserialized or validated. + /// Be very careful when using this directly. pub remaining_accounts: &'c [AccountInfo<'info>], } diff --git a/lang/src/error.rs b/lang/src/error.rs index 7c94c761..66342d58 100644 --- a/lang/src/error.rs +++ b/lang/src/error.rs @@ -1,5 +1,7 @@ use solana_program::program_error::ProgramError; +// Error type that can be returned by internal framework code. +#[doc(hidden)] #[derive(thiserror::Error, Debug)] pub enum Error { #[error(transparent)] diff --git a/lang/src/idl.rs b/lang/src/idl.rs index fcb1086c..279ae4f1 100644 --- a/lang/src/idl.rs +++ b/lang/src/idl.rs @@ -1,4 +1,4 @@ -//! idl.rs defines the instructions and account state used to store a program's +//! Defines the instructions and account state used to store a program's //! IDL on-chain at a canonical account address, which can be derived as a //! function of nothing other than the program's ID. //! diff --git a/lang/src/lib.rs b/lang/src/lib.rs index d1e95110..c6c253e0 100644 --- a/lang/src/lib.rs +++ b/lang/src/lib.rs @@ -35,6 +35,7 @@ mod context; mod cpi_account; mod ctor; mod error; +#[doc(hidden)] pub mod idl; mod program_account; mod state; @@ -44,26 +45,27 @@ mod vec; // Internal module used by macros. #[doc(hidden)] pub mod __private { + pub use crate::ctor::Ctor; + pub use crate::error::Error; + pub use anchor_attribute_event::EventIndex; pub use base64; } pub use crate::context::{Context, CpiContext}; pub use crate::cpi_account::CpiAccount; -pub use crate::ctor::Ctor; pub use crate::program_account::ProgramAccount; pub use crate::state::ProgramState; pub use crate::sysvar::Sysvar; pub use anchor_attribute_access_control::access_control; pub use anchor_attribute_account::account; pub use anchor_attribute_error::error; -pub use anchor_attribute_event::{emit, event, EventIndex}; +pub use anchor_attribute_event::{emit, event}; pub use anchor_attribute_interface::interface; pub use anchor_attribute_program::program; pub use anchor_attribute_state::state; pub use anchor_derive_accounts::Accounts; /// Borsh is the default serialization format for instructions and accounts. pub use borsh::{BorshDeserialize as AnchorDeserialize, BorshSerialize as AnchorSerialize}; -pub use error::Error; pub use solana_program; /// A data structure of validated accounts that can be deserialized from the @@ -176,18 +178,27 @@ pub trait InstructionData: AnchorSerialize { fn data(&self) -> Vec; } -/// Calculates the size of an account, which may be larger than the deserialized -/// data in it. This trait is currently only used for `#[state]` accounts. +// Calculates the size of an account, which may be larger than the deserialized +// data in it. This trait is currently only used for `#[state]` accounts. +#[doc(hidden)] pub trait AccountSize: AnchorSerialize { fn size(&self) -> Result; } -/// The serialized event data to be emitted via a Solana log. +/// An event that can be emitted via a Solana log. +pub trait Event: AnchorSerialize + AnchorDeserialize + Discriminator { + fn data(&self) -> Vec; +} + +// The serialized event data to be emitted via a Solana log. +// TODO: remove this on the next major version upgrade. +#[doc(hidden)] +#[deprecated(since = "0.4.2", note = "Please use Event instead")] pub trait EventData: AnchorSerialize + Discriminator { fn data(&self) -> Vec; } -/// 8 byte identifier for a type. +/// 8 byte unique identifier for a type. pub trait Discriminator { fn discriminator() -> [u8; 8]; } @@ -198,7 +209,7 @@ pub mod prelude { pub use super::{ access_control, account, emit, error, event, interface, program, state, AccountDeserialize, AccountSerialize, Accounts, AccountsExit, AccountsInit, AnchorDeserialize, AnchorSerialize, - Context, CpiAccount, CpiContext, Ctor, ProgramAccount, ProgramState, Sysvar, ToAccountInfo, + Context, CpiAccount, CpiContext, ProgramAccount, ProgramState, Sysvar, ToAccountInfo, ToAccountInfos, ToAccountMetas, }; diff --git a/lang/syn/src/codegen/program.rs b/lang/syn/src/codegen/program.rs index c7b8e1e2..c68a27a9 100644 --- a/lang/syn/src/codegen/program.rs +++ b/lang/syn/src/codegen/program.rs @@ -401,7 +401,7 @@ pub fn generate_non_inlined_handlers(program: &Program) -> proc_macro2::TokenStr let mut remaining_accounts: &[AccountInfo] = accounts; // Deserialize accounts. - let ctor_accounts = anchor_lang::Ctor::try_accounts(program_id, &mut remaining_accounts)?; + let ctor_accounts = anchor_lang::__private::Ctor::try_accounts(program_id, &mut remaining_accounts)?; let mut ctor_user_def_accounts = #anchor_ident::try_accounts(program_id, &mut remaining_accounts)?; // Invoke the ctor.