This repository was archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchain_spec.go
63 lines (53 loc) · 1.95 KB
/
chain_spec.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package commander
import (
"os"
"github.com/Worldcoin/hubble-commander/models"
"github.com/Worldcoin/hubble-commander/utils/ref"
"gopkg.in/yaml.v2"
)
func ReadChainSpecFile(path string) (*models.ChainSpec, error) {
yamlFile, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var chainSpec models.ChainSpec
err = yaml.Unmarshal(yamlFile, &chainSpec)
if err != nil {
return nil, err
}
return &chainSpec, nil
}
func GenerateChainSpec(chainState *models.ChainState) (*string, error) {
chainSpec := makeChainSpec(chainState)
yamlChainSpec, err := yaml.Marshal(chainSpec)
if err != nil {
return nil, err
}
return ref.String(string(yamlChainSpec)), nil
}
func makeChainSpec(chainState *models.ChainState) models.ChainSpec {
return models.ChainSpec{
ChainID: chainState.ChainID,
AccountRegistry: chainState.AccountRegistry,
AccountRegistryDeploymentBlock: chainState.AccountRegistryDeploymentBlock,
TokenRegistry: chainState.TokenRegistry,
SpokeRegistry: chainState.SpokeRegistry,
DepositManager: chainState.DepositManager,
WithdrawManager: chainState.WithdrawManager,
Rollup: chainState.Rollup,
GenesisAccounts: chainState.GenesisAccounts,
}
}
func newChainStateFromChainSpec(chainSpec *models.ChainSpec) *models.ChainState {
return &models.ChainState{
ChainID: chainSpec.ChainID,
AccountRegistry: chainSpec.AccountRegistry,
AccountRegistryDeploymentBlock: chainSpec.AccountRegistryDeploymentBlock,
TokenRegistry: chainSpec.TokenRegistry,
SpokeRegistry: chainSpec.SpokeRegistry,
DepositManager: chainSpec.DepositManager,
WithdrawManager: chainSpec.WithdrawManager,
Rollup: chainSpec.Rollup,
GenesisAccounts: chainSpec.GenesisAccounts,
}
}