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 balances
to show rune balances (ordinals#2782)
- Loading branch information
Showing
8 changed files
with
167 additions
and
20 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
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,21 @@ | ||
use super::*; | ||
|
||
#[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct Output { | ||
pub runes: BTreeMap<Rune, BTreeMap<OutPoint, u128>>, | ||
} | ||
|
||
pub(crate) fn run(options: Options) -> SubcommandResult { | ||
let index = Index::open(&options)?; | ||
|
||
ensure!( | ||
index.has_rune_index(), | ||
"`ord balances` requires index created with `--index-runes-pre-alpha-i-agree-to-get-rekt` flag", | ||
); | ||
|
||
index.update()?; | ||
|
||
Ok(Box::new(Output { | ||
runes: index.get_rune_balance_map()?, | ||
})) | ||
} |
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,86 @@ | ||
use {super::*, ord::subcommand::balances::Output}; | ||
|
||
#[test] | ||
fn flag_is_required() { | ||
let rpc_server = test_bitcoincore_rpc::builder() | ||
.network(Network::Regtest) | ||
.build(); | ||
|
||
CommandBuilder::new("--regtest balances") | ||
.rpc_server(&rpc_server) | ||
.expected_exit_code(1) | ||
.expected_stderr( | ||
"error: `ord balances` requires index created with `--index-runes-pre-alpha-i-agree-to-get-rekt` flag\n", | ||
) | ||
.run_and_extract_stdout(); | ||
} | ||
|
||
#[test] | ||
fn no_runes() { | ||
let rpc_server = test_bitcoincore_rpc::builder() | ||
.network(Network::Regtest) | ||
.build(); | ||
|
||
let output = | ||
CommandBuilder::new("--regtest --index-runes-pre-alpha-i-agree-to-get-rekt balances") | ||
.rpc_server(&rpc_server) | ||
.run_and_deserialize_output::<Output>(); | ||
|
||
assert_eq!( | ||
output, | ||
Output { | ||
runes: BTreeMap::new() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_runes() { | ||
let rpc_server = test_bitcoincore_rpc::builder() | ||
.network(Network::Regtest) | ||
.build(); | ||
|
||
create_wallet(&rpc_server); | ||
|
||
let a = etch(&rpc_server, Rune(RUNE)); | ||
let b = etch(&rpc_server, Rune(RUNE + 1)); | ||
|
||
let output = | ||
CommandBuilder::new("--regtest --index-runes-pre-alpha-i-agree-to-get-rekt balances") | ||
.rpc_server(&rpc_server) | ||
.run_and_deserialize_output::<Output>(); | ||
|
||
assert_eq!( | ||
output, | ||
Output { | ||
runes: vec![ | ||
( | ||
Rune(RUNE), | ||
vec![( | ||
OutPoint { | ||
txid: a.transaction, | ||
vout: 1 | ||
}, | ||
1000 | ||
)] | ||
.into_iter() | ||
.collect() | ||
), | ||
( | ||
Rune(RUNE + 1), | ||
vec![( | ||
OutPoint { | ||
txid: b.transaction, | ||
vout: 1 | ||
}, | ||
1000 | ||
)] | ||
.into_iter() | ||
.collect() | ||
), | ||
] | ||
.into_iter() | ||
.collect(), | ||
} | ||
); | ||
} |
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