diff --git a/coordinator/tributary/src/blockchain.rs b/coordinator/tributary/src/blockchain.rs index 91a8a2b3..adbe946b 100644 --- a/coordinator/tributary/src/blockchain.rs +++ b/coordinator/tributary/src/blockchain.rs @@ -92,6 +92,15 @@ impl Blockchain { self.block_number } + pub(crate) fn block(&self, block: &[u8; 32]) -> Option> { + self + .db + .as_ref() + .unwrap() + .get(self.block_key(block)) + .map(|bytes| Block::::read::<&[u8]>(&mut bytes.as_ref()).unwrap()) + } + pub(crate) fn commit(&self, block: &[u8; 32]) -> Option> { self.db.as_ref().unwrap().get(self.commit_key(block)) } diff --git a/coordinator/tributary/src/lib.rs b/coordinator/tributary/src/lib.rs index f5427431..60be7030 100644 --- a/coordinator/tributary/src/lib.rs +++ b/coordinator/tributary/src/lib.rs @@ -126,6 +126,16 @@ impl Tributary { 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> { + self.network.blockchain.read().unwrap().block(hash) + } + pub fn commit(&self, hash: &[u8; 32]) -> Option> { + self.network.blockchain.read().unwrap().commit(hash) + } + pub fn provide_transaction(&self, tx: T) -> Result<(), ProvidedError> { self.network.blockchain.write().unwrap().provide_transaction(tx) }