1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
extern crate nitrate_macro;
pub use *;
/// Declare the program entrypoint and set up global handlers.
///
/// The main difference from the standard `entrypoint!` macro is that this macro represents an
/// entrypoint that does not perform allocattions or copies when reading the input buffer.
///
/// This macro emits the common boilerplate necessary to begin program execution, calling a
/// provided function to process the program instruction supplied by the runtime, and reporting
/// its result to the runtime.
///
/// It also sets up a [global allocator] and [panic handler], using the [`custom_heap_default`]
/// and [`custom_panic_default`] macros from the [`solana_program`] crate.
///
/// [`custom_heap_default`]: https://docs.rs/solana-program/latest/solana_program/macro.custom_heap_default.html
/// [`custom_panic_default`]: https://docs.rs/solana-program/latest/solana_program/macro.custom_panic_default.html
/// [`solana_program`]: https://docs.rs/solana-program/latest/solana_program/index.html
///
/// The first argument is the name of a function with this type signature:
///
/// ```ignore
/// fn process_instruction(
/// program_id: &Pubkey, // Public key of the account the program was loaded into
/// accounts: &[AccountInfo], // All accounts required to process the instruction
/// instruction_data: &[u8], // Serialized instruction-specific data
/// ) -> ProgramResult;
/// ```
///
/// The second argument is the maximum number of accounts that the program is expecting. A program
/// can receive more than the specified maximum, but any account exceeding the maximum will be
/// ignored.
///
/// # Examples
///
/// Defining an entrypoint which reads up to 10 accounts and making it conditional on the
/// `no-entrypoint` feature. Although the `entrypoint` module is written inline in this example,
/// it is common to put it into its own file.
///
/// ```no_run
/// #[cfg(not(feature = "no-entrypoint"))]
/// pub mod entrypoint {
///
/// use nitrate::{entrypoint, program::AccountInfo};
/// use solana_program::{
/// entrypoint::ProgramResult,
/// msg,
/// pubkey::Pubkey,
/// };
///
/// entrypoint!(process_instruction, 10);
///
/// pub fn process_instruction(
/// program_id: &Pubkey,
/// accounts: &[AccountInfo],
/// instruction_data: &[u8],
/// ) -> ProgramResult {
/// msg!("Hello from my program!");
///
/// Ok(())
/// }
///
/// }
/// ```