|
@@ -487,7 +487,7 @@ impl<'a> TokenInstruction<'a> {
|
|
|
}
|
|
|
1 => Self::InitializeAccount,
|
|
|
2 => {
|
|
|
- let &m = rest.get(0).ok_or(InvalidInstruction)?;
|
|
|
+ let &m = rest.first().ok_or(InvalidInstruction)?;
|
|
|
Self::InitializeMultisig { m }
|
|
|
}
|
|
|
3 | 4 | 7 | 8 => {
|
|
@@ -546,7 +546,7 @@ impl<'a> TokenInstruction<'a> {
|
|
|
Self::InitializeAccount3 { owner }
|
|
|
}
|
|
|
19 => {
|
|
|
- let &m = rest.get(0).ok_or(InvalidInstruction)?;
|
|
|
+ let &m = rest.first().ok_or(InvalidInstruction)?;
|
|
|
Self::InitializeMultisig2 { m }
|
|
|
}
|
|
|
20 => {
|
|
@@ -686,7 +686,7 @@ impl<'a> TokenInstruction<'a> {
|
|
|
fn unpack_pubkey(input: &[u8]) -> Result<(Pubkey, &[u8]), ProgramError> {
|
|
|
if input.len() >= 32 {
|
|
|
let (key, rest) = input.split_at(32);
|
|
|
- let pk = Pubkey::new(key);
|
|
|
+ let pk = Pubkey::try_from(key).map_err(|_| TokenError::InvalidInstruction)?;
|
|
|
Ok((pk, rest))
|
|
|
} else {
|
|
|
Err(TokenError::InvalidInstruction.into())
|
|
@@ -698,7 +698,7 @@ impl<'a> TokenInstruction<'a> {
|
|
|
Option::Some((&0, rest)) => Ok((COption::None, rest)),
|
|
|
Option::Some((&1, rest)) if rest.len() >= 32 => {
|
|
|
let (key, rest) = rest.split_at(32);
|
|
|
- let pk = Pubkey::new(key);
|
|
|
+ let pk = Pubkey::try_from(key).map_err(|_| TokenError::InvalidInstruction)?;
|
|
|
Ok((COption::Some(pk), rest))
|
|
|
}
|
|
|
_ => Err(TokenError::InvalidInstruction.into()),
|
|
@@ -1437,7 +1437,7 @@ mod test {
|
|
|
fn test_instruction_packing() {
|
|
|
let check = TokenInstruction::InitializeMint {
|
|
|
decimals: 2,
|
|
|
- mint_authority: Pubkey::new(&[1u8; 32]),
|
|
|
+ mint_authority: Pubkey::new_from_array([1u8; 32]),
|
|
|
freeze_authority: COption::None,
|
|
|
};
|
|
|
let packed = check.pack();
|
|
@@ -1450,8 +1450,8 @@ mod test {
|
|
|
|
|
|
let check = TokenInstruction::InitializeMint {
|
|
|
decimals: 2,
|
|
|
- mint_authority: Pubkey::new(&[2u8; 32]),
|
|
|
- freeze_authority: COption::Some(Pubkey::new(&[3u8; 32])),
|
|
|
+ mint_authority: Pubkey::new_from_array([2u8; 32]),
|
|
|
+ freeze_authority: COption::Some(Pubkey::new_from_array([3u8; 32])),
|
|
|
};
|
|
|
let packed = check.pack();
|
|
|
let mut expect = vec![0u8, 2];
|
|
@@ -1499,7 +1499,7 @@ mod test {
|
|
|
|
|
|
let check = TokenInstruction::SetAuthority {
|
|
|
authority_type: AuthorityType::FreezeAccount,
|
|
|
- new_authority: COption::Some(Pubkey::new(&[4u8; 32])),
|
|
|
+ new_authority: COption::Some(Pubkey::new_from_array([4u8; 32])),
|
|
|
};
|
|
|
let packed = check.pack();
|
|
|
let mut expect = Vec::from([6u8, 1]);
|
|
@@ -1585,7 +1585,7 @@ mod test {
|
|
|
assert_eq!(unpacked, check);
|
|
|
|
|
|
let check = TokenInstruction::InitializeAccount2 {
|
|
|
- owner: Pubkey::new(&[2u8; 32]),
|
|
|
+ owner: Pubkey::new_from_array([2u8; 32]),
|
|
|
};
|
|
|
let packed = check.pack();
|
|
|
let mut expect = vec![16u8];
|
|
@@ -1602,7 +1602,7 @@ mod test {
|
|
|
assert_eq!(unpacked, check);
|
|
|
|
|
|
let check = TokenInstruction::InitializeAccount3 {
|
|
|
- owner: Pubkey::new(&[2u8; 32]),
|
|
|
+ owner: Pubkey::new_from_array([2u8; 32]),
|
|
|
};
|
|
|
let packed = check.pack();
|
|
|
let mut expect = vec![18u8];
|
|
@@ -1620,7 +1620,7 @@ mod test {
|
|
|
|
|
|
let check = TokenInstruction::InitializeMint2 {
|
|
|
decimals: 2,
|
|
|
- mint_authority: Pubkey::new(&[1u8; 32]),
|
|
|
+ mint_authority: Pubkey::new_from_array([1u8; 32]),
|
|
|
freeze_authority: COption::None,
|
|
|
};
|
|
|
let packed = check.pack();
|
|
@@ -1633,8 +1633,8 @@ mod test {
|
|
|
|
|
|
let check = TokenInstruction::InitializeMint2 {
|
|
|
decimals: 2,
|
|
|
- mint_authority: Pubkey::new(&[2u8; 32]),
|
|
|
- freeze_authority: COption::Some(Pubkey::new(&[3u8; 32])),
|
|
|
+ mint_authority: Pubkey::new_from_array([2u8; 32]),
|
|
|
+ freeze_authority: COption::Some(Pubkey::new_from_array([3u8; 32])),
|
|
|
};
|
|
|
let packed = check.pack();
|
|
|
let mut expect = vec![20u8, 2];
|