Display fee per size in explorer transaction detail

This commit is contained in:
Martin Boehm 2022-08-28 22:30:04 +02:00 committed by Martin
parent 6edbc2d99b
commit 84b931f42b
3 changed files with 26 additions and 8 deletions

View File

@ -415,6 +415,8 @@ func (w *Worker) getTransactionFromBchainTx(bchainTx *bchain.Tx, height int, spe
ValueInSat: (*Amount)(pValInSat), ValueInSat: (*Amount)(pValInSat),
ValueOutSat: (*Amount)(&valOutSat), ValueOutSat: (*Amount)(&valOutSat),
Version: bchainTx.Version, Version: bchainTx.Version,
Size: len(bchainTx.Hex) >> 1,
VSize: int(bchainTx.VSize),
Hex: bchainTx.Hex, Hex: bchainTx.Hex,
Rbf: rbf, Rbf: rbf,
Vin: vins, Vin: vins,
@ -423,11 +425,6 @@ func (w *Worker) getTransactionFromBchainTx(bchainTx *bchain.Tx, height int, spe
TokenTransfers: tokens, TokenTransfers: tokens,
EthereumSpecific: ethSpecific, EthereumSpecific: ethSpecific,
} }
if w.chainParser.SupportsVSize() {
r.Size = len(bchainTx.Hex) >> 1
r.VSize = int(bchainTx.VSize)
}
return r, nil return r, nil
} }

View File

@ -454,6 +454,7 @@ func (s *PublicServer) parseTemplates() []*template.Template {
"formatAmount": s.formatAmount, "formatAmount": s.formatAmount,
"formatAmountWithDecimals": formatAmountWithDecimals, "formatAmountWithDecimals": formatAmountWithDecimals,
"setTxToTemplateData": setTxToTemplateData, "setTxToTemplateData": setTxToTemplateData,
"feePerByte": feePerByte,
"isOwnAddress": isOwnAddress, "isOwnAddress": isOwnAddress,
"toJSON": toJSON, "toJSON": toJSON,
"tokenTransfersCount": tokenTransfersCount, "tokenTransfersCount": tokenTransfersCount,
@ -556,6 +557,19 @@ func setTxToTemplateData(td *TemplateData, tx *api.Tx) *TemplateData {
return td return td
} }
// feePerByte returns fee per vByte or Byte if vsize is unknown
func feePerByte(tx *api.Tx) string {
if tx.FeesSat != nil {
if tx.VSize > 0 {
return fmt.Sprintf("%.2f sat/vByte", float64(tx.FeesSat.AsInt64())/float64(tx.VSize))
}
if tx.Size > 0 {
return fmt.Sprintf("%.2f sat/Byte", float64(tx.FeesSat.AsInt64())/float64(tx.Size))
}
}
return ""
}
// isOwnAddress returns true if the address is the one that is being shown in the explorer // isOwnAddress returns true if the address is the one that is being shown in the explorer
func isOwnAddress(td *TemplateData, a string) bool { func isOwnAddress(td *TemplateData, a string) bool {
return a == td.AddrStr return a == td.AddrStr

View File

@ -59,17 +59,24 @@
<td>Total Output</td> <td>Total Output</td>
<td class="data">{{formatAmount $tx.ValueOutSat}} {{$cs}}</td> <td class="data">{{formatAmount $tx.ValueOutSat}} {{$cs}}</td>
</tr> </tr>
{{- if $tx.VSize -}}
<tr>
<td>Size / vSize</td>
<td class="data">{{$tx.Size}} / {{$tx.VSize}}</td>
</tr>
{{- else -}}
{{- if $tx.Size -}} {{- if $tx.Size -}}
<tr> <tr>
<td>Size/VSize</td> <td>Size</td>
<td class="data">{{$tx.Size}}/{{$tx.VSize}}</td> <td class="data">{{$tx.Size}}</td>
</tr> </tr>
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}}
{{- if $tx.FeesSat -}} {{- if $tx.FeesSat -}}
<tr> <tr>
<td>Fees</td> <td>Fees</td>
<td class="data">{{formatAmount $tx.FeesSat}} {{$cs}}</td> <td class="data">{{formatAmount $tx.FeesSat}} {{$cs}}{{if $tx.Size}} ({{feePerByte $tx}}){{end}}</td>
</tr>{{end -}} </tr>{{end -}}
{{- if not $tx.Confirmations}} {{- if not $tx.Confirmations}}
<tr> <tr>