Skip to content

Commit

Permalink
add DummyDB tx storage
Browse files Browse the repository at this point in the history
  • Loading branch information
thdaraujo committed Jun 24, 2022
1 parent 0298a37 commit 0194465
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions fuel-core-interfaces/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,30 +667,36 @@ pub mod helpers {
}
}

impl Storage<Bytes32, Transaction> for DummyDb {
impl Storage<Bytes32, Arc<Transaction>> for DummyDb {
type Error = KvStoreError;

fn insert(
&mut self,
_key: &Bytes32,
_value: &Transaction,
) -> Result<Option<Transaction>, Self::Error> {
unreachable!()
key: &Bytes32,
value: &Arc<Transaction>,
) -> Result<Option<Arc<Transaction>>, Self::Error> {
Ok(self.data.lock().tx.insert(*key, value.clone()))
}

fn remove(&mut self, _key: &Bytes32) -> Result<Option<Transaction>, Self::Error> {
unreachable!()
fn remove(&mut self, key: &Bytes32) -> Result<Option<Arc<Transaction>>, Self::Error> {
Ok(self.data.lock().tx.remove(key))
}

fn get<'a>(
&'a self,
_key: &Bytes32,
) -> Result<Option<std::borrow::Cow<'a, Transaction>>, Self::Error> {
unreachable!()
key: &Bytes32,
) -> Result<Option<std::borrow::Cow<'a, Arc<Transaction>>>, Self::Error> {

Ok(self
.data
.lock()
.tx
.get(key)
.map(|i| Cow::Owned(i.clone())))
}

fn contains_key(&self, _key: &Bytes32) -> Result<bool, Self::Error> {
unreachable!()
fn contains_key(&self, key: &Bytes32) -> Result<bool, Self::Error> {
Ok(self.data.lock().tx.contains_key(key))
}
}
impl Storage<ContractId, Contract> for DummyDb {
Expand Down

0 comments on commit 0194465

Please sign in to comment.