Skip to content

Commit

Permalink
rename everything to reflect sapling
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Nov 15, 2023
1 parent 541642d commit a0d981f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
38 changes: 19 additions & 19 deletions zebra-scan/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,44 @@ pub type SaplingScanningKey = String;
/// Store key info and results of the scan.
#[allow(dead_code)]
pub struct Storage {
/// The key and an optional birthday for it.
keys: HashMap<SaplingScanningKey, Option<Height>>,
/// The sapling key and an optional birthday for it.
sapling_keys: HashMap<SaplingScanningKey, Option<Height>>,

/// The key and the related transaction id.
results: HashMap<SaplingScanningKey, Vec<Hash>>,
/// The sapling key and the related transaction id.
sapling_results: HashMap<SaplingScanningKey, Vec<Hash>>,
}

#[allow(dead_code)]
impl Storage {
/// Create a new storage.
pub fn new() -> Self {
Self {
keys: HashMap::new(),
results: HashMap::new(),
sapling_keys: HashMap::new(),
sapling_results: HashMap::new(),
}
}

/// Add a key to the storage.
pub fn add_key(&mut self, key: SaplingScanningKey, birthday: Option<Height>) {
self.keys.insert(key, birthday);
/// Add a sapling key to the storage.
pub fn add_sapling_key(&mut self, key: SaplingScanningKey, birthday: Option<Height>) {
self.sapling_keys.insert(key, birthday);
}

/// Add a result to the storage.
pub fn add_result(&mut self, key: SaplingScanningKey, txid: Hash) {
if let Some(results) = self.results.get_mut(&key) {
/// Add a sapling result to the storage.
pub fn add_sapling_result(&mut self, key: SaplingScanningKey, txid: Hash) {
if let Some(results) = self.sapling_results.get_mut(&key) {
results.push(txid);
} else {
self.results.insert(key, vec![txid]);
self.sapling_results.insert(key, vec![txid]);
}
}

/// Get the results of a key.
pub fn get_results(&self, key: &str) -> Option<&Vec<Hash>> {
self.results.get(key)
/// Get the results of a sapling key.
pub fn get_sapling_results(&self, key: &str) -> Option<&Vec<Hash>> {
self.sapling_results.get(key)
}

/// Get all keys.
pub fn get_keys(&self) -> Vec<SaplingScanningKey> {
self.keys.keys().cloned().collect()
/// Get all sapling keys.
pub fn get_sapling_keys(&self) -> Vec<SaplingScanningKey> {
self.sapling_keys.keys().cloned().collect()
}
}
10 changes: 5 additions & 5 deletions zebra-scan/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ async fn scanning_fake_blocks_store_key_and_results() -> Result<()> {
let mut s = crate::storage::Storage::new();

// Insert the generated key to the database
s.add_key(key_to_be_stored.clone(), None);
s.add_sapling_key(key_to_be_stored.clone(), None);

// Check key was added
assert_eq!(s.get_keys().len(), 1);
assert_eq!(s.get_keys()[0], key_to_be_stored.clone());
assert_eq!(s.get_sapling_keys().len(), 1);
assert_eq!(s.get_sapling_keys()[0], key_to_be_stored.clone());

let vks: Vec<(&AccountId, &SaplingIvk)> = vec![];
let nf = Nullifier([7; 32]);
Expand Down Expand Up @@ -336,11 +336,11 @@ async fn scanning_fake_blocks_store_key_and_results() -> Result<()> {
let found_transaction_hash = Hash::from_bytes_in_display_order(found_transaction);

// Add result to database
s.add_result(key_to_be_stored.clone(), found_transaction_hash);
s.add_sapling_result(key_to_be_stored.clone(), found_transaction_hash);

// Check the result was added
assert_eq!(
s.get_results(key_to_be_stored.as_str()).unwrap()[0],
s.get_sapling_results(key_to_be_stored.as_str()).unwrap()[0],
found_transaction_hash
);

Expand Down

0 comments on commit a0d981f

Please sign in to comment.