mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-29 07:07:16 +00:00
38 lines
962 B
Go
38 lines
962 B
Go
|
package stateless
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"fmt"
|
||
|
"github.com/ledgerwatch/turbo-geth/common/changeset"
|
||
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
||
|
"github.com/ledgerwatch/turbo-geth/core"
|
||
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
||
|
)
|
||
|
|
||
|
func RegenerateIndex(chaindata string, indexBucket []byte, csBucket []byte) error {
|
||
|
db, err := ethdb.NewBoltDatabase(chaindata)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
var walker func([]byte) core.ChangesetWalker
|
||
|
if bytes.Equal(dbutils.AccountChangeSetBucket, csBucket) {
|
||
|
walker = func(cs []byte) core.ChangesetWalker {
|
||
|
return changeset.AccountChangeSetBytes(cs)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if bytes.Equal(dbutils.StorageChangeSetBucket, csBucket) {
|
||
|
walker = func(cs []byte) core.ChangesetWalker {
|
||
|
return changeset.StorageChangeSetBytes(cs)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ig := core.NewIndexGenerator(db, csBucket, indexBucket, walker)
|
||
|
err = ig.GenerateIndex()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
fmt.Println("Index is successfully regenerated")
|
||
|
return nil
|
||
|
}
|