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: remove gnovm and gno.land dependencies from tm2 #1483

Merged
merged 17 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
5 changes: 0 additions & 5 deletions contribs/gnokeykc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ require (
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dgraph-io/badger/v3 v3.2103.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
Expand All @@ -43,13 +41,10 @@ require (
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.opencensus.io v0.22.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
10 changes: 0 additions & 10 deletions contribs/gnokeykc/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gno.land/cmd/gnokey/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"fmt"
"os"

"github.com/gnolang/gno/gno.land/pkg/keyscli"
"github.com/gnolang/gno/gnovm/pkg/gnoenv"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/crypto/keys/client"
Expand All @@ -16,7 +17,7 @@
Remote: "127.0.0.1:26657",
}

cmd := client.NewRootCmdWithBaseConfig(commands.NewDefaultIO(), baseCfg)
cmd := keyscli.NewRootCmd(commands.NewDefaultIO(), baseCfg)

Check warning on line 20 in gno.land/cmd/gnokey/main.go

View check run for this annotation

Codecov / codecov/patch

gno.land/cmd/gnokey/main.go#L20

Added line #L20 was not covered by tests
if err := cmd.ParseAndRun(context.Background(), os.Args[1:]); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%+v\n", err)

Expand Down
3 changes: 2 additions & 1 deletion gno.land/pkg/integration/testing_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"testing"

"github.com/gnolang/gno/gno.land/pkg/keyscli"
"github.com/gnolang/gno/gnovm/pkg/gnoenv"
"github.com/gnolang/gno/tm2/pkg/bft/node"
"github.com/gnolang/gno/tm2/pkg/commands"
Expand Down Expand Up @@ -181,7 +182,7 @@ func setupGnolandTestScript(t *testing.T, txtarDir string) testscript.Params {
io := commands.NewTestIO()
io.SetOut(commands.WriteNopCloser(ts.Stdout()))
io.SetErr(commands.WriteNopCloser(ts.Stderr()))
cmd := client.NewRootCmd(io)
cmd := keyscli.NewRootCmd(io, client.DefaultBaseOptions)

io.SetIn(strings.NewReader("\n")) // Inject empty password to stdin.
defaultArgs := []string{
Expand Down
140 changes: 140 additions & 0 deletions gno.land/pkg/keyscli/addpkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package keyscli
Copy link
Member

Choose a reason for hiding this comment

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

please, add a small readme explaining the goal of this package and its relationships and add a link to this PR.


// TODO: move most of the logic in ROOT/gno.land/...

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO: move most of the logic in ROOT/gno.land/...

import (
"context"
"flag"
"fmt"

"github.com/gnolang/gno/gno.land/pkg/sdk/vm"
gno "github.com/gnolang/gno/gnovm/pkg/gnolang"
"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/crypto/keys"
"github.com/gnolang/gno/tm2/pkg/crypto/keys/client"
"github.com/gnolang/gno/tm2/pkg/errors"
"github.com/gnolang/gno/tm2/pkg/std"
)

type MakeAddPkgCfg struct {
RootCfg *client.MakeTxCfg

PkgPath string
PkgDir string
Deposit string
}

func NewMakeAddPkgCmd(rootCfg *client.MakeTxCfg, io commands.IO) *commands.Command {
cfg := &MakeAddPkgCfg{
RootCfg: rootCfg,
}

return commands.NewCommand(
commands.Metadata{
Name: "addpkg",
ShortUsage: "addpkg [flags] <key-name>",
ShortHelp: "Uploads a new package",
},
cfg,
func(_ context.Context, args []string) error {
return execMakeAddPkg(cfg, args, io)
},
)
}

func (c *MakeAddPkgCfg) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(
&c.PkgPath,
"pkgpath",
"",
"package path (required)",
)

fs.StringVar(
&c.PkgDir,
"pkgdir",
"",
"path to package files (required)",
)

fs.StringVar(
&c.Deposit,
"deposit",
"",
"deposit coins",
)
}

func execMakeAddPkg(cfg *MakeAddPkgCfg, args []string, io commands.IO) error {
if cfg.PkgPath == "" {
return errors.New("pkgpath not specified")
}
if cfg.PkgDir == "" {
return errors.New("pkgdir not specified")
}

if len(args) != 1 {
return flag.ErrHelp
}

// read account pubkey.
nameOrBech32 := args[0]
kb, err := keys.NewKeyBaseFromDir(cfg.RootCfg.RootCfg.Home)
if err != nil {
return err
}
info, err := kb.GetByNameOrAddress(nameOrBech32)
if err != nil {
return err
}
creator := info.GetAddress()
// info.GetPubKey()

// parse deposit.
deposit, err := std.ParseCoins(cfg.Deposit)
if err != nil {
panic(err)
}

// open files in directory as MemPackage.
memPkg := gno.ReadMemPackage(cfg.PkgDir, cfg.PkgPath)
if memPkg.IsEmpty() {
panic(fmt.Sprintf("found an empty package %q", cfg.PkgPath))
}

// precompile and validate syntax
err = gno.PrecompileAndCheckMempkg(memPkg)
if err != nil {
panic(err)
}

// parse gas wanted & fee.
gaswanted := cfg.RootCfg.GasWanted
gasfee, err := std.ParseCoin(cfg.RootCfg.GasFee)
if err != nil {
panic(err)
}
// construct msg & tx and marshal.
msg := vm.MsgAddPackage{
Creator: creator,
Package: memPkg,
Deposit: deposit,
}
tx := std.Tx{
Msgs: []std.Msg{msg},
Fee: std.NewFee(gaswanted, gasfee),
Signatures: nil,
Memo: cfg.RootCfg.Memo,
}

if cfg.RootCfg.Broadcast {
err := client.ExecSignAndBroadcast(cfg.RootCfg, args, tx, io)
if err != nil {
return err
}
} else {
fmt.Println(string(amino.MustMarshalJSON(tx)))
}
return nil
}
Loading
Loading