From 2d8ba6c83691498fde6869cf0d8fe510966eaba0 Mon Sep 17 00:00:00 2001 From: Omar Sy Date: Sat, 19 Oct 2024 23:29:20 +0200 Subject: [PATCH] feat(genesis): deployerAddres passed as parameter Co-authored-by: 6h057 --- .../cmd/gnoland/genesis_txs_add_packages.go | 36 ++++++++++++++----- gno.land/cmd/gnoland/start.go | 16 +++++---- 2 files changed, 36 insertions(+), 16 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..b5dee89419d 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" @@ -15,13 +16,28 @@ import ( var errInvalidPackageDir = errors.New("invalid package directory") -var ( - genesisDeployAddress = crypto.MustAddressFromString("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // test1 - genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000))) -) +var 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 +45,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 +87,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..c0fb45620f7 100644 --- a/gno.land/cmd/gnoland/start.go +++ b/gno.land/cmd/gnoland/start.go @@ -402,19 +402,21 @@ 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...) // Construct genesis AppState.