forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis_txs.go
76 lines (61 loc) · 1.7 KB
/
genesis_txs.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
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"errors"
"flag"
"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/std"
)
type txsCfg struct {
commonCfg
}
var errInvalidGenesisStateType = errors.New("invalid genesis state type")
// newTxsCmd creates the genesis txs subcommand
func newTxsCmd(io commands.IO) *commands.Command {
cfg := &txsCfg{}
cmd := commands.NewCommand(
commands.Metadata{
Name: "txs",
ShortUsage: "txs <subcommand> [flags]",
ShortHelp: "manages the initial genesis transactions",
LongHelp: "Manages genesis transactions through input files",
},
cfg,
commands.HelpExec,
)
cmd.AddSubCommands(
newTxsAddCmd(cfg, io),
newTxsRemoveCmd(cfg, io),
newTxsExportCmd(cfg, io),
newTxsListCmd(cfg, io),
)
return cmd
}
func (c *txsCfg) RegisterFlags(fs *flag.FlagSet) {
c.commonCfg.RegisterFlags(fs)
}
// appendGenesisTxs saves the given transactions to the genesis doc
func appendGenesisTxs(genesis *types.GenesisDoc, txs []std.Tx) error {
// Initialize the app state if it's not present
if genesis.AppState == nil {
genesis.AppState = gnoland.GnoGenesisState{}
}
// Make sure the app state is the Gno genesis state
state, ok := genesis.AppState.(gnoland.GnoGenesisState)
if !ok {
return errInvalidGenesisStateType
}
// Left merge the transactions
fileTxStore := txStore(txs)
genesisTxStore := txStore(state.Txs)
// The genesis transactions have preference with the order
// in the genesis.json
if err := genesisTxStore.leftMerge(fileTxStore); err != nil {
return err
}
// Save the state
state.Txs = genesisTxStore
genesis.AppState = state
return nil
}