Skip to content

Commit

Permalink
Add address field to /r/inscription/:id (ordinals#3891)
Browse files Browse the repository at this point in the history
  • Loading branch information
elocremarc authored Sep 3, 2024
1 parent 0ae0572 commit e9353f3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/src/inscriptions/recursion.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ percentile in sats/vB.
"sat": null,
"satpoint": "3bd72a7ef68776c9429961e43043ff65efa7fb2d8bb407386a9e3b19f149bc36:0:0",
"timestamp": 1708312562,
"value": 10000
"value": 10000,
"address": "bc1pz4kvfpurqc2hwgrq0nwtfve2lfxvdpfcdpzc6ujchyr3ztj6gd9sfr6ayf"
}
```

Expand Down
1 change: 1 addition & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub struct InscriptionRecursive {
pub satpoint: SatPoint,
pub timestamp: i64,
pub value: Option<u64>,
pub address: Option<String>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down
15 changes: 15 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -1074,6 +1082,7 @@ impl Server {
sat: entry.sat,
satpoint,
timestamp: timestamp(entry.timestamp.into()).timestamp(),
address,
})
.into_response(),
)
Expand Down Expand Up @@ -6695,6 +6704,7 @@ next
},
timestamp: 2,
value: Some(50 * COIN_VALUE),
address: Some("bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202".to_string())
}
);

Expand Down Expand Up @@ -6724,6 +6734,7 @@ next
},
timestamp: 2,
value: Some(50 * COIN_VALUE),
address: Some("bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202".to_string())
}
);

Expand All @@ -6746,6 +6757,7 @@ next
},
timestamp: 2,
value: Some(50 * COIN_VALUE),
address: Some("bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202".to_string())
}
);
}
Expand Down Expand Up @@ -6931,6 +6943,7 @@ next
},
timestamp: 2,
value: Some(50 * COIN_VALUE),
address: None
}
);
}
Expand Down Expand Up @@ -6985,6 +6998,7 @@ next
},
timestamp: 2,
value: Some(50 * COIN_VALUE),
address: Some("bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202".to_string())
}
);

Expand Down Expand Up @@ -7029,6 +7043,7 @@ next
},
timestamp: 2,
value: Some(50 * COIN_VALUE),
address: None
}
);
}
Expand Down
6 changes: 5 additions & 1 deletion tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -516,6 +519,7 @@ fn recursive_inscription_endpoint() {
},
timestamp: 2,
value: Some(10000),
address: None,
}
)
}
Expand Down

0 comments on commit e9353f3

Please sign in to comment.