mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-07 11:32:20 +00:00
c68f00045a
* Revert "remove tombstones (#426)"
This reverts commit aa6bab40e8
.
* tombstones don't hide storage or account anymore
* auto-format code by prettier (similar to gofmt)
* wow, it works.....
* small simplification, but need make it more clear
* rebase to master
* rebase to master
* rebase to master
* re-run ci
* clean test files
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package apis
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
)
|
|
|
|
func RegisterIntermediateHashAPI(router *gin.RouterGroup, e *Env) error {
|
|
router.GET("/", e.FindIntermediateHash)
|
|
return nil
|
|
}
|
|
|
|
func (e *Env) FindIntermediateHash(c *gin.Context) {
|
|
results, err := findIntermediateHashByPrefix(c.Query("prefix"), c.Query("tombstones") == "on", e.DB)
|
|
if err != nil {
|
|
c.Error(err) //nolint:errcheck
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, results)
|
|
}
|
|
|
|
type IntermediateHashResponse struct {
|
|
Prefix string `json:"prefix"`
|
|
Value string `json:"value"`
|
|
}
|
|
|
|
func findIntermediateHashByPrefix(prefixS string, tombstones bool, remoteDB ethdb.KV) ([]*IntermediateHashResponse, error) {
|
|
var results []*IntermediateHashResponse
|
|
prefix := common.FromHex(prefixS)
|
|
if err := remoteDB.View(context.TODO(), func(tx ethdb.Tx) error {
|
|
interBucket := tx.Bucket(dbutils.IntermediateTrieHashBucket)
|
|
c := interBucket.Cursor().Prefix(prefix)
|
|
|
|
for k, v, err := c.First(); k != nil || err != nil; k, v, err = c.Next() {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if tombstones && len(v) > 0 {
|
|
continue
|
|
}
|
|
if !tombstones && len(v) == 0 {
|
|
continue
|
|
}
|
|
|
|
results = append(results, &IntermediateHashResponse{
|
|
Prefix: fmt.Sprintf("%x\n", k),
|
|
Value: fmt.Sprintf("%x\n", v),
|
|
})
|
|
|
|
if len(results) > 50 {
|
|
results = append(results, &IntermediateHashResponse{
|
|
Prefix: "too much results",
|
|
})
|
|
return nil
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return results, nil
|
|
}
|