Skip to content

Commit

Permalink
Add amount field to wallet inscriptions output. (ordinals#1928)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmart7t2 committed Jul 24, 2023
1 parent df60f0d commit 9c16801
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/subcommand/wallet/inscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct Output {
pub inscription: InscriptionId,
pub location: SatPoint,
pub explorer: String,
pub postage: u64,
}

pub(crate) fn run(options: Options) -> Result {
Expand All @@ -24,12 +25,13 @@ pub(crate) fn run(options: Options) -> Result {
let mut output = Vec::new();

for (location, inscription) in inscriptions {
if unspent_outputs.contains_key(&location.outpoint) {
if let Some(postage) = unspent_outputs.get(&location.outpoint) {
output.push(Output {
location,
inscription,
explorer: format!("{explorer}{inscription}"),
});
postage: postage.to_sat(),
})
}
}

Expand Down
37 changes: 37 additions & 0 deletions tests/wallet/inscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,40 @@ fn inscriptions_includes_locked_utxos() {
assert_eq!(output[0].inscription, inscription.parse().unwrap());
assert_eq!(output[0].location, format!("{reveal}:0:0").parse().unwrap());
}

#[test]
fn inscriptions_with_postage() {
let rpc_server = test_bitcoincore_rpc::spawn();
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

let Inscribe { inscription, .. } = inscribe(&rpc_server);

let output = CommandBuilder::new("wallet inscriptions")
.rpc_server(&rpc_server)
.run_and_check_output::<Vec<Output>>();

assert_eq!(output[0].postage, 10000);

let address = CommandBuilder::new("wallet receive")
.rpc_server(&rpc_server)
.run_and_check_output::<receive::Output>()
.address;

CommandBuilder::new(format!(
"wallet send --fee-rate 1 {} {inscription}",
address.assume_checked()
))
.rpc_server(&rpc_server)
.expected_exit_code(0)
.stdout_regex(".*")
.run_and_extract_stdout();

rpc_server.mine_blocks(1);

let output = CommandBuilder::new("wallet inscriptions")
.rpc_server(&rpc_server)
.run_and_check_output::<Vec<Output>>();

assert_eq!(output[0].postage, 9889);
}

0 comments on commit 9c16801

Please sign in to comment.