Skip to content

Commit 939c650

Browse files
authored
Merge pull request #5512 from stacks-network/chore/add_missing_functions_to_trait
add missing functions to trait
2 parents f7c2ca7 + b3f7bd0 commit 939c650

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

clarity/src/vm/database/clarity_store.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::path::PathBuf;
1818

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

2424
use crate::vm::analysis::AnalysisDatabase;
@@ -64,9 +64,15 @@ pub trait ClarityBackingStore {
6464
fn put_all_data(&mut self, items: Vec<(String, String)>) -> Result<()>;
6565
/// fetch K-V out of the committed datastore
6666
fn get_data(&mut self, key: &str) -> Result<Option<String>>;
67+
/// fetch Hash(K)-V out of the commmitted datastore
68+
fn get_data_from_path(&mut self, hash: &TrieHash) -> Result<Option<String>>;
6769
/// fetch K-V out of the committed datastore, along with the byte representation
6870
/// of the Merkle proof for that key-value pair
6971
fn get_data_with_proof(&mut self, key: &str) -> Result<Option<(String, Vec<u8>)>>;
72+
fn get_data_with_proof_from_path(
73+
&mut self,
74+
hash: &TrieHash,
75+
) -> Result<Option<(String, Vec<u8>)>>;
7076
fn has_entry(&mut self, key: &str) -> Result<bool> {
7177
Ok(self.get_data(key)?.is_some())
7278
}
@@ -209,10 +215,21 @@ impl ClarityBackingStore for NullBackingStore {
209215
panic!("NullBackingStore can't retrieve data")
210216
}
211217

218+
fn get_data_from_path(&mut self, _hash: &TrieHash) -> Result<Option<String>> {
219+
panic!("NullBackingStore can't retrieve data")
220+
}
221+
212222
fn get_data_with_proof(&mut self, _key: &str) -> Result<Option<(String, Vec<u8>)>> {
213223
panic!("NullBackingStore can't retrieve data")
214224
}
215225

226+
fn get_data_with_proof_from_path(
227+
&mut self,
228+
_hash: &TrieHash,
229+
) -> Result<Option<(String, Vec<u8>)>> {
230+
panic!("NullBackingStore can't retrieve data")
231+
}
232+
216233
#[cfg(feature = "canonical")]
217234
fn get_side_store(&mut self) -> &Connection {
218235
panic!("NullBackingStore has no side store")

clarity/src/vm/database/sqlite.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rusqlite::{
1919
params, Connection, Error as SqliteError, ErrorCode as SqliteErrorCode, OptionalExtension, Row,
2020
Savepoint,
2121
};
22-
use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId};
22+
use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId, TrieHash};
2323
use stacks_common::types::sqlite::NO_PARAMS;
2424
use stacks_common::util::db::tx_busy_handler;
2525
use stacks_common::util::hash::Sha512Trunc256Sum;
@@ -324,10 +324,21 @@ impl ClarityBackingStore for MemoryBackingStore {
324324
SqliteConnection::get(self.get_side_store(), key)
325325
}
326326

327+
fn get_data_from_path(&mut self, hash: &TrieHash) -> Result<Option<String>> {
328+
SqliteConnection::get(self.get_side_store(), hash.to_string().as_str())
329+
}
330+
327331
fn get_data_with_proof(&mut self, key: &str) -> Result<Option<(String, Vec<u8>)>> {
328332
Ok(SqliteConnection::get(self.get_side_store(), key)?.map(|x| (x, vec![])))
329333
}
330334

335+
fn get_data_with_proof_from_path(
336+
&mut self,
337+
hash: &TrieHash,
338+
) -> Result<Option<(String, Vec<u8>)>> {
339+
self.get_data_with_proof(&hash.to_string())
340+
}
341+
331342
fn get_side_store(&mut self) -> &Connection {
332343
&self.side_store
333344
}

stackslib/src/clarity_vm/database/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,10 +1232,24 @@ impl ClarityBackingStore for MemoryBackingStore {
12321232
SqliteConnection::get(self.get_side_store(), key)
12331233
}
12341234

1235+
fn get_data_from_path(&mut self, hash: &TrieHash) -> InterpreterResult<Option<String>> {
1236+
SqliteConnection::get(self.get_side_store(), hash.to_string().as_str())
1237+
}
1238+
12351239
fn get_data_with_proof(&mut self, key: &str) -> InterpreterResult<Option<(String, Vec<u8>)>> {
12361240
Ok(SqliteConnection::get(self.get_side_store(), key)?.map(|x| (x, vec![])))
12371241
}
12381242

1243+
fn get_data_with_proof_from_path(
1244+
&mut self,
1245+
key: &TrieHash,
1246+
) -> InterpreterResult<Option<(String, Vec<u8>)>> {
1247+
Ok(
1248+
SqliteConnection::get(self.get_side_store(), key.to_string().as_str())?
1249+
.map(|x| (x, vec![])),
1250+
)
1251+
}
1252+
12391253
fn get_side_store(&mut self) -> &Connection {
12401254
&self.side_store
12411255
}

0 commit comments

Comments
 (0)