diff --git a/cmd/web/api.go b/cmd/web/api.go index bc31ba8..6d6d7f4 100644 --- a/cmd/web/api.go +++ b/cmd/web/api.go @@ -70,7 +70,7 @@ func getSliceFromAPI[T any](method string, cacheTime ...int) []T { }) } -func getStreamFromAPI[T any](method string, cacheTime ...int) chan T { +func getStreamFromAPI[T any](method string) <-chan T { result := make(chan T, 1) go func() { @@ -86,10 +86,26 @@ func getStreamFromAPI[T any](method string, cacheTime ...int) chan T { defer io.ReadAll(response.Body) if response.StatusCode == http.StatusOK { + + var err error + + // Read opening + var b [1]byte + for { + if _, err = response.Body.Read(b[:]); err != nil { + return + } + if b[0] == '[' { + break + } else if b[0] != ' ' && b[0] != 0xa { + return + } + } + decoder := utils.NewJSONDecoder(response.Body) for decoder.More() { var item T - if decoder.Decode(&item) != nil { + if err := decoder.Decode(&item); err != nil { return } else { result <- item @@ -102,7 +118,7 @@ func getStreamFromAPI[T any](method string, cacheTime ...int) chan T { return result } -func getSideBlocksStreamFromAPI(method string) chan *index.SideBlock { +func getSideBlocksStreamFromAPI(method string) <-chan *index.SideBlock { return getStreamFromAPI[*index.SideBlock](method) } diff --git a/cmd/web/views/connectivity-check.qtpl b/cmd/web/views/connectivity-check.qtpl index 6343179..1376503 100644 --- a/cmd/web/views/connectivity-check.qtpl +++ b/cmd/web/views/connectivity-check.qtpl @@ -90,16 +90,16 @@ type ConnectivityCheckPage struct { {% if p.Check.Tip != nil %}
Payout Address: {%z= p.Miner.ToBase58() %}
-Estimated total: {%s monero_to_xmr(p.Total) %} XMR
- {%= TemplatePayouts(p.Context(), p.Payouts) %} + {% code var total uint64 %} + + {%= TemplatePayouts(p.Context(), p.Payouts, &total) %} + +Estimated total: {%s monero_to_xmr(total) %} XMR
Payout Address: {%z= encodedMinerAddress %}
{% endif %} -Received {%s monero_to_xmr(p.Output.Value) %} XMR on transaction id {%= hex(p.Output.Id) %} (output index #{%dul uint64(p.Output.Index) %}, global output index #{%dul p.Output.GlobalOutputIndex %}).
+Received {%s monero_to_xmr(p.Output.Value) %} XMR on transaction id {%= hex(p.Context(), p.Output.Id) %} (output index #{%dul uint64(p.Output.Index) %}, global output index #{%dul p.Output.GlobalOutputIndex %}).
{%dul p.Context().Pool.MainChain.Height - p.Block.MainHeight + 1 %} confirmation(s). Coinbase outputs will unlock after 60 confirmations.
Stealth Address: {%s address.GetEphemeralPublicKey(p.Output.MinerAddress, &p.Raw.Side.CoinbasePrivateKey, uint64(p.Output.Index)).String() %}
Transaction Private Key: {%= hex(p.Raw.Side.CoinbasePrivateKey) %}
-Verify on Monero CLI: check_tx_proof {%= hex(p.Output.Id) %} {%z= encodedMinerAddress %} {%= hex(p.Raw.Side.CoinbasePrivateKey) %}
+Transaction Private Key: {%= hex(p.Context(), p.Raw.Side.CoinbasePrivateKey) %}
+Verify on Monero CLI: check_tx_proof {%= hex(p.Context(), p.Output.Id) %} {%z= encodedMinerAddress %} {%= hex(p.Context(), p.Raw.Side.CoinbasePrivateKey) %}
- Verify on LocalMonero
- Verify on Explore Monero
- Verify on Monero.com
+ Verify on LocalMonero
+ Verify on Explore Monero
+ Verify on Monero.com
OutProofV2: {%= hex(address.GetTxProofV2(p.Output.MinerAddress, p.Output.Id, &p.Raw.Side.CoinbasePrivateKey, "")) %}
-OutProofV1: {%= hex(address.GetTxProofV1(p.Output.MinerAddress, p.Output.Id, &p.Raw.Side.CoinbasePrivateKey, "")) %}
+OutProofV2: {%= hex(p.Context(), address.GetTxProofV2(p.Output.MinerAddress, p.Output.Id, &p.Raw.Side.CoinbasePrivateKey, "")) %}
+OutProofV1: {%= hex(p.Context(), address.GetTxProofV1(p.Output.MinerAddress, p.Output.Id, &p.Raw.Side.CoinbasePrivateKey, "")) %}
Verify on Monero GUI (Advanced -> Prove/check -> Check Transaction)
Monero Height | +P2Pool Height | +Age [h:m:s] | +Reward | +Global Output Index | +Coinbase Transaction | +Payout Proof | +
---|---|---|---|---|---|---|
{%dul p.MainHeight %} | +{%dul p.SideHeight %} | +{%s date_diff_short(p.Timestamp) %} | +{%s monero_to_xmr(p.Reward) %} XMR | +{%dul p.GlobalOutputIndex %} | +{%= shorten(ctx, p.CoinbaseId, 10) %} | +[Payout Proof #{%dul uint64(p.Index) %}] | +
Monero Height | @@ -13,13 +39,13 @@||||||||||
---|---|---|---|---|---|---|---|---|---|---|
{%dul p.MainHeight %} | -{%dul p.SideHeight %} | +{%dul p.MainHeight %} | +{%dul p.SideHeight %} | {%s date_diff_short(p.Timestamp) %} | {%s monero_to_xmr(p.Reward) %} XMR | {%dul p.GlobalOutputIndex %} | -{%= shorten(p.CoinbaseId, 10) %} | -[Payout Proof #{%dul uint64(p.Index) %}] | +{%= shorten(ctx, p.CoinbaseId, 10) %} | +[Payout Proof #{%dul uint64(p.Index) %}] |
Unknown Decoys | Swept Coinbase Value | - {% for _, s := range sweeps %} + {% for s := range sweeps %}|||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{%= shorten(s.Id, 10) %} | +{%= shorten(ctx, s.Id, 10) %} | {%s date_diff_short(s.Timestamp) %} | {% if !isMiner %} {% code addr := s.Address.ToBase58() %} -{%= shorten(addr, 10) %} | +{%= shorten(ctx, addr, 10) %} | {% endif %}{%d s.InputDecoyCount %} | {%d s.InputCount %} / {%d len(s.GlobalOutputIndices) %} | diff --git a/cmd/web/views/transaction-lookup.qtpl b/cmd/web/views/transaction-lookup.qtpl index 507cf6e..e5f9932 100644 --- a/cmd/web/views/transaction-lookup.qtpl +++ b/cmd/web/views/transaction-lookup.qtpl @@ -55,7 +55,7 @@ type TransactionLookupPage struct {
- Transaction Id: {%= hex(p.TransactionId) %} +Transaction Id: {%= hex(p.Context(), p.TransactionId) %} {% code minerAddress := p.Miner.Address.ToBase58() %}Miner Payout Address: {%z= minerAddress %} Likely: {% if p.LikelyMiner %}Yes{% else %}Not likely{% endif %} @@ -127,11 +127,11 @@ type TransactionLookupPage struct { {% else %} | |||||||||||
{%d index %} | -{%= shorten(input.Input.KeyImage, 10) %} | +{%= shorten(p.Context(), input.Input.KeyImage, 10) %} | {% endif %}- | {% code out := p.Result.Outs[totalInputCount] %} -{%= shorten(out.TransactionId, 10) %} | +{%= shorten(p.Context(), out.TransactionId, 10) %} | {%dul input.Input.KeyOffsets[oindex] %} | - | - | @@ -142,19 +142,19 @@ type TransactionLookupPage struct { {% else %}|||
{%d index %} | -{%= shorten(input.Input.KeyImage, 10) %} | +{%= shorten(p.Context(), input.Input.KeyImage, 10) %} | {% endif %} {% code addr := o.Address.ToBase58() %} -{%= shorten(addr, 10) %} | +{%= shorten(p.Context(), addr, 10) %} | {% if o.Coinbase != nil %} -{%= shorten(o.Coinbase.Id, 10) %} #{%dul uint64(o.Coinbase.Index) %} | +{%= shorten(p.Context(), o.Coinbase.Id, 10) %} #{%dul uint64(o.Coinbase.Index) %} | {%dul o.GlobalOutputIndex %} | Coinbase | {%s monero_to_xmr(o.Coinbase.Value) %} XMR | {% elseif o.Sweep != nil %} -{%= shorten(o.Sweep.Id, 10) %} + | {%= shorten(p.Context(), o.Sweep.Id, 10) %} {% for oindex, goi := range o.Sweep.GlobalOutputIndices %} {% if goi == o.GlobalOutputIndex %} #{%d oindex %}/{%d len(o.Sweep.GlobalOutputIndices) %} diff --git a/cmd/web/web.go b/cmd/web/web.go index 8130168..8778d44 100644 --- a/cmd/web/web.go +++ b/cmd/web/web.go @@ -585,13 +585,13 @@ func main() { if miner != nil { renderPage(request, writer, &views.SweepsPage{ Refresh: refresh, - Sweeps: getSliceFromAPI[*index.MainLikelySweepTransaction](fmt.Sprintf("sweeps/%d?limit=100", miner.Id)), + Sweeps: getStreamFromAPI[*index.MainLikelySweepTransaction](fmt.Sprintf("sweeps/%d?limit=100", miner.Id)), Miner: miner.Address, }, poolInfo) } else { renderPage(request, writer, &views.SweepsPage{ Refresh: refresh, - Sweeps: getSliceFromAPI[*index.MainLikelySweepTransaction]("sweeps?limit=100", 30), + Sweeps: getStreamFromAPI[*index.MainLikelySweepTransaction]("sweeps?limit=100"), Miner: nil, }, poolInfo) } @@ -759,7 +759,7 @@ func main() { raw = b } - payouts := getSliceFromAPI[*index.Payout](fmt.Sprintf("block_by_id/%s/payouts", block.MainId)) + payouts := getStreamFromAPI[*index.Payout](fmt.Sprintf("block_by_id/%s/payouts", block.MainId)) sweepsCount := 0 @@ -858,7 +858,7 @@ func main() { var lastFound []*index.FoundBlock var payouts []*index.Payout - var sweeps []*index.MainLikelySweepTransaction + var sweeps <-chan *index.MainLikelySweepTransaction var raw *sidechain.PoolBlock @@ -891,11 +891,7 @@ func main() { defer wg.Done() lastFound = getSliceFromAPI[*index.FoundBlock](fmt.Sprintf("found_blocks?limit=10&miner=%d", miner.Id)) }() - wg.Add(1) - go func() { - defer wg.Done() - sweeps = getSliceFromAPI[*index.MainLikelySweepTransaction](fmt.Sprintf("sweeps/%d?limit=5", miner.Id)) - }() + sweeps = getStreamFromAPI[*index.MainLikelySweepTransaction](fmt.Sprintf("sweeps/%d?limit=5", miner.Id)) wg.Add(1) go func() { defer wg.Done() @@ -1026,6 +1022,7 @@ func main() { if hashRate > 0 && magnitude > 0 { dailyHashRate = uint64(hashRate * magnitude) } + minerPage.HashrateSubmit = true } minerPage.HashrateLocal = hashRate @@ -1117,18 +1114,8 @@ func main() { return } - payouts := getSliceFromAPI[*index.Payout](fmt.Sprintf("payouts/%d?search_limit=0", miner.Id)) - if len(payouts) == 0 { - renderPage(request, writer, views.NewErrorPage(http.StatusNotFound, "Address Not Found", "You need to have mined at least one share in the past, and a main block found during that period. Come back later :)")) - return - } + payouts := getStreamFromAPI[*index.Payout](fmt.Sprintf("payouts/%d?search_limit=0", miner.Id)) renderPage(request, writer, &views.PayoutsPage{ - Total: func() (result uint64) { - for _, p := range payouts { - result += p.Reward - } - return - }(), Miner: miner.Address, Payouts: payouts, Refresh: refresh, |