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

fix sui cli split-coin by amounts #5104

Merged
merged 1 commit into from
Oct 11, 2022
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
fix sui cli split-coin by amounts
  • Loading branch information
emmazzz committed Oct 10, 2022
commit 5de3f9ad984c2bdf8ebc30cfe4bc9bfb5dda94cc
2 changes: 1 addition & 1 deletion crates/sui-faucet/src/faucet/simple_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ mod tests {
amounts: Some(vec![tiny_value + TRANSFER_SUI_GAS]),
gas_budget: 50000,
gas: None,
count: 0,
count: None,
}
.execute(&mut context)
.await
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-open-rpc/src/generate_json_rpc_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ async fn create_coin_split_response(
let result = SuiClientCommands::SplitCoin {
coin_id: coins.first().unwrap().object_id,
amounts: Some(vec![20, 20, 20, 20, 20]),
count: 0,
count: None,
gas: None,
gas_budget: 1000,
}
Expand Down
36 changes: 21 additions & 15 deletions crates/sui/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub enum SuiClientCommands {
amounts: Option<Vec<u64>>,
/// Count of equal-size coins to split into
#[clap(long)]
count: u64,
count: Option<u64>,
/// ID of the gas object for gas payment, in 20 bytes Hex string
/// If not provided, a gas object with at least gas_budget value will be selected
#[clap(long)]
Expand Down Expand Up @@ -511,21 +511,27 @@ impl SuiClientCommands {
gas_budget,
} => {
let signer = context.get_object_owner(&coin_id).await?;
let data = if let Some(amounts) = amounts {
context
.client
.transaction_builder()
.split_coin(signer, coin_id, amounts, gas, gas_budget)
.await?
} else {
if count == 0 {
return Err(anyhow!("Coin split count must be greater than 0"));
let data = match (amounts, count) {
(Some(amounts), None) => {
context
.client
.transaction_builder()
.split_coin(signer, coin_id, amounts, gas, gas_budget)
.await?
}
(None, Some(count)) => {
if count == 0 {
return Err(anyhow!("Coin split count must be greater than 0"));
}
context
.client
.transaction_builder()
.split_coin_equal(signer, coin_id, count, gas, gas_budget)
.await?
}
_ => {
return Err(anyhow!("Exactly one of `count` and `amounts` must be present for split-coin command."));
}
context
.client
.transaction_builder()
.split_coin_equal(signer, coin_id, count, gas, gas_budget)
.await?
};
let signature = context.config.keystore.sign(&signer, &data.to_bytes())?;
let response = context
Expand Down
6 changes: 3 additions & 3 deletions crates/sui/src/unit_tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ async fn test_split_coin() -> Result<(), anyhow::Error> {
gas_budget: 1000,
coin_id: coin,
amounts: Some(vec![1000, 10]),
count: 0,
count: None,
}
.execute(context)
.await?;
Expand Down Expand Up @@ -1073,7 +1073,7 @@ async fn test_split_coin() -> Result<(), anyhow::Error> {
gas_budget: 1000,
coin_id: coin,
amounts: None,
count: 3,
count: Some(3),
}
.execute(context)
.await?;
Expand Down Expand Up @@ -1132,7 +1132,7 @@ async fn test_split_coin() -> Result<(), anyhow::Error> {
gas_budget: 1000,
coin_id: coin,
amounts: Some(vec![1000, 10]),
count: 0,
count: None,
}
.execute(context)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/sui/tests/full_node_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ async fn test_full_node_sync_flood() -> Result<(), anyhow::Error> {
let context = &mut context.lock().await;
SuiClientCommands::SplitCoin {
amounts: Some(vec![1]),
count: 0,
count: None,
coin_id: object_to_split.0,
gas: Some(gas_object_id),
gas_budget: 50000,
Expand Down
2 changes: 1 addition & 1 deletion crates/test-utils/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub async fn split_coin_with_wallet_context(context: &mut WalletContext, coin_id
SuiClientCommands::SplitCoin {
coin_id,
amounts: None,
count: 2,
count: Some(2),
gas: None,
gas_budget: MAX_GAS,
}
Expand Down