mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
3bec75cdc4
* initial * update rpc deamon readme * use read-only transactions
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/core/forkid"
|
|
"github.com/ledgerwatch/turbo-geth/rpc"
|
|
"github.com/ledgerwatch/turbo-geth/turbo/rpchelper"
|
|
)
|
|
|
|
type Forks struct {
|
|
GenesisHash common.Hash `json:"genesis"`
|
|
Passed []uint64 `json:"passed"`
|
|
Next *uint64 `json:"next,omitempty"`
|
|
}
|
|
|
|
// returns forkID hash, sorted list of already passed forks and next fork block
|
|
func (api *TgImpl) Forks(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (Forks, error) {
|
|
blockNumber, _, err := rpchelper.GetBlockNumber(blockNrOrHash, api.dbReader)
|
|
if err != nil {
|
|
return Forks{}, err
|
|
}
|
|
|
|
tx, err := api.db.Begin(ctx, nil, false)
|
|
if err != nil {
|
|
return Forks{}, err
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
chainConfig, genesisHash := getChainConfigWithGenesis(tx)
|
|
forksBlocks := forkid.GatherForks(chainConfig)
|
|
|
|
lastAddedIdx := -1
|
|
passedForks := make([]uint64, 0, len(forksBlocks))
|
|
for i, num := range forksBlocks {
|
|
if num <= blockNumber {
|
|
passedForks = append(passedForks, num)
|
|
lastAddedIdx = i
|
|
}
|
|
}
|
|
|
|
var nextFork *uint64
|
|
if len(forksBlocks) > lastAddedIdx+1 {
|
|
nextFork = new(uint64)
|
|
*nextFork = forksBlocks[lastAddedIdx+1]
|
|
}
|
|
return Forks{genesisHash, passedForks, nextFork}, nil
|
|
}
|