Skip to content

Commit

Permalink
Merge branch 'master' into feat/gnodev-handle-tx
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton authored Jun 25, 2024
2 parents e165f62 + 4f16ad3 commit 3c91107
Show file tree
Hide file tree
Showing 50 changed files with 9,319 additions and 501 deletions.
8 changes: 5 additions & 3 deletions docs/gno-infrastructure/setting-up-a-local-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ In this tutorial, you will learn how to start a local Gno node (and chain!).
Additionally, you will see the different options you can use to make your Gno instance unique.

## Prerequisites

- **Git**
- **`make` (for running Makefiles)**
- **Go 1.21+**
- **Go Environment Setup**: Ensure you have Go set up as outlined in the [Go official installation documentation](https://go.dev/doc/install) for your environment
- **Go Environment Setup**: Ensure you have Go set up as outlined in
the [Go official installation documentation](https://go.dev/doc/install) for your environment

## Installation

Expand Down Expand Up @@ -153,7 +155,7 @@ A couple of things to note:
- `gnoland config init` initializes a default configuration
- `gnoland secrets init` initializes new node secrets (validator key, node p2p key)

Essentially, `gnoland start --lazy` is simply a combination of `gnoland secrets generate` and `gnoland config generate`,
Essentially, `gnoland start --lazy` is simply a combination of `gnoland secrets init` and `gnoland config init`,
with the default options enabled.

#### Changing the node configuration
Expand Down Expand Up @@ -244,7 +246,7 @@ locally will be the validator node for the new Gno network.
To display the generated node key data, run the following command:

```shell
gnoland secrets get ValidatorPrivateKey
gnoland secrets get validator_key
```

This will display the information we need for updating the `genesis.json`:
Expand Down
9 changes: 5 additions & 4 deletions docs/how-to-guides/connecting-from-go.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ func main() {
A few things to note:
- You can view keys in your local keybase by running `gnokey list`.
- You can get the password from a user input using the IO package.
- `Signer` can also be initialized in-memory from a BIP39 mnemonic, using the
[`SignerFromBip39`](../reference/gnoclient/signer.md#func-signerfrombip39) function.
- `Signer` can also be initialized in-memory from a BIP39 mnemonic, using the
[`SignerFromBip39`](https://gnolang.github.io/gno/github.com/gnolang/[email protected]/gno.land/pkg/gnoclient.html#SignerFromBip39)
function.

## Initialize the RPC connection & Client

Expand All @@ -115,8 +116,8 @@ if err != nil {
}
```

A list of Gno.land network endpoints & chain IDs can be found in the [Gno RPC
endpoints](../reference/rpc-endpoints.md#network-configurations) page.
A list of Gno.land network endpoints & chain IDs can be found in the
[Gno RPC endpoints](../reference/network-config.md) page.

With this, we can initialize the `gnoclient.Client` struct:

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/gnoclient/gnoclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ To see the full reference documentation for the `gnoclient` package, we recommen
visiting the [`gnoclient godoc page`](https://gnolang.github.io/gno/github.com/gnolang/[email protected]/gno.land/pkg/gnoclient.html).

For a tutorial on how to use the `gnoclient` package, check out
["How to connect a Go app to Gno.land"](../../how-to-guides/connecting-from-go.md.)
["How to connect a Go app to Gno.land"](../../how-to-guides/connecting-from-go.md)

57 changes: 57 additions & 0 deletions gno.land/cmd/gnoland/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"path/filepath"
Expand Down Expand Up @@ -58,6 +59,62 @@ func constructConfigPath(nodeDir string) string {
)
}

// printKeyValue searches and prints the given key value in JSON
func printKeyValue[T *secrets | *config.Config](
input T,
raw bool,
io commands.IO,
key ...string,
) error {
// prepareOutput prepares the JSON output, taking into account raw mode
prepareOutput := func(input any) (string, error) {
encoded, err := json.MarshalIndent(input, "", " ")
if err != nil {
return "", fmt.Errorf("unable to marshal JSON, %w", err)
}

output := string(encoded)

if raw {
if err := json.Unmarshal(encoded, &output); err != nil {
return "", fmt.Errorf("unable to unmarshal raw JSON, %w", err)
}
}

return output, nil
}

if len(key) == 0 {
// Print the entire input
output, err := prepareOutput(input)
if err != nil {
return err
}

io.Println(output)

return nil
}

// Get the value using reflect
secretValue := reflect.ValueOf(input).Elem()

// Get the value path, with sections separated out by a period
field, err := getFieldAtPath(secretValue, strings.Split(key[0], "."))
if err != nil {
return err
}

output, err := prepareOutput(field.Interface())
if err != nil {
return err
}

io.Println(output)

return nil
}

// getFieldAtPath fetches the given field from the given path
func getFieldAtPath(currentValue reflect.Value, path []string) (*reflect.Value, error) {
// Look at the current section, and figure out if
Expand Down
52 changes: 25 additions & 27 deletions gno.land/cmd/gnoland/config_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@ package main
import (
"context"
"errors"
"flag"
"fmt"
"reflect"
"strings"

"github.com/gnolang/gno/tm2/pkg/bft/config"
"github.com/gnolang/gno/tm2/pkg/commands"
)

var errInvalidConfigGetArgs = errors.New("invalid number of config get arguments provided")

type configGetCfg struct {
configCfg

raw bool
}

// newConfigGetCmd creates the config get command
func newConfigGetCmd(io commands.IO) *commands.Command {
cfg := &configCfg{}
cfg := &configGetCfg{}

cmd := commands.NewCommand(
commands.Metadata{
Name: "get",
ShortUsage: "config get <key>",
ShortUsage: "config get [flags] [<key>]",
ShortHelp: "shows the Gno node configuration",
LongHelp: "Shows the Gno node configuration at the given path " +
"by fetching the option specified at <key>",
Expand All @@ -34,40 +39,33 @@ func newConfigGetCmd(io commands.IO) *commands.Command {
return cmd
}

func execConfigGet(cfg *configCfg, io commands.IO, args []string) error {
func (c *configGetCfg) RegisterFlags(fs *flag.FlagSet) {
c.configCfg.RegisterFlags(fs)

fs.BoolVar(
&c.raw,
"raw",
false,
"output raw string values, rather than as JSON strings",
)
}

func execConfigGet(cfg *configGetCfg, io commands.IO, args []string) error {
// Load the config
loadedCfg, err := config.LoadConfigFile(cfg.configPath)
if err != nil {
return fmt.Errorf("%s, %w", tryConfigInit, err)
}

// Make sure the edit arguments are valid
if len(args) != 1 {
// Make sure the get arguments are valid
if len(args) > 1 {
return errInvalidConfigGetArgs
}

// Find and print the config field, if any
if err := printConfigField(loadedCfg, args[0], io); err != nil {
return fmt.Errorf("unable to update config field, %w", err)
}

return nil
}

// printConfigField prints the value of the field at the given path
func printConfigField(config *config.Config, key string, io commands.IO) error {
// Get the config value using reflect
configValue := reflect.ValueOf(config).Elem()

// Get the value path, with sections separated out by a period
path := strings.Split(key, ".")

field, err := getFieldAtPath(configValue, path)
if err != nil {
return err
if err := printKeyValue(loadedCfg, cfg.raw, io, args...); err != nil {
return fmt.Errorf("unable to get config field, %w", err)
}

io.Printf("%v", field.Interface())

return nil
}
Loading

0 comments on commit 3c91107

Please sign in to comment.