Skip to content

Commit

Permalink
Merge branch 'master' into dev/moul/rolist
Browse files Browse the repository at this point in the history
  • Loading branch information
moul authored Jan 9, 2025
2 parents 724cd6e + 2438505 commit 4c47c7b
Show file tree
Hide file tree
Showing 276 changed files with 23,036 additions and 9,307 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
go.sum linguist-generated text
gnovm/stdlibs/generated.go linguist-generated
gnovm/tests/stdlibs/generated.go linguist-generated
*.gen.gno linguist-generated
*.gen_test.gno linguist-generated
*.gen.go linguist-generated
*.gen_test.go linguist-generated
1 change: 1 addition & 0 deletions .github/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ issues:
- gosec # Disabled linting of weak number generators
- makezero # Disabled linting of intentional slice appends
- goconst # Disabled linting of common mnemonics and test case strings
- unused # Disabled linting of unused mock methods
- path: _\.gno
linters:
- errorlint # Disabled linting of error comparisons, because of lacking std lib support
9 changes: 9 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
paths:
- gnovm/**/*.gno
- examples/**/*.gno
- examples/**/gno.mod

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down Expand Up @@ -70,12 +71,20 @@ jobs:
- run: make lint -C ./examples
# TODO: consider running lint on every other directories, maybe in "warning" mode?
# TODO: track coverage

fmt:
name: Run gno fmt on examples
uses: ./.github/workflows/gnofmt_template.yml
with:
path: "examples/..."

generate:
name: Check generated files are up to date
uses: ./.github/workflows/build_template.yml
with:
modulepath: "examples"
go-version: "1.22.x"

mod-tidy:
strategy:
fail-fast: false
Expand Down
2 changes: 2 additions & 0 deletions contribs/gnodev/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ require (
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/sig-0/insertion-queue v0.0.0-20241004125609-6b3ca841346b // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/yuin/goldmark v1.7.2 // indirect
github.com/yuin/goldmark-emoji v1.0.2 // indirect
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.11 // indirect
Expand Down
9 changes: 9 additions & 0 deletions contribs/gnodev/go.sum

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

2 changes: 2 additions & 0 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ func (n *Node) rebuildNode(ctx context.Context, genesis gnoland.GnoGenesisState)
// Speed up stdlib loading after first start (saves about 2-3 seconds on each reload).
nodeConfig.CacheStdlibLoad = true
nodeConfig.Genesis.ConsensusParams.Block.MaxGas = n.config.MaxGasPerBlock
// Genesis verification is always false with Gnodev
nodeConfig.SkipGenesisVerification = true

// recoverFromError handles panics and converts them to errors.
recoverFromError := func() {
Expand Down
1 change: 1 addition & 0 deletions contribs/gnofaucet/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/sig-0/insertion-queue v0.0.0-20241004125609-6b3ca841346b // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions contribs/gnofaucet/go.sum

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

2 changes: 2 additions & 0 deletions contribs/gnogenesis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/sig-0/insertion-queue v0.0.0-20241004125609-6b3ca841346b // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
Expand All @@ -49,6 +50,7 @@ require (
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions contribs/gnogenesis/go.sum

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

112 changes: 86 additions & 26 deletions contribs/gnogenesis/internal/txs/txs_add_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"errors"
"flag"
"fmt"
"os"

"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/crypto/keys"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
Expand All @@ -15,28 +16,45 @@ import (
"github.com/gnolang/gno/tm2/pkg/std"
)

var (
errInvalidPackageDir = errors.New("invalid package directory")
errInvalidDeployerAddr = errors.New("invalid deployer address")
const (
defaultAccount_Name = "test1"
defaultAccount_Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
defaultAccount_Seed = "source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast"
defaultAccount_publicKey = "gpub1pgfj7ard9eg82cjtv4u4xetrwqer2dntxyfzxz3pq0skzdkmzu0r9h6gny6eg8c9dc303xrrudee6z4he4y7cs5rnjwmyf40yaj"
)

var errInvalidPackageDir = errors.New("invalid package directory")

// Keep in sync with gno.land/cmd/start.go
var (
defaultCreator = crypto.MustAddressFromString("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // test1
genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000)))
)
var genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000)))

type addPkgCfg struct {
txsCfg *txsCfg
deployerAddress string
txsCfg *txsCfg
keyName string
gnoHome string // default GNOHOME env var, just here to ease testing with parallel tests
insecurePasswordStdin bool
}

func (c *addPkgCfg) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(
&c.deployerAddress,
"deployer-address",
defaultCreator.String(),
"the address that will be used to deploy the package",
&c.keyName,
"key-name",
"",
"The package deployer key name or address contained on gnokey",
)

fs.StringVar(
&c.gnoHome,
"gno-home",
os.Getenv("GNOHOME"),
"the gno home directory",
)

fs.BoolVar(
&c.insecurePasswordStdin,
"insecure-password-stdin",
false,
"the gno home directory",
)
}

Expand Down Expand Up @@ -65,30 +83,46 @@ func execTxsAddPackages(
io commands.IO,
args []string,
) error {
var (
keyname = defaultAccount_Name
keybase keys.Keybase
pass string
)
// Load the genesis
genesis, loadErr := types.GenesisDocFromFile(cfg.txsCfg.GenesisPath)
if loadErr != nil {
return fmt.Errorf("unable to load genesis, %w", loadErr)
genesis, err := types.GenesisDocFromFile(cfg.txsCfg.GenesisPath)
if err != nil {
return fmt.Errorf("unable to load genesis, %w", err)
}

// Make sure the package dir is set
if len(args) == 0 {
return errInvalidPackageDir
}

var (
creator = defaultCreator
err error
)

// Check if the deployer address is set
if cfg.deployerAddress != defaultCreator.String() {
creator, err = crypto.AddressFromString(cfg.deployerAddress)
if cfg.keyName != "" {
keyname = cfg.keyName
keybase, err = keys.NewKeyBaseFromDir(cfg.gnoHome)
if err != nil {
return fmt.Errorf("unable to load keybase: %w", err)
}
pass, err = io.GetPassword("Enter password.", cfg.insecurePasswordStdin)
if err != nil {
return fmt.Errorf("cannot read password: %w", err)
}
} else {
keybase = keys.NewInMemory()
_, err := keybase.CreateAccount(defaultAccount_Name, defaultAccount_Seed, "", "", 0, 0)
if err != nil {
return fmt.Errorf("%w, %w", errInvalidDeployerAddr, err)
return fmt.Errorf("unable to create account: %w", err)
}
}

info, err := keybase.GetByNameOrAddress(keyname)
if err != nil {
return fmt.Errorf("unable to find key in keybase: %w", err)
}

creator := info.GetAddress()
parsedTxs := make([]gnoland.TxWithMetadata, 0)
for _, path := range args {
// Generate transactions from the packages (recursively)
Expand All @@ -97,6 +131,10 @@ func execTxsAddPackages(
return fmt.Errorf("unable to load txs from directory, %w", err)
}

if err := signTxs(txs, keybase, genesis.ChainID, keyname, pass); err != nil {
return fmt.Errorf("unable to sign txs, %w", err)
}

parsedTxs = append(parsedTxs, txs...)
}

Expand All @@ -117,3 +155,25 @@ func execTxsAddPackages(

return nil
}

func signTxs(txs []gnoland.TxWithMetadata, keybase keys.Keybase, chainID, keyname string, password string) error {
for index, tx := range txs {
// Here accountNumber and sequenceNumber are set to 0 because they are considered as 0 on genesis transactions.
signBytes, err := tx.Tx.GetSignBytes(chainID, 0, 0)
if err != nil {
return fmt.Errorf("unable to load txs from directory, %w", err)
}
signature, publicKey, err := keybase.Sign(keyname, password, signBytes)
if err != nil {
return fmt.Errorf("unable sign tx %w", err)
}
txs[index].Tx.Signatures = []std.Signature{
{
PubKey: publicKey,
Signature: signature,
},
}
}

return nil
}
Loading

0 comments on commit 4c47c7b

Please sign in to comment.