Refactor create-token to go through token client

* cli: remove offline args from commands that create accounts
* cli: implement finish_tx, to be a replacement for handle_tx, which branches on the client return
* client: validate a transaction is fully signed before sending over rpc
* client: convert payer from Signer to Arc<dyn Signer> to support cli signers
* client: support nonce mode
* client: change create_mint to be an object method that returns SendTransaction::Output
* client: rename S2 to S everywhere that Token<T, S> is Token<T>
This commit is contained in:
hanako mumei 2022-08-04 19:21:40 -07:00 committed by hana
parent 65769ce23d
commit c426ed9749
7 changed files with 306 additions and 207 deletions

View File

@ -46,6 +46,7 @@ use spl_token_2022::{
instruction::*, instruction::*,
state::{Account, Mint, Multisig}, state::{Account, Mint, Multisig},
}; };
use spl_token_client::{client::RpcClientResponse, token::Token};
use std::{ use std::{
collections::HashMap, fmt::Display, process::exit, str::FromStr, string::ToString, sync::Arc, collections::HashMap, fmt::Display, process::exit, str::FromStr, string::ToString, sync::Arc,
}; };
@ -327,59 +328,51 @@ pub fn signers_of(
async fn command_create_token( async fn command_create_token(
config: &Config<'_>, config: &Config<'_>,
decimals: u8, decimals: u8,
token: Pubkey, token_pubkey: Pubkey,
authority: Pubkey, authority: Pubkey,
enable_freeze: bool, enable_freeze: bool,
memo: Option<String>, memo: Option<String>,
bulk_signers: Vec<Arc<dyn Signer>>, bulk_signers: Vec<Arc<dyn Signer>>,
) -> CommandResult { ) -> CommandResult {
println_display(config, format!("Creating token {}", token)); println_display(config, format!("Creating token {}", token_pubkey));
let minimum_balance_for_rent_exemption = if !config.sign_only { let token = Token::new(
config config.program_client.clone(),
.program_client &config.program_id,
.get_minimum_balance_for_rent_exemption(Mint::LEN) &token_pubkey,
.await? config.default_signer.clone(),
);
let token = if let (Some(nonce_account), Some(nonce_authority)) =
(config.nonce_account, config.nonce_authority)
{
token.with_nonce(&nonce_account, &nonce_authority)
} else { } else {
0 token
}; };
let freeze_authority_pubkey = if enable_freeze { Some(authority) } else { None };
let mut instructions = vec![
system_instruction::create_account(
&config.fee_payer,
&token,
minimum_balance_for_rent_exemption,
Mint::LEN as u64,
&config.program_id,
),
initialize_mint(
&config.program_id,
&token,
&authority,
freeze_authority_pubkey.as_ref(),
decimals,
)?,
];
if let Some(text) = memo { if let Some(text) = memo {
instructions.push(spl_memo::build_memo(text.as_bytes(), &[&config.fee_payer])); token.with_memo(text);
} }
let tx_return = handle_tx( let freeze_authority = if enable_freeze { Some(authority) } else { None };
&CliSignerInfo {
signers: bulk_signers, let res = token
}, .create_mint(
config, &authority,
false, freeze_authority.as_ref(),
minimum_balance_for_rent_exemption, decimals,
instructions, vec![],
&bulk_signers,
) )
.await?; .await?;
let tx_return = finish_tx(config, &res, false).await?;
Ok(match tx_return { Ok(match tx_return {
TransactionReturnData::CliSignature(cli_signature) => format_output( TransactionReturnData::CliSignature(cli_signature) => format_output(
CliMint { CliMint {
address: token.to_string(), address: token_pubkey.to_string(),
decimals, decimals,
transaction_data: cli_signature, transaction_data: cli_signature,
}, },
@ -1970,7 +1963,6 @@ fn app<'a, 'b>(
) )
.nonce_args(true) .nonce_args(true)
.arg(memo_arg()) .arg(memo_arg())
.offline_args(),
) )
.subcommand( .subcommand(
SubCommand::with_name(CommandName::CreateAccount.into()) SubCommand::with_name(CommandName::CreateAccount.into())
@ -1998,7 +1990,6 @@ fn app<'a, 'b>(
) )
.arg(owner_address_arg()) .arg(owner_address_arg())
.nonce_args(true) .nonce_args(true)
.offline_args(),
) )
.subcommand( .subcommand(
SubCommand::with_name(CommandName::CreateMultisig.into()) SubCommand::with_name(CommandName::CreateMultisig.into())
@ -2036,7 +2027,6 @@ fn app<'a, 'b>(
), ),
) )
.nonce_args(true) .nonce_args(true)
.offline_args(),
) )
.subcommand( .subcommand(
SubCommand::with_name(CommandName::Authorize.into()) SubCommand::with_name(CommandName::Authorize.into())
@ -2147,7 +2137,7 @@ fn app<'a, 'b>(
.arg(owner_keypair_arg_with_value_name("SENDER_TOKEN_OWNER_KEYPAIR") .arg(owner_keypair_arg_with_value_name("SENDER_TOKEN_OWNER_KEYPAIR")
.help( .help(
"Specify the owner of the sending token account. \ "Specify the owner of the sending token account. \
This may be a keypair file, the ASK keyword. \ This may be a keypair file or the ASK keyword. \
Defaults to the client keypair.", Defaults to the client keypair.",
), ),
) )
@ -2218,7 +2208,7 @@ fn app<'a, 'b>(
.arg(owner_keypair_arg_with_value_name("SOURCE_TOKEN_OWNER_KEYPAIR") .arg(owner_keypair_arg_with_value_name("SOURCE_TOKEN_OWNER_KEYPAIR")
.help( .help(
"Specify the source token owner account. \ "Specify the source token owner account. \
This may be a keypair file, the ASK keyword. \ This may be a keypair file or the ASK keyword. \
Defaults to the client keypair.", Defaults to the client keypair.",
), ),
) )
@ -2486,7 +2476,7 @@ fn app<'a, 'b>(
.help( .help(
"Specify the token's close authority if it has one, \ "Specify the token's close authority if it has one, \
otherwise specify the token's owner keypair. \ otherwise specify the token's owner keypair. \
This may be a keypair file, the ASK keyword. \ This may be a keypair file or the ASK keyword. \
Defaults to the client keypair.", Defaults to the client keypair.",
), ),
) )
@ -3129,6 +3119,8 @@ enum TransactionReturnData {
CliSignature(CliSignature), CliSignature(CliSignature),
CliSignOnlyData(CliSignOnlyData), CliSignOnlyData(CliSignOnlyData),
} }
// XXX this goes away once everything is converted to token client
async fn handle_tx<'a>( async fn handle_tx<'a>(
signer_info: &CliSignerInfo, signer_info: &CliSignerInfo,
config: &Config<'a>, config: &Config<'a>,
@ -3184,6 +3176,43 @@ async fn handle_tx<'a>(
} }
} }
async fn finish_tx<'a>(
config: &Config<'a>,
rpc_response: &RpcClientResponse,
no_wait: bool,
) -> Result<TransactionReturnData, Error> {
match rpc_response {
RpcClientResponse::Transaction(transaction) => {
Ok(TransactionReturnData::CliSignOnlyData(return_signers_data(
transaction,
&ReturnSignersConfig {
dump_transaction_message: config.dump_transaction_message,
},
)))
}
RpcClientResponse::Signature(signature) if no_wait => {
Ok(TransactionReturnData::CliSignature(CliSignature {
signature: signature.to_string(),
}))
}
RpcClientResponse::Signature(signature) => {
let blockhash = config.program_client.get_latest_blockhash().await?;
config
.rpc_client
.confirm_transaction_with_spinner(
signature,
&blockhash,
config.rpc_client.commitment(),
)
.await?;
Ok(TransactionReturnData::CliSignature(CliSignature {
signature: signature.to_string(),
}))
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use { use {

View File

@ -79,6 +79,10 @@ impl SendTransactionRpc for ProgramRpcClientSendTransaction {
transaction: &'a Transaction, transaction: &'a Transaction,
) -> BoxFuture<'a, ProgramClientResult<Self::Output>> { ) -> BoxFuture<'a, ProgramClientResult<Self::Output>> {
Box::pin(async move { Box::pin(async move {
if !transaction.is_signed() {
return Err("Cannot send transaction: not fully signed".into());
}
client client
.send_and_confirm_transaction(transaction) .send_and_confirm_transaction(transaction)
.await .await

View File

@ -6,6 +6,7 @@ use {
epoch_info::EpochInfo, epoch_info::EpochInfo,
hash::Hash, hash::Hash,
instruction::Instruction, instruction::Instruction,
message::Message,
program_error::ProgramError, program_error::ProgramError,
pubkey::Pubkey, pubkey::Pubkey,
signer::{signers::Signers, Signer, SignerError}, signer::{signers::Signers, Signer, SignerError},
@ -64,11 +65,18 @@ impl PartialEq for TokenError {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
match (self, other) { match (self, other) {
// TODO not great, but workable for tests // TODO not great, but workable for tests
// currently missing: proof error, signer error
(Self::Client(ref a), Self::Client(ref b)) => a.to_string() == b.to_string(), (Self::Client(ref a), Self::Client(ref b)) => a.to_string() == b.to_string(),
(Self::Program(ref a), Self::Program(ref b)) => a == b, (Self::Program(ref a), Self::Program(ref b)) => a == b,
(Self::AccountNotFound, Self::AccountNotFound) => true, (Self::AccountNotFound, Self::AccountNotFound) => true,
(Self::AccountInvalidOwner, Self::AccountInvalidOwner) => true, (Self::AccountInvalidOwner, Self::AccountInvalidOwner) => true,
(Self::AccountInvalidMint, Self::AccountInvalidMint) => true, (Self::AccountInvalidMint, Self::AccountInvalidMint) => true,
(
Self::MaximumDepositTransferAmountExceeded,
Self::MaximumDepositTransferAmountExceeded,
) => true,
(Self::AccountDecryption, Self::AccountDecryption) => true,
(Self::NotEnoughFunds, Self::NotEnoughFunds) => true,
_ => false, _ => false,
} }
} }
@ -164,18 +172,17 @@ impl ExtensionInitializationParams {
pub type TokenResult<T> = Result<T, TokenError>; pub type TokenResult<T> = Result<T, TokenError>;
pub struct Token<T, S> { pub struct Token<T> {
client: Arc<dyn ProgramClient<T>>, client: Arc<dyn ProgramClient<T>>,
pubkey: Pubkey, /*token mint*/ pubkey: Pubkey, /*token mint*/
payer: S, payer: Arc<dyn Signer>,
program_id: Pubkey, program_id: Pubkey,
nonce_account: Option<Pubkey>,
nonce_authority: Option<Pubkey>,
memo: Arc<RwLock<Option<String>>>, memo: Arc<RwLock<Option<String>>>,
} }
impl<T, S> fmt::Debug for Token<T, S> impl<T> fmt::Debug for Token<T> {
where
S: Signer,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Token") f.debug_struct("Token")
.field("pubkey", &self.pubkey) .field("pubkey", &self.pubkey)
@ -185,22 +192,23 @@ where
} }
} }
impl<T, S> Token<T, S> impl<T> Token<T>
where where
T: SendTransaction, T: SendTransaction,
S: Signer,
{ {
pub fn new( pub fn new(
client: Arc<dyn ProgramClient<T>>, client: Arc<dyn ProgramClient<T>>,
program_id: &Pubkey, program_id: &Pubkey,
address: &Pubkey, address: &Pubkey,
payer: S, payer: Arc<dyn Signer>,
) -> Self { ) -> Self {
Token { Token {
client, client,
pubkey: *address, pubkey: *address,
payer, payer,
program_id: *program_id, program_id: *program_id,
nonce_account: None,
nonce_authority: None,
memo: Arc::new(RwLock::new(None)), memo: Arc::new(RwLock::new(None)),
} }
} }
@ -210,12 +218,26 @@ where
&self.pubkey &self.pubkey
} }
pub fn with_payer<S2: Signer>(&self, payer: S2) -> Token<T, S2> { pub fn with_payer(&self, payer: Arc<dyn Signer>) -> Token<T> {
Token { Token {
client: Arc::clone(&self.client), client: Arc::clone(&self.client),
pubkey: self.pubkey, pubkey: self.pubkey,
payer, payer,
program_id: self.program_id, program_id: self.program_id,
nonce_account: self.nonce_account,
nonce_authority: self.nonce_authority,
memo: Arc::new(RwLock::new(None)),
}
}
pub fn with_nonce(&self, nonce_account: &Pubkey, nonce_authority: &Pubkey) -> Token<T> {
Token {
client: Arc::clone(&self.client),
pubkey: self.pubkey,
payer: self.payer.clone(),
program_id: self.program_id,
nonce_account: Some(*nonce_account),
nonce_authority: Some(*nonce_authority),
memo: Arc::new(RwLock::new(None)), memo: Arc::new(RwLock::new(None)),
} }
} }
@ -259,85 +281,118 @@ where
)))) ))))
} }
pub async fn process_ixs<S2: Signers>( pub async fn construct_tx<S: Signers>(
&self, &self,
token_instructions: &[Instruction], token_instructions: &[Instruction],
signing_keypairs: &S2, signing_keypairs: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<Transaction> {
let mut instructions = vec![]; let mut instructions = vec![];
let payer_key = self.payer.pubkey();
let fee_payer = Some(&payer_key);
{
let mut w_memo = self.memo.write().unwrap(); let mut w_memo = self.memo.write().unwrap();
if let Some(memo) = w_memo.take() { if let Some(memo) = w_memo.take() {
instructions.push(spl_memo::build_memo(memo.as_bytes(), &[])); instructions.push(spl_memo::build_memo(memo.as_bytes(), &[&payer_key]));
} }
}
instructions.extend_from_slice(token_instructions); instructions.extend_from_slice(token_instructions);
let latest_blockhash = self let latest_blockhash = self
.client .client
.get_latest_blockhash() .get_latest_blockhash()
.await .await
.map_err(TokenError::Client)?; .map_err(TokenError::Client)?;
let mut tx = Transaction::new_with_payer(&instructions, Some(&self.payer.pubkey())); let message = if let (Some(nonce_account), Some(nonce_authority)) =
tx.try_partial_sign(&[&self.payer], latest_blockhash) (self.nonce_account, self.nonce_authority)
{
let mut message = Message::new_with_nonce(
token_instructions.to_vec(),
fee_payer,
&nonce_account,
&nonce_authority,
);
message.recent_blockhash = latest_blockhash;
message
} else {
Message::new_with_blockhash(&instructions, fee_payer, &latest_blockhash)
};
let mut transaction = Transaction::new_unsigned(message);
transaction
.try_partial_sign(&vec![self.payer.clone()], latest_blockhash)
.map_err(|error| TokenError::Client(error.into()))?; .map_err(|error| TokenError::Client(error.into()))?;
tx.try_sign(signing_keypairs, latest_blockhash) transaction
.try_partial_sign(signing_keypairs, latest_blockhash)
.map_err(|error| TokenError::Client(error.into()))?; .map_err(|error| TokenError::Client(error.into()))?;
Ok(transaction)
}
pub async fn process_ixs<S: Signers>(
&self,
token_instructions: &[Instruction],
signing_keypairs: &S,
) -> TokenResult<T::Output> {
let transaction = self
.construct_tx(token_instructions, signing_keypairs)
.await?;
self.client self.client
.send_transaction(&tx) .send_transaction(&transaction)
.await .await
.map_err(TokenError::Client) .map_err(TokenError::Client)
} }
/// Create and initialize a token.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn create_mint<'a, S2: Signer>( pub async fn create_mint<'a, S: Signers>(
client: Arc<dyn ProgramClient<T>>, &self,
program_id: &'a Pubkey,
payer: S,
mint_account: &'a S2,
mint_authority: &'a Pubkey, mint_authority: &'a Pubkey,
freeze_authority: Option<&'a Pubkey>, freeze_authority: Option<&'a Pubkey>,
decimals: u8, decimals: u8,
extension_initialization_params: Vec<ExtensionInitializationParams>, extension_initialization_params: Vec<ExtensionInitializationParams>,
) -> TokenResult<Self> { signing_keypairs: &S,
let mint_pubkey = mint_account.pubkey(); ) -> TokenResult<T::Output> {
let extension_types = extension_initialization_params let extension_types = extension_initialization_params
.iter() .iter()
.map(|e| e.extension()) .map(|e| e.extension())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let space = ExtensionType::get_account_len::<Mint>(&extension_types); let space = ExtensionType::get_account_len::<Mint>(&extension_types);
let token = Self::new(client, program_id, &mint_account.pubkey(), payer);
let mut instructions = vec![system_instruction::create_account( let mut instructions = vec![system_instruction::create_account(
&token.payer.pubkey(), &self.payer.pubkey(),
&mint_pubkey, &self.pubkey,
token self.client
.client
.get_minimum_balance_for_rent_exemption(space) .get_minimum_balance_for_rent_exemption(space)
.await .await
.map_err(TokenError::Client)?, .map_err(TokenError::Client)?,
space as u64, space as u64,
program_id, &self.program_id,
)]; )];
for params in extension_initialization_params { for params in extension_initialization_params {
instructions.push(params.instruction(program_id, &mint_pubkey)?); instructions.push(params.instruction(&self.program_id, &self.pubkey)?);
} }
instructions.push(instruction::initialize_mint( instructions.push(instruction::initialize_mint(
program_id, &self.program_id,
&mint_pubkey, &self.pubkey,
mint_authority, mint_authority,
freeze_authority, freeze_authority,
decimals, decimals,
)?); )?);
token.process_ixs(&instructions, &[mint_account]).await?;
Ok(token) self.process_ixs(&instructions, signing_keypairs).await
} }
/// Create native mint /// Create native mint
pub async fn create_native_mint( pub async fn create_native_mint(
client: Arc<dyn ProgramClient<T>>, client: Arc<dyn ProgramClient<T>>,
program_id: &Pubkey, program_id: &Pubkey,
payer: S, payer: Arc<dyn Signer>,
) -> TokenResult<Self> { ) -> TokenResult<Self> {
let token = Self::new(client, program_id, &native_mint::id(), payer); let token = Self::new(client, program_id, &native_mint::id(), payer);
token token
@ -377,7 +432,7 @@ where
/// Create and initialize a new token account. /// Create and initialize a new token account.
pub async fn create_auxiliary_token_account( pub async fn create_auxiliary_token_account(
&self, &self,
account: &S, account: &dyn Signer,
owner: &Pubkey, owner: &Pubkey,
) -> TokenResult<Pubkey> { ) -> TokenResult<Pubkey> {
self.create_auxiliary_token_account_with_extension_space(account, owner, vec![]) self.create_auxiliary_token_account_with_extension_space(account, owner, vec![])
@ -387,7 +442,7 @@ where
/// Create and initialize a new token account. /// Create and initialize a new token account.
pub async fn create_auxiliary_token_account_with_extension_space( pub async fn create_auxiliary_token_account_with_extension_space(
&self, &self,
account: &S, account: &dyn Signer,
owner: &Pubkey, owner: &Pubkey,
extensions: Vec<ExtensionType>, extensions: Vec<ExtensionType>,
) -> TokenResult<Pubkey> { ) -> TokenResult<Pubkey> {
@ -420,7 +475,7 @@ where
owner, owner,
)?, )?,
], ],
&[account], &vec![account],
) )
.await .await
.map(|_| account.pubkey()) .map(|_| account.pubkey())
@ -481,12 +536,12 @@ where
} }
/// Assign a new authority to the account. /// Assign a new authority to the account.
pub async fn set_authority<S2: Signer>( pub async fn set_authority<S: Signer>(
&self, &self,
account: &Pubkey, account: &Pubkey,
new_authority: Option<&Pubkey>, new_authority: Option<&Pubkey>,
authority_type: instruction::AuthorityType, authority_type: instruction::AuthorityType,
owner: &S2, owner: &S,
) -> TokenResult<()> { ) -> TokenResult<()> {
self.process_ixs( self.process_ixs(
&[instruction::set_authority( &[instruction::set_authority(
@ -504,10 +559,10 @@ where
} }
/// Mint new tokens /// Mint new tokens
pub async fn mint_to<S2: Signer>( pub async fn mint_to<S: Signer>(
&self, &self,
destination: &Pubkey, destination: &Pubkey,
authority: &S2, authority: &S,
amount: u64, amount: u64,
) -> TokenResult<()> { ) -> TokenResult<()> {
self.process_ixs( self.process_ixs(
@ -526,11 +581,11 @@ where
} }
/// Transfer tokens to another account /// Transfer tokens to another account
pub async fn transfer_unchecked<S2: Signer>( pub async fn transfer_unchecked<S: Signer>(
&self, &self,
source: &Pubkey, source: &Pubkey,
destination: &Pubkey, destination: &Pubkey,
authority: &S2, authority: &S,
amount: u64, amount: u64,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
@ -549,11 +604,11 @@ where
} }
/// Transfer tokens to another account /// Transfer tokens to another account
pub async fn transfer_checked<S2: Signer>( pub async fn transfer_checked<S: Signer>(
&self, &self,
source: &Pubkey, source: &Pubkey,
destination: &Pubkey, destination: &Pubkey,
authority: &S2, authority: &S,
amount: u64, amount: u64,
decimals: u8, decimals: u8,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
@ -574,11 +629,11 @@ where
} }
/// Transfer tokens to another account, given an expected fee /// Transfer tokens to another account, given an expected fee
pub async fn transfer_checked_with_fee<S2: Signer>( pub async fn transfer_checked_with_fee<S: Signer>(
&self, &self,
source: &Pubkey, source: &Pubkey,
destination: &Pubkey, destination: &Pubkey,
authority: &S2, authority: &S,
amount: u64, amount: u64,
decimals: u8, decimals: u8,
fee: u64, fee: u64,
@ -601,10 +656,10 @@ where
} }
/// Burn tokens from account /// Burn tokens from account
pub async fn burn<S2: Signer>( pub async fn burn<S: Signer>(
&self, &self,
source: &Pubkey, source: &Pubkey,
authority: &S2, authority: &S,
amount: u64, amount: u64,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
@ -622,10 +677,10 @@ where
} }
/// Burn tokens from account /// Burn tokens from account
pub async fn burn_checked<S2: Signer>( pub async fn burn_checked<S: Signer>(
&self, &self,
source: &Pubkey, source: &Pubkey,
authority: &S2, authority: &S,
amount: u64, amount: u64,
decimals: u8, decimals: u8,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
@ -645,11 +700,11 @@ where
} }
/// Approve a delegate to spend tokens /// Approve a delegate to spend tokens
pub async fn approve<S2: Signer>( pub async fn approve<S: Signer>(
&self, &self,
source: &Pubkey, source: &Pubkey,
delegate: &Pubkey, delegate: &Pubkey,
authority: &S2, authority: &S,
amount: u64, amount: u64,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
@ -667,11 +722,11 @@ where
} }
/// Approve a delegate to spend tokens, with decimal check /// Approve a delegate to spend tokens, with decimal check
pub async fn approve_checked<S2: Signer>( pub async fn approve_checked<S: Signer>(
&self, &self,
source: &Pubkey, source: &Pubkey,
delegate: &Pubkey, delegate: &Pubkey,
authority: &S2, authority: &S,
amount: u64, amount: u64,
decimals: u8, decimals: u8,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
@ -692,10 +747,10 @@ where
} }
/// Revoke a delegate /// Revoke a delegate
pub async fn revoke<S2: Signer>( pub async fn revoke<S: Signer>(
&self, &self,
source: &Pubkey, source: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
&[instruction::revoke( &[instruction::revoke(
@ -710,11 +765,11 @@ where
} }
/// Close account into another /// Close account into another
pub async fn close_account<S2: Signer>( pub async fn close_account<S: Signer>(
&self, &self,
account: &Pubkey, account: &Pubkey,
destination: &Pubkey, destination: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
&[instruction::close_account( &[instruction::close_account(
@ -730,10 +785,10 @@ where
} }
/// Freeze a token account /// Freeze a token account
pub async fn freeze_account<S2: Signer>( pub async fn freeze_account<S: Signer>(
&self, &self,
account: &Pubkey, account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
&[instruction::freeze_account( &[instruction::freeze_account(
@ -749,10 +804,10 @@ where
} }
/// Thaw / unfreeze a token account /// Thaw / unfreeze a token account
pub async fn thaw_account<S2: Signer>( pub async fn thaw_account<S: Signer>(
&self, &self,
account: &Pubkey, account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
&[instruction::thaw_account( &[instruction::thaw_account(
@ -777,9 +832,9 @@ where
} }
/// Set transfer fee /// Set transfer fee
pub async fn set_transfer_fee<S2: Signer>( pub async fn set_transfer_fee<S: Signer>(
&self, &self,
authority: &S2, authority: &S,
transfer_fee_basis_points: u16, transfer_fee_basis_points: u16,
maximum_fee: u64, maximum_fee: u64,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
@ -798,9 +853,9 @@ where
} }
/// Set default account state on mint /// Set default account state on mint
pub async fn set_default_account_state<S2: Signer>( pub async fn set_default_account_state<S: Signer>(
&self, &self,
authority: &S2, authority: &S,
state: &AccountState, state: &AccountState,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
@ -835,10 +890,10 @@ where
} }
/// Withdraw withheld tokens from mint /// Withdraw withheld tokens from mint
pub async fn withdraw_withheld_tokens_from_mint<S2: Signer>( pub async fn withdraw_withheld_tokens_from_mint<S: Signer>(
&self, &self,
destination: &Pubkey, destination: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
&[ &[
@ -856,10 +911,10 @@ where
} }
/// Withdraw withheld tokens from accounts /// Withdraw withheld tokens from accounts
pub async fn withdraw_withheld_tokens_from_accounts<S2: Signer>( pub async fn withdraw_withheld_tokens_from_accounts<S: Signer>(
&self, &self,
destination: &Pubkey, destination: &Pubkey,
authority: &S2, authority: &S,
sources: &[&Pubkey], sources: &[&Pubkey],
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
@ -879,10 +934,10 @@ where
} }
/// Reallocate a token account to be large enough for a set of ExtensionTypes /// Reallocate a token account to be large enough for a set of ExtensionTypes
pub async fn reallocate<S2: Signer>( pub async fn reallocate<S: Signer>(
&self, &self,
account: &Pubkey, account: &Pubkey,
authority: &S2, authority: &S,
extension_types: &[ExtensionType], extension_types: &[ExtensionType],
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
@ -900,10 +955,10 @@ where
} }
/// Require memos on transfers into this account /// Require memos on transfers into this account
pub async fn enable_required_transfer_memos<S2: Signer>( pub async fn enable_required_transfer_memos<S: Signer>(
&self, &self,
account: &Pubkey, account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
&[memo_transfer::instruction::enable_required_transfer_memos( &[memo_transfer::instruction::enable_required_transfer_memos(
@ -918,10 +973,10 @@ where
} }
/// Stop requiring memos on transfers into this account /// Stop requiring memos on transfers into this account
pub async fn disable_required_transfer_memos<S2: Signer>( pub async fn disable_required_transfer_memos<S: Signer>(
&self, &self,
account: &Pubkey, account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
&[memo_transfer::instruction::disable_required_transfer_memos( &[memo_transfer::instruction::disable_required_transfer_memos(
@ -936,9 +991,9 @@ where
} }
/// Update interest rate /// Update interest rate
pub async fn update_interest_rate<S2: Signer>( pub async fn update_interest_rate<S: Signer>(
&self, &self,
authority: &S2, authority: &S,
new_rate: i16, new_rate: i16,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
@ -955,11 +1010,11 @@ where
} }
/// Update confidential transfer mint /// Update confidential transfer mint
pub async fn confidential_transfer_update_mint<S2: Signer>( pub async fn confidential_transfer_update_mint<S: Signer>(
&self, &self,
authority: &S2, authority: &S,
new_ct_mint: confidential_transfer::ConfidentialTransferMint, new_ct_mint: confidential_transfer::ConfidentialTransferMint,
new_authority: Option<&S2>, new_authority: Option<&S>,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
let mut signers = vec![authority]; let mut signers = vec![authority];
if let Some(new_authority) = new_authority { if let Some(new_authority) = new_authority {
@ -978,10 +1033,10 @@ where
} }
/// Configures confidential transfers for a token account /// Configures confidential transfers for a token account
pub async fn confidential_transfer_configure_token_account<S2: Signer>( pub async fn confidential_transfer_configure_token_account<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
let maximum_pending_balance_credit_counter = let maximum_pending_balance_credit_counter =
2 << confidential_transfer::MAXIMUM_DEPOSIT_TRANSFER_AMOUNT_BIT_LENGTH; 2 << confidential_transfer::MAXIMUM_DEPOSIT_TRANSFER_AMOUNT_BIT_LENGTH;
@ -994,10 +1049,10 @@ where
.await .await
} }
pub async fn confidential_transfer_configure_token_account_with_pending_counter<S2: Signer>( pub async fn confidential_transfer_configure_token_account_with_pending_counter<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
maximum_pending_balance_credit_counter: u64, maximum_pending_balance_credit_counter: u64,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
let elgamal_pubkey = ElGamalKeypair::new(authority, token_account) let elgamal_pubkey = ElGamalKeypair::new(authority, token_account)
@ -1018,11 +1073,11 @@ where
} }
pub async fn confidential_transfer_configure_token_account_with_pending_counter_and_keypair< pub async fn confidential_transfer_configure_token_account_with_pending_counter_and_keypair<
S2: Signer, S: Signer,
>( >(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
maximum_pending_balance_credit_counter: u64, maximum_pending_balance_credit_counter: u64,
elgamal_pubkey: ElGamalPubkey, elgamal_pubkey: ElGamalPubkey,
decryptable_zero_balance: AeCiphertext, decryptable_zero_balance: AeCiphertext,
@ -1044,10 +1099,10 @@ where
} }
/// Approves a token account for confidential transfers /// Approves a token account for confidential transfers
pub async fn confidential_transfer_approve_account<S2: Signer>( pub async fn confidential_transfer_approve_account<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
&[confidential_transfer::instruction::approve_account( &[confidential_transfer::instruction::approve_account(
@ -1062,10 +1117,10 @@ where
} }
/// Prepare a token account with the confidential transfer extension for closing /// Prepare a token account with the confidential transfer extension for closing
pub async fn confidential_transfer_empty_account<S2: Signer>( pub async fn confidential_transfer_empty_account<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
let elgamal_keypair = let elgamal_keypair =
ElGamalKeypair::new(authority, token_account).map_err(TokenError::Key)?; ElGamalKeypair::new(authority, token_account).map_err(TokenError::Key)?;
@ -1077,10 +1132,10 @@ where
.await .await
} }
pub async fn confidential_transfer_empty_account_with_keypair<S2: Signer>( pub async fn confidential_transfer_empty_account_with_keypair<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
elgamal_keypair: &ElGamalKeypair, elgamal_keypair: &ElGamalKeypair,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
let state = self.get_account_info(token_account).await.unwrap(); let state = self.get_account_info(token_account).await.unwrap();
@ -1108,10 +1163,10 @@ where
/// Fetch and decrypt the available balance of a confidential token account using the uniquely /// Fetch and decrypt the available balance of a confidential token account using the uniquely
/// derived decryption key from a signer /// derived decryption key from a signer
pub async fn confidential_transfer_get_available_balance<S2: Signer>( pub async fn confidential_transfer_get_available_balance<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<u64> { ) -> TokenResult<u64> {
let authenticated_encryption_key = let authenticated_encryption_key =
AeKey::new(authority, token_account).map_err(TokenError::Key)?; AeKey::new(authority, token_account).map_err(TokenError::Key)?;
@ -1147,10 +1202,10 @@ where
/// Fetch and decrypt the pending balance of a confidential token account using the uniquely /// Fetch and decrypt the pending balance of a confidential token account using the uniquely
/// derived decryption key from a signer /// derived decryption key from a signer
pub async fn confidential_transfer_get_pending_balance<S2: Signer>( pub async fn confidential_transfer_get_pending_balance<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<u64> { ) -> TokenResult<u64> {
let elgamal_keypair = let elgamal_keypair =
ElGamalKeypair::new(authority, token_account).map_err(TokenError::Key)?; ElGamalKeypair::new(authority, token_account).map_err(TokenError::Key)?;
@ -1187,9 +1242,9 @@ where
Ok(pending_balance) Ok(pending_balance)
} }
pub async fn confidential_transfer_get_withheld_amount<S2: Signer>( pub async fn confidential_transfer_get_withheld_amount<S: Signer>(
&self, &self,
withdraw_withheld_authority: &S2, withdraw_withheld_authority: &S,
sources: &[&Pubkey], sources: &[&Pubkey],
) -> TokenResult<u64> { ) -> TokenResult<u64> {
let withdraw_withheld_authority_elgamal_keypair = let withdraw_withheld_authority_elgamal_keypair =
@ -1229,7 +1284,7 @@ where
} }
/// Fetch the ElGamal public key associated with a confidential token account /// Fetch the ElGamal public key associated with a confidential token account
pub async fn confidential_transfer_get_encryption_pubkey<S2: Signer>( pub async fn confidential_transfer_get_encryption_pubkey<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
) -> TokenResult<ElGamalPubkey> { ) -> TokenResult<ElGamalPubkey> {
@ -1245,7 +1300,7 @@ where
} }
/// Fetch the ElGamal pubkey key of the auditor associated with a confidential token mint /// Fetch the ElGamal pubkey key of the auditor associated with a confidential token mint
pub async fn confidential_transfer_get_auditor_encryption_pubkey<S2: Signer>( pub async fn confidential_transfer_get_auditor_encryption_pubkey<S: Signer>(
&self, &self,
) -> TokenResult<ElGamalPubkey> { ) -> TokenResult<ElGamalPubkey> {
let mint_state = self.get_mint_info().await.unwrap(); let mint_state = self.get_mint_info().await.unwrap();
@ -1262,7 +1317,7 @@ where
/// Fetch the ElGamal pubkey key of the withdraw withheld authority associated with a /// Fetch the ElGamal pubkey key of the withdraw withheld authority associated with a
/// confidential token mint /// confidential token mint
pub async fn confidential_transfer_get_withdraw_withheld_authority_encryption_pubkey< pub async fn confidential_transfer_get_withdraw_withheld_authority_encryption_pubkey<
S2: Signer, S: Signer,
>( >(
&self, &self,
) -> TokenResult<ElGamalPubkey> { ) -> TokenResult<ElGamalPubkey> {
@ -1278,11 +1333,11 @@ where
} }
/// Deposit SPL Tokens into the pending balance of a confidential token account /// Deposit SPL Tokens into the pending balance of a confidential token account
pub async fn confidential_transfer_deposit<S2: Signer>( pub async fn confidential_transfer_deposit<S: Signer>(
&self, &self,
source_token_account: &Pubkey, source_token_account: &Pubkey,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
source_token_authority: &S2, source_token_authority: &S,
amount: u64, amount: u64,
decimals: u8, decimals: u8,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
@ -1309,11 +1364,11 @@ where
/// Withdraw SPL Tokens from the available balance of a confidential token account using the /// Withdraw SPL Tokens from the available balance of a confidential token account using the
/// uniquely derived decryption key from a signer /// uniquely derived decryption key from a signer
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn confidential_transfer_withdraw<S2: Signer>( pub async fn confidential_transfer_withdraw<S: Signer>(
&self, &self,
source_token_account: &Pubkey, source_token_account: &Pubkey,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
source_token_authority: &S2, source_token_authority: &S,
amount: u64, amount: u64,
source_available_balance: u64, source_available_balance: u64,
source_available_balance_ciphertext: &ElGamalCiphertext, source_available_balance_ciphertext: &ElGamalCiphertext,
@ -1342,11 +1397,11 @@ where
/// Withdraw SPL Tokens from the available balance of a confidential token account using custom /// Withdraw SPL Tokens from the available balance of a confidential token account using custom
/// keys /// keys
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn confidential_transfer_withdraw_with_key<S2: Signer>( pub async fn confidential_transfer_withdraw_with_key<S: Signer>(
&self, &self,
source_token_account: &Pubkey, source_token_account: &Pubkey,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
source_token_authority: &S2, source_token_authority: &S,
amount: u64, amount: u64,
decimals: u8, decimals: u8,
source_available_balance: u64, source_available_balance: u64,
@ -1388,11 +1443,11 @@ where
/// Transfer tokens confidentially using the uniquely derived decryption keys from a signer /// Transfer tokens confidentially using the uniquely derived decryption keys from a signer
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn confidential_transfer_transfer<S2: Signer>( pub async fn confidential_transfer_transfer<S: Signer>(
&self, &self,
source_token_account: &Pubkey, source_token_account: &Pubkey,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
source_token_authority: &S2, source_token_authority: &S,
amount: u64, amount: u64,
source_available_balance: u64, source_available_balance: u64,
source_available_balance_ciphertext: &ElGamalCiphertext, source_available_balance_ciphertext: &ElGamalCiphertext,
@ -1422,11 +1477,11 @@ where
/// Transfer tokens confidentially using custom decryption keys /// Transfer tokens confidentially using custom decryption keys
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn confidential_transfer_transfer_with_key<S2: Signer>( pub async fn confidential_transfer_transfer_with_key<S: Signer>(
&self, &self,
source_token_account: &Pubkey, source_token_account: &Pubkey,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
source_token_authority: &S2, source_token_authority: &S,
amount: u64, amount: u64,
source_available_balance: u64, source_available_balance: u64,
source_available_balance_ciphertext: &ElGamalCiphertext, source_available_balance_ciphertext: &ElGamalCiphertext,
@ -1475,11 +1530,11 @@ where
/// Transfer tokens confidentially with fee using the uniquely derived decryption keys from a /// Transfer tokens confidentially with fee using the uniquely derived decryption keys from a
/// signer /// signer
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn confidential_transfer_transfer_with_fee<S2: Signer>( pub async fn confidential_transfer_transfer_with_fee<S: Signer>(
&self, &self,
source_token_account: &Pubkey, source_token_account: &Pubkey,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
source_token_authority: &S2, source_token_authority: &S,
amount: u64, amount: u64,
source_available_balance: u64, source_available_balance: u64,
source_available_balance_ciphertext: &ElGamalCiphertext, source_available_balance_ciphertext: &ElGamalCiphertext,
@ -1513,11 +1568,11 @@ where
/// Transfer tokens confidential with fee using custom decryption keys /// Transfer tokens confidential with fee using custom decryption keys
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn confidential_transfer_transfer_with_fee_with_key<S2: Signer>( pub async fn confidential_transfer_transfer_with_fee_with_key<S: Signer>(
&self, &self,
source_token_account: &Pubkey, source_token_account: &Pubkey,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
source_token_authority: &S2, source_token_authority: &S,
amount: u64, amount: u64,
source_available_balance: u64, source_available_balance: u64,
source_available_balance_ciphertext: &ElGamalCiphertext, source_available_balance_ciphertext: &ElGamalCiphertext,
@ -1579,10 +1634,10 @@ where
/// Applies the confidential transfer pending balance to the available balance using the /// Applies the confidential transfer pending balance to the available balance using the
/// uniquely derived decryption key /// uniquely derived decryption key
pub async fn confidential_transfer_apply_pending_balance<S2: Signer>( pub async fn confidential_transfer_apply_pending_balance<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
available_balance: u64, available_balance: u64,
pending_balance: u64, pending_balance: u64,
expected_pending_balance_credit_counter: u64, expected_pending_balance_credit_counter: u64,
@ -1603,10 +1658,10 @@ where
/// Applies the confidential transfer pending balance to the available balance using a custom /// Applies the confidential transfer pending balance to the available balance using a custom
/// decryption key /// decryption key
pub async fn confidential_transfer_apply_pending_balance_with_key<S2: Signer>( pub async fn confidential_transfer_apply_pending_balance_with_key<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
available_balance: u64, available_balance: u64,
pending_balance: u64, pending_balance: u64,
expected_pending_balance_credit_counter: u64, expected_pending_balance_credit_counter: u64,
@ -1631,10 +1686,10 @@ where
} }
/// Enable confidential transfer `Deposit` and `Transfer` instructions for a token account /// Enable confidential transfer `Deposit` and `Transfer` instructions for a token account
pub async fn confidential_transfer_enable_balance_credits<S2: Signer>( pub async fn confidential_transfer_enable_balance_credits<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
&[confidential_transfer::instruction::enable_balance_credits( &[confidential_transfer::instruction::enable_balance_credits(
@ -1649,10 +1704,10 @@ where
} }
/// Disable confidential transfer `Deposit` and `Transfer` instructions for a token account /// Disable confidential transfer `Deposit` and `Transfer` instructions for a token account
pub async fn confidential_transfer_disable_balance_credits<S2: Signer>( pub async fn confidential_transfer_disable_balance_credits<S: Signer>(
&self, &self,
token_account: &Pubkey, token_account: &Pubkey,
authority: &S2, authority: &S,
) -> TokenResult<T::Output> { ) -> TokenResult<T::Output> {
self.process_ixs( self.process_ixs(
&[confidential_transfer::instruction::disable_balance_credits( &[confidential_transfer::instruction::disable_balance_credits(
@ -1667,9 +1722,9 @@ where
} }
/// Withdraw withheld confidential tokens from mint using the uniquely derived decryption key /// Withdraw withheld confidential tokens from mint using the uniquely derived decryption key
pub async fn confidential_transfer_withdraw_withheld_tokens_from_mint<S2: Signer>( pub async fn confidential_transfer_withdraw_withheld_tokens_from_mint<S: Signer>(
&self, &self,
withdraw_withheld_authority: &S2, withdraw_withheld_authority: &S,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
destination_elgamal_pubkey: &ElGamalPubkey, destination_elgamal_pubkey: &ElGamalPubkey,
withheld_amount: u64, withheld_amount: u64,
@ -1692,9 +1747,9 @@ where
} }
/// Withdraw withheld confidential tokens from mint using a custom decryption key /// Withdraw withheld confidential tokens from mint using a custom decryption key
pub async fn confidential_transfer_withdraw_withheld_tokens_from_mint_with_key<S2: Signer>( pub async fn confidential_transfer_withdraw_withheld_tokens_from_mint_with_key<S: Signer>(
&self, &self,
withdraw_withheld_authority: &S2, withdraw_withheld_authority: &S,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
destination_elgamal_pubkey: &ElGamalPubkey, destination_elgamal_pubkey: &ElGamalPubkey,
withheld_amount: u64, withheld_amount: u64,
@ -1725,9 +1780,9 @@ where
/// Withdraw withheld confidential tokens from accounts using the uniquely derived decryption /// Withdraw withheld confidential tokens from accounts using the uniquely derived decryption
/// key /// key
pub async fn confidential_transfer_withdraw_withheld_tokens_from_accounts<S2: Signer>( pub async fn confidential_transfer_withdraw_withheld_tokens_from_accounts<S: Signer>(
&self, &self,
withdraw_withheld_authority: &S2, withdraw_withheld_authority: &S,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
destination_elgamal_pubkey: &ElGamalPubkey, destination_elgamal_pubkey: &ElGamalPubkey,
aggregate_withheld_amount: u64, aggregate_withheld_amount: u64,
@ -1753,10 +1808,10 @@ where
/// Withdraw withheld confidential tokens from accounts using a custom decryption key /// Withdraw withheld confidential tokens from accounts using a custom decryption key
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub async fn confidential_transfer_withdraw_withheld_tokens_from_accounts_with_key< pub async fn confidential_transfer_withdraw_withheld_tokens_from_accounts_with_key<
S2: Signer, S: Signer,
>( >(
&self, &self,
withdraw_withheld_authority: &S2, withdraw_withheld_authority: &S,
destination_token_account: &Pubkey, destination_token_account: &Pubkey,
destination_elgamal_pubkey: &ElGamalPubkey, destination_elgamal_pubkey: &ElGamalPubkey,
aggregate_withheld_amount: u64, aggregate_withheld_amount: u64,

View File

@ -18,7 +18,7 @@ use {
struct TestContext { struct TestContext {
pub decimals: u8, pub decimals: u8,
pub mint_authority: Keypair, pub mint_authority: Keypair,
pub token: Token<ProgramBanksClientProcessTransaction, Keypair>, pub token: Token<ProgramBanksClientProcessTransaction>,
pub alice: Keypair, pub alice: Keypair,
pub bob: Keypair, pub bob: Keypair,
@ -44,15 +44,20 @@ impl TestContext {
let mint_authority = Keypair::new(); let mint_authority = Keypair::new();
let mint_authority_pubkey = mint_authority.pubkey(); let mint_authority_pubkey = mint_authority.pubkey();
let token = Token::create_mint( let token = Token::new(
Arc::clone(&client), Arc::clone(&client),
&spl_token_2022::id(), &spl_token_2022::id(),
keypair_clone(&payer), &mint_account.pubkey(),
&mint_account, Arc::new(keypair_clone(&payer)),
);
token
.create_mint(
&mint_authority_pubkey, &mint_authority_pubkey,
None, None,
decimals, decimals,
vec![], vec![],
&[&mint_account],
) )
.await .await
.expect("failed to create mint"); .expect("failed to create mint");

View File

@ -14,7 +14,7 @@ use {
pub struct TokenContext { pub struct TokenContext {
pub decimals: u8, pub decimals: u8,
pub mint_authority: Keypair, pub mint_authority: Keypair,
pub token: Token<ProgramBanksClientProcessTransaction, Keypair>, pub token: Token<ProgramBanksClientProcessTransaction>,
pub alice: Keypair, pub alice: Keypair,
pub bob: Keypair, pub bob: Keypair,
pub freeze_authority: Option<Keypair>, pub freeze_authority: Option<Keypair>,
@ -75,17 +75,23 @@ impl TestContext {
.as_ref() .as_ref()
.map(|authority| authority.pubkey()); .map(|authority| authority.pubkey());
let token = Token::create_mint( let token = Token::new(
Arc::clone(&client), Arc::clone(&client),
&id(), &id(),
payer, &mint_account.pubkey(),
&mint_account, Arc::new(payer),
);
token
.create_mint(
&mint_authority_pubkey, &mint_authority_pubkey,
freeze_authority_pubkey.as_ref(), freeze_authority_pubkey.as_ref(),
decimals, decimals,
extension_init_params, extension_init_params,
&[&mint_account],
) )
.await?; .await?;
self.token_context = Some(TokenContext { self.token_context = Some(TokenContext {
decimals, decimals,
mint_authority, mint_authority,
@ -106,7 +112,7 @@ impl TestContext {
ProgramBanksClientProcessTransaction, ProgramBanksClientProcessTransaction,
)); ));
let token = Token::create_native_mint(Arc::clone(&client), &id(), payer).await?; let token = Token::create_native_mint(Arc::clone(&client), &id(), Arc::new(payer)).await?;
self.token_context = Some(TokenContext { self.token_context = Some(TokenContext {
decimals: native_mint::DECIMALS, decimals: native_mint::DECIMALS,
mint_authority: Keypair::new(), /*bogus*/ mint_authority: Keypair::new(), /*bogus*/

View File

@ -17,7 +17,7 @@ use {
}; };
async fn run_basic( async fn run_basic(
token: Token<ProgramBanksClientProcessTransaction, Keypair>, token: Token<ProgramBanksClientProcessTransaction>,
context: Arc<Mutex<ProgramTestContext>>, context: Arc<Mutex<ProgramTestContext>>,
account: Pubkey, account: Pubkey,
) { ) {

View File

@ -74,7 +74,7 @@ fn test_transfer_fee_config_with_keypairs() -> TransferFeeConfigWithKeypairs {
struct TokenWithAccounts { struct TokenWithAccounts {
context: TestContext, context: TestContext,
token: Token<ProgramBanksClientProcessTransaction, Keypair>, token: Token<ProgramBanksClientProcessTransaction>,
transfer_fee_config: TransferFeeConfig, transfer_fee_config: TransferFeeConfig,
withdraw_withheld_authority: Keypair, withdraw_withheld_authority: Keypair,
freeze_authority: Keypair, freeze_authority: Keypair,
@ -1093,7 +1093,7 @@ async fn no_fees_from_self_transfer() {
} }
async fn create_and_transfer_to_account( async fn create_and_transfer_to_account(
token: &Token<ProgramBanksClientProcessTransaction, Keypair>, token: &Token<ProgramBanksClientProcessTransaction>,
source: &Pubkey, source: &Pubkey,
authority: &Keypair, authority: &Keypair,
owner: &Pubkey, owner: &Pubkey,