Skip to content

Commit

Permalink
Test that the transfer source now displays as a viewing key.
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi committed Dec 2, 2024
1 parent 2105731 commit ba5dbbb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions crates/apps_lib/src/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,14 +716,14 @@ impl ArgFromMutContext for TransferSource {
.map(Self::Address)
.or_else(|_| {
ExtendedSpendingKey::arg_from_mut_ctx(ctx, raw).map(|x| {
Self::ExtendedSpendingKey(PseudoExtendedKey::from(
Self::ExtendedKey(PseudoExtendedKey::from(
MaspExtendedSpendingKey::from(x),
))
})
})
.or_else(|_| {
ExtendedViewingKey::arg_from_mut_ctx(ctx, raw).map(|x| {
Self::ExtendedSpendingKey(PseudoExtendedKey::from(
Self::ExtendedKey(PseudoExtendedKey::from(
MaspExtendedViewingKey::from(x),
))
})
Expand Down
6 changes: 3 additions & 3 deletions crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ fn prepare_ibc_tx_and_ctx(bench_name: &str) -> (BenchShieldedCtx, BatchedTx) {
shielded_ctx.shell.write().commit_block();
shielded_ctx.generate_shielded_action(
Amount::native_whole(10),
TransferSource::ExtendedSpendingKey(
TransferSource::ExtendedKey(
ExtendedSpendingKey::from(albert_spending_key).into(),
),
defaults::bertha_address().to_string(),
Expand Down Expand Up @@ -605,14 +605,14 @@ fn setup_storage_for_masp_verification(
),
"unshielding" => shielded_ctx.generate_masp_tx(
amount,
TransferSource::ExtendedSpendingKey(
TransferSource::ExtendedKey(
ExtendedSpendingKey::from(albert_spending_key).into(),
),
TransferTarget::Address(defaults::albert_address()),
),
"shielded" => shielded_ctx.generate_masp_tx(
amount,
TransferSource::ExtendedSpendingKey(
TransferSource::ExtendedKey(
ExtendedSpendingKey::from(albert_spending_key).into(),
),
TransferTarget::PaymentAddress(bertha_payment_addr),
Expand Down
20 changes: 10 additions & 10 deletions crates/core/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ pub enum TransferSource {
/// A transfer coming from a transparent address
Address(Address),
/// A transfer coming from a shielded address
ExtendedSpendingKey(PseudoExtendedKey),
ExtendedKey(PseudoExtendedKey),
}

impl TransferSource {
Expand All @@ -549,22 +549,22 @@ impl TransferSource {
Self::Address(x) => x.clone(),
// An ExtendedSpendingKey for a source effectively means that
// assets will be drawn from the MASP
Self::ExtendedSpendingKey(_) => MASP,
Self::ExtendedKey(_) => MASP,
}
}

/// Get the contained ExtendedSpendingKey contained, if any
pub fn spending_key(&self) -> Option<PseudoExtendedKey> {
match self {
Self::ExtendedSpendingKey(x) => Some(*x),
Self::ExtendedKey(x) => Some(*x),
_ => None,
}
}

/// Get the contained ExtendedSpendingKey contained, if any
pub fn spending_key_mut(&mut self) -> Option<&mut PseudoExtendedKey> {
match self {
Self::ExtendedSpendingKey(x) => Some(x),
Self::ExtendedKey(x) => Some(x),
_ => None,
}
}
Expand All @@ -590,7 +590,7 @@ impl Display for TransferSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Address(x) => x.fmt(f),
Self::ExtendedSpendingKey(x) => {
Self::ExtendedKey(x) => {
ExtendedViewingKey::from(x.to_viewing_key()).fmt(f)
}
}
Expand Down Expand Up @@ -829,8 +829,8 @@ mod test {

let sk = masp_primitives::zip32::ExtendedSpendingKey::master(&[0_u8]);
assert_eq!(
ExtendedSpendingKey::from(sk).to_string(),
TransferSource::ExtendedSpendingKey(sk.into()).to_string()
ExtendedViewingKey::from(sk.to_viewing_key()).to_string(),
TransferSource::ExtendedKey(sk.into()).to_string()
);
}

Expand All @@ -841,7 +841,7 @@ mod test {
.address();
assert_eq!(addr.unwrap(), address::testing::established_address_1());

let addr = TransferSource::ExtendedSpendingKey(
let addr = TransferSource::ExtendedKey(
masp_primitives::zip32::ExtendedSpendingKey::master(&[0_u8]).into(),
)
.address();
Expand All @@ -858,7 +858,7 @@ mod test {
TAddrData::Addr(address::testing::established_address_1())
);

let addr = TransferSource::ExtendedSpendingKey(
let addr = TransferSource::ExtendedKey(
masp_primitives::zip32::ExtendedSpendingKey::master(&[0_u8]).into(),
)
.address();
Expand All @@ -875,7 +875,7 @@ mod test {
);

let sk = masp_primitives::zip32::ExtendedSpendingKey::master(&[0_u8]);
let source = TransferSource::ExtendedSpendingKey(sk.into());
let source = TransferSource::ExtendedKey(sk.into());
assert_eq!(source.effective_address(), MASP);
}

Expand Down
10 changes: 5 additions & 5 deletions crates/sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,7 @@ pub async fn build_ibc_transfer(
)
.await?;
let (fee_per_gas_unit, updated_balance) =
if let TransferSource::ExtendedSpendingKey(_) = args.source {
if let TransferSource::ExtendedKey(_) = args.source {
// MASP fee payment
(validate_fee(context, &args.tx).await?, None)
} else {
Expand Down Expand Up @@ -3084,7 +3084,7 @@ pub async fn build_shielded_transfer<N: Namada>(
.await?;

transfer_data.push(MaspTransferData {
source: TransferSource::ExtendedSpendingKey(source.to_owned()),
source: TransferSource::ExtendedKey(source.to_owned()),
target: TransferTarget::PaymentAddress(target.to_owned()),
token: token.to_owned(),
amount: validated_amount,
Expand Down Expand Up @@ -3370,7 +3370,7 @@ pub async fn build_unshielding_transfer<N: Namada>(
.await?;

transfer_data.push(MaspTransferData {
source: TransferSource::ExtendedSpendingKey(args.source),
source: TransferSource::ExtendedKey(args.source),
target: TransferTarget::Address(target.to_owned()),
token: token.to_owned(),
amount: validated_amount,
Expand Down Expand Up @@ -4032,10 +4032,10 @@ async fn get_refund_target(
)))
}
(
TransferSource::ExtendedSpendingKey(_),
TransferSource::ExtendedKey(_),
Some(TransferTarget::Address(addr)),
) => Ok(Some(addr.clone())),
(TransferSource::ExtendedSpendingKey(_), None) => {
(TransferSource::ExtendedKey(_), None) => {
// Generate a new transparent address if it doesn't exist
let mut rng = OsRng;
let mut wallet = context.wallet_mut().await;
Expand Down
8 changes: 4 additions & 4 deletions crates/shielded_token/src/masp/shielded_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,17 +1269,17 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
if let Some(source) = fee_data.source {
source_data.insert(
MaspSourceTransferData {
source: TransferSource::ExtendedSpendingKey(source),
source: TransferSource::ExtendedKey(source),
token: fee_data.token.clone(),
},
amount,
);
}
target_data.insert(
MaspTargetTransferData {
source: fee_data.source.map(|source| {
TransferSource::ExtendedSpendingKey(source)
}),
source: fee_data
.source
.map(|source| TransferSource::ExtendedKey(source)),
target: TransferTarget::Address(fee_data.target),
token: fee_data.token,
},
Expand Down

0 comments on commit ba5dbbb

Please sign in to comment.