Skip to content

Commit

Permalink
SDK uses core helper functions for masp keys
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Dec 28, 2023
1 parent 978c24a commit 3f1d8c1
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions sdk/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ use namada_core::types::masp::{
BalanceOwner, ExtendedViewingKey, PaymentAddress, TransferSource,
TransferTarget,
};
use namada_core::types::storage::{BlockHeight, Epoch, Key, KeySeg, TxIndex};
use namada_core::types::storage::{BlockHeight, Epoch, TxIndex};
use namada_core::types::token;
use namada_core::types::token::{
Change, MaspDenom, Transfer, HEAD_TX_KEY, PIN_KEY_PREFIX, TX_KEY_PREFIX,
};
use namada_core::types::token::{Change, MaspDenom, Transfer};
use namada_core::types::transaction::WrapperTx;
use rand_core::{CryptoRng, OsRng, RngCore};
use ripemd::Digest as RipemdDigest;
Expand Down Expand Up @@ -739,14 +737,8 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
BTreeMap<(BlockHeight, TxIndex), (Epoch, Transfer, Transaction)>,
Error,
> {
// The address of the MASP account
let masp_addr = MASP;
// Construct the key where last transaction pointer is stored
let head_tx_key = Key::from(masp_addr.to_db_key())
.push(&HEAD_TX_KEY.to_owned())
.map_err(|k| {
Error::Other(format!("Cannot obtain a storage key: {}", k))
})?;
let head_tx_key = namada_core::types::token::masp_head_tx_key();
// Query for the index of the last accepted transaction
let head_txidx = query_storage_value::<C, u64>(client, &head_tx_key)
.await
Expand All @@ -755,11 +747,7 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
// Fetch all the transactions we do not have yet
for i in last_txidx..head_txidx {
// Construct the key for where the current transaction is stored
let current_tx_key = Key::from(masp_addr.to_db_key())
.push(&(TX_KEY_PREFIX.to_owned() + &i.to_string()))
.map_err(|e| {
Error::Other(format!("Cannot obtain a storage key {}", e))
})?;
let current_tx_key = namada_core::types::token::masp_tx_key(i);
// Obtain the current transaction
let (tx_epoch, tx_height, tx_index, current_tx, current_stx) =
query_storage_value::<
Expand Down Expand Up @@ -1339,26 +1327,16 @@ impl<U: ShieldedUtils> ShieldedContext<U> {
return Err(Error::from(PinnedBalanceError::InvalidViewingKey));
}
}
// The address of the MASP account
let masp_addr = MASP;
// Construct the key for where the transaction ID would be stored
let pin_key = Key::from(masp_addr.to_db_key())
.push(&(PIN_KEY_PREFIX.to_owned() + &owner.hash()))
.map_err(|_| {
Error::Other("Cannot obtain a storage key".to_string())
})?;
let pin_key = namada_core::types::token::masp_pin_tx_key(&owner.hash());
// Obtain the transaction pointer at the key
// If we don't discard the error message then a test fails,
// however the error underlying this will go undetected
let txidx = rpc::query_storage_value::<C, u64>(client, &pin_key)
.await
.map_err(|_| PinnedBalanceError::NoTransactionPinned)?;
// Construct the key for where the pinned transaction is stored
let tx_key = Key::from(masp_addr.to_db_key())
.push(&(TX_KEY_PREFIX.to_owned() + &txidx.to_string()))
.map_err(|_| {
Error::Other("Cannot obtain a storage key".to_string())
})?;
let tx_key = namada_core::types::token::masp_tx_key(txidx);
// Obtain the pointed to transaction
let (tx_epoch, _tx_height, _tx_index, _tx, shielded) =
rpc::query_storage_value::<
Expand Down

0 comments on commit 3f1d8c1

Please sign in to comment.