Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(genesis): deployerAddress passed as parameter #2986

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions contribs/gnogenesis/internal/txs/txs_add_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package txs
import (
"context"
"errors"
"flag"
"fmt"

"github.com/gnolang/gno/tm2/pkg/crypto"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
"github.com/gnolang/gno/gnovm/pkg/gnoenv"
"github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/crypto/keys"
"github.com/gnolang/gno/tm2/pkg/std"
)

Expand All @@ -21,29 +25,47 @@ var (
genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000)))
)

type addPkgCfg struct {
txsCfg *txsCfg
keyName string
}

func (c *addPkgCfg) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(
&c.keyName,
"key-name",
"",
"The package deployer key name or address",
)
}

// newTxsAddPackagesCmd creates the genesis txs add packages subcommand
func newTxsAddPackagesCmd(txsCfg *txsCfg, io commands.IO) *commands.Command {
cfg := &addPkgCfg{
txsCfg: txsCfg,
}

return commands.NewCommand(
commands.Metadata{
Name: "packages",
ShortUsage: "txs add packages <package-path ...>",
ShortHelp: "imports transactions from the given packages into the genesis.json",
LongHelp: "Imports the transactions from a given package directory recursively to the genesis.json",
},
commands.NewEmptyConfig(),
cfg,
func(_ context.Context, args []string) error {
return execTxsAddPackages(txsCfg, io, args)
return execTxsAddPackages(cfg, io, args)
},
)
}

func execTxsAddPackages(
cfg *txsCfg,
cfg *addPkgCfg,
io commands.IO,
args []string,
) error {
// Load the genesis
genesis, loadErr := types.GenesisDocFromFile(cfg.GenesisPath)
genesis, loadErr := types.GenesisDocFromFile(cfg.txsCfg.GenesisPath)
if loadErr != nil {
return fmt.Errorf("unable to load genesis, %w", loadErr)
}
Expand All @@ -52,11 +74,25 @@ func execTxsAddPackages(
if len(args) == 0 {
return errInvalidPackageDir
}
var creator crypto.Address
if cfg.keyName != "" {
kb, err := keys.NewKeyBaseFromDir(gnoenv.HomeDir())
if err != nil {
return err
}
info, err := kb.GetByNameOrAddress(cfg.keyName)
if err != nil {
return err
}
creator = info.GetAddress()
} else {
creator = genesisDeployAddress
}

parsedTxs := make([]gnoland.TxWithMetadata, 0)
for _, path := range args {
// Generate transactions from the packages (recursively)
txs, err := gnoland.LoadPackagesFromDir(path, genesisDeployAddress, genesisDeployFee)
txs, err := gnoland.LoadPackagesFromDir(path, creator, genesisDeployFee)
if err != nil {
return fmt.Errorf("unable to load txs from directory, %w", err)
}
Expand All @@ -70,7 +106,7 @@ func execTxsAddPackages(
}

// Save the updated genesis
if err := genesis.SaveAs(cfg.GenesisPath); err != nil {
if err := genesis.SaveAs(cfg.txsCfg.GenesisPath); err != nil {
return fmt.Errorf("unable to save genesis.json, %w", err)
}

Expand Down
Loading