Skip to content

Commit

Permalink
Proxy recursive sat_at_index_content endpoint (#4205)
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so authored Feb 2, 2025
1 parent f05ed9b commit a67a6ef
Showing 1 changed file with 88 additions and 4 deletions.
92 changes: 88 additions & 4 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,6 @@ impl Server {
)
.route("/r/sat/{sat_number}", get(r::sat))
.route("/r/sat/{sat_number}/at/{index}", get(r::sat_at_index))
.route(
"/r/sat/{sat_number}/at/{index}/content",
get(r::sat_at_index_content),
)
.route("/r/sat/{sat_number}/{page}", get(r::sat_paginated))
.route("/r/tx/{txid}", get(r::tx))
.route(
Expand All @@ -287,6 +283,10 @@ impl Server {
)
.route("/r/inscription/{inscription_id}", get(r::inscription))
.route("/r/metadata/{inscription_id}", get(r::metadata))
.route(
"/r/sat/{sat_number}/at/{index}/content",
get(r::sat_at_index_content),
)
.layer(axum::middleware::from_fn(Self::proxy_fallback));

let router = router.merge(proxiable_routes);
Expand Down Expand Up @@ -6906,6 +6906,90 @@ next
);
}

#[test]
fn sat_at_index_content_proxy() {
let server = TestServer::builder()
.index_sats()
.chain(Chain::Regtest)
.build();

server.mine_blocks(1);

let inscription = Inscription {
content_type: Some("text/html".into()),
body: Some("foo".into()),
..default()
};

let txid = server.core.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0, inscription.to_witness())],
..default()
});

server.mine_blocks(1);

let id = InscriptionId { txid, index: 0 };
let ordinal: u64 = 5000000000;

pretty_assert_eq!(
server.get_json::<api::InscriptionRecursive>(format!("/r/inscription/{id}")),
api::InscriptionRecursive {
charms: vec![Charm::Coin, Charm::Uncommon],
content_type: Some("text/html".into()),
content_length: Some(3),
delegate: None,
fee: 0,
height: 2,
id,
number: 0,
output: OutPoint { txid, vout: 0 },
sat: Some(Sat(ordinal)),
satpoint: SatPoint {
outpoint: OutPoint { txid, vout: 0 },
offset: 0
},
timestamp: 2,
value: Some(50 * COIN_VALUE),
address: Some("bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqdku202".to_string())
}
);

server.assert_response(
format!("/r/sat/{ordinal}/at/-1/content"),
StatusCode::OK,
"foo",
);

let server_with_proxy = TestServer::builder()
.chain(Chain::Regtest)
.server_option("--proxy", server.url.as_ref())
.build();
let sat_indexed_server_with_proxy = TestServer::builder()
.index_sats()
.chain(Chain::Regtest)
.server_option("--proxy", server.url.as_ref())
.build();

server_with_proxy.mine_blocks(1);
sat_indexed_server_with_proxy.mine_blocks(1);

server.assert_response(
format!("/r/sat/{ordinal}/at/-1/content"),
StatusCode::OK,
"foo",
);
server_with_proxy.assert_response(
format!("/r/sat/{ordinal}/at/-1/content"),
StatusCode::OK,
"foo",
);
sat_indexed_server_with_proxy.assert_response(
format!("/r/sat/{ordinal}/at/-1/content"),
StatusCode::OK,
"foo",
);
}

#[test]
fn block_info() {
let server = TestServer::new();
Expand Down

0 comments on commit a67a6ef

Please sign in to comment.