Skip to content

Commit

Permalink
brc20db reader
Browse files Browse the repository at this point in the history
  • Loading branch information
cwbhhjl committed May 9, 2023
1 parent bdc673c commit 136fc83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,15 +920,15 @@ impl Index {
}

pub(crate) fn brc20_get_tick_info(&self, name: &String) -> Result<Option<brc20::TokenInfo>> {
let wtx = self.database.begin_write().unwrap();
let brc20_db = crate::okx::BRC20Database::new(&wtx);
let wtx = self.database.begin_read().unwrap();
let brc20_db = crate::okx::BRC20DatabaseReader::new(&wtx);
let info = brc20_db.get_token_info(&brc20::Tick::from_str(name)?)?;
Ok(info)
}

pub(crate) fn brc20_get_all_tick_info(&self) -> Result<Vec<brc20::TokenInfo>> {
let wtx = self.database.begin_write().unwrap();
let brc20_db = crate::okx::BRC20Database::new(&wtx);
let wtx = self.database.begin_read().unwrap();
let brc20_db = crate::okx::BRC20DatabaseReader::new(&wtx);
let info = brc20_db.get_tokens_info()?;
Ok(info)
}
Expand All @@ -938,8 +938,8 @@ impl Index {
tick: &str,
address: &bitcoin::Address,
) -> Result<Option<brc20::Balance>> {
let wtx = self.database.begin_write().unwrap();
let brc20_db = crate::okx::BRC20Database::new(&wtx);
let wtx = self.database.begin_read().unwrap();
let brc20_db = crate::okx::BRC20DatabaseReader::new(&wtx);
let bal = brc20_db.get_balance(
&brc20::ScriptKey::from_address(address.clone()),
&brc20::Tick::from_str(tick)?,
Expand All @@ -951,8 +951,8 @@ impl Index {
&self,
address: &bitcoin::Address,
) -> Result<Vec<(brc20::Tick, brc20::Balance)>> {
let wtx = self.database.begin_write().unwrap();
let brc20_db = crate::okx::BRC20Database::new(&wtx);
let wtx = self.database.begin_read().unwrap();
let brc20_db = crate::okx::BRC20DatabaseReader::new(&wtx);
let all_balance = brc20_db.get_balances(&brc20::ScriptKey::from_address(address.clone()))?;
Ok(all_balance)
}
Expand All @@ -961,8 +961,8 @@ impl Index {
&self,
txid: &bitcoin::Txid,
) -> Result<Option<Vec<brc20::ActionReceipt>>> {
let wtx = self.database.begin_write().unwrap();
let brc20_db = crate::okx::BRC20Database::new(&wtx);
let wtx = self.database.begin_read().unwrap();
let brc20_db = crate::okx::BRC20DatabaseReader::new(&wtx);
let res = brc20_db.get_transaction_receipts(txid)?;

if res.len() == 0 {
Expand Down Expand Up @@ -995,8 +995,8 @@ impl Index {
return Ok(None);
}

let wtx = self.database.begin_write().unwrap();
let brc20_db = crate::okx::BRC20Database::new(&wtx);
let wtx = self.database.begin_read().unwrap();
let brc20_db = crate::okx::BRC20DatabaseReader::new(&wtx);

let mut result = Vec::new();

Expand All @@ -1016,8 +1016,8 @@ impl Index {
tick: &str,
address: &bitcoin::Address,
) -> Result<Vec<brc20::TransferableLog>> {
let wtx = self.database.begin_write().unwrap();
let brc20_db = crate::okx::BRC20Database::new(&wtx);
let wtx = self.database.begin_read().unwrap();
let brc20_db = crate::okx::BRC20DatabaseReader::new(&wtx);
let res = brc20_db.get_transferable_by_tick(
&ScriptKey::from_address(address.clone()),
&brc20::Tick::from_str(tick)?,
Expand All @@ -1030,8 +1030,8 @@ impl Index {
&self,
address: &bitcoin::Address,
) -> Result<Vec<brc20::TransferableLog>> {
let wtx = self.database.begin_write().unwrap();
let brc20_db = crate::okx::BRC20Database::new(&wtx);
let wtx = self.database.begin_read().unwrap();
let brc20_db = crate::okx::BRC20DatabaseReader::new(&wtx);
let res = brc20_db.get_transferable(&ScriptKey::from_address(address.clone()))?;

Ok(res)
Expand Down
1 change: 1 addition & 0 deletions src/okx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod brc20_db;

pub use self::brc20_db::BRC20Database;
pub use self::brc20_db::BRC20DatabaseReader;

0 comments on commit 136fc83

Please sign in to comment.