Skip to content

Commit

Permalink
Merge pull request #5512 from stacks-network/chore/add_missing_functi…
Browse files Browse the repository at this point in the history
…ons_to_trait

add missing functions to trait
  • Loading branch information
csgui authored Nov 27, 2024
2 parents f7c2ca7 + b3f7bd0 commit 939c650
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
19 changes: 18 additions & 1 deletion clarity/src/vm/database/clarity_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::path::PathBuf;

#[cfg(feature = "canonical")]
use rusqlite::Connection;
use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId, VRFSeed};
use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId, TrieHash, VRFSeed};
use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, Sha512Trunc256Sum};

use crate::vm::analysis::AnalysisDatabase;
Expand Down Expand Up @@ -64,9 +64,15 @@ pub trait ClarityBackingStore {
fn put_all_data(&mut self, items: Vec<(String, String)>) -> Result<()>;
/// fetch K-V out of the committed datastore
fn get_data(&mut self, key: &str) -> Result<Option<String>>;
/// fetch Hash(K)-V out of the commmitted datastore
fn get_data_from_path(&mut self, hash: &TrieHash) -> Result<Option<String>>;
/// fetch K-V out of the committed datastore, along with the byte representation
/// of the Merkle proof for that key-value pair
fn get_data_with_proof(&mut self, key: &str) -> Result<Option<(String, Vec<u8>)>>;
fn get_data_with_proof_from_path(
&mut self,
hash: &TrieHash,
) -> Result<Option<(String, Vec<u8>)>>;
fn has_entry(&mut self, key: &str) -> Result<bool> {
Ok(self.get_data(key)?.is_some())
}
Expand Down Expand Up @@ -209,10 +215,21 @@ impl ClarityBackingStore for NullBackingStore {
panic!("NullBackingStore can't retrieve data")
}

fn get_data_from_path(&mut self, _hash: &TrieHash) -> Result<Option<String>> {
panic!("NullBackingStore can't retrieve data")
}

fn get_data_with_proof(&mut self, _key: &str) -> Result<Option<(String, Vec<u8>)>> {
panic!("NullBackingStore can't retrieve data")
}

fn get_data_with_proof_from_path(
&mut self,
_hash: &TrieHash,
) -> Result<Option<(String, Vec<u8>)>> {
panic!("NullBackingStore can't retrieve data")
}

#[cfg(feature = "canonical")]
fn get_side_store(&mut self) -> &Connection {
panic!("NullBackingStore has no side store")
Expand Down
13 changes: 12 additions & 1 deletion clarity/src/vm/database/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rusqlite::{
params, Connection, Error as SqliteError, ErrorCode as SqliteErrorCode, OptionalExtension, Row,
Savepoint,
};
use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId};
use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId, TrieHash};
use stacks_common::types::sqlite::NO_PARAMS;
use stacks_common::util::db::tx_busy_handler;
use stacks_common::util::hash::Sha512Trunc256Sum;
Expand Down Expand Up @@ -324,10 +324,21 @@ impl ClarityBackingStore for MemoryBackingStore {
SqliteConnection::get(self.get_side_store(), key)
}

fn get_data_from_path(&mut self, hash: &TrieHash) -> Result<Option<String>> {
SqliteConnection::get(self.get_side_store(), hash.to_string().as_str())
}

fn get_data_with_proof(&mut self, key: &str) -> Result<Option<(String, Vec<u8>)>> {
Ok(SqliteConnection::get(self.get_side_store(), key)?.map(|x| (x, vec![])))
}

fn get_data_with_proof_from_path(
&mut self,
hash: &TrieHash,
) -> Result<Option<(String, Vec<u8>)>> {
self.get_data_with_proof(&hash.to_string())
}

fn get_side_store(&mut self) -> &Connection {
&self.side_store
}
Expand Down
14 changes: 14 additions & 0 deletions stackslib/src/clarity_vm/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,10 +1232,24 @@ impl ClarityBackingStore for MemoryBackingStore {
SqliteConnection::get(self.get_side_store(), key)
}

fn get_data_from_path(&mut self, hash: &TrieHash) -> InterpreterResult<Option<String>> {
SqliteConnection::get(self.get_side_store(), hash.to_string().as_str())
}

fn get_data_with_proof(&mut self, key: &str) -> InterpreterResult<Option<(String, Vec<u8>)>> {
Ok(SqliteConnection::get(self.get_side_store(), key)?.map(|x| (x, vec![])))
}

fn get_data_with_proof_from_path(
&mut self,
key: &TrieHash,
) -> InterpreterResult<Option<(String, Vec<u8>)>> {
Ok(
SqliteConnection::get(self.get_side_store(), key.to_string().as_str())?
.map(|x| (x, vec![])),
)
}

fn get_side_store(&mut self) -> &Connection {
&self.side_store
}
Expand Down

0 comments on commit 939c650

Please sign in to comment.