Revert "Revert "spl-token: New program feature flag (backport #21354) (#21376)""

This reverts commit 36838427d4.
This commit is contained in:
Tyera Eulberg
2021-12-16 13:46:27 -07:00
committed by Tyera Eulberg
parent a931b3f868
commit 83676aed53
23 changed files with 229 additions and 245 deletions

View File

@@ -29,8 +29,8 @@ solana-runtime = { path = "../runtime", version = "=1.8.12" }
solana-sdk = { path = "../sdk", version = "=1.8.12" }
solana-transaction-status = { path = "../transaction-status", version = "=1.8.12" }
solana-version = { path = "../version", version = "=1.8.12" }
spl-associated-token-account-v1-0 = { package = "spl-associated-token-account", version = "=1.0.3" }
spl-token-v2-0 = { package = "spl-token", version = "=3.2.0", features = ["no-entrypoint"] }
spl-associated-token-account = { package = "spl-associated-token-account", version = "=1.0.3" }
spl-token = { version = "=3.2.0", features = ["no-entrypoint"] }
tempfile = "3.1.0"
thiserror = "1.0"

View File

@@ -12,7 +12,7 @@ use indicatif::{ProgressBar, ProgressStyle};
use pickledb::PickleDb;
use serde::{Deserialize, Serialize};
use solana_account_decoder::parse_token::{
pubkey_from_spl_token_v2_0, real_number_string, spl_token_v2_0_pubkey,
pubkey_from_spl_token, real_number_string, spl_token_pubkey,
};
use solana_client::{
client_error::{ClientError, Result as ClientResult},
@@ -36,8 +36,8 @@ use solana_sdk::{
transaction::Transaction,
};
use solana_transaction_status::TransactionStatus;
use spl_associated_token_account_v1_0::get_associated_token_address;
use spl_token_v2_0::solana_program::program_error::ProgramError;
use spl_associated_token_account::get_associated_token_address;
use spl_token::solana_program::program_error::ProgramError;
use std::{
cmp::{self},
io,
@@ -310,12 +310,11 @@ fn build_messages(
let wallet_address = allocation.recipient.parse().unwrap();
let associated_token_address = get_associated_token_address(
&wallet_address,
&spl_token_v2_0_pubkey(&spl_token_args.mint),
&spl_token_pubkey(&spl_token_args.mint),
);
let do_create_associated_token_account = client
.get_multiple_accounts(&[pubkey_from_spl_token_v2_0(&associated_token_address)])?
[0]
.is_none();
.get_multiple_accounts(&[pubkey_from_spl_token(&associated_token_address)])?[0]
.is_none();
if do_create_associated_token_account {
*created_accounts += 1;
}

View File

@@ -4,16 +4,13 @@ use crate::{
};
use console::style;
use solana_account_decoder::parse_token::{
pubkey_from_spl_token_v2_0, real_number_string, real_number_string_trimmed,
spl_token_v2_0_pubkey,
pubkey_from_spl_token, real_number_string, real_number_string_trimmed, spl_token_pubkey,
};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{instruction::Instruction, native_token::lamports_to_sol};
use solana_transaction_status::parse_token::spl_token_v2_0_instruction;
use spl_associated_token_account_v1_0::{
create_associated_token_account, get_associated_token_address,
};
use spl_token_v2_0::{
use solana_transaction_status::parse_token::spl_token_instruction;
use spl_associated_token_account::{create_associated_token_account, get_associated_token_address};
use spl_token::{
solana_program::program_pack::Pack,
state::{Account as SplTokenAccount, Mint},
};
@@ -24,7 +21,7 @@ pub fn update_token_args(client: &RpcClient, args: &mut Option<SplTokenArgs>) ->
.get_account(&spl_token_args.token_account_address)
.unwrap_or_default();
let mint_address =
pubkey_from_spl_token_v2_0(&SplTokenAccount::unpack(&sender_account.data)?.mint);
pubkey_from_spl_token(&SplTokenAccount::unpack(&sender_account.data)?.mint);
spl_token_args.mint = mint_address;
update_decimals(client, args)?;
}
@@ -54,33 +51,31 @@ pub fn build_spl_token_instructions(
.as_ref()
.expect("spl_token_args must be some");
let wallet_address = allocation.recipient.parse().unwrap();
let associated_token_address = get_associated_token_address(
&wallet_address,
&spl_token_v2_0_pubkey(&spl_token_args.mint),
);
let associated_token_address =
get_associated_token_address(&wallet_address, &spl_token_pubkey(&spl_token_args.mint));
let mut instructions = vec![];
if do_create_associated_token_account {
let create_associated_token_account_instruction = create_associated_token_account(
&spl_token_v2_0_pubkey(&args.fee_payer.pubkey()),
&spl_token_pubkey(&args.fee_payer.pubkey()),
&wallet_address,
&spl_token_v2_0_pubkey(&spl_token_args.mint),
&spl_token_pubkey(&spl_token_args.mint),
);
instructions.push(spl_token_v2_0_instruction(
instructions.push(spl_token_instruction(
create_associated_token_account_instruction,
));
}
let spl_instruction = spl_token_v2_0::instruction::transfer_checked(
&spl_token_v2_0::id(),
&spl_token_v2_0_pubkey(&spl_token_args.token_account_address),
&spl_token_v2_0_pubkey(&spl_token_args.mint),
let spl_instruction = spl_token::instruction::transfer_checked(
&spl_token::id(),
&spl_token_pubkey(&spl_token_args.token_account_address),
&spl_token_pubkey(&spl_token_args.mint),
&associated_token_address,
&spl_token_v2_0_pubkey(&args.sender_keypair.pubkey()),
&spl_token_pubkey(&args.sender_keypair.pubkey()),
&[],
allocation.amount,
spl_token_args.decimals,
)
.unwrap();
instructions.push(spl_token_v2_0_instruction(spl_instruction));
instructions.push(spl_token_instruction(spl_instruction));
instructions
}
@@ -134,11 +129,11 @@ pub fn print_token_balances(
let address = allocation.recipient.parse().unwrap();
let expected = allocation.amount;
let associated_token_address = get_associated_token_address(
&spl_token_v2_0_pubkey(&address),
&spl_token_v2_0_pubkey(&spl_token_args.mint),
&spl_token_pubkey(&address),
&spl_token_pubkey(&spl_token_args.mint),
);
let recipient_account = client
.get_account(&pubkey_from_spl_token_v2_0(&associated_token_address))
.get_account(&pubkey_from_spl_token(&associated_token_address))
.unwrap_or_default();
let (actual, difference) = if let Ok(recipient_token) =
SplTokenAccount::unpack(&recipient_account.data)