-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
4 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
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,59 @@ | ||
use super::*; | ||
|
||
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)] | ||
pub struct Output { | ||
pub output: OutPoint, | ||
pub amount: u64, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub inscriptions: Option<Vec<InscriptionId>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub runes: Option<BTreeMap<SpacedRune, Decimal>>, | ||
} | ||
|
||
pub(crate) fn run(wallet: Wallet) -> SubcommandResult { | ||
let mut addresses: BTreeMap<Address<NetworkUnchecked>, Vec<Output>> = BTreeMap::new(); | ||
|
||
for (output, txout) in wallet.utxos() { | ||
let address = wallet.chain().address_from_script(&txout.script_pubkey)?; | ||
|
||
let inscriptions = if wallet.has_inscription_index() { | ||
Some(wallet.get_inscriptions_in_output(output)) | ||
} else { | ||
None | ||
}; | ||
|
||
let runes = if wallet.has_rune_index() { | ||
Some( | ||
wallet | ||
.get_runes_balances_in_output(output)? | ||
.iter() | ||
.map(|(rune, pile)| { | ||
( | ||
*rune, | ||
Decimal { | ||
value: pile.amount, | ||
scale: pile.divisibility, | ||
}, | ||
) | ||
}) | ||
.collect(), | ||
) | ||
} else { | ||
None | ||
}; | ||
|
||
let output = Output { | ||
output: *output, | ||
amount: txout.value.to_sat(), | ||
inscriptions, | ||
runes, | ||
}; | ||
|
||
addresses | ||
.entry(address.as_unchecked().clone()) | ||
.or_default() | ||
.push(output); | ||
} | ||
|
||
Ok(Some(Box::new(addresses))) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use super::*; | ||
|
||
mod addresses; | ||
mod authentication; | ||
mod balance; | ||
mod batch_command; | ||
|
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,76 @@ | ||
use {super::*, ord::subcommand::wallet::addresses::Output}; | ||
|
||
#[test] | ||
fn addresses() { | ||
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); | ||
|
||
let etched = batch( | ||
&core, | ||
&ord, | ||
batch::File { | ||
etching: Some(batch::Etching { | ||
divisibility: 3, | ||
premine: "1.111".parse().unwrap(), | ||
rune: SpacedRune { rune, spacers: 1 }, | ||
supply: "2.222".parse().unwrap(), | ||
symbol: '¢', | ||
terms: Some(batch::Terms { | ||
amount: "1.111".parse().unwrap(), | ||
cap: 1, | ||
..default() | ||
}), | ||
turbo: false, | ||
}), | ||
inscriptions: vec![batch::Entry { | ||
file: Some("inscription.jpeg".into()), | ||
..default() | ||
}], | ||
..default() | ||
}, | ||
); | ||
|
||
let output = CommandBuilder::new("--regtest --index-runes wallet addresses") | ||
.core(&core) | ||
.ord(&ord) | ||
.run_and_deserialize_output::<BTreeMap<Address<NetworkUnchecked>, Vec<Output>>>(); | ||
|
||
pretty_assert_eq!( | ||
output | ||
.get(&etched.output.rune.clone().unwrap().destination.unwrap()) | ||
.unwrap(), | ||
&vec![Output { | ||
output: etched.output.rune.unwrap().location.unwrap(), | ||
amount: 10000, | ||
inscriptions: Some(Vec::new()), | ||
runes: Some( | ||
vec![( | ||
SpacedRune { rune, spacers: 1 }, | ||
ord::decimal::Decimal { | ||
value: 1111, | ||
scale: 3, | ||
} | ||
)] | ||
.into_iter() | ||
.collect() | ||
), | ||
}] | ||
); | ||
|
||
pretty_assert_eq!( | ||
output | ||
.get(&etched.output.inscriptions[0].destination) | ||
.unwrap(), | ||
&vec![Output { | ||
output: etched.output.inscriptions[0].location.outpoint, | ||
amount: 10000, | ||
inscriptions: Some(vec![etched.output.inscriptions[0].id]), | ||
runes: Some(BTreeMap::new()), | ||
}] | ||
); | ||
} |
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