Skip to content

Commit

Permalink
cleanup docs and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Dec 16, 2023
1 parent 96c9437 commit 6c5d5f5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
29 changes: 29 additions & 0 deletions lang/attribute/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@ pub fn program(
/// The `#[interface]` attribute is used to mark an instruction as belonging
/// to an interface implementation, thus transforming its discriminator to the
/// proper bytes for that interface instruction.
///
/// # Example
///
/// ```rust,ignore
/// use anchor_lang::prelude::*;
///
/// // SPL Transfer Hook Interface: `Execute` instruction.
/// //
/// // This instruction is invoked by Token-2022 when a transfer occurs,
/// // if a mint has specified this program as its transfer hook.
/// #[interface(spl_transfer_hook_interface::execute)]
/// pub fn execute_transfer(ctx: Context<Execute>, amount: u64) -> Result<()> {
/// // Check that all extra accounts were provided
/// let data = ctx.accounts.extra_metas_account.try_borrow_data()?;
/// ExtraAccountMetaList::check_account_infos::<ExecuteInstruction>(
/// &ctx.accounts.to_account_infos(),
/// &TransferHookInstruction::Execute { amount }.pack(),
/// &ctx.program_id,
/// &data,
/// )?;
///
/// // Or maybe perform some custom logic
/// if ctx.accounts.token_metadata.mint != ctx.accounts.token_account.mint {
/// return Err(ProgramError::IncorrectAccount);
/// }
///
/// Ok(())
/// }
/// ```
#[cfg(feature = "interface-instructions")]
#[proc_macro_attribute]
pub fn interface(
Expand Down
1 change: 0 additions & 1 deletion tests/spl/transfer-hook/programs/transfer-hook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ pub struct Initialize<'info> {
}

#[derive(Accounts)]
#[instruction(amount: u64)]
pub struct Execute<'info> {
#[account(
token::mint = mint,
Expand Down
1 change: 0 additions & 1 deletion ts/packages/anchor/src/program/namespace/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export class MethodsBuilder<IDL extends Idl, I extends AllInstructions<IDL>> {
>;
}

// TODO: Remove the hard-coded discriminators once we have a JS package for Transfer Hook
public interface(splInterface: SplInterface): MethodsBuilder<IDL, I> {
if (
splInterface ===
Expand Down

0 comments on commit 6c5d5f5

Please sign in to comment.