diff --git a/server/html_templates.go b/server/html_templates.go
index 4d044c3b..a06ff0e6 100644
--- a/server/html_templates.go
+++ b/server/html_templates.go
@@ -219,6 +219,49 @@ func appendAmountSpan(rv *strings.Builder, class, amount, shortcut, txDate strin
rv.WriteString("")
}
+func appendAmountSpanBitcoinType(rv *strings.Builder, class, amount, shortcut, txDate string) {
+ if amount == "0" {
+ appendAmountSpan(rv, class, amount, shortcut, txDate)
+ return
+ }
+ rv.WriteString(`")
+ i := strings.IndexByte(amount, '.')
+ var decimals string
+ if i < 0 {
+ appendSeparatedNumberSpans(rv, amount, "nc")
+ decimals = "00000000"
+ } else {
+ appendSeparatedNumberSpans(rv, amount[:i], "nc")
+ decimals = amount[i+1:] + "00000000"
+ }
+ rv.WriteString(`.`)
+ rv.WriteString(``)
+ rv.WriteString(decimals[:2])
+ rv.WriteString(``)
+ rv.WriteString(decimals[2:5])
+ rv.WriteString("")
+ rv.WriteString(``)
+ rv.WriteString(decimals[5:8])
+ rv.WriteString("")
+ rv.WriteString("")
+ if shortcut != "" {
+ rv.WriteString(" ")
+ rv.WriteString(shortcut)
+ }
+ rv.WriteString("")
+}
+
func appendAmountWrapperSpan(rv *strings.Builder, primary, symbol, classes string) {
rv.WriteString(`1.23456789 BTC`,
+ },
+ {
+ name: "prim-amt 1432134.23456 BTC",
+ class: "prim-amt",
+ amount: "1432134.23456",
+ shortcut: "BTC",
+ want: `1432134.23456000 BTC`,
+ },
+ {
+ name: "prim-amt 1 BTC",
+ class: "prim-amt",
+ amount: "1",
+ shortcut: "BTC",
+ want: `1.00000000 BTC`,
+ },
+ {
+ name: "prim-amt 0 BTC",
+ class: "prim-amt",
+ amount: "0",
+ shortcut: "BTC",
+ want: `0 BTC`,
+ },
+ {
+ name: "prim-amt 34.2 BTC",
+ class: "prim-amt",
+ amount: "34.2",
+ shortcut: "BTC",
+ want: `34.20000000 BTC`,
+ },
+ {
+ name: "prim-amt -34.2345678 BTC",
+ class: "prim-amt",
+ amount: "-34.2345678",
+ shortcut: "BTC",
+ want: `-34.23456780 BTC`,
+ },
+ {
+ name: "prim-amt -1234.2345 BTC",
+ class: "prim-amt",
+ amount: "-1234.2345",
+ shortcut: "BTC",
+ want: `-1234.23450000 BTC`,
+ },
+ {
+ name: "prim-amt -123.23 BTC",
+ class: "prim-amt",
+ amount: "-123.23",
+ shortcut: "BTC",
+ want: `-123.23000000 BTC`,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ var rv strings.Builder
+ appendAmountSpanBitcoinType(&rv, tt.class, tt.amount, tt.shortcut, tt.txDate)
+ if got := rv.String(); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("appendAmountSpanBitcoinType() = %v, want %v", got, tt.want)
}
})
}
diff --git a/server/public.go b/server/public.go
index d0f50854..236f6e0d 100644
--- a/server/public.go
+++ b/server/public.go
@@ -44,21 +44,22 @@ const (
// PublicServer provides public http server functionality
type PublicServer struct {
htmlTemplates[TemplateData]
- binding string
- certFiles string
- socketio *SocketIoServer
- websocket *WebsocketServer
- https *http.Server
- db *db.RocksDB
- txCache *db.TxCache
- chain bchain.BlockChain
- chainParser bchain.BlockChainParser
- mempool bchain.Mempool
- api *api.Worker
- explorerURL string
- internalExplorer bool
- is *common.InternalState
- fiatRates *fiat.FiatRates
+ binding string
+ certFiles string
+ socketio *SocketIoServer
+ websocket *WebsocketServer
+ https *http.Server
+ db *db.RocksDB
+ txCache *db.TxCache
+ chain bchain.BlockChain
+ chainParser bchain.BlockChainParser
+ mempool bchain.Mempool
+ api *api.Worker
+ explorerURL string
+ internalExplorer bool
+ is *common.InternalState
+ fiatRates *fiat.FiatRates
+ useSatsAmountFormat bool
}
// NewPublicServer creates new public server http interface to blockbook and returns its handle
@@ -92,21 +93,22 @@ func NewPublicServer(binding string, certFiles string, db *db.RocksDB, chain bch
metrics: metrics,
debug: debugMode,
},
- binding: binding,
- certFiles: certFiles,
- https: https,
- api: api,
- socketio: socketio,
- websocket: websocket,
- db: db,
- txCache: txCache,
- chain: chain,
- chainParser: chain.GetChainParser(),
- mempool: mempool,
- explorerURL: explorerURL,
- internalExplorer: explorerURL == "",
- is: is,
- fiatRates: fiatRates,
+ binding: binding,
+ certFiles: certFiles,
+ https: https,
+ api: api,
+ socketio: socketio,
+ websocket: websocket,
+ db: db,
+ txCache: txCache,
+ chain: chain,
+ chainParser: chain.GetChainParser(),
+ mempool: mempool,
+ explorerURL: explorerURL,
+ internalExplorer: explorerURL == "",
+ is: is,
+ fiatRates: fiatRates,
+ useSatsAmountFormat: chain.GetChainParser().GetChainType() == bchain.ChainBitcoinType && chain.GetChainParser().AmountDecimals() == 8,
}
s.htmlTemplates.newTemplateData = s.newTemplateData
s.htmlTemplates.newTemplateDataWithError = s.newTemplateDataWithError
@@ -569,7 +571,11 @@ func (s *PublicServer) amountSpan(a *api.Amount, td *TemplateData, classes strin
primary := s.formatAmount(a)
var rv strings.Builder
appendAmountWrapperSpan(&rv, primary, td.CoinShortcut, classes)
- appendAmountSpan(&rv, "prim-amt", primary, td.CoinShortcut, "")
+ if s.useSatsAmountFormat {
+ appendAmountSpanBitcoinType(&rv, "prim-amt", primary, td.CoinShortcut, "")
+ } else {
+ appendAmountSpan(&rv, "prim-amt", primary, td.CoinShortcut, "")
+ }
if td.SecondaryCoin != "" {
p, err := strconv.ParseFloat(primary, 64)
if err == nil {
diff --git a/server/public_test.go b/server/public_test.go
index d3a8fc3d..6ca010ec 100644
--- a/server/public_test.go
+++ b/server/public_test.go
@@ -275,7 +275,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `
Trezor Fake Coin ExplorerTransaction
fdd824a780cbb718eeb766eb05d83fdefc793a27082cd5e67f856d69798cf7db
| Mined Time | 1639 days 11 hours ago |
| In Block | 00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6 |
| In Block Height | 225494 |
| Total Input | 0 FAKE |
| Total Output | 13.60030331 FAKE |
| Fees | 0 FAKE |
mined 1639 days 11 hours ago
No Inputs (Newly Generated Coins)
`,
+ `Trezor Fake Coin ExplorerTransaction
fdd824a780cbb718eeb766eb05d83fdefc793a27082cd5e67f856d69798cf7db
| Mined Time | 1639 days 11 hours ago |
| In Block | 00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6 |
| In Block Height | 225494 |
| Total Input | 0 FAKE |
| Total Output | 13.60030331 FAKE |
| Fees | 0 FAKE |
mined 1639 days 11 hours ago
No Inputs (Newly Generated Coins)
`,
},
},
{
@@ -284,7 +284,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `Trezor Fake Coin ExplorerAddress
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz
0.00012345 FAKE
Confirmed | |
| Total Received | 0.0002469 FAKE |
| Total Sent | 0.00012345 FAKE |
| Final Balance | 0.00012345 FAKE |
| No. Transactions | 2 |
Transactions
mined 1639 days 11 hours ago
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE
OP_RETURN 2020f1686f6a200 FAKE×
mined 1640 days 9 hours ago
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE→ mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE×
`,
+ `Trezor Fake Coin ExplorerAddress
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz
0.00012345 FAKE
Confirmed | |
| Total Received | 0.00024690 FAKE |
| Total Sent | 0.00012345 FAKE |
| Final Balance | 0.00012345 FAKE |
| No. Transactions | 2 |
Transactions
mined 1639 days 11 hours ago
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE
OP_RETURN 2020f1686f6a200 FAKE×
mined 1640 days 9 hours ago
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE→ mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE×
`,
},
},
{
@@ -293,7 +293,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `Trezor Fake Coin ExplorerTransaction
3d90d15ed026dc45e19ffb52875ed18fa9e8012ad123d7f7212176e2b0ebdb71
| Mined Time | 1639 days 11 hours ago |
| In Block | 00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6 |
| In Block Height | 225494 |
| Total Input | 3172.83951062 FAKE |
| Total Output | 3172.83951 FAKE |
| Fees | 0.00000062 FAKE |
mined 1639 days 11 hours ago
`,
+ `Trezor Fake Coin ExplorerTransaction
3d90d15ed026dc45e19ffb52875ed18fa9e8012ad123d7f7212176e2b0ebdb71
| Mined Time | 1639 days 11 hours ago |
| In Block | 00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6 |
| In Block Height | 225494 |
| Total Input | 3172.83951062 FAKE |
| Total Output | 3172.83951000 FAKE |
| Fees | 0.00000062 FAKE |
mined 1639 days 11 hours ago
`,
},
},
{
@@ -320,7 +320,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `Trezor Fake Coin Explorer225494
00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6
| Transactions | 4 |
| Height | 225494 |
| Confirmations | 1 |
| Timestamp | 1639 days 11 hours ago |
| Size (bytes) | 2345678 |
| Version | |
| Merkle Root | |
| Nonce | |
| Bits | |
| Difficulty | |
mined 1639 days 11 hours ago
OP_RETURN 2020f1686f6a200 FAKE×
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
No Inputs (Newly Generated Coins)
`,
+ `Trezor Fake Coin Explorer225494
00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6
| Transactions | 4 |
| Height | 225494 |
| Confirmations | 1 |
| Timestamp | 1639 days 11 hours ago |
| Size (bytes) | 2345678 |
| Version | |
| Merkle Root | |
| Nonce | |
| Bits | |
| Difficulty | |
mined 1639 days 11 hours ago
OP_RETURN 2020f1686f6a200 FAKE×
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
No Inputs (Newly Generated Coins)
`,
},
},
{
@@ -340,7 +340,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `Trezor Fake Coin Explorer225494
00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6
| Transactions | 4 |
| Height | 225494 |
| Confirmations | 1 |
| Timestamp | 1639 days 11 hours ago |
| Size (bytes) | 2345678 |
| Version | |
| Merkle Root | |
| Nonce | |
| Bits | |
| Difficulty | |
mined 1639 days 11 hours ago
OP_RETURN 2020f1686f6a200 FAKE×
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
No Inputs (Newly Generated Coins)
`,
+ `Trezor Fake Coin Explorer225494
00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6
| Transactions | 4 |
| Height | 225494 |
| Confirmations | 1 |
| Timestamp | 1639 days 11 hours ago |
| Size (bytes) | 2345678 |
| Version | |
| Merkle Root | |
| Nonce | |
| Bits | |
| Difficulty | |
mined 1639 days 11 hours ago
OP_RETURN 2020f1686f6a200 FAKE×
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
No Inputs (Newly Generated Coins)
`,
},
},
{
@@ -349,7 +349,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `Trezor Fake Coin Explorer225494
00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6
| Transactions | 4 |
| Height | 225494 |
| Confirmations | 1 |
| Timestamp | 1639 days 11 hours ago |
| Size (bytes) | 2345678 |
| Version | |
| Merkle Root | |
| Nonce | |
| Bits | |
| Difficulty | |
mined 1639 days 11 hours ago
OP_RETURN 2020f1686f6a200 FAKE×
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
No Inputs (Newly Generated Coins)
`,
+ `Trezor Fake Coin Explorer225494
00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6
| Transactions | 4 |
| Height | 225494 |
| Confirmations | 1 |
| Timestamp | 1639 days 11 hours ago |
| Size (bytes) | 2345678 |
| Version | |
| Merkle Root | |
| Nonce | |
| Bits | |
| Difficulty | |
mined 1639 days 11 hours ago
OP_RETURN 2020f1686f6a200 FAKE×
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
mined 1639 days 11 hours ago
No Inputs (Newly Generated Coins)
`,
},
},
{
@@ -358,7 +358,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `Trezor Fake Coin ExplorerTransaction
fdd824a780cbb718eeb766eb05d83fdefc793a27082cd5e67f856d69798cf7db
| Mined Time | 1639 days 11 hours ago |
| In Block | 00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6 |
| In Block Height | 225494 |
| Total Input | 0 FAKE |
| Total Output | 13.60030331 FAKE |
| Fees | 0 FAKE |
mined 1639 days 11 hours ago
No Inputs (Newly Generated Coins)
`,
+ `Trezor Fake Coin ExplorerTransaction
fdd824a780cbb718eeb766eb05d83fdefc793a27082cd5e67f856d69798cf7db
| Mined Time | 1639 days 11 hours ago |
| In Block | 00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6 |
| In Block Height | 225494 |
| Total Input | 0 FAKE |
| Total Output | 13.60030331 FAKE |
| Fees | 0 FAKE |
mined 1639 days 11 hours ago
No Inputs (Newly Generated Coins)
`,
},
},
{
@@ -367,7 +367,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `Trezor Fake Coin ExplorerAddress
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz
0.00012345 FAKE
Confirmed | |
| Total Received | 0.0002469 FAKE |
| Total Sent | 0.00012345 FAKE |
| Final Balance | 0.00012345 FAKE |
| No. Transactions | 2 |
Transactions
mined 1639 days 11 hours ago
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE
OP_RETURN 2020f1686f6a200 FAKE×
mined 1640 days 9 hours ago
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE→ mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE×
`,
+ `Trezor Fake Coin ExplorerAddress
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz
0.00012345 FAKE
Confirmed | |
| Total Received | 0.00024690 FAKE |
| Total Sent | 0.00012345 FAKE |
| Final Balance | 0.00012345 FAKE |
| No. Transactions | 2 |
Transactions
mined 1639 days 11 hours ago
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE
OP_RETURN 2020f1686f6a200 FAKE×
mined 1640 days 9 hours ago
mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE→ mtGXQvBowMkBpnhLckhxhbwYK44Gs9eEtz0.00012345 FAKE×
`,
},
},
{
@@ -376,7 +376,7 @@ func httpTestsBitcoinType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `Trezor Fake Coin ExplorerXPUB
upub5E1xjDmZ7Hhej6LPpS8duATdKXnRYui7bDYj6ehfFGzWDZtmCmQkZhc3Zb7kgRLtHWd16QFxyP86JKL3ShZEBFX88aciJ3xyocuyhZZ8g6q
1186.419755 FAKE
Confirmed | |
| Total Received | 1186.41975501 FAKE |
| Total Sent | 0.00000001 FAKE |
| Final Balance | 1186.419755 FAKE |
| No. Transactions | 2 |
| Used XPUB Addresses | 2 |
Transactions
mined 1639 days 11 hours ago
mined 1640 days 9 hours ago
`,
+ `Trezor Fake Coin ExplorerXPUB
upub5E1xjDmZ7Hhej6LPpS8duATdKXnRYui7bDYj6ehfFGzWDZtmCmQkZhc3Zb7kgRLtHWd16QFxyP86JKL3ShZEBFX88aciJ3xyocuyhZZ8g6q
1186.419755 FAKE
Confirmed | |
| Total Received | 1186.41975501 FAKE |
| Total Sent | 0.00000001 FAKE |
| Final Balance | 1186.41975500 FAKE |
| No. Transactions | 2 |
| Used XPUB Addresses | 2 |
Transactions
mined 1639 days 11 hours ago
mined 1640 days 9 hours ago
`,
},
},
{