2020-05-23 09:19:56 +00:00
|
|
|
package generate
|
2020-04-20 10:35:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2020-05-30 07:00:35 +00:00
|
|
|
|
2020-04-20 10:35:33 +00:00
|
|
|
"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
|
|
|
|
}
|
2020-05-30 07:00:35 +00:00
|
|
|
var walker func([]byte) changeset.Walker
|
2020-04-20 10:35:33 +00:00
|
|
|
if bytes.Equal(dbutils.AccountChangeSetBucket, csBucket) {
|
2020-05-30 07:00:35 +00:00
|
|
|
walker = func(cs []byte) changeset.Walker {
|
2020-04-20 10:35:33 +00:00
|
|
|
return changeset.AccountChangeSetBytes(cs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if bytes.Equal(dbutils.StorageChangeSetBucket, csBucket) {
|
2020-05-30 07:00:35 +00:00
|
|
|
walker = func(cs []byte) changeset.Walker {
|
2020-04-20 10:35:33 +00:00
|
|
|
return changeset.StorageChangeSetBytes(cs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-23 09:19:56 +00:00
|
|
|
ig := core.NewIndexGenerator(db)
|
|
|
|
err = ig.GenerateIndex(0, csBucket, indexBucket, walker, nil)
|
2020-04-20 10:35:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println("Index is successfully regenerated")
|
|
|
|
return nil
|
|
|
|
}
|