Skip to content

Commit

Permalink
Merge branch 'master' into assert-created-runestone
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Mar 23, 2024
2 parents 4004643 + 9a6c0e9 commit 21fa75f
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,9 @@ impl Index {
Ok(balances)
}

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

let rtx = self.database.begin_read()?;
Expand Down Expand Up @@ -960,7 +962,7 @@ impl Index {
);

rune_balances.insert(
spaced_rune.rune,
spaced_rune,
balances
.into_iter()
.map(|(outpoint, amount)| {
Expand Down
6 changes: 6 additions & 0 deletions src/runes/spaced_rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ pub struct SpacedRune {
pub spacers: u32,
}

impl SpacedRune {
pub fn new(rune: Rune, spacers: u32) -> Self {
Self { rune, spacers }
}
}

impl FromStr for SpacedRune {
type Err = Error;

Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;

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

pub(crate) fn run(settings: Settings) -> SubcommandResult {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ impl Server {
.collect(),
)
})
.collect::<BTreeMap<Rune, BTreeMap<OutPoint, u128>>>(),
.collect::<BTreeMap<SpacedRune, BTreeMap<OutPoint, u128>>>(),
)
.into_response()
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/wallet/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct Output {
pub cardinal: u64,
pub ordinal: u64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub runes: Option<BTreeMap<Rune, u128>>,
pub runes: Option<BTreeMap<SpacedRune, u128>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub runic: Option<u64>,
pub total: u64,
Expand Down Expand Up @@ -37,7 +37,7 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult {

if is_runic {
for (spaced_rune, pile) in rune_balances {
*runes.entry(spaced_rune.rune).or_default() += pile.amount;
*runes.entry(spaced_rune).or_default() += pile.amount;
}
runic += txout.value;
}
Expand Down
8 changes: 4 additions & 4 deletions src/templates/rune_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;

#[derive(Boilerplate, Debug, PartialEq, Serialize, Deserialize)]
pub struct RuneBalancesHtml {
pub balances: BTreeMap<Rune, BTreeMap<OutPoint, Pile>>,
pub balances: BTreeMap<SpacedRune, BTreeMap<OutPoint, Pile>>,
}

impl PageContent for RuneBalancesHtml {
Expand All @@ -19,9 +19,9 @@ mod tests {

#[test]
fn display_rune_balances() {
let balances: BTreeMap<Rune, BTreeMap<OutPoint, Pile>> = vec![
let balances: BTreeMap<SpacedRune, BTreeMap<OutPoint, Pile>> = vec![
(
Rune(RUNE),
SpacedRune::new(Rune(RUNE), 0),
vec![(
OutPoint {
txid: txid(1),
Expand All @@ -37,7 +37,7 @@ mod tests {
.collect(),
),
(
Rune(RUNE + 1),
SpacedRune::new(Rune(RUNE + 1), 0),
vec![(
OutPoint {
txid: txid(2),
Expand Down
4 changes: 2 additions & 2 deletions tests/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn with_runes() {
Output {
runes: vec![
(
Rune(RUNE),
SpacedRune::new(Rune(RUNE), 0),
vec![(
OutPoint {
txid: a.inscribe.reveal,
Expand All @@ -70,7 +70,7 @@ fn with_runes() {
.collect()
),
(
Rune(RUNE + 1),
SpacedRune::new(Rune(RUNE + 1), 0),
vec![(
OutPoint {
txid: b.inscribe.reveal,
Expand Down
27 changes: 25 additions & 2 deletions tests/wallet/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,26 @@ fn runic_utxos_are_deducted_from_cardinal() {
}
);

etch(&bitcoin_rpc_server, &ord_rpc_server, Rune(RUNE));
let rune = Rune(RUNE);

batch(
&bitcoin_rpc_server,
&ord_rpc_server,
Batchfile {
etch: Some(Etch {
divisibility: 0,
mint: None,
premine: "1000".parse().unwrap(),
rune: SpacedRune { rune, spacers: 1 },
symbol: '¢',
}),
inscriptions: vec![BatchEntry {
file: "inscription.jpeg".into(),
..Default::default()
}],
..Default::default()
},
);

pretty_assert_eq!(
CommandBuilder::new("--regtest --index-runes wallet balance")
Expand All @@ -109,7 +128,11 @@ fn runic_utxos_are_deducted_from_cardinal() {
cardinal: 50 * COIN_VALUE * 8 - 20_000,
ordinal: 10000,
runic: Some(10_000),
runes: Some(vec![(Rune(RUNE), 1000)].into_iter().collect()),
runes: Some(
vec![(SpacedRune { rune, spacers: 1 }, 1000)]
.into_iter()
.collect()
),
total: 50 * COIN_VALUE * 8,
}
);
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn minting_rune_and_fails_if_after_end() {
balances,
ord::subcommand::balances::Output {
runes: vec![(
output.rune.rune,
output.rune,
vec![(
OutPoint {
txid: output.mint,
Expand Down
10 changes: 5 additions & 5 deletions tests/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ fn sending_rune_works() {
balances,
ord::subcommand::balances::Output {
runes: vec![(
Rune(RUNE),
SpacedRune::new(Rune(RUNE), 0),
vec![(
OutPoint {
txid: output.txid,
Expand Down Expand Up @@ -842,7 +842,7 @@ fn sending_spaced_rune_works() {
balances,
ord::subcommand::balances::Output {
runes: vec![(
Rune(RUNE),
SpacedRune::new(Rune(RUNE), 0),
vec![(
OutPoint {
txid: output.txid,
Expand Down Expand Up @@ -916,7 +916,7 @@ fn sending_rune_with_divisibility_works() {
balances,
ord::subcommand::balances::Output {
runes: vec![(
Rune(RUNE),
SpacedRune::new(Rune(RUNE), 0),
vec![
(
OutPoint {
Expand Down Expand Up @@ -982,7 +982,7 @@ fn sending_rune_leaves_unspent_runes_in_wallet() {
balances,
ord::subcommand::balances::Output {
runes: vec![(
Rune(RUNE),
SpacedRune::new(Rune(RUNE), 0),
vec![
(
OutPoint {
Expand Down Expand Up @@ -1064,7 +1064,7 @@ fn sending_rune_creates_transaction_with_expected_runestone() {
balances,
ord::subcommand::balances::Output {
runes: vec![(
Rune(RUNE),
SpacedRune::new(Rune(RUNE), 0),
vec![
(
OutPoint {
Expand Down

0 comments on commit 21fa75f

Please sign in to comment.