Skip to content

Commit

Permalink
webui/transaction: link to script
Browse files Browse the repository at this point in the history
  • Loading branch information
RaghavSood committed Jun 7, 2024
1 parent 437bf06 commit dba15c3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
19 changes: 10 additions & 9 deletions templates/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ type Template struct {

func New() *Template {
funcMap := template.FuncMap{
"now": func() interface{} { return time.Now() },
"Int64ToBTC": util.Int64ToBTC,
"NoEscape": util.NoEscapeHTML,
"PrettyPrintJSON": util.PrettyPrintJSON,
"ScriptPubKeyDisplay": types.ScriptPubKeyDisplay,
"IsScriptInNotes": util.IsScriptInNotes,
"ValueToBigInt": types.ValueToBigInt,
"TimeDisclaimer": util.TimeDisclaimer,
"GitCommit": util.GitCommit,
"now": func() interface{} { return time.Now() },
"Int64ToBTC": util.Int64ToBTC,
"NoEscape": util.NoEscapeHTML,
"PrettyPrintJSON": util.PrettyPrintJSON,
"ScriptPubKeyDisplay": types.ScriptPubKeyDisplay,
"IsScriptInBurnScripts": util.IsScriptInBurnScripts,
"IsScriptInNotes": util.IsScriptInNotes,
"ValueToBigInt": types.ValueToBigInt,
"TimeDisclaimer": util.TimeDisclaimer,
"GitCommit": util.GitCommit,
}

templates := template.Must(template.New("").Funcs(funcMap).ParseFS(Templates, "footer.tmpl", "header.tmpl", "base.tmpl", "note.tmpl"))
Expand Down
14 changes: 12 additions & 2 deletions templates/transaction.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
{{ range .Transaction.Vout }}
{{ $bgc := "bg-slate-950/30" }}
{{ $burnText := "" }}
{{ if IsScriptInNotes .ScriptPubKey.Hex $.Notes }}
{{ $linkscript := false }}
{{ if IsScriptInBurnScripts .ScriptPubKey.Hex $.BurnScripts }}
{{ $bgc = "bg-red-900/30" }}
{{ $burnText = "🔥" }}
{{ $linkscript = true }}
{{ end }}
{{ if eq .ScriptPubKey.Type "nulldata" }}
{{ $bgc = "bg-yellow-700/30" }}
Expand All @@ -47,7 +49,15 @@
{{ end }}
<div class="border rounded-lg border-slate-700 {{ $bgc }} p-4 mb-4 font-mono">
<div class="flex flex-row gap-x-2 text-wrap font-medium">
<span class="basis-9/12 break-words min-w-0">{{ .ScriptPubKey | ScriptPubKeyDisplay }}</span>
<span class="basis-9/12 break-words min-w-0">
{{ if $linkscript }}
<a href="/script/{{ .ScriptPubKey.Hex }}" class="break-words text-sky-400/70 hover:underline hover:decoration-dotted hover:text-slate-200">
{{ end }}
{{ .ScriptPubKey | ScriptPubKeyDisplay }}
{{ if $linkscript }}
</a>
{{ end }}
</span>
<span class="text-right ml-auto">{{ $burnText }}{{ (.Value | ValueToBigInt).SatoshisToBTC true }} BTC{{ $burnText }}</span>
</div>
<div class="flex gap-x-2 text-wrap text-sm text-gray-600">
Expand Down
11 changes: 11 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,23 @@ func RevaluePriceWithAdjustedSupply(expectedSupply, circulatingSupply *types.Big
return currentPrice * (expectedSupplyFloat / circulatingSupplyFloat)
}

func IsScriptInBurnScripts(script string, burnScripts []types.BurnScript) bool {
for _, burnScript := range burnScripts {
if burnScript.Script == script {
return true
}
}

return false
}

func IsScriptInNotes(script string, noteList []notes.Note) bool {
for _, note := range noteList {
if note.PathElements[0] == script {
return true
}
}

return false
}

Expand Down
1 change: 1 addition & 0 deletions webui/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (w *WebUI) Transaction(c *gin.Context) {
"Losses": losses,
"Transaction": transaction,
"Notes": notes,
"BurnScripts": burnScripts,
"Block": block,
})
if err != nil {
Expand Down

0 comments on commit dba15c3

Please sign in to comment.