Skip to content

Commit 2d57e10

Browse files
committed
Improve comments
1 parent 7c9d9bc commit 2d57e10

5 files changed

Lines changed: 74 additions & 197 deletions

File tree

program/src/assertions.rs

Lines changed: 0 additions & 182 deletions
This file was deleted.

program/src/instruction.rs

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use pinocchio::program_error::ProgramError;
22

3+
/// Instructions supported by the program metadata program.
34
#[derive(Clone, Copy, Debug)]
45
pub enum ProgramMetadataInstruction {
56
/// Writes data to a pre-funded buffer.
@@ -45,7 +46,7 @@ pub enum ProgramMetadataInstruction {
4546
/// - `u8`: compression
4647
/// - `u8`: format
4748
/// - `u8`: data source
48-
/// - `[u8]`: (optional) bytes
49+
/// - `[u8]`: (optional) bytes to write
4950
Initialize,
5051

5152
/// Sets the authority of a buffer or metadata account.
@@ -55,13 +56,20 @@ pub enum ProgramMetadataInstruction {
5556
/// required.
5657
///
5758
/// Special cases:
58-
/// - It is not possible to set an authority if the metadata account
59-
/// is non-canonical, otherwise the derivation becomes invalid.
60-
/// - It is not possible to set an authority if the metadata account
61-
/// is immutable.
62-
/// - If no new authority is provided for a metadata account, the
63-
/// authority is removed.
64-
/// - It is not possible to remove the authority of a buffer account.
59+
/// - It is not possible to set an authority if the metadata account
60+
/// is non-canonical, otherwise the derivation becomes invalid.
61+
/// - It is not possible to set an authority if the metadata account
62+
/// is immutable.
63+
/// - If no new authority is provided for a metadata account, the
64+
/// authority is removed. For canonical metadata accounts, the program
65+
/// upgrade authority will still be able to manage the account.
66+
/// - It is not possible to remove the authority of a buffer account.
67+
///
68+
/// There are 2 optional accounts:
69+
/// - `program`: required to validate whether the authority is the program upgrade
70+
/// authority.
71+
/// - `program_data`: required to validate whether the authority is the program upgrade
72+
/// authority.
6573
///
6674
/// Accounts expected by this instruction:
6775
///
@@ -76,7 +84,7 @@ pub enum ProgramMetadataInstruction {
7684
/// - `[u8; 32]`: (optional) new authority
7785
SetAuthority,
7886

79-
/// Sets the data and its metadata.
87+
/// Sets the data to a program metadata account.
8088
///
8189
/// The data can be provided as instruction data or copied from a buffer
8290
/// account. When setting the data to a `canonical` metadata account
@@ -85,6 +93,13 @@ pub enum ProgramMetadataInstruction {
8593
///
8694
/// Note: It is not possible to set data if the account is immutable.
8795
///
96+
/// There are 2 optional accounts:
97+
/// - `buffer`: used to specify the data to be copied.
98+
/// - `program`: required to validate whether the authority is the program upgrade
99+
/// authority.
100+
/// - `program_data`: required to validate whether the authority is the program upgrade
101+
/// authority.
102+
///
88103
/// Accounts expected by this instruction:
89104
///
90105
/// 0. `[w]` Metadata account.
@@ -99,11 +114,17 @@ pub enum ProgramMetadataInstruction {
99114
/// - `u8`: compression
100115
/// - `u8`: format
101116
/// - `u8`: data source
102-
/// - `[u8]`: (optional) bytes
117+
/// - `[u8]`: (optional) bytes to write
103118
SetData,
104119

105120
/// Sets the metadata account as immutable.
106121
///
122+
/// There are 2 optional accounts:
123+
/// - `program`: required to validate whether the authority is the program upgrade
124+
/// authority.
125+
/// - `program_data`: required to validate whether the authority is the program upgrade
126+
/// authority.
127+
///
107128
/// Accounts expected by this instruction:
108129
///
109130
/// 0. `[w]` Metadata account.
@@ -112,12 +133,18 @@ pub enum ProgramMetadataInstruction {
112133
/// 3. `[o]` (optional) Program data account.
113134
SetImmutable,
114135

115-
/// Withdraws excess lamports from a buffer or metadata account.
136+
/// Resizes and withdraws excess lamports from a buffer or metadata account.
116137
///
117138
/// This instruction will attempt to resize the account to its
118139
/// minimum size required to be rent exempt, returning any extra
119140
/// lamports to the `destination` account.
120141
///
142+
/// There are 2 optional accounts:
143+
/// - `program`: required to validate whether the authority is the program upgrade
144+
/// authority.
145+
/// - `program_data`: required to validate whether the authority is the program upgrade
146+
/// authority.
147+
///
121148
/// Accounts expected by this instruction:
122149
///
123150
/// 0. `[w]` Buffer or metadata account.
@@ -128,14 +155,20 @@ pub enum ProgramMetadataInstruction {
128155
/// 6. `[]` Rent sysvar account.
129156
Trim,
130157

131-
/// Closes a program-owned account.
158+
/// Closes a program-owned buffer or metadata account.
132159
///
133160
/// The lamports in the metadata account are transferred to the destination
134161
/// account.
135162
///
136163
/// Note: It is not possible to close a metadata account if the account
137164
/// is immutable.
138165
///
166+
/// There are 2 optional accounts:
167+
/// - `program`: required to validate whether the authority is the program upgrade
168+
/// authority.
169+
/// - `program_data`: required to validate whether the authority is the program upgrade
170+
/// authority.
171+
///
139172
/// Accounts expected by this instruction:
140173
///
141174
/// 0. `[w]` Account to close.
@@ -157,6 +190,14 @@ pub enum ProgramMetadataInstruction {
157190
///
158191
/// A `seed` value is required for PDA buffer accounts.
159192
///
193+
/// There are 2 optional accounts:
194+
/// - `program`: required to validate whether the authority is the program upgrade
195+
/// authority.
196+
/// - `program_data`: required to validate whether the authority is the program upgrade
197+
/// authority.
198+
/// - `system_program`: required to allocate the account. When using a pre-allocated buffer,
199+
/// this is not required.
200+
///
160201
/// Accounts expected by this instruction:
161202
///
162203
/// 0. `[w]` Buffer account to allocate.
@@ -170,11 +211,17 @@ pub enum ProgramMetadataInstruction {
170211
/// - `[u8; 16]`: seed (optional)
171212
Allocate,
172213

173-
/// Extends the buffer or metadata account data by the requested length.
214+
/// Extends a buffer or metadata account data by the requested length.
174215
///
175216
/// The account is expected to be pre-funded with the required lamports
176217
/// for the new size.
177218
///
219+
/// There are 2 optional accounts:
220+
/// - `program`: required to validate whether the authority is the program upgrade
221+
/// authority.
222+
/// - `program_data`: required to validate whether the authority is the program upgrade
223+
/// authority.
224+
///
178225
/// Accounts expected by this instruction:
179226
///
180227
/// 0. `[w]` Buffer or metadata account.

program/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! A program to store metadata information for programs.
2+
13
#![no_std]
24

35
pub mod entrypoint;

program/src/state/buffer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ pub struct Buffer {
3434
/// Only for buffer PDA accounts; otherwise `[0u8; 16]`.
3535
pub seed: [u8; SEED_LEN],
3636

37-
// Extra padding for alignment.
37+
/// Extra padding for alignment.
38+
///
39+
/// This makes the `Buffer` header section to be the same size as
40+
/// the metadata [`Header`](`super::Header`).
3841
_padding: [u8; 14],
3942
}
4043

0 commit comments

Comments
 (0)