Skip to content

Commit 567dcc7

Browse files
committed
add account drop subcommand
1 parent 0f46dd8 commit 567dcc7

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/db.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,23 @@ impl Db {
13241324
self.auto_save(true)
13251325
}
13261326

1327+
#[allow(clippy::too_many_arguments)]
1328+
pub fn record_drop(
1329+
&mut self,
1330+
from_address: Pubkey,
1331+
token: MaybeToken,
1332+
amount: u64,
1333+
lot_selection_method: LotSelectionMethod,
1334+
lot_numbers: Option<HashSet<usize>>,
1335+
) -> DbResult<()> {
1336+
let mut from_account = self
1337+
.get_account(from_address, token)
1338+
.ok_or(DbError::AccountDoesNotExist(from_address, token))?;
1339+
let _ = from_account.extract_lots(self, amount, lot_selection_method, lot_numbers)?;
1340+
self.update_account(from_account)?; // `update_account` calls `save`...
1341+
Ok(())
1342+
}
1343+
13271344
#[allow(clippy::too_many_arguments)]
13281345
pub fn record_disposal(
13291346
&mut self,

src/main.rs

+63
Original file line numberDiff line numberDiff line change
@@ -4680,6 +4680,42 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
46804680
.arg(lot_selection_arg())
46814681
.arg(lot_numbers_arg()),
46824682
)
4683+
.subcommand(
4684+
SubCommand::with_name("drop")
4685+
.about("Manually drop SOL/tokens from an account")
4686+
.arg(
4687+
Arg::with_name("token")
4688+
.value_name("SOL or SPL Token")
4689+
.takes_value(true)
4690+
.required(true)
4691+
.validator(is_valid_token_or_sol)
4692+
.help("Token type"),
4693+
)
4694+
.arg(
4695+
Arg::with_name("address")
4696+
.value_name("ADDRESS")
4697+
.takes_value(true)
4698+
.required(true)
4699+
.validator(is_valid_pubkey)
4700+
.help("Account that the SOL/tokens should be dropped from"),
4701+
)
4702+
.arg(
4703+
Arg::with_name("amount")
4704+
.value_name("AMOUNT")
4705+
.takes_value(true)
4706+
.validator(is_amount)
4707+
.required(true)
4708+
.help("Amount of SOL/tokens to drop"),
4709+
)
4710+
.arg(
4711+
Arg::with_name("confirm")
4712+
.long("confirm")
4713+
.takes_value(false)
4714+
.help("Confirm the operation"),
4715+
)
4716+
.arg(lot_selection_arg())
4717+
.arg(lot_numbers_arg()),
4718+
)
46834719
.subcommand(
46844720
SubCommand::with_name("ls")
46854721
.about("List registered accounts")
@@ -6308,6 +6344,33 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
63086344
)
63096345
.await?;
63106346
}
6347+
("drop", Some(arg_matches)) => {
6348+
let address = pubkey_of(arg_matches, "address").unwrap();
6349+
let token = MaybeToken::from(value_t!(arg_matches, "token", Token).ok());
6350+
let ui_amount = value_t_or_exit!(arg_matches, "amount", f64);
6351+
let lot_numbers = lot_numbers_of(arg_matches, "lot_numbers");
6352+
let lot_selection_method =
6353+
value_t_or_exit!(arg_matches, "lot_selection", LotSelectionMethod);
6354+
let confirm = arg_matches.is_present("confirm");
6355+
6356+
if !confirm {
6357+
println!(
6358+
"Add --confirm to drop {} from {} ({})",
6359+
token.format_ui_amount(ui_amount),
6360+
address,
6361+
token
6362+
);
6363+
return Ok(());
6364+
}
6365+
6366+
db.record_drop(
6367+
address,
6368+
token,
6369+
token.amount(ui_amount),
6370+
lot_selection_method,
6371+
lot_numbers,
6372+
)?;
6373+
}
63116374
("ls", Some(arg_matches)) => {
63126375
let all = arg_matches.is_present("all");
63136376
let summary = arg_matches.is_present("summary");

0 commit comments

Comments
 (0)