Skip to content

Commit

Permalink
webui/scriptgroups: show group details on group page
Browse files Browse the repository at this point in the history
  • Loading branch information
RaghavSood committed Jun 7, 2024
1 parent e80a297 commit 3091d5f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
20 changes: 20 additions & 0 deletions storage/sqlite/script_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ package sqlite

import "github.com/RaghavSood/btcsupply/types"

func (d *SqliteBackend) GetScriptGroupSummary(group string) (types.ScriptGroupSummary, error) {
query := `SELECT
bs.script_group,
SUM(l.amount) AS total_loss,
count(DISTINCT(bs.script)) AS scripts,
count(DISTINCT(l.tx_id)) AS transactions
FROM
burn_scripts bs
JOIN
losses l ON bs.script = l.burn_script
WHERE
bs.script_group = ?
GROUP BY bs.script_group`

var summary types.ScriptGroupSummary
err := d.db.QueryRow(query, group).Scan(&summary.ScriptGroup, &summary.TotalLoss, &summary.Scripts, &summary.Transactions)

return summary, err
}

func (d *SqliteBackend) GetScriptGroupSummaries(limit int) ([]types.ScriptGroupSummary, error) {
query := `SELECT
bs.script_group,
Expand Down
1 change: 1 addition & 0 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Storage interface {
GetBurnScriptSummary(script string) (types.BurnScriptSummary, error)

GetScriptGroupSummaries(limit int) ([]types.ScriptGroupSummary, error)
GetScriptGroupSummary(group string) (types.ScriptGroupSummary, error)

GetScriptQueue() ([]types.ScriptQueue, error)
IncrementScriptQueueTryCount(scriptID int) error
Expand Down
6 changes: 4 additions & 2 deletions templates/scriptgroup.tmpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{{ define "content" }}
<div class="container mx-auto p-4">
<div class="border rounded-lg border-slate-700 bg-slate-950/30 p-4">
<h1 class="text-2xl font-semibold break-words">Script Group <span class="select-all">{{ .ScriptSummary.Script }}</span></h1>
<h3 class="text-lg text-gray-400 font-mono">Total Lost {{ .ScriptSummary.TotalLoss.SatoshisToBTC true }} BTC</a></h3>
<h1 class="text-2xl font-semibold break-words">Script Group <span class="select-all">{{ .GroupSummary.ScriptGroup }}</span></h1>
<h3 class="text-lg text-gray-400 font-mono">Total Lost: {{ .GroupSummary.TotalLoss.SatoshisToBTC true }} BTC</a></h3>
<h3 class="text-lg text-gray-400 font-mono">Transactions: {{ .GroupSummary.Transactions }}</a></h3>
<h3 class="text-lg text-gray-400 font-mono">Scripts: {{ .GroupSummary.Scripts }}</a></h3>
</div>
<table class="min-w-full bg-slate-950/30 border border-slate-700">
<thead>
Expand Down
8 changes: 8 additions & 0 deletions webui/script_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import (
func (w *WebUI) ScriptGroup(c *gin.Context) {
scriptGroup := c.Param("scriptgroup")

groupSummary, err := w.db.GetScriptGroupSummary(scriptGroup)
if err != nil {
log.Error().Err(err).Msg("Failed to get script group summary")
c.AbortWithError(http.StatusInternalServerError, err)
return
}

burnScriptSummaries, err := w.db.GetBurnScriptSummariesForGroup(scriptGroup)
if err != nil {
log.Error().Err(err).Msg("Failed to get script summaries for group")
Expand All @@ -22,6 +29,7 @@ func (w *WebUI) ScriptGroup(c *gin.Context) {
err = tmpl.Render(c.Writer, "scriptgroup.tmpl", map[string]interface{}{
"Title": "Script Group",
"BurnTransactions": burnScriptSummaries,
"GroupSummary": groupSummary,
})
if err != nil {
log.Error().Err(err).Msg("Failed to render template")
Expand Down

0 comments on commit 3091d5f

Please sign in to comment.