From 32511b39c51fdecf2e5b10f89cae5323a5ca1e5a Mon Sep 17 00:00:00 2001 From: gfanton <8671905+gfanton@users.noreply.github.com> Date: Thu, 21 Dec 2023 23:36:25 +0100 Subject: [PATCH] fix: extract gnoland and gnovm outside tm2 Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com> --- .../client => gno.land/cmd/gnokey}/addpkg.go | 9 +- .../client => gno.land/cmd/gnokey}/call.go | 11 +-- gno.land/cmd/gnokey/maketx.go | 83 +++++++++++++++++++ gno.land/cmd/gnokey/root.go | 1 + .../client => gno.land/cmd/gnokey}/run.go | 9 +- tm2/pkg/crypto/keys/client/maketx.go | 5 +- tm2/pkg/crypto/keys/client/send.go | 2 +- tm2/pkg/crypto/keys/client/sign.go | 2 +- 8 files changed, 103 insertions(+), 19 deletions(-) rename {tm2/pkg/crypto/keys/client => gno.land/cmd/gnokey}/addpkg.go (91%) rename {tm2/pkg/crypto/keys/client => gno.land/cmd/gnokey}/call.go (89%) create mode 100644 gno.land/cmd/gnokey/maketx.go create mode 100644 gno.land/cmd/gnokey/root.go rename {tm2/pkg/crypto/keys/client => gno.land/cmd/gnokey}/run.go (92%) diff --git a/tm2/pkg/crypto/keys/client/addpkg.go b/gno.land/cmd/gnokey/addpkg.go similarity index 91% rename from tm2/pkg/crypto/keys/client/addpkg.go rename to gno.land/cmd/gnokey/addpkg.go index fc9b1c991d7..df21298387c 100644 --- a/tm2/pkg/crypto/keys/client/addpkg.go +++ b/gno.land/cmd/gnokey/addpkg.go @@ -1,4 +1,4 @@ -package client +package main // TODO: move most of the logic in ROOT/gno.land/... @@ -12,19 +12,20 @@ import ( "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 *MakeTxCfg + RootCfg *client.MakeTxCfg PkgPath string PkgDir string Deposit string } -func NewMakeAddPkgCmd(rootCfg *MakeTxCfg, io commands.IO) *commands.Command { +func NewMakeAddPkgCmd(rootCfg *client.MakeTxCfg, io commands.IO) *commands.Command { cfg := &MakeAddPkgCfg{ RootCfg: rootCfg, } @@ -128,7 +129,7 @@ func execMakeAddPkg(cfg *MakeAddPkgCfg, args []string, io commands.IO) error { } if cfg.RootCfg.Broadcast { - err := signAndBroadcast(cfg.RootCfg, args, tx, io) + err := client.ExecSignAndBroadcast(cfg.RootCfg, args, tx, io) if err != nil { return err } diff --git a/tm2/pkg/crypto/keys/client/call.go b/gno.land/cmd/gnokey/call.go similarity index 89% rename from tm2/pkg/crypto/keys/client/call.go rename to gno.land/cmd/gnokey/call.go index a5ffec97d01..71d66263ba1 100644 --- a/tm2/pkg/crypto/keys/client/call.go +++ b/gno.land/cmd/gnokey/call.go @@ -1,4 +1,4 @@ -package client +package main import ( "context" @@ -9,12 +9,13 @@ import ( "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 MakeCallCfg struct { - RootCfg *MakeTxCfg + RootCfg *client.MakeTxCfg Send string PkgPath string @@ -22,7 +23,7 @@ type MakeCallCfg struct { Args commands.StringArr } -func NewMakeCallCmd(rootCfg *MakeTxCfg, io commands.IO) *commands.Command { +func NewMakeCallCmd(rootCfg *client.MakeTxCfg, io commands.IO) *commands.Command { cfg := &MakeCallCfg{ RootCfg: rootCfg, } @@ -30,7 +31,7 @@ func NewMakeCallCmd(rootCfg *MakeTxCfg, io commands.IO) *commands.Command { return commands.NewCommand( commands.Metadata{ Name: "call", - ShortUsage: "call [flags] ", + 1ShortUsage: "call [flags] ", ShortHelp: "Executes a Realm function call", }, cfg, @@ -131,7 +132,7 @@ func execMakeCall(cfg *MakeCallCfg, args []string, io commands.IO) error { } if cfg.RootCfg.Broadcast { - err := signAndBroadcast(cfg.RootCfg, args, tx, io) + err := client.ExecSignAndBroadcast(cfg.RootCfg, args, tx, io) if err != nil { return err } diff --git a/gno.land/cmd/gnokey/maketx.go b/gno.land/cmd/gnokey/maketx.go new file mode 100644 index 00000000000..73254c02955 --- /dev/null +++ b/gno.land/cmd/gnokey/maketx.go @@ -0,0 +1,83 @@ +package main + +import ( + "flag" + + "github.com/gnolang/gno/tm2/pkg/commands" + "github.com/gnolang/gno/tm2/pkg/crypto/keys/client" +) + +type MakeTxCfg struct { + RootCfg *client.BaseCfg + + GasWanted int64 + GasFee string + Memo string + + Broadcast bool + ChainID string +} + +func NewMakeTxCmd(rootCfg *client.BaseCfg, io commands.IO) *commands.Command { + cfg := &client.MakeTxCfg{ + RootCfg: rootCfg, + } + + cmd := commands.NewCommand( + commands.Metadata{ + Name: "maketx", + ShortUsage: " [flags] [...]", + ShortHelp: "Composes a tx document to sign", + }, + cfg, + commands.HelpExec, + ) + + cmd.AddSubCommands( + client.NewMakeSendCmd(cfg, io), + + // custom commands + NewMakeAddPkgCmd(cfg, io), + NewMakeCallCmd(cfg, io), + NewMakeRunCmd(cfg, io), + ) + + return cmd +} + +func (c *MakeTxCfg) RegisterFlags(fs *flag.FlagSet) { + fs.Int64Var( + &c.GasWanted, + "gas-wanted", + 0, + "gas requested for tx", + ) + + fs.StringVar( + &c.GasFee, + "gas-fee", + "", + "gas payment fee", + ) + + fs.StringVar( + &c.Memo, + "memo", + "", + "any descriptive text", + ) + + fs.BoolVar( + &c.Broadcast, + "broadcast", + false, + "sign and broadcast", + ) + + fs.StringVar( + &c.ChainID, + "chainid", + "dev", + "chainid to sign for (only useful if --broadcast)", + ) +} diff --git a/gno.land/cmd/gnokey/root.go b/gno.land/cmd/gnokey/root.go new file mode 100644 index 00000000000..06ab7d0f9a3 --- /dev/null +++ b/gno.land/cmd/gnokey/root.go @@ -0,0 +1 @@ +package main diff --git a/tm2/pkg/crypto/keys/client/run.go b/gno.land/cmd/gnokey/run.go similarity index 92% rename from tm2/pkg/crypto/keys/client/run.go rename to gno.land/cmd/gnokey/run.go index 931000b1e00..10a31fb592d 100644 --- a/tm2/pkg/crypto/keys/client/run.go +++ b/gno.land/cmd/gnokey/run.go @@ -1,4 +1,4 @@ -package client +package main import ( "context" @@ -12,15 +12,16 @@ import ( "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 MakeRunCfg struct { - RootCfg *MakeTxCfg + RootCfg *client.MakeTxCfg } -func NewMakeRunCmd(rootCfg *MakeTxCfg, io commands.IO) *commands.Command { +func NewMakeRunCmd(rootCfg *client.MakeTxCfg, io commands.IO) *commands.Command { cfg := &MakeRunCfg{ RootCfg: rootCfg, } @@ -128,7 +129,7 @@ func execMakeRun(cfg *MakeRunCfg, args []string, io commands.IO) error { } if cfg.RootCfg.Broadcast { - err := signAndBroadcast(cfg.RootCfg, args, tx, io) + err := client.ExecSignAndBroadcast(cfg.RootCfg, args, tx, io) if err != nil { return err } diff --git a/tm2/pkg/crypto/keys/client/maketx.go b/tm2/pkg/crypto/keys/client/maketx.go index cd60fc26d74..12033c59222 100644 --- a/tm2/pkg/crypto/keys/client/maketx.go +++ b/tm2/pkg/crypto/keys/client/maketx.go @@ -39,10 +39,7 @@ func NewMakeTxCmd(rootCfg *BaseCfg, io commands.IO) *commands.Command { ) cmd.AddSubCommands( - NewMakeAddPkgCmd(cfg, io), NewMakeSendCmd(cfg, io), - NewMakeCallCmd(cfg, io), - NewMakeRunCmd(cfg, io), ) return cmd @@ -146,7 +143,7 @@ func SignAndBroadcastHandler( return BroadcastHandler(bopts) } -func signAndBroadcast( +func ExecSignAndBroadcast( cfg *MakeTxCfg, args []string, tx std.Tx, diff --git a/tm2/pkg/crypto/keys/client/send.go b/tm2/pkg/crypto/keys/client/send.go index cf1b6028348..a253f9d9f4e 100644 --- a/tm2/pkg/crypto/keys/client/send.go +++ b/tm2/pkg/crypto/keys/client/send.go @@ -119,7 +119,7 @@ func execMakeSend(cfg *MakeSendCfg, args []string, io commands.IO) error { } if cfg.RootCfg.Broadcast { - err := signAndBroadcast(cfg.RootCfg, args, tx, io) + err := ExecSignAndBroadcast(cfg.RootCfg, args, tx, io) if err != nil { return err } diff --git a/tm2/pkg/crypto/keys/client/sign.go b/tm2/pkg/crypto/keys/client/sign.go index fd1f3253f7a..19022eaba81 100644 --- a/tm2/pkg/crypto/keys/client/sign.go +++ b/tm2/pkg/crypto/keys/client/sign.go @@ -2,7 +2,6 @@ package client import ( "context" - "errors" "flag" "fmt" "os" @@ -10,6 +9,7 @@ import ( "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/errors" "github.com/gnolang/gno/tm2/pkg/std" )