-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot-go_modules-master-golang.org-x-…
…crypto-0.18.0
- Loading branch information
Showing
37 changed files
with
975 additions
and
776 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## keycli | ||
|
||
`keycli` is an extension of `tm2/keys/client`, enhancing its functionality. It provides the following features: | ||
|
||
- **addpkg**: Allows you to upload a new package to the blockchain. | ||
- **run**: Execute Gno code by invoking the main() function from the target package. | ||
- **call**: Executes a single function call within a Realm. | ||
- **maketx**: Compose a transaction (tx) document to sign (and possibly broadcast). | ||
|
||
--- | ||
|
||
Most of these features have been extracted from `tm2/keys/client` to ensure that `tm2` remains completely independent of `gnovm` and `gno.land`. For more detailed information regarding this change, please refer to [PR#1483](https://github.com/gnolang/gno/pull/1483) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package keyscli | ||
|
||
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 | ||
} |
Oops, something went wrong.