forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis_txs_list.go
55 lines (45 loc) · 1.33 KB
/
genesis_txs_list.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
package main
import (
"bytes"
"context"
"errors"
"fmt"
"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/commands"
)
var ErrWrongGenesisType = errors.New("genesis state is not using the correct Gno Genesis type")
// newTxsListCmd list all transactions on the specified genesis file
func newTxsListCmd(txsCfg *txsCfg, io commands.IO) *commands.Command {
cmd := commands.NewCommand(
commands.Metadata{
Name: "list",
ShortUsage: "txs list [flags] [<arg>...]",
ShortHelp: "lists transactions existing on genesis.json",
LongHelp: "Lists transactions existing on genesis.json",
},
commands.NewEmptyConfig(),
func(ctx context.Context, args []string) error {
return execTxsListCmd(io, txsCfg)
},
)
return cmd
}
func execTxsListCmd(io commands.IO, cfg *txsCfg) error {
genesis, err := types.GenesisDocFromFile(cfg.genesisPath)
if err != nil {
return fmt.Errorf("%w, %w", errUnableToLoadGenesis, err)
}
gs, ok := genesis.AppState.(gnoland.GnoGenesisState)
if !ok {
return ErrWrongGenesisType
}
b, err := amino.MarshalJSONIndent(gs.Txs, "", " ")
if err != nil {
return errors.New("error marshalling data to amino JSON")
}
buf := bytes.NewBuffer(b)
_, err = buf.WriteTo(io.Out())
return err
}