-
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.
Add
ord wallet cardinals
command to list the cardinal outputs (#1904)
Co-authored-by: Greg Martin <[email protected]> Co-authored-by: raphjaph <[email protected]>
- Loading branch information
1 parent
92157e5
commit ab2f178
Showing
4 changed files
with
66 additions
and
1 deletion.
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,37 @@ | ||
use {super::*, crate::wallet::Wallet, std::collections::BTreeSet}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct Cardinal { | ||
pub output: OutPoint, | ||
pub amount: u64, | ||
} | ||
|
||
pub(crate) fn run(options: Options) -> Result { | ||
let index = Index::open(&options)?; | ||
index.update()?; | ||
|
||
let inscribed_utxos = index | ||
.get_inscriptions(None)? | ||
.keys() | ||
.map(|satpoint| satpoint.outpoint) | ||
.collect::<BTreeSet<OutPoint>>(); | ||
|
||
let cardinal_utxos = index | ||
.get_unspent_outputs(Wallet::load(&options)?)? | ||
.iter() | ||
.filter_map(|(output, amount)| { | ||
if inscribed_utxos.contains(output) { | ||
None | ||
} else { | ||
Some(Cardinal { | ||
output: *output, | ||
amount: amount.to_sat(), | ||
}) | ||
} | ||
}) | ||
.collect::<Vec<Cardinal>>(); | ||
|
||
print_json(cardinal_utxos)?; | ||
|
||
Ok(()) | ||
} |
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,6 +1,7 @@ | ||
use super::*; | ||
|
||
mod balance; | ||
mod cardinals; | ||
mod create; | ||
mod inscribe; | ||
mod inscriptions; | ||
|
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,23 @@ | ||
use { | ||
super::*, | ||
ord::subcommand::wallet::{cardinals::Cardinal, outputs::Output}, | ||
}; | ||
|
||
#[test] | ||
fn cardinals() { | ||
let rpc_server = test_bitcoincore_rpc::spawn(); | ||
create_wallet(&rpc_server); | ||
|
||
// this creates 2 more cardinal outputs and one inscribed output | ||
inscribe(&rpc_server); | ||
|
||
let all_outputs = CommandBuilder::new("wallet outputs") | ||
.rpc_server(&rpc_server) | ||
.output::<Vec<Output>>(); | ||
|
||
let cardinal_outputs = CommandBuilder::new("wallet cardinals") | ||
.rpc_server(&rpc_server) | ||
.output::<Vec<Cardinal>>(); | ||
|
||
assert_eq!(all_outputs.len() - cardinal_outputs.len(), 1); | ||
} |