Skip to content

Commit

Permalink
Add html page for /runes/balances
Browse files Browse the repository at this point in the history
  • Loading branch information
lugondev committed Jan 29, 2024
1 parent 3598200 commit 425748a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use {
InscriptionsBlockHtml, InscriptionsHtml, InscriptionsJson, OutputHtml, OutputJson,
PageContent, PageHtml, PreviewAudioHtml, PreviewCodeHtml, PreviewFontHtml, PreviewImageHtml,
PreviewMarkdownHtml, PreviewModelHtml, PreviewPdfHtml, PreviewTextHtml, PreviewUnknownHtml,
PreviewVideoHtml, RangeHtml, RareTxt, RuneHtml, RuneJson, RunesHtml, RunesJson, SatHtml,
SatInscriptionJson, SatInscriptionsJson, SatJson, TransactionHtml, TransactionJson,
PreviewVideoHtml, RangeHtml, RareTxt, RuneHtml, RuneJson, RunesBalancesHtml, RunesHtml,
RunesJson, SatHtml, SatInscriptionJson, SatInscriptionsJson, SatJson, TransactionHtml,
TransactionJson,
},
},
axum::{
Expand Down Expand Up @@ -686,8 +687,22 @@ impl Server {
})
}

async fn runes_balances(Extension(index): Extension<Arc<Index>>) -> ServerResult<Response> {
task::block_in_place(|| Ok(Json(index.get_rune_balance_map()?).into_response()))
async fn runes_balances(
Extension(server_config): Extension<Arc<ServerConfig>>,
Extension(index): Extension<Arc<Index>>,
AcceptJson(accept_json): AcceptJson,
) -> ServerResult<Response> {
task::block_in_place(|| {
Ok(if accept_json {
Json(index.get_rune_balance_map()?).into_response()
} else {
RunesBalancesHtml {
runes_balances: index.get_rune_balance_map()?,
}
.page(server_config)
.into_response()
})
})
}

async fn home(
Expand Down
2 changes: 1 addition & 1 deletion src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) use {
range::RangeHtml,
rare::RareTxt,
rune::{RuneHtml, RuneJson},
runes::{RunesHtml, RunesJson},
runes::{RunesBalancesHtml, RunesHtml, RunesJson},
sat::{SatHtml, SatInscriptionJson, SatInscriptionsJson, SatJson},
server_config::ServerConfig,
status::{StatusHtml, StatusJson},
Expand Down
11 changes: 11 additions & 0 deletions src/templates/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ impl PageContent for RunesHtml {
}
}

#[derive(Boilerplate, Debug, PartialEq, Serialize, Deserialize)]
pub struct RunesBalancesHtml {
pub runes_balances: BTreeMap<Rune, BTreeMap<OutPoint, u128>>,
}

impl PageContent for RunesBalancesHtml {
fn title(&self) -> String {
"Runes balances".to_string()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
24 changes: 24 additions & 0 deletions templates/runes-balances.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h1>Runes Balances</h1>
<ul>
%% for (rune, runes_balances) in &self.runes_balances {
<li>
<a href=/rune/{{ rune }}>{{ rune }}</a>
<table>
<tr>
<th>outpoint</th>
<th>balance</th>
</tr>
%% for (outpoint, balance) in runes_balances {
<tr>
<td>
<a href=/output/{{outpoint.txid}}:{{outpoint.vout}}>{{outpoint.txid}}:{{outpoint.vout}}</a>
</td>
<td>
{{ balance }}
</td>
</tr>
%% }
</table>
</li>
%% }
</ul>

0 comments on commit 425748a

Please sign in to comment.