forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ord wallet runics
command (ordinals#3734)
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use super::*; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct RunicUtxo { | ||
pub output: OutPoint, | ||
pub runes: BTreeMap<SpacedRune, Decimal>, | ||
} | ||
|
||
pub(crate) fn run(wallet: Wallet) -> SubcommandResult { | ||
let unspent_outputs = wallet.utxos(); | ||
let runic_utxos = wallet.get_runic_outputs()?; | ||
|
||
let runic_utxos = unspent_outputs | ||
.iter() | ||
.filter_map(|(output, _)| { | ||
if runic_utxos.contains(output) { | ||
let rune_balances = wallet.get_runes_balances_in_output(output).ok()?; | ||
let mut runes = BTreeMap::new(); | ||
|
||
for (spaced_rune, pile) in rune_balances { | ||
runes | ||
.entry(spaced_rune) | ||
.and_modify(|decimal: &mut Decimal| { | ||
assert_eq!(decimal.scale, pile.divisibility); | ||
decimal.value += pile.amount; | ||
}) | ||
.or_insert(Decimal { | ||
value: pile.amount, | ||
scale: pile.divisibility, | ||
}); | ||
} | ||
|
||
Some(RunicUtxo { | ||
output: *output, | ||
runes, | ||
}) | ||
} else { | ||
None | ||
} | ||
}) | ||
.collect::<Vec<RunicUtxo>>(); | ||
|
||
Ok(Some(Box::new(runic_utxos))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ mod receive; | |
mod restore; | ||
#[cfg(unix)] | ||
mod resume; | ||
mod runics; | ||
mod sats; | ||
mod selection; | ||
mod send; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use { | ||
super::*, | ||
ord::{decimal::Decimal, subcommand::wallet::runics::RunicUtxo}, | ||
}; | ||
|
||
#[test] | ||
fn wallet_runics() { | ||
let core = mockcore::builder().network(Network::Regtest).build(); | ||
let ord = TestServer::spawn_with_server_args(&core, &["--regtest", "--index-runes"], &[]); | ||
|
||
create_wallet(&core, &ord); | ||
|
||
let rune = Rune(RUNE); | ||
|
||
batch( | ||
&core, | ||
&ord, | ||
batch::File { | ||
etching: Some(batch::Etching { | ||
divisibility: 0, | ||
premine: "1000".parse().unwrap(), | ||
rune: SpacedRune { rune, spacers: 1 }, | ||
supply: "1000".parse().unwrap(), | ||
symbol: '¢', | ||
terms: None, | ||
turbo: false, | ||
}), | ||
inscriptions: vec![batch::Entry { | ||
file: Some("inscription.jpeg".into()), | ||
..default() | ||
}], | ||
..default() | ||
}, | ||
); | ||
|
||
pretty_assert_eq!( | ||
CommandBuilder::new("--regtest --index-runes wallet runics") | ||
.core(&core) | ||
.ord(&ord) | ||
.run_and_deserialize_output::<Vec<RunicUtxo>>() | ||
.first() | ||
.unwrap() | ||
.runes, | ||
vec![( | ||
SpacedRune { rune, spacers: 1 }, | ||
Decimal { | ||
value: 1000, | ||
scale: 0 | ||
} | ||
)] | ||
.into_iter() | ||
.collect() | ||
); | ||
} |