token-client: convert approve/revoke interface
This commit is contained in:
parent
b30aac80a6
commit
1fb05454e7
|
@ -194,7 +194,7 @@ impl<T> fmt::Debug for Token<T> {
|
||||||
|
|
||||||
// HANA XXX OK what are we doing
|
// HANA XXX OK what are we doing
|
||||||
//these are all the remaining "normal" methods to rework:
|
//these are all the remaining "normal" methods to rework:
|
||||||
// * transfer
|
// X transfer
|
||||||
// * approve
|
// * approve
|
||||||
// * revoke
|
// * revoke
|
||||||
// * close
|
// * close
|
||||||
|
@ -723,66 +723,59 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Approve a delegate to spend tokens
|
/// Approve a delegate to spend tokens
|
||||||
pub async fn approve<S: Signer>(
|
pub async fn approve<S: Signers>(
|
||||||
&self,
|
&self,
|
||||||
source: &Pubkey,
|
source: &Pubkey,
|
||||||
delegate: &Pubkey,
|
delegate: &Pubkey,
|
||||||
authority: &S,
|
authority: &Pubkey,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
|
decimals: Option<u8>,
|
||||||
|
signing_keypairs: &S,
|
||||||
) -> TokenResult<T::Output> {
|
) -> TokenResult<T::Output> {
|
||||||
self.process_ixs(
|
let multisig_signers = self.get_multisig_signers(authority, signing_keypairs);
|
||||||
&[instruction::approve(
|
|
||||||
&self.program_id,
|
|
||||||
source,
|
|
||||||
delegate,
|
|
||||||
&authority.pubkey(),
|
|
||||||
&[],
|
|
||||||
amount,
|
|
||||||
)?],
|
|
||||||
&[authority],
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Approve a delegate to spend tokens, with decimal check
|
let instructions = if let Some(decimals) = decimals {
|
||||||
pub async fn approve_checked<S: Signer>(
|
[instruction::approve_checked(
|
||||||
&self,
|
|
||||||
source: &Pubkey,
|
|
||||||
delegate: &Pubkey,
|
|
||||||
authority: &S,
|
|
||||||
amount: u64,
|
|
||||||
decimals: u8,
|
|
||||||
) -> TokenResult<T::Output> {
|
|
||||||
self.process_ixs(
|
|
||||||
&[instruction::approve_checked(
|
|
||||||
&self.program_id,
|
&self.program_id,
|
||||||
source,
|
source,
|
||||||
&self.pubkey,
|
&self.pubkey,
|
||||||
delegate,
|
delegate,
|
||||||
&authority.pubkey(),
|
authority,
|
||||||
&[],
|
&multisig_signers.iter().collect::<Vec<_>>(),
|
||||||
amount,
|
amount,
|
||||||
decimals,
|
decimals,
|
||||||
)?],
|
)?]
|
||||||
&[authority],
|
} else {
|
||||||
)
|
[instruction::approve(
|
||||||
.await
|
&self.program_id,
|
||||||
|
source,
|
||||||
|
delegate,
|
||||||
|
authority,
|
||||||
|
&multisig_signers.iter().collect::<Vec<_>>(),
|
||||||
|
amount,
|
||||||
|
)?]
|
||||||
|
};
|
||||||
|
|
||||||
|
self.process_ixs(&instructions, signing_keypairs).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Revoke a delegate
|
/// Revoke a delegate
|
||||||
pub async fn revoke<S: Signer>(
|
pub async fn revoke<S: Signers>(
|
||||||
&self,
|
&self,
|
||||||
source: &Pubkey,
|
source: &Pubkey,
|
||||||
authority: &S,
|
authority: &Pubkey,
|
||||||
|
signing_keypairs: &S,
|
||||||
) -> TokenResult<T::Output> {
|
) -> TokenResult<T::Output> {
|
||||||
|
let multisig_signers = self.get_multisig_signers(authority, signing_keypairs);
|
||||||
|
|
||||||
self.process_ixs(
|
self.process_ixs(
|
||||||
&[instruction::revoke(
|
&[instruction::revoke(
|
||||||
&self.program_id,
|
&self.program_id,
|
||||||
source,
|
source,
|
||||||
&authority.pubkey(),
|
authority,
|
||||||
&[],
|
&multisig_signers.iter().collect::<Vec<_>>(),
|
||||||
)?],
|
)?],
|
||||||
&[authority],
|
signing_keypairs,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,16 +81,24 @@ async fn run_basic(
|
||||||
let delegated_amount = 10;
|
let delegated_amount = 10;
|
||||||
match approve_mode {
|
match approve_mode {
|
||||||
ApproveMode::Unchecked => token
|
ApproveMode::Unchecked => token
|
||||||
.approve(&alice_account, &bob.pubkey(), &alice, delegated_amount)
|
.approve(
|
||||||
|
&alice_account,
|
||||||
|
&bob.pubkey(),
|
||||||
|
&alice.pubkey(),
|
||||||
|
delegated_amount,
|
||||||
|
None,
|
||||||
|
&vec![&alice],
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
ApproveMode::Checked => token
|
ApproveMode::Checked => token
|
||||||
.approve_checked(
|
.approve(
|
||||||
&alice_account,
|
&alice_account,
|
||||||
&bob.pubkey(),
|
&bob.pubkey(),
|
||||||
&alice,
|
&alice.pubkey(),
|
||||||
delegated_amount,
|
delegated_amount,
|
||||||
decimals,
|
Some(decimals),
|
||||||
|
&vec![&alice],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
@ -185,7 +193,10 @@ async fn run_basic(
|
||||||
);
|
);
|
||||||
|
|
||||||
// revoke
|
// revoke
|
||||||
token.revoke(&alice_account, &alice).await.unwrap();
|
token
|
||||||
|
.revoke(&alice_account, &alice.pubkey(), &vec![&alice])
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// now fails
|
// now fails
|
||||||
let error = token
|
let error = token
|
||||||
|
|
Loading…
Reference in New Issue