forked from forbole/juno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis.go
36 lines (30 loc) · 1.03 KB
/
genesis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package utils
import (
"encoding/json"
"fmt"
tmjson "github.com/cometbft/cometbft/libs/json"
tmos "github.com/cometbft/cometbft/libs/os"
tmtypes "github.com/cometbft/cometbft/types"
)
// ReadGenesisFileGenesisDoc reads the genesis file located at the given path
func ReadGenesisFileGenesisDoc(genesisPath string) (*tmtypes.GenesisDoc, error) {
var genesisDoc *tmtypes.GenesisDoc
bz, err := tmos.ReadFile(genesisPath)
if err != nil {
return nil, fmt.Errorf("failed to read genesis file: %s", err)
}
err = tmjson.Unmarshal(bz, &genesisDoc)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis doc: %s", err)
}
return genesisDoc, nil
}
// GetGenesisState returns the genesis state by getting it from the given genesis doc
func GetGenesisState(doc *tmtypes.GenesisDoc) (map[string]json.RawMessage, error) {
var genesisState map[string]json.RawMessage
err := json.Unmarshal(doc.AppState, &genesisState)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis state: %s", err)
}
return genesisState, nil
}