Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add receiver account transfer option #266

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ indexmap = { version = "1.9.1", features = ["serde"] }
indicatif = { version = "0.16.2", features = ["rayon"] }
lazy_static = "1.4.0"
log = "0.4.17"
metaboss_lib = "0.7.1"
metaboss_lib = "0.8.1"
mpl-token-metadata = { version = "1.9.0", features = [ "no-entrypoint", "serde-feature"] }
num_cpus = "1.13.1"
phf = { version = "0.10", features = ["macros"] }
Expand Down
1 change: 0 additions & 1 deletion src/collections/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ fn set_and_verify(
payer: None,
token: None::<String>,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set: None::<String>,
update_args,
},
)
Expand Down
4 changes: 4 additions & 0 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,10 @@ pub enum TransferSubcommands {
/// Amount of tokens to transfer, for NonFungible types this must be 1.
#[structopt(long, default_value = "1")]
amount: u64,

/// Receiver token account, if not provided an ATA will be created.
#[structopt(long)]
receiver_account: Option<String>,
},
}

Expand Down
3 changes: 2 additions & 1 deletion src/process_subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,8 @@ pub fn process_transfer(client: RpcClient, commands: TransferSubcommands) -> Res
receiver,
mint,
amount,
} => process_transfer_asset(&client, keypair, receiver, mint, amount),
receiver_account,
} => process_transfer_asset(&client, keypair, receiver, receiver_account, mint, amount),
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/transfer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub fn process_transfer_asset(
client: &RpcClient,
keypair_path: Option<String>,
receiver: String,
receiver_account: Option<String>,
mint: String,
amount: u64,
) -> Result<()> {
Expand All @@ -23,7 +24,11 @@ pub fn process_transfer_asset(
let mint = Pubkey::from_str(&mint)?;

let source_ata = get_associated_token_address(&authority.pubkey(), &mint);
let destination_ata = get_associated_token_address(&receiver, &mint);
let destination_token = if let Some(account) = receiver_account {
Pubkey::from_str(&account)?
} else {
get_associated_token_address(&receiver, &mint)
};

let args = TransferAssetArgs::V1 {
payer: None,
Expand All @@ -32,7 +37,7 @@ pub fn process_transfer_asset(
source_owner: authority.pubkey(),
source_token: source_ata,
destination_owner: receiver,
destination_token: destination_ata,
destination_token,
amount,
authorization_data: None,
};
Expand Down
3 changes: 1 addition & 2 deletions src/update/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct UpdateCreatorArgs {
}

pub async fn update_creator(args: UpdateCreatorArgs) -> Result<Signature, ActionError> {
let (mut current_md, token, current_rule_set) =
let (mut current_md, token, _current_rule_set) =
update_asset_preface(&args.client, &args.mint_account)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;

Expand Down Expand Up @@ -62,7 +62,6 @@ pub async fn update_creator(args: UpdateCreatorArgs) -> Result<Signature, Action
mint: args.mint_account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down
3 changes: 1 addition & 2 deletions src/update/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct UpdateDataArgs {
}

pub async fn update_data(args: UpdateDataArgs) -> Result<Signature, ActionError> {
let (_current_md, token, current_rule_set) =
let (_current_md, token, _current_rule_set) =
update_asset_preface(&args.client, &args.mint_account)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;

Expand All @@ -43,7 +43,6 @@ pub async fn update_data(args: UpdateDataArgs) -> Result<Signature, ActionError>
mint: args.mint_account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down
3 changes: 1 addition & 2 deletions src/update/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct SetImmutableAllArgs {
}

pub async fn set_immutable(args: SetImmutableArgs) -> Result<Signature, ActionError> {
let (_current_md, token, current_rule_set) =
let (_current_md, token, _current_rule_set) =
update_asset_preface(&args.client, &args.mint_account)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;

Expand All @@ -39,7 +39,6 @@ pub async fn set_immutable(args: SetImmutableArgs) -> Result<Signature, ActionEr
mint: args.mint_account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down
3 changes: 1 addition & 2 deletions src/update/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct UpdateNameArgs {
}

pub async fn update_name(args: UpdateNameArgs) -> Result<Signature, ActionError> {
let (mut current_md, token, current_rule_set) =
let (mut current_md, token, _current_rule_set) =
update_asset_preface(&args.client, &args.mint_account)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;

Expand All @@ -27,7 +27,6 @@ pub async fn update_name(args: UpdateNameArgs) -> Result<Signature, ActionError>
mint: args.mint_account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down
3 changes: 1 addition & 2 deletions src/update/primary_sale_happened.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct SetPrimarySaleHappenedArgs {
pub async fn set_primary_sale_happened(
args: SetPrimarySaleHappenedArgs,
) -> Result<Signature, ActionError> {
let (_, token, current_rule_set) = update_asset_preface(&args.client, &args.mint_account)
let (_, token, _current_rule_set) = update_asset_preface(&args.client, &args.mint_account)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;

// Token Metadata UpdateArgs enum.
Expand All @@ -39,7 +39,6 @@ pub async fn set_primary_sale_happened(
mint: args.mint_account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down
26 changes: 12 additions & 14 deletions src/update/rule_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ pub async fn update_rule_set(args: UpdateRuleSetArgs) -> Result<Signature, Actio

*rule_set = RuleSetToggle::Set(new_rule_set);

let current_rule_set = if let Some(ProgrammableConfig::V1 { rule_set }) = md.programmable_config
{
rule_set
} else {
None
};
let _current_rule_set =
if let Some(ProgrammableConfig::V1 { rule_set }) = md.programmable_config {
rule_set
} else {
None
};

// Metaboss UpdateAssetArgs enum.
let update_args = UpdateAssetArgs::V1 {
Expand All @@ -73,7 +73,6 @@ pub async fn update_rule_set(args: UpdateRuleSetArgs) -> Result<Signature, Actio
mint: args.mint_account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down Expand Up @@ -106,12 +105,12 @@ pub async fn clear_rule_set(args: ClearRuleSetArgs) -> Result<Signature, ActionE

*rule_set = RuleSetToggle::Clear;

let current_rule_set = if let Some(ProgrammableConfig::V1 { rule_set }) = md.programmable_config
{
rule_set
} else {
None
};
let _current_rule_set =
if let Some(ProgrammableConfig::V1 { rule_set }) = md.programmable_config {
rule_set
} else {
None
};

// Metaboss UpdateAssetArgs enum.
let update_args = UpdateAssetArgs::V1 {
Expand All @@ -120,7 +119,6 @@ pub async fn clear_rule_set(args: ClearRuleSetArgs) -> Result<Signature, ActionE
mint,
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down
3 changes: 1 addition & 2 deletions src/update/seller_fee_basis_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct UpdateSellerFeeBasisPointsAllArgs {
}

pub async fn update_sfbp(args: UpdateSellerFeeBasisPointsArgs) -> Result<Signature, ActionError> {
let (mut current_md, token, current_rule_set) =
let (mut current_md, token, _current_rule_set) =
update_asset_preface(&args.client, &args.mint_account)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;

Expand All @@ -41,7 +41,6 @@ pub async fn update_sfbp(args: UpdateSellerFeeBasisPointsArgs) -> Result<Signatu
mint: args.mint_account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down
3 changes: 1 addition & 2 deletions src/update/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct UpdateSymbolArgs {
}

pub async fn update_symbol(args: UpdateSymbolArgs) -> Result<Signature, ActionError> {
let (mut current_md, token, current_rule_set) =
let (mut current_md, token, _current_rule_set) =
update_asset_preface(&args.client, &args.mint_account)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;

Expand All @@ -39,7 +39,6 @@ pub async fn update_symbol(args: UpdateSymbolArgs) -> Result<Signature, ActionEr
mint: args.mint_account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down
3 changes: 1 addition & 2 deletions src/update/update_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct SetUpdateAuthorityArgs {
}

pub async fn set_update_authority(args: SetUpdateAuthorityArgs) -> Result<Signature, ActionError> {
let (_current_md, token, current_rule_set) =
let (_current_md, token, _current_rule_set) =
update_asset_preface(&args.client, &args.mint_account)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;

Expand All @@ -46,7 +46,6 @@ pub async fn set_update_authority(args: SetUpdateAuthorityArgs) -> Result<Signat
mint: args.mint_account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down
3 changes: 1 addition & 2 deletions src/update/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct UpdateUriArgs {
}

pub async fn update_uri(args: UpdateUriArgs) -> Result<Signature, ActionError> {
let (mut current_md, token, current_rule_set) =
let (mut current_md, token, _current_rule_set) =
update_asset_preface(&args.client, &args.mint_account)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;

Expand All @@ -49,7 +49,6 @@ pub async fn update_uri(args: UpdateUriArgs) -> Result<Signature, ActionError> {
mint: args.mint_account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down
6 changes: 2 additions & 4 deletions src/update/uses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ pub fn update_uses_one(args: UsesArgs) -> Result<Signature, ActionError> {
let solana_opts = parse_solana_config();
let keypair = parse_keypair(args.keypair, solana_opts);

let (current_md, token, current_rule_set) =
update_asset_preface(&args.client, &args.account)
.map_err(|e| ActionError::ActionFailed(args.account.to_string(), e.to_string()))?;
let (current_md, token, _current_rule_set) = update_asset_preface(&args.client, &args.account)
.map_err(|e| ActionError::ActionFailed(args.account.to_string(), e.to_string()))?;

let use_method = match args.method.to_lowercase().as_str() {
"burn" => UseMethod::Burn,
Expand Down Expand Up @@ -64,7 +63,6 @@ pub fn update_uses_one(args: UsesArgs) -> Result<Signature, ActionError> {
mint: args.account.clone(),
token,
delegate_record: None::<String>, // Not supported yet in update.
current_rule_set,
update_args,
};

Expand Down