diff --git a/docs/src/inscriptions/recursion.md b/docs/src/inscriptions/recursion.md index 77b2ef2fb0..bde18fc6e7 100644 --- a/docs/src/inscriptions/recursion.md +++ b/docs/src/inscriptions/recursion.md @@ -192,7 +192,8 @@ percentile in sats/vB. "sat": null, "satpoint": "3bd72a7ef68776c9429961e43043ff65efa7fb2d8bb407386a9e3b19f149bc36:0:0", "timestamp": 1708312562, - "value": 10000 + "value": 10000, + "address": "bc1pz4kvfpurqc2hwgrq0nwtfve2lfxvdpfcdpzc6ujchyr3ztj6gd9sfr6ayf" } ``` diff --git a/src/api.rs b/src/api.rs index 45200115e6..604caf5999 100644 --- a/src/api.rs +++ b/src/api.rs @@ -126,6 +126,7 @@ pub struct InscriptionRecursive { pub satpoint: SatPoint, pub timestamp: i64, pub value: Option, + pub address: Option, } #[derive(Debug, PartialEq, Serialize, Deserialize)] diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index f233e3a1d6..5a48afd79b 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -1059,6 +1059,14 @@ impl Server { ) }; + let address = output.as_ref().and_then(|output| { + server_config + .chain + .address_from_script(&output.script_pubkey) + .ok() + .map(|address| address.to_string()) + }); + Ok( Json(api::InscriptionRecursive { charms: Charm::charms(entry.charms), @@ -1074,6 +1082,7 @@ impl Server { sat: entry.sat, satpoint, timestamp: timestamp(entry.timestamp.into()).timestamp(), + address, }) .into_response(), ) @@ -6695,6 +6704,7 @@ next }, timestamp: 2, value: Some(50 * COIN_VALUE), + address: Some("bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202".to_string()) } ); @@ -6724,6 +6734,7 @@ next }, timestamp: 2, value: Some(50 * COIN_VALUE), + address: Some("bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202".to_string()) } ); @@ -6746,6 +6757,7 @@ next }, timestamp: 2, value: Some(50 * COIN_VALUE), + address: Some("bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202".to_string()) } ); } @@ -6931,6 +6943,7 @@ next }, timestamp: 2, value: Some(50 * COIN_VALUE), + address: None } ); } @@ -6985,6 +6998,7 @@ next }, timestamp: 2, value: Some(50 * COIN_VALUE), + address: Some("bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202".to_string()) } ); @@ -7029,6 +7043,7 @@ next }, timestamp: 2, value: Some(50 * COIN_VALUE), + address: None } ); } diff --git a/tests/server.rs b/tests/server.rs index 788bb8be70..f8f62af7bf 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -494,9 +494,12 @@ fn recursive_inscription_endpoint() { "application/json" ); - let inscription_recursive_json: api::InscriptionRecursive = + let mut inscription_recursive_json: api::InscriptionRecursive = serde_json::from_str(&response.text().unwrap()).unwrap(); + assert_regex_match!(inscription_recursive_json.address.unwrap(), r"bc1p.*"); + inscription_recursive_json.address = None; + pretty_assert_eq!( inscription_recursive_json, api::InscriptionRecursive { @@ -516,6 +519,7 @@ fn recursive_inscription_endpoint() { }, timestamp: 2, value: Some(10000), + address: None, } ) }