Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed unused associated type from ShieldedUtils #1670

Merged
merged 3 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Removed associated type on `masp::ShieldedUtils`. This type was an
attempt to reduce the number of generic parameters needed when interacting
with MASP but resulted in making code re-use extremely difficult.
([\#1670](https://github.com/anoma/namada/pull/1670))
8 changes: 4 additions & 4 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub async fn query_results<C: namada::ledger::queries::Client + Sync>(
/// Query the specified accepted transfers from the ledger
pub async fn query_transfers<
C: namada::ledger::queries::Client + Sync,
U: ShieldedUtils<C = C>,
U: ShieldedUtils,
>(
client: &C,
wallet: &mut Wallet<CliWalletUtils>,
Expand Down Expand Up @@ -262,7 +262,7 @@ pub async fn query_raw_bytes<C: namada::ledger::queries::Client + Sync>(
/// Query token balance(s)
pub async fn query_balance<
C: namada::ledger::queries::Client + Sync,
U: ShieldedUtils<C = C>,
U: ShieldedUtils,
>(
client: &C,
wallet: &mut Wallet<CliWalletUtils>,
Expand Down Expand Up @@ -396,7 +396,7 @@ pub async fn query_transparent_balance<
/// Query the token pinned balance(s)
pub async fn query_pinned_balance<
C: namada::ledger::queries::Client + Sync,
U: ShieldedUtils<C = C>,
U: ShieldedUtils,
>(
client: &C,
wallet: &mut Wallet<CliWalletUtils>,
Expand Down Expand Up @@ -760,7 +760,7 @@ pub async fn query_proposal<C: namada::ledger::queries::Client + Sync>(
/// Query token shielded balance(s)
pub async fn query_shielded_balance<
C: namada::ledger::queries::Client + Sync,
U: ShieldedUtils<C = C>,
U: ShieldedUtils,
>(
client: &C,
wallet: &mut Wallet<CliWalletUtils>,
Expand Down
2 changes: 0 additions & 2 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,6 @@ impl Default for CLIShieldedUtils {

#[async_trait(?Send)]
impl masp::ShieldedUtils for CLIShieldedUtils {
type C = crate::facade::tendermint_rpc::HttpClient;

fn local_tx_prover(&self) -> LocalTxProver {
if let Ok(params_dir) = env::var(masp::ENV_VAR_MASP_PARAMS_DIR) {
let params_dir = PathBuf::from(params_dir);
Expand Down
75 changes: 36 additions & 39 deletions shared/src/ledger/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,6 @@ impl<P1, R1, N1>
pub trait ShieldedUtils:
Sized + BorshDeserialize + BorshSerialize + Default + Clone
{
/// The type of the Tendermint client to make queries with
type C: crate::ledger::queries::Client + std::marker::Sync;

/// Get a MASP transaction prover
fn local_tx_prover(&self) -> LocalTxProver;

Expand Down Expand Up @@ -631,9 +628,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {

/// Fetch the current state of the multi-asset shielded pool into a
/// ShieldedContext
pub async fn fetch(
pub async fn fetch<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
sks: &[ExtendedSpendingKey],
fvks: &[ViewingKey],
) {
Expand Down Expand Up @@ -699,8 +696,8 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// transactions as a vector. More concretely, the HEAD_TX_KEY location
/// stores the index of the last accepted transaction and each transaction
/// is stored at a key derived from its index.
pub async fn fetch_shielded_transfers(
client: &U::C,
pub async fn fetch_shielded_transfers<C: Client + Sync>(
client: &C,
last_txidx: u64,
) -> BTreeMap<(BlockHeight, TxIndex), (Epoch, Transfer, Transaction)> {
// The address of the MASP account
Expand All @@ -710,7 +707,7 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
.push(&HEAD_TX_KEY.to_owned())
.expect("Cannot obtain a storage key");
// Query for the index of the last accepted transaction
let head_txidx = query_storage_value::<U::C, u64>(client, &head_tx_key)
let head_txidx = query_storage_value::<C, u64>(client, &head_tx_key)
.await
.unwrap_or(0);
let mut shielded_txs = BTreeMap::new();
Expand All @@ -723,7 +720,7 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
// Obtain the current transaction
let (tx_epoch, tx_height, tx_index, current_tx, current_stx) =
query_storage_value::<
U::C,
C,
(Epoch, BlockHeight, TxIndex, Transfer, Transaction),
>(client, &current_tx_key)
.await
Expand All @@ -745,9 +742,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// we have spent are updated. The witness map is maintained to make it
/// easier to construct note merkle paths in other code. See
/// https://zips.z.cash/protocol/protocol.pdf#scan
pub async fn scan_tx(
pub async fn scan_tx<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
height: BlockHeight,
index: TxIndex,
epoch: Epoch,
Expand Down Expand Up @@ -883,9 +880,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// Compute the total unspent notes associated with the viewing key in the
/// context. If the key is not in the context, then we do not know the
/// balance and hence we return None.
pub async fn compute_shielded_balance(
pub async fn compute_shielded_balance<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
vk: &ViewingKey,
) -> Option<MaspAmount> {
// Cannot query the balance of a key that's not in the map
Expand Down Expand Up @@ -913,9 +910,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {

/// Query the ledger for the decoding of the given asset type and cache it
/// if it is found.
pub async fn decode_asset_type(
pub async fn decode_asset_type<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
asset_type: AssetType,
) -> Option<(Address, Option<Key>, MaspDenom, Epoch)> {
// Try to find the decoding in the cache
Expand All @@ -938,9 +935,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {

/// Query the ledger for the conversion that is allowed for the given asset
/// type and cache it.
async fn query_allowed_conversion<'a>(
async fn query_allowed_conversion<'a, C: Client + Sync>(
&'a mut self,
client: &U::C,
client: &C,
asset_type: AssetType,
conversions: &'a mut Conversions,
) {
Expand All @@ -963,9 +960,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// context and express that value in terms of the currently timestamped
/// asset types. If the key is not in the context, then we do not know the
/// balance and hence we return None.
pub async fn compute_exchanged_balance(
pub async fn compute_exchanged_balance<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
vk: &ViewingKey,
target_epoch: Epoch,
) -> Option<MaspAmount> {
Expand Down Expand Up @@ -993,9 +990,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// the trace amount that could not be converted is moved from input to
/// output.
#[allow(clippy::too_many_arguments)]
async fn apply_conversion(
async fn apply_conversion<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
conv: AllowedConversion,
asset_type: (Epoch, TokenAddress, MaspDenom),
value: i128,
Expand Down Expand Up @@ -1047,9 +1044,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// note of the conversions that were used. Note that this function does
/// not assume that allowed conversions from the ledger are expressed in
/// terms of the latest asset types.
pub async fn compute_exchanged_amount(
pub async fn compute_exchanged_amount<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
mut input: MaspAmount,
target_epoch: Epoch,
mut conversions: Conversions,
Expand Down Expand Up @@ -1156,9 +1153,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// of the specified asset type. Return the total value accumulated plus
/// notes and the corresponding diversifiers/merkle paths that were used to
/// achieve the total value.
pub async fn collect_unspent_notes(
pub async fn collect_unspent_notes<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
vk: &ViewingKey,
target: Amount,
target_epoch: Epoch,
Expand Down Expand Up @@ -1226,8 +1223,8 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// keys to try to decrypt the output notes. If no transaction is pinned at
/// the given payment address fails with
/// `PinnedBalanceError::NoTransactionPinned`.
pub async fn compute_pinned_balance(
client: &U::C,
pub async fn compute_pinned_balance<C: Client + Sync>(
client: &C,
owner: PaymentAddress,
viewing_key: &ViewingKey,
) -> Result<(Amount, Epoch), PinnedBalanceError> {
Expand All @@ -1249,7 +1246,7 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
.push(&(PIN_KEY_PREFIX.to_owned() + &owner.hash()))
.expect("Cannot obtain a storage key");
// Obtain the transaction pointer at the key
let txidx = rpc::query_storage_value::<U::C, u64>(client, &pin_key)
let txidx = rpc::query_storage_value::<C, u64>(client, &pin_key)
.await
.ok_or(PinnedBalanceError::NoTransactionPinned)?;
// Construct the key for where the pinned transaction is stored
Expand All @@ -1259,7 +1256,7 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
// Obtain the pointed to transaction
let (tx_epoch, _tx_height, _tx_index, _tx, shielded) =
rpc::query_storage_value::<
U::C,
C,
(Epoch, BlockHeight, TxIndex, Transfer, Transaction),
>(client, &tx_key)
.await
Expand Down Expand Up @@ -1297,9 +1294,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// the epoch of the transaction or even before, so exchange all these
/// amounts to the epoch of the transaction in order to get the value that
/// would have been displayed in the epoch of the transaction.
pub async fn compute_exchanged_pinned_balance(
pub async fn compute_exchanged_pinned_balance<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
owner: PaymentAddress,
viewing_key: &ViewingKey,
) -> Result<(MaspAmount, Epoch), PinnedBalanceError> {
Expand All @@ -1322,9 +1319,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// Convert an amount whose units are AssetTypes to one whose units are
/// Addresses that they decode to. All asset types not corresponding to
/// the given epoch are ignored.
pub async fn decode_amount(
pub async fn decode_amount<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
amt: Amount,
target_epoch: Epoch,
) -> HashMap<TokenAddress, token::Change> {
Expand Down Expand Up @@ -1355,9 +1352,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {

/// Convert an amount whose units are AssetTypes to one whose units are
/// Addresses that they decode to.
pub async fn decode_all_amounts(
pub async fn decode_all_amounts<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
amt: Amount,
) -> MaspAmount {
let mut res: HashMap<(Epoch, TokenAddress), Change> =
Expand Down Expand Up @@ -1394,9 +1391,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// understood that transparent account changes are effected only by the
/// amounts and signatures specified by the containing Transfer object.
#[cfg(feature = "masp-tx-gen")]
pub async fn gen_shielded_transfer(
pub async fn gen_shielded_transfer<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
args: &args::TxTransfer,
shielded_gas: bool,
) -> Result<
Expand Down Expand Up @@ -1611,9 +1608,9 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
/// transactions. If an owner is specified, then restrict the set to only
/// transactions crediting/debiting the given owner. If token is specified,
/// then restrict set to only transactions involving the given token.
pub async fn query_tx_deltas(
pub async fn query_tx_deltas<C: Client + Sync>(
&mut self,
client: &U::C,
client: &C,
query_owner: &Either<BalanceOwner, Vec<Address>>,
query_token: &Option<Address>,
viewing_keys: &HashMap<String, ExtendedViewingKey>,
Expand Down
6 changes: 3 additions & 3 deletions shared/src/ledger/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ pub async fn submit_ibc_transfer<
/// Returns true only if a new decoding has been added to the given set.
async fn add_asset_type<
C: crate::ledger::queries::Client + Sync,
U: ShieldedUtils<C = C>,
U: ShieldedUtils,
>(
asset_types: &mut HashSet<(Address, Option<Key>, MaspDenom, Epoch)>,
shielded: &mut ShieldedContext<U>,
Expand All @@ -1178,7 +1178,7 @@ async fn add_asset_type<
/// type information.
async fn used_asset_types<
C: crate::ledger::queries::Client + Sync,
U: ShieldedUtils<C = C>,
U: ShieldedUtils,
P,
R,
K,
Expand Down Expand Up @@ -1230,7 +1230,7 @@ async fn used_asset_types<
pub async fn submit_transfer<
C: crate::ledger::queries::Client + Sync,
V: WalletUtils,
U: ShieldedUtils<C = C>,
U: ShieldedUtils,
>(
client: &C,
wallet: &mut Wallet<V>,
Expand Down