Skip to content

Commit

Permalink
Merge pull request #517 from liuck8080/develop
Browse files Browse the repository at this point in the history
fix: Fix 2 problems of wallet subcommands
  • Loading branch information
TheWaWaR authored Nov 20, 2022
2 parents a394de2 + e351098 commit 29d8988
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 84 deletions.
2 changes: 2 additions & 0 deletions src/subcommands/api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ pub struct HttpTransferArgs {
pub to_address: String,
pub from_locked_address: Option<String>,
pub to_data: Option<Bytes>,
pub force_small_change_as_fee: Option<String>,
}

impl HttpTransferArgs {
Expand All @@ -397,6 +398,7 @@ impl HttpTransferArgs {
derive_change_address: None,
capacity,
fee_rate,
force_small_change_as_fee: self.force_small_change_as_fee,
to_address: self.to_address,
to_data: self.to_data,
is_type_id: false,
Expand Down
8 changes: 7 additions & 1 deletion src/subcommands/dao/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::utils::{
other::{get_address, get_network_type},
};
use ckb_crypto::secp::SECP256K1;
use ckb_sdk::{Address, AddressPayload, NetworkType};
use ckb_sdk::{Address, AddressPayload, HumanCapacity, NetworkType};
use ckb_types::{packed::Script, H160};
use clap::{App, Arg, ArgMatches};
use std::collections::HashSet;
Expand Down Expand Up @@ -109,6 +109,7 @@ pub struct TransactArgs {
pub(crate) privkey: Option<PrivkeyWrapper>,
pub(crate) address: Address,
pub(crate) fee_rate: u64,
pub(crate) force_small_change_as_fee: Option<u64>,
}

impl TransactArgs {
Expand Down Expand Up @@ -142,10 +143,14 @@ impl TransactArgs {
Address::new(network_type, payload, false)
};
let fee_rate: u64 = FromStrParser::<u64>::default().from_matches(m, "fee-rate")?;

let force_small_change_as_fee =
FromStrParser::<HumanCapacity>::default().from_matches_opt(m, "max-tx-fee")?;
Ok(Self {
privkey,
address,
fee_rate,
force_small_change_as_fee,
})
}

Expand All @@ -154,6 +159,7 @@ impl TransactArgs {
arg::privkey_path().required_unless(arg::from_account().get_name()),
arg::from_account().required_unless(arg::privkey_path().get_name()),
arg::fee_rate(),
arg::max_tx_fee(),
]
}
}
20 changes: 13 additions & 7 deletions src/subcommands/dao/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ use ckb_types::{
use plugin_protocol::LiveCellInfo;

use self::command::TransactArgs;
use crate::plugin::PluginManager;
use crate::utils::genesis_info::GenesisInfo;
use crate::utils::other::{read_password, to_live_cell_info};
use crate::utils::rpc::HttpRpcClient;
use crate::utils::signer::KeyStoreHandlerSigner;
use crate::{
plugin::PluginManager,
utils::{
genesis_info::GenesisInfo,
other::{map_tx_builder_error_2_str, read_password, to_live_cell_info},
rpc::HttpRpcClient,
signer::KeyStoreHandlerSigner,
},
};

mod command;
mod util;
Expand Down Expand Up @@ -85,7 +89,7 @@ impl<'a> DAOSubCommand<'a> {
.lock(Some(Bytes::from(vec![0u8; 65])).pack())
.build(),
)]),
force_small_change_as_fee: None,
force_small_change_as_fee: args.force_small_change_as_fee,
};

let signer: Box<dyn Signer> = if let Some(privkey) = args.privkey.as_ref() {
Expand Down Expand Up @@ -123,7 +127,9 @@ impl<'a> DAOSubCommand<'a> {
&balancer,
&unlockers,
)
.map_err(|err| err.to_string())?;
.map_err(|err| {
map_tx_builder_error_2_str(balancer.force_small_change_as_fee.is_none(), err)
})?;
assert!(still_locked_groups.is_empty());
Ok(tx)
}
Expand Down
Loading

0 comments on commit 29d8988

Please sign in to comment.