token-client: convert freeze/thaw interface

This commit is contained in:
hanako mumei 2022-08-26 00:36:12 -07:00 committed by hana
parent 1fb05454e7
commit db4a950ca8
3 changed files with 34 additions and 16 deletions

View File

@ -195,9 +195,9 @@ impl<T> fmt::Debug for Token<T> {
// HANA XXX OK what are we doing
//these are all the remaining "normal" methods to rework:
// X transfer
// * approve
// * revoke
// * close
// X approve
// X revoke
// X close
// * freeze
// * thaw
// and then just a bunch of extension ones. this isnt hard
@ -812,39 +812,45 @@ where
}
/// Freeze a token account
pub async fn freeze_account<S: Signer>(
pub async fn freeze<S: Signers>(
&self,
account: &Pubkey,
authority: &S,
authority: &Pubkey,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
let multisig_signers = self.get_multisig_signers(authority, signing_keypairs);
self.process_ixs(
&[instruction::freeze_account(
&self.program_id,
account,
&self.pubkey,
&authority.pubkey(),
&[],
authority,
&multisig_signers.iter().collect::<Vec<_>>(),
)?],
&[authority],
signing_keypairs,
)
.await
}
/// Thaw / unfreeze a token account
pub async fn thaw_account<S: Signer>(
pub async fn thaw<S: Signers>(
&self,
account: &Pubkey,
authority: &S,
authority: &Pubkey,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
let multisig_signers = self.get_multisig_signers(authority, signing_keypairs);
self.process_ixs(
&[instruction::thaw_account(
&self.program_id,
account,
&self.pubkey,
&authority.pubkey(),
&[],
authority,
&multisig_signers.iter().collect::<Vec<_>>(),
)?],
&[authority],
signing_keypairs,
)
.await
}

View File

@ -29,14 +29,22 @@ async fn basic() {
assert_eq!(state.base.state, AccountState::Initialized);
token
.freeze_account(&account, &freeze_authority)
.freeze(
&account,
&freeze_authority.pubkey(),
&vec![&freeze_authority],
)
.await
.unwrap();
let state = token.get_account_info(&account).await.unwrap();
assert_eq!(state.base.state, AccountState::Frozen);
token
.thaw_account(&account, &freeze_authority)
.thaw(
&account,
&freeze_authority.pubkey(),
&vec![&freeze_authority],
)
.await
.unwrap();
let state = token.get_account_info(&account).await.unwrap();

View File

@ -1430,7 +1430,11 @@ async fn withdraw_withheld_tokens_from_mint() {
)
.await;
token
.freeze_account(&account, &freeze_authority)
.freeze(
&account,
&freeze_authority.pubkey(),
&vec![&freeze_authority],
)
.await
.unwrap();
let error = token