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
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 27 additions & 9 deletions gno.land/cmd/gnoland/genesis_txs_add_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"errors"
"flag"
"fmt"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
Expand All @@ -15,38 +16,55 @@ 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",
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)
}

genesisDeployAddress := crypto.MustAddressFromString(cfg.deployerAdd)

// Make sure the package dir is set
if len(args) == 0 {
return errInvalidPackageDir
Expand All @@ -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)
}

Expand Down
16 changes: 9 additions & 7 deletions gno.land/cmd/gnoland/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,21 @@
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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first tx is not necessarily what has been passed to TxsAddPackages command

also loading the examples here will be removed from what I understand so maybe we should not change his file until #1952 is fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review @n0izn0iz changed back while waiting for that change :)


// 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)
}

Check warning on line 418 in gno.land/cmd/gnoland/start.go

View check run for this annotation

Codecov / codecov/patch

gno.land/cmd/gnoland/start.go#L417-L418

Added lines #L417 - L418 were not covered by tests

genesisTxs = append(pkgsTxs, genesisTxs...)

// Construct genesis AppState.
Expand Down
Loading