Skip to content

Commit

Permalink
feat(querydb): get_utxo_from_reference endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MaicoLeberle committed Mar 26, 2024
1 parent 614697d commit c616b19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/querydb/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub const TX_TABLE: TableDefinition<TxTableKeyType, TxTableValueType> = TableDef
// representation.
pub type UTxOKeyType<'a> = (&'a [u8], u8);
pub type UTxOValueType<'a> = &'a [u8];
pub type UTxOResultType<'a> = Vec<u8>;
pub const UTXO_TABLE: TableDefinition<UTxOKeyType, UTxOValueType> = TableDefinition::new("utxo");
// Given an address, table "utxo_by_addr" maps it to a list of pairs of a tx
// hash and an (output) index (each one representing a UTxO sitting at that
Expand Down
11 changes: 9 additions & 2 deletions src/querydb/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,15 @@ impl Store {
res
}

pub fn get_utxo_from_reference(&self) -> Option<&[u8]> {
unimplemented!()
pub fn get_utxo_from_reference(&self, tx_hash: &Hash<32>, tx_index: u8) -> Option<Vec<u8>> {
let read_tx: ReadTransaction = self.inner_store.begin_read().ok()?;
let utxo_table: ReadOnlyTable<UTxOKeyType, UTxOValueType> =
read_tx.open_table(UTXO_TABLE).ok()?;
let res = utxo_table
.get((tx_hash.as_ref(), tx_index))
.ok()?
.map(|val| Vec::from(val.value()));
res
}

pub fn get_tx_from_hash(&self, _tx_hash: Hash<32>) -> Option<&[u8]> {
Expand Down

0 comments on commit c616b19

Please sign in to comment.