diff --git a/token/program2/src/instruction.rs b/token/program2/src/instruction.rs index 7320d26bd61..e48082eb861 100644 --- a/token/program2/src/instruction.rs +++ b/token/program2/src/instruction.rs @@ -33,9 +33,9 @@ pub enum TokenInstruction { amount: u64, /// Number of base 10 digits to the right of the decimal place. decimals: u8, - /// The mint-tokens authority/multisignature of the mint if supply is non-zero. If present, + /// The authority/multisignature to mint tokens, if supply is non-zero. If present, /// further minting is supported. - owner: COption, + mint_authority: COption, /// The freeze authority/multisignature of the mint. freeze_authority: COption, }, @@ -234,7 +234,7 @@ impl TokenInstruction { let decimals = unsafe { *(&input[input_len] as *const u8) }; input_len += size_of::(); - let owner = match input[input_len] { + let mint_authority = match input[input_len] { 0 => { input_len += size_of::(); COption::None @@ -242,9 +242,10 @@ impl TokenInstruction { 1 => { input_len += size_of::(); #[allow(clippy::cast_ptr_alignment)] - let owner = unsafe { *(&input[input_len] as *const u8 as *const Pubkey) }; + let mint_authority = + unsafe { *(&input[input_len] as *const u8 as *const Pubkey) }; input_len += size_of::(); - COption::Some(owner) + COption::Some(mint_authority) } _ => { return Err(TokenError::InvalidInstruction.into()); @@ -266,7 +267,7 @@ impl TokenInstruction { }; Self::InitializeMint { - owner, + mint_authority, freeze_authority, amount, decimals, @@ -345,7 +346,7 @@ impl TokenInstruction { let mut output_len = 0; match self { Self::InitializeMint { - owner, + mint_authority, freeze_authority, amount, decimals, @@ -362,15 +363,15 @@ impl TokenInstruction { *value = *decimals; output_len += size_of::(); - match owner { - COption::Some(owner) => { + match mint_authority { + COption::Some(mint_authority) => { output[output_len] = 1; output_len += size_of::(); #[allow(clippy::cast_ptr_alignment)] let value = unsafe { &mut *(&mut output[output_len] as *mut u8 as *mut Pubkey) }; - *value = *owner; + *value = *mint_authority; output_len += size_of::(); } COption::None => { @@ -498,23 +499,23 @@ pub fn initialize_mint( token_program_id: &Pubkey, mint_pubkey: &Pubkey, account_pubkey: Option<&Pubkey>, - owner_pubkey: Option<&Pubkey>, - freeze_pubkey: Option<&Pubkey>, + mint_authority_pubkey: Option<&Pubkey>, + freeze_authority_pubkey: Option<&Pubkey>, amount: u64, decimals: u8, ) -> Result { - let owner = if let Some(owner) = owner_pubkey { - COption::Some(*owner) + let mint_authority = if let Some(mint_authority) = mint_authority_pubkey { + COption::Some(*mint_authority) } else { COption::None }; - let freeze_authority = if let Some(freeze_authority) = freeze_pubkey { + let freeze_authority = if let Some(freeze_authority) = freeze_authority_pubkey { COption::Some(*freeze_authority) } else { COption::None }; let data = TokenInstruction::InitializeMint { - owner, + mint_authority, freeze_authority, amount, decimals, @@ -828,7 +829,7 @@ mod test { let check = TokenInstruction::InitializeMint { amount: 1, decimals: 2, - owner: COption::None, + mint_authority: COption::None, freeze_authority: COption::None, }; let packed = check.pack().unwrap(); @@ -840,7 +841,7 @@ mod test { let check = TokenInstruction::InitializeMint { amount: 1, decimals: 2, - owner: COption::Some(Pubkey::new(&[2u8; 32])), + mint_authority: COption::Some(Pubkey::new(&[2u8; 32])), freeze_authority: COption::Some(Pubkey::new(&[3u8; 32])), }; let packed = check.pack().unwrap(); diff --git a/token/program2/src/processor.rs b/token/program2/src/processor.rs index 46b60254ac4..4f603f0fbc1 100644 --- a/token/program2/src/processor.rs +++ b/token/program2/src/processor.rs @@ -27,7 +27,7 @@ impl Processor { accounts: &[AccountInfo], amount: u64, decimals: u8, - owner: COption, + mint_authority: COption, freeze_authority: COption, ) -> ProgramResult { let account_info_iter = &mut accounts.iter(); @@ -49,11 +49,11 @@ impl Processor { } dest_account.amount = amount; - } else if owner.is_none() { + } else if mint_authority.is_none() { return Err(TokenError::OwnerRequiredIfNoInitialSupply.into()); } - mint.owner = owner; + mint.mint_authority = mint_authority; mint.decimals = decimals; mint.is_initialized = true; mint.freeze_authority = freeze_authority; @@ -249,7 +249,7 @@ impl Processor { ) -> ProgramResult { let account_info_iter = &mut accounts.iter(); let account_info = next_account_info(account_info_iter)?; - let new_owner_info = next_account_info(account_info_iter)?; + let new_authority_info = next_account_info(account_info_iter)?; let authority_info = next_account_info(account_info_iter)?; if account_info.data_len() == size_of::() { @@ -270,25 +270,25 @@ impl Processor { account_info_iter.as_slice(), )?; - account.owner = *new_owner_info.key; + account.owner = *new_authority_info.key; } else if account_info.data_len() == size_of::() { let mut account_data = account_info.data.borrow_mut(); let mut mint: &mut Mint = state::unpack(&mut account_data)?; match authority_type { AuthorityType::MintTokens => { - match mint.owner { - COption::Some(ref owner) => { + match mint.mint_authority { + COption::Some(ref mint_authority) => { Self::validate_owner( program_id, - owner, + mint_authority, authority_info, account_info_iter.as_slice(), )?; } COption::None => return Err(TokenError::FixedSupply.into()), } - mint.owner = COption::Some(*new_owner_info.key); + mint.mint_authority = COption::Some(*new_authority_info.key); } AuthorityType::FreezeAccount => match mint.freeze_authority { COption::Some(ref freeze_authority) => { @@ -340,9 +340,14 @@ impl Processor { let mut mint_info_data = mint_info.data.borrow_mut(); let mint: &mut Mint = state::unpack(&mut mint_info_data)?; - match mint.owner { - COption::Some(owner) => { - Self::validate_owner(program_id, &owner, owner_info, account_info_iter.as_slice())?; + match mint.mint_authority { + COption::Some(mint_authority) => { + Self::validate_owner( + program_id, + &mint_authority, + owner_info, + account_info_iter.as_slice(), + )?; } COption::None => { return Err(TokenError::FixedSupply.into()); @@ -496,11 +501,17 @@ impl Processor { TokenInstruction::InitializeMint { amount, decimals, - owner, + mint_authority, freeze_authority, } => { info!("Instruction: InitializeMint"); - Self::process_initialize_mint(accounts, amount, decimals, owner, freeze_authority) + Self::process_initialize_mint( + accounts, + amount, + decimals, + mint_authority, + freeze_authority, + ) } TokenInstruction::InitializeAccount => { info!("Instruction: InitializeAccount"); @@ -1252,7 +1263,7 @@ mod tests { assert_eq!( *mint, Mint { - owner: COption::Some(owner_key), + mint_authority: COption::Some(owner_key), decimals, is_initialized: true, freeze_authority: COption::None, diff --git a/token/program2/src/state.rs b/token/program2/src/state.rs index ddaaf526abc..7ad2f52ff42 100644 --- a/token/program2/src/state.rs +++ b/token/program2/src/state.rs @@ -8,10 +8,10 @@ use std::mem::size_of; #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq)] pub struct Mint { - /// Optional owner, used to mint new tokens. The owner may only - /// be provided during mint creation. If no owner is present then the mint - /// has a fixed supply and no further tokens may be minted. - pub owner: COption, + /// Optional authority used to mint new tokens. The mint authority may only be provided during + /// mint creation. If no mint authority is present then the mint has a fixed supply and no + /// further tokens may be minted. + pub mint_authority: COption, /// Number of base 10 digits to the right of the decimal place. pub decimals: u8, /// Is `true` if this structure has been initialized