-
Notifications
You must be signed in to change notification settings - Fork 374
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
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b222d72
fix: expose most of the method/fields in keys/client
gfanton 489e4a4
feat: add SignAndBroadcastHandler
gfanton 32511b3
fix: extract gnoland and gnovm outside tm2
gfanton 9ec535f
fix: remove deprecated ioutil
gfanton 4e7da28
chore: cleanup root
gfanton 150c8d2
fixup: wrong home config
gfanton f7aa61f
chore: mod tidy
gfanton ddbddd2
fix: use keyscli module to be able to share package code with test in…
gfanton b0cfbbf
chore: add keycli readme
gfanton 840ba7c
chore: cleanup
gfanton 95f16f4
chore: use cmdio instead of io
gfanton 61f6fde
Merge branch 'master' into feat/reworks-keys-client
gfanton cc506ef
Merge remote-tracking branch 'master' into feat/reworks-keys-client
gfanton 65e16b7
Merge remote-tracking branch 'master' into feat/reworks-keys-client
gfanton 13b3af1
chore: lint
gfanton 589d7e9
Merge remote-tracking branch 'master' into feat/reworks-keys-client
gfanton 6f92d37
fix: rebase
gfanton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.