From 9c1680158475433063cc4b46df2af47ae11f0418 Mon Sep 17 00:00:00 2001 From: gmart7t2 <49558347+gmart7t2@users.noreply.github.com> Date: Mon, 24 Jul 2023 17:48:30 -0300 Subject: [PATCH] Add `amount` field to `wallet inscriptions` output. (#1928) --- src/subcommand/wallet/inscriptions.rs | 6 +++-- tests/wallet/inscriptions.rs | 37 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/subcommand/wallet/inscriptions.rs b/src/subcommand/wallet/inscriptions.rs index 73f8a1fc0a..020ac5ce61 100644 --- a/src/subcommand/wallet/inscriptions.rs +++ b/src/subcommand/wallet/inscriptions.rs @@ -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 { @@ -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(), + }) } } diff --git a/tests/wallet/inscriptions.rs b/tests/wallet/inscriptions.rs index f8c9a2f5d1..3951e8f072 100644 --- a/tests/wallet/inscriptions.rs +++ b/tests/wallet/inscriptions.rs @@ -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::>(); + + assert_eq!(output[0].postage, 10000); + + let address = CommandBuilder::new("wallet receive") + .rpc_server(&rpc_server) + .run_and_check_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::>(); + + assert_eq!(output[0].postage, 9889); +}