Skip to content

Commit

Permalink
submit_unbond: only print out the unbond tx amount and its withdrawab…
Browse files Browse the repository at this point in the history
…le epoch
  • Loading branch information
brentstone committed Mar 20, 2023
1 parent 85f6c74 commit 895f3c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 16 additions & 1 deletion apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,7 @@ pub async fn submit_unbond(ctx: Context, args: args::Unbond) {
let bond_source = source.clone().unwrap_or_else(|| validator.clone());
let bond_amount =
rpc::query_bond(&client, &bond_source, &validator, None).await;
println!("BOND AMOUNT REMAINING IS {}", bond_amount);
println!("Bond amount available for unbonding: {} NAM", bond_amount);

if args.amount > bond_amount {
eprintln!(
Expand Down Expand Up @@ -2424,6 +2424,21 @@ pub async fn submit_unbond(ctx: Context, args: args::Unbond) {
)
.await;

let unbonds =
rpc::query_unbond_with_slashing(&client, &bond_source, &validator)
.await;
let mut withdrawable = BTreeMap::<Epoch, token::Amount>::new();
for ((_start_epoch, withdraw_epoch), amount) in unbonds.into_iter() {
let to_withdraw = withdrawable.entry(withdraw_epoch).or_default();
*to_withdraw += amount;
}
let (withdraw_epoch, withdraw_amount) = withdrawable.iter().last().unwrap();
debug_assert!(args.amount <= *withdraw_amount);
println!(
"Amount {} withdrawable starting from epoch {}",
args.amount, *withdraw_epoch
);

rpc::query_and_print_unbonds(&client, &bond_source, &validator).await;
}

Expand Down
9 changes: 1 addition & 8 deletions tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1907,14 +1907,7 @@ fn pos_bonds() -> Result<()> {
let mut client = run!(test, Bin::Client, tx_args, Some(40))?;
let expected = "Amount 32 withdrawable starting from epoch ";
let (_unread, matched) = client.exp_regex(&format!("{expected}.*\n"))?;
let epoch_raw = matched
.trim()
.split_once(expected)
.unwrap()
.1
.split_once('.')
.unwrap()
.0;
let epoch_raw = matched.trim().split_once(expected).unwrap().1;
let delegation_withdrawable_epoch = Epoch::from_str(epoch_raw).unwrap();
client.assert_success();

Expand Down

0 comments on commit 895f3c0

Please sign in to comment.