Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Nov 30, 2023
1 parent 46e9128 commit 9552d24
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
26 changes: 26 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,32 @@ impl Index {
Ok(runic)
}

pub(crate) fn get_rune_balance_map(&self) -> Result<BTreeMap<OutPoint, BTreeMap<Rune, u128>>> {
let rune_balances = self.get_rune_balances()?;

let rtx = self.database.begin_read()?;

let rune_id_to_rune_entry = rtx.open_table(RUNE_ID_TO_RUNE_ENTRY)?;

rune_balances
.into_iter()
.map(|(outpoint, balances)| {
Ok((
outpoint,
balances
.into_iter()
.map(|(rune_id, amount)| {
Ok((
RuneEntry::load(rune_id_to_rune_entry.get(rune_id.store())?.unwrap().value()).rune,
amount,
))
})
.collect::<Result<BTreeMap<Rune, u128>>>()?,
))
})
.collect()
}

pub(crate) fn get_rune_balances(&self) -> Result<Vec<(OutPoint, Vec<(RuneId, u128)>)>> {
let mut result = Vec::new();

Expand Down
45 changes: 42 additions & 3 deletions src/subcommand/balances.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
use super::*;

// - remove op return limit
// - remove max transaction size limit

// todo:
// - nested or flattened?
// - test flag is required
// - print as pile or number?

// get all balances
// get balances on output
// get balances of rune

// OUTPOINT RUNE BALANCE
// OUTPOINT RUNE BALANCE
// OUTPOINT RUNE BALANCE
// OUTPOINT RUNE BALANCE
// OUTPOINT RUNE BALANCE
//
// {
// outpoint: {
// rune: balance,
// rune: balance,
// rune: balance,
// rune: balance,
// rune: balance,
// rune: balance,
// rune: balance,
// },
// outpoint: {
// rune: balance,
// rune: balance,
// rune: balance,
// rune: balance,
// rune: balance,
// }
// outpoint: {
// rune: balance,
// rune: balance,
// rune: balance,
// rune: balance,
// rune: balance,
// }
// }

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Output {
pub balances: BTreeMap<OutPoint, BTreeMap<Rune, u128>>,
pub runes: BTreeMap<OutPoint, BTreeMap<Rune, u128>>,
}

pub(crate) fn run(options: Options) -> SubcommandResult {
Expand All @@ -21,8 +60,8 @@ pub(crate) fn run(options: Options) -> SubcommandResult {
index.update()?;

Ok(Box::new(Output {
balances: index
.get_rune_balances()?
runes: index
.get_rune_balance_map()?
.into_iter()
.map(|(outpoint, balances)| (outpoint, balances.into_iter().collect()))
.collect(),
Expand Down

0 comments on commit 9552d24

Please sign in to comment.