Skip to content

Commit

Permalink
Merge commit '9c1680158475433063cc4b46df2af47ae11f0418'
Browse files Browse the repository at this point in the history
  • Loading branch information
gmart7t2 committed Jul 26, 2023
2 parents a5248bc + 9c16801 commit 9acf9be
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/subcommand/wallet/inscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct OutputWithSat {
pub inscription: InscriptionId,
pub location: SatPoint,
pub explorer: String,
pub amount: u64,
pub postage: u64,
}

#[derive(Serialize, Deserialize)]
Expand All @@ -16,7 +16,7 @@ pub struct OutputWithoutSat {
pub inscription: InscriptionId,
pub location: SatPoint,
pub explorer: String,
pub amount: u64,
pub postage: u64,
}

pub(crate) fn run(options: Options) -> Result {
Expand All @@ -39,7 +39,7 @@ pub(crate) fn run(options: Options) -> Result {
let mut output_without_sat = Vec::new();

for (location, inscription) in inscriptions {
if unspent_outputs.contains_key(&location.outpoint) {
if let Some(postage) = unspent_outputs.get(&location.outpoint) {
let entry = index
.get_inscription_entry(inscription)?
.ok_or_else(|| anyhow!("Inscription {inscription} not found"))?;
Expand All @@ -50,15 +50,15 @@ pub(crate) fn run(options: Options) -> Result {
location,
inscription,
explorer: format!("{explorer}{inscription}"),
amount: unspent_outputs.get(&location.outpoint).unwrap().to_sat(),
postage: postage.to_sat(),
});
} else {
output_without_sat.push(OutputWithoutSat {
number: entry.number,
location,
inscription,
explorer: format!("{explorer}{inscription}"),
amount: unspent_outputs.get(&location.outpoint).unwrap().to_sat(),
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 @@ -86,3 +86,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 9acf9be

Please sign in to comment.