mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-22 02:34:55 +00:00
Add basic getters to tributary
This commit is contained in:
parent
124b994c23
commit
f48022c6eb
2 changed files with 19 additions and 0 deletions
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue