Skip to content

Commit

Permalink
feat(genesis): deployerAddres passed as parameter
Browse files Browse the repository at this point in the history
Co-authored-by: 6h057 <[email protected]>
  • Loading branch information
omarsy and omarsy committed Oct 19, 2024
1 parent f6bd2d3 commit 2d8ba6c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
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 @@ 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.
Expand Down

0 comments on commit 2d8ba6c

Please sign in to comment.