Skip to content

Commit 58110f2

Browse files
committed
Fix formatting
1 parent 2e70a74 commit 58110f2

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

src/main.rs

+57-39
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,14 @@ async fn process_account_cost_basis(
19291929
}
19301930

19311931
fn print_current_holdings(
1932-
held_tokens: &BTreeMap::<MaybeToken, (/*price*/ Option<Decimal>, /*amount*/ u64, RealizedGain)>,
1932+
held_tokens: &BTreeMap<
1933+
MaybeToken,
1934+
(
1935+
/*price*/ Option<Decimal>,
1936+
/*amount*/ u64,
1937+
RealizedGain,
1938+
),
1939+
>,
19331940
tax_rate: Option<&TaxRate>,
19341941
) {
19351942
println!("Current Holdings");
@@ -1957,8 +1964,7 @@ fn print_current_holdings(
19571964
.collect::<Vec<_>>();
19581965

19591966
// Order current holdings by `total_value`
1960-
held_tokens
1961-
.sort_unstable_by(|a, b| b.1.partial_cmp(&a.1).unwrap_or(std::cmp::Ordering::Equal));
1967+
held_tokens.sort_unstable_by(|a, b| b.1.partial_cmp(&a.1).unwrap_or(std::cmp::Ordering::Equal));
19621968

19631969
for (held_token, total_value, current_token_price, total_held_amount, unrealized_gain) in
19641970
held_tokens
@@ -2017,7 +2023,11 @@ fn print_current_holdings(
20172023
println!();
20182024
}
20192025

2020-
fn merge_lots(db: &mut Db, account_filter: Option<Pubkey>, verbose: bool) -> Result<(), Box<dyn std::error::Error>> {
2026+
fn merge_lots(
2027+
db: &mut Db,
2028+
account_filter: Option<Pubkey>,
2029+
verbose: bool,
2030+
) -> Result<(), Box<dyn std::error::Error>> {
20212031
let mut accounts = db.get_accounts();
20222032
accounts.sort_by(|a, b| {
20232033
let mut result = a.last_update_balance.cmp(&b.last_update_balance);
@@ -2049,17 +2059,15 @@ fn merge_lots(db: &mut Db, account_filter: Option<Pubkey>, verbose: bool) -> Res
20492059
let this_lot = account.lots.get_mut(lot_num).unwrap();
20502060
let this_price = this_lot.acquisition.price();
20512061
let this_lot_number = this_lot.lot_number;
2052-
if this_lot.acquisition.when == next_lot.acquisition.when
2053-
&& this_price == next_price {
2054-
this_lot.amount += next_lot.amount;
2055-
account.lots.remove(lot_num + 1);
2056-
if verbose {
2057-
println!(
2058-
"merged lot {} into lot {}",
2059-
next_lot_number,
2060-
this_lot_number,
2061-
);
2062-
}
2062+
if this_lot.acquisition.when == next_lot.acquisition.when && this_price == next_price {
2063+
this_lot.amount += next_lot.amount;
2064+
account.lots.remove(lot_num + 1);
2065+
if verbose {
2066+
println!(
2067+
"merged lot {} into lot {}",
2068+
next_lot_number, this_lot_number,
2069+
);
2070+
}
20632071
} else {
20642072
lot_num += 1;
20652073
}
@@ -2083,19 +2091,19 @@ fn merge_lots(db: &mut Db, account_filter: Option<Pubkey>, verbose: bool) -> Res
20832091
if this_lot.when == next_lot.when
20842092
&& this_price == next_price
20852093
&& this_lot_acq_when == next_lot_acq_when
2086-
&& this_lot_acq_price == next_lot_acq_price {
2087-
this_lot.lot.amount += next_lot.lot.amount;
2088-
disposed_lots.remove(lot_num + 1);
2089-
if verbose {
2090-
println!(
2091-
"merged disposed lot {} into disposed lot {}",
2092-
next_lot_number,
2093-
this_lot_number,
2094-
);
2095-
}
2096-
} else {
2097-
lot_num += 1;
2094+
&& this_lot_acq_price == next_lot_acq_price
2095+
{
2096+
this_lot.lot.amount += next_lot.lot.amount;
2097+
disposed_lots.remove(lot_num + 1);
2098+
if verbose {
2099+
println!(
2100+
"merged disposed lot {} into disposed lot {}",
2101+
next_lot_number, this_lot_number,
2102+
);
20982103
}
2104+
} else {
2105+
lot_num += 1;
2106+
}
20992107
}
21002108
db.update_disposed_lots(disposed_lots)?;
21012109
}
@@ -2215,10 +2223,10 @@ async fn process_account_list(
22152223
for lot in account.lots.iter() {
22162224
let value = current_token_price.map(|price| {
22172225
f64::try_from(
2218-
Decimal::from_f64(
2219-
account.token.ui_amount(lot.amount)
2220-
).unwrap() * price
2221-
).unwrap()
2226+
Decimal::from_f64(account.token.ui_amount(lot.amount)).unwrap()
2227+
* price,
2228+
)
2229+
.unwrap()
22222230
});
22232231
account_basis += lot.basis(account.token);
22242232
account_value += value.unwrap_or_default();
@@ -2402,7 +2410,7 @@ async fn process_account_list(
24022410
(((total_current_value - total_current_fiat_value) - total_current_basis)
24032411
/ total_current_basis
24042412
* 100.)
2405-
.separated_string_with_fixed_place(2),
2413+
.separated_string_with_fixed_place(2),
24062414
);
24072415
}
24082416
if account_filter.is_some() || summary_only {
@@ -2856,7 +2864,7 @@ async fn process_account_csv(
28562864
// Exclude disposed lots that were neither acquired nor disposed of in the filter year
28572865
disposed_lots.retain(|disposed_lot| {
28582866
(disposed_lot.lot.acquisition.when.year() == year
2859-
&& disposed_lot.lot.income(disposed_lot.token) > 0.)
2867+
&& disposed_lot.lot.income(disposed_lot.token) > 0.)
28602868
|| disposed_lot.when.year() == year
28612869
})
28622870
}
@@ -2870,7 +2878,7 @@ async fn process_account_csv(
28702878
"Sale Date",
28712879
"Sale Proceedings (USD)",
28722880
"Acquisition Description",
2873-
"Sale Description"
2881+
"Sale Description",
28742882
])?;
28752883

28762884
for disposed_lot in disposed_lots {
@@ -2881,20 +2889,30 @@ async fn process_account_csv(
28812889
}
28822890
}
28832891
let cost = Decimal::from_u64(disposed_lot.lot.amount).unwrap()
2884-
* disposed_lot.lot.acquisition.price() / Decimal::from_f64(1e9).unwrap();
2892+
* disposed_lot.lot.acquisition.price()
2893+
/ Decimal::from_f64(1e9).unwrap();
28852894
let proceedings = Decimal::from_u64(disposed_lot.lot.amount).unwrap()
2886-
* disposed_lot.price() / Decimal::from_f64(1e9).unwrap();
2895+
* disposed_lot.price()
2896+
/ Decimal::from_f64(1e9).unwrap();
28872897
wtr.write_record(&[
28882898
disposed_lot.token.to_string(),
2889-
format!("{:.9}", disposed_lot.token.ui_amount(disposed_lot.lot.amount)),
2899+
format!(
2900+
"{:.9}",
2901+
disposed_lot.token.ui_amount(disposed_lot.lot.amount)
2902+
),
28902903
format!("{:.9}", income),
2891-
format!("{:.9}", disposed_lot.lot.cap_gain(disposed_lot.token, disposed_lot.price())),
2904+
format!(
2905+
"{:.9}",
2906+
disposed_lot
2907+
.lot
2908+
.cap_gain(disposed_lot.token, disposed_lot.price())
2909+
),
28922910
disposed_lot.lot.acquisition.when.to_string(),
28932911
format!("{:.9}", cost),
28942912
disposed_lot.when.to_string(),
28952913
format!("{:.9}", proceedings),
28962914
disposed_lot.lot.acquisition.kind.to_string(),
2897-
disposed_lot.kind.to_string()
2915+
disposed_lot.kind.to_string(),
28982916
])?;
28992917
}
29002918

0 commit comments

Comments
 (0)