Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Jan 15, 2025
1 parent 7b7e9e9 commit 5d7a202
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions shared/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,49 @@ impl TransactionKind {
if let Ok(data) = Transfer::try_from_slice(data) {
let has_shielded_section =
data.shielded_section_hash.is_some();
let all_sources_are_masp = data
.sources
.iter()
.all(|(acc, _)| acc.owner.eq(masp_address));
let any_sources_are_masp = data

let (all_sources_are_masp, any_sources_are_masp) = data
.sources
.iter()
.all(|(acc, _)| acc.owner.eq(masp_address));
let all_targets_are_masp = data
.targets
.iter()
.all(|(acc, _)| acc.owner.eq(masp_address));
let any_targets_are_masp = data
.fold((true, false), |(all, any), (acc, _)| {
let is_masp = acc.owner.eq(masp_address);
(all && is_masp, any || is_masp)
});

let (all_targets_are_masp, any_targets_are_masp) = data
.targets
.iter()
.all(|(acc, _)| acc.owner.eq(masp_address));
if all_sources_are_masp
&& all_targets_are_masp
&& has_shielded_section
{
TransactionKind::ShieldedTransfer(Some(data.into()))
} else if all_sources_are_masp
&& !any_targets_are_masp
&& has_shielded_section
{
TransactionKind::UnshieldingTransfer(Some(data.into()))
} else if !any_sources_are_masp
&& all_targets_are_masp
&& has_shielded_section
{
TransactionKind::ShieldingTransfer(Some(data.into()))
} else if !any_sources_are_masp
&& !any_targets_are_masp
&& !has_shielded_section
{
TransactionKind::TransparentTransfer(Some(data.into()))
} else {
TransactionKind::MixedTransfer(Some(data.into()))
.fold((true, false), |(all, any), (acc, _)| {
let is_masp = acc.owner.eq(masp_address);
(all && is_masp, any || is_masp)
});

match (
all_sources_are_masp,
any_sources_are_masp,
all_targets_are_masp,
any_targets_are_masp,
has_shielded_section,
) {
(true, _, true, _, true) => {
TransactionKind::ShieldedTransfer(Some(data.into()))
}
(true, _, _, false, true) => {
TransactionKind::UnshieldingTransfer(Some(
data.into(),
))
}
(false, _, true, _, true) => {
TransactionKind::ShieldingTransfer(Some(
data.into(),
))
}
(false, _, false, _, false) => {
TransactionKind::TransparentTransfer(Some(
data.into(),
))
}
_ => TransactionKind::MixedTransfer(Some(data.into())),
}
} else {
TransactionKind::Unknown
Expand Down

0 comments on commit 5d7a202

Please sign in to comment.