From 2c5540c472f84f2ef6bc6ab067ee44e0c0d1488a Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sat, 19 Oct 2024 23:19:07 +0200 Subject: [PATCH] feat(genesis): deployerAddres passed as parameter Co-authored-by: 6h057 --- .../cmd/gnoland/genesis_txs_add_packages.go | 34 +++++++++++++++---- gno.land/cmd/gnoland/start.go | 16 +++++---- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/gno.land/cmd/gnoland/genesis_txs_add_packages.go b/gno.land/cmd/gnoland/genesis_txs_add_packages.go index 56d165c070b..c984de7c2cb 100644 --- a/gno.land/cmd/gnoland/genesis_txs_add_packages.go +++ b/gno.land/cmd/gnoland/genesis_txs_add_packages.go @@ -3,6 +3,7 @@ package main import ( "context" "errors" + "flag" "fmt" "github.com/gnolang/gno/gno.land/pkg/gnoland" @@ -16,12 +17,29 @@ import ( var errInvalidPackageDir = errors.New("invalid package directory") var ( - genesisDeployAddress = crypto.MustAddressFromString("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // test1 - genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000))) + genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000))) ) +type addPkgCfg struct { + txsCfg *txsCfg + deployerAdd string +} + +func (c *addPkgCfg) RegisterFlags(fs *flag.FlagSet) { + fs.StringVar( + &c.deployerAdd, + "deployer-address", + "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5", // test1 + "The address that will create package on the transaction genesis", + ) +} + // 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", @@ -29,24 +47,26 @@ func newTxsAddPackagesCmd(txsCfg *txsCfg, io commands.IO) *commands.Command { 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) } + genesisDeployAddress := crypto.MustAddressFromString(cfg.deployerAdd) + // Make sure the package dir is set if len(args) == 0 { return errInvalidPackageDir @@ -69,7 +89,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) } diff --git a/gno.land/cmd/gnoland/start.go b/gno.land/cmd/gnoland/start.go index 21f0cb4b1a6..11ea3cb1189 100644 --- a/gno.land/cmd/gnoland/start.go +++ b/gno.land/cmd/gnoland/start.go @@ -402,18 +402,20 @@ func generateGenesisFile(genesisFile string, pk crypto.PubKey, c *startCfg) erro return fmt.Errorf("unable to load genesis balances file %q: %w", c.genesisBalancesFile, err) } - // Load examples folder - examplesDir := filepath.Join(c.gnoRootDir, "examples") - pkgsTxs, err := gnoland.LoadPackagesFromDir(examplesDir, genesisDeployAddress, genesisDeployFee) - if err != nil { - return fmt.Errorf("unable to load examples folder: %w", err) - } - // Load Genesis TXs genesisTxs, err := gnoland.LoadGenesisTxsFile(c.genesisTxsFile, c.chainID, c.genesisRemote) if err != nil { return fmt.Errorf("unable to load genesis txs file: %w", err) } + + signer := genesisTxs[0].Msgs[0].GetSigners()[0] + + // Load examples folder + examplesDir := filepath.Join(c.gnoRootDir, "examples") + pkgsTxs, err := gnoland.LoadPackagesFromDir(examplesDir, signer, genesisDeployFee) + if err != nil { + return fmt.Errorf("unable to load examples folder: %w", err) + } genesisTxs = append(pkgsTxs, genesisTxs...)