Add basic getters to tributary

This commit is contained in:
Luke Parker 2023-04-15 00:41:48 -04:00
parent 124b994c23
commit f48022c6eb
No known key found for this signature in database
2 changed files with 19 additions and 0 deletions

View file

@ -92,6 +92,15 @@ impl<D: Db, T: Transaction> Blockchain<D, T> {
self.block_number self.block_number
} }
pub(crate) fn block(&self, block: &[u8; 32]) -> Option<Block<T>> {
self
.db
.as_ref()
.unwrap()
.get(self.block_key(block))
.map(|bytes| Block::<T>::read::<&[u8]>(&mut bytes.as_ref()).unwrap())
}
pub(crate) fn commit(&self, block: &[u8; 32]) -> Option<Vec<u8>> { pub(crate) fn commit(&self, block: &[u8; 32]) -> Option<Vec<u8>> {
self.db.as_ref().unwrap().get(self.commit_key(block)) self.db.as_ref().unwrap().get(self.commit_key(block))
} }

View file

@ -126,6 +126,16 @@ impl<D: Db, T: Transaction, P: P2p> Tributary<D, T, P> {
Some(Self { network, synced_block, messages }) Some(Self { network, synced_block, messages })
} }
pub fn tip(&self) -> [u8; 32] {
self.network.blockchain.read().unwrap().tip()
}
pub fn block(&self, hash: &[u8; 32]) -> Option<Block<T>> {
self.network.blockchain.read().unwrap().block(hash)
}
pub fn commit(&self, hash: &[u8; 32]) -> Option<Vec<u8>> {
self.network.blockchain.read().unwrap().commit(hash)
}
pub fn provide_transaction(&self, tx: T) -> Result<(), ProvidedError> { pub fn provide_transaction(&self, tx: T) -> Result<(), ProvidedError> {
self.network.blockchain.write().unwrap().provide_transaction(tx) self.network.blockchain.write().unwrap().provide_transaction(tx)
} }