Skip to content

Commit 6f6bb36

Browse files
committed
chore: Merge branch 'forbid-import-cycle' into gno-resolver
2 parents 95963dc + 6e1a134 commit 6f6bb36

File tree

106 files changed

+3801
-2589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+3801
-2589
lines changed

.gitattributes

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
go.sum linguist-generated text
44
gnovm/stdlibs/generated.go linguist-generated
55
gnovm/tests/stdlibs/generated.go linguist-generated
6+
*.gen.gno linguist-generated
7+
*.gen_test.gno linguist-generated
8+
*.gen.go linguist-generated
9+
*.gen_test.go linguist-generated

.github/workflows/examples.yml

+8
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,20 @@ jobs:
7171
- run: make lint -C ./examples
7272
# TODO: consider running lint on every other directories, maybe in "warning" mode?
7373
# TODO: track coverage
74+
7475
fmt:
7576
name: Run gno fmt on examples
7677
uses: ./.github/workflows/gnofmt_template.yml
7778
with:
7879
path: "examples/..."
7980

81+
generate:
82+
name: Check generated files are up to date
83+
uses: ./.github/workflows/build_template.yml
84+
with:
85+
modulepath: "examples"
86+
go-version: "1.22.x"
87+
8088
mod-tidy:
8189
strategy:
8290
fail-fast: false

contribs/gnodev/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ require (
8282
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
8383
github.com/yuin/goldmark v1.7.2 // indirect
8484
github.com/yuin/goldmark-emoji v1.0.2 // indirect
85+
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc // indirect
8586
github.com/zondax/hid v0.9.2 // indirect
8687
github.com/zondax/ledger-go v0.14.3 // indirect
8788
go.etcd.io/bbolt v1.3.11 // indirect

contribs/gnodev/go.sum

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contribs/gnodev/pkg/dev/node.go

+2
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ func (n *Node) rebuildNode(ctx context.Context, genesis gnoland.GnoGenesisState)
496496
// Speed up stdlib loading after first start (saves about 2-3 seconds on each reload).
497497
nodeConfig.CacheStdlibLoad = true
498498
nodeConfig.Genesis.ConsensusParams.Block.MaxGas = n.config.MaxGasPerBlock
499+
// Genesis verification is always false with Gnodev
500+
nodeConfig.SkipGenesisVerification = true
499501

500502
// recoverFromError handles panics and converts them to errors.
501503
recoverFromError := func() {

contribs/gnogenesis/internal/txs/txs_add_packages.go

+87-28
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,56 @@ import (
55
"errors"
66
"flag"
77
"fmt"
8-
9-
"github.com/gnolang/gno/gnovm/pkg/packages"
10-
"github.com/gnolang/gno/tm2/pkg/crypto"
8+
"os"
119

1210
"github.com/gnolang/gno/gno.land/pkg/gnoland"
1311
"github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot"
12+
"github.com/gnolang/gno/gnovm/pkg/packages"
1413
"github.com/gnolang/gno/tm2/pkg/bft/types"
1514
"github.com/gnolang/gno/tm2/pkg/commands"
15+
"github.com/gnolang/gno/tm2/pkg/crypto/keys"
1616
"github.com/gnolang/gno/tm2/pkg/std"
1717
)
1818

19-
var (
20-
errInvalidPackageDir = errors.New("invalid package directory")
21-
errInvalidDeployerAddr = errors.New("invalid deployer address")
19+
const (
20+
defaultAccount_Name = "test1"
21+
defaultAccount_Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
22+
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"
23+
defaultAccount_publicKey = "gpub1pgfj7ard9eg82cjtv4u4xetrwqer2dntxyfzxz3pq0skzdkmzu0r9h6gny6eg8c9dc303xrrudee6z4he4y7cs5rnjwmyf40yaj"
2224
)
2325

26+
var errInvalidPackageDir = errors.New("invalid package directory")
27+
2428
// Keep in sync with gno.land/cmd/start.go
25-
var (
26-
defaultCreator = crypto.MustAddressFromString("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // test1
27-
genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000)))
28-
)
29+
var genesisDeployFee = std.NewFee(50000, std.MustParseCoin(ugnot.ValueString(1000000)))
2930

3031
type addPkgCfg struct {
31-
txsCfg *txsCfg
32-
deployerAddress string
32+
txsCfg *txsCfg
33+
keyName string
34+
gnoHome string // default GNOHOME env var, just here to ease testing with parallel tests
35+
insecurePasswordStdin bool
3336
}
3437

3538
func (c *addPkgCfg) RegisterFlags(fs *flag.FlagSet) {
3639
fs.StringVar(
37-
&c.deployerAddress,
38-
"deployer-address",
39-
defaultCreator.String(),
40-
"the address that will be used to deploy the package",
40+
&c.keyName,
41+
"key-name",
42+
"",
43+
"The package deployer key name or address contained on gnokey",
44+
)
45+
46+
fs.StringVar(
47+
&c.gnoHome,
48+
"gno-home",
49+
os.Getenv("GNOHOME"),
50+
"the gno home directory",
51+
)
52+
53+
fs.BoolVar(
54+
&c.insecurePasswordStdin,
55+
"insecure-password-stdin",
56+
false,
57+
"the gno home directory",
4158
)
4259
}
4360

@@ -66,30 +83,46 @@ func execTxsAddPackages(
6683
io commands.IO,
6784
args []string,
6885
) error {
86+
var (
87+
keyname = defaultAccount_Name
88+
keybase keys.Keybase
89+
pass string
90+
)
6991
// Load the genesis
70-
genesis, loadErr := types.GenesisDocFromFile(cfg.txsCfg.GenesisPath)
71-
if loadErr != nil {
72-
return fmt.Errorf("unable to load genesis, %w", loadErr)
92+
genesis, err := types.GenesisDocFromFile(cfg.txsCfg.GenesisPath)
93+
if err != nil {
94+
return fmt.Errorf("unable to load genesis, %w", err)
7395
}
7496

7597
// Make sure the package dir is set
7698
if len(args) == 0 {
7799
return errInvalidPackageDir
78100
}
79101

80-
var (
81-
creator = defaultCreator
82-
err error
83-
)
84-
85-
// Check if the deployer address is set
86-
if cfg.deployerAddress != defaultCreator.String() {
87-
creator, err = crypto.AddressFromString(cfg.deployerAddress)
102+
if cfg.keyName != "" {
103+
keyname = cfg.keyName
104+
keybase, err = keys.NewKeyBaseFromDir(cfg.gnoHome)
105+
if err != nil {
106+
return fmt.Errorf("unable to load keybase: %w", err)
107+
}
108+
pass, err = io.GetPassword("Enter password.", cfg.insecurePasswordStdin)
88109
if err != nil {
89-
return fmt.Errorf("%w, %w", errInvalidDeployerAddr, err)
110+
return fmt.Errorf("cannot read password: %w", err)
111+
}
112+
} else {
113+
keybase = keys.NewInMemory()
114+
_, err := keybase.CreateAccount(defaultAccount_Name, defaultAccount_Seed, "", "", 0, 0)
115+
if err != nil {
116+
return fmt.Errorf("unable to create account: %w", err)
90117
}
91118
}
92119

120+
info, err := keybase.GetByNameOrAddress(keyname)
121+
if err != nil {
122+
return fmt.Errorf("unable to find key in keybase: %w", err)
123+
}
124+
125+
creator := info.GetAddress()
93126
parsedTxs := make([]gnoland.TxWithMetadata, 0)
94127
for _, path := range args {
95128
// Generate transactions from the packages (recursively)
@@ -99,6 +132,10 @@ func execTxsAddPackages(
99132
return fmt.Errorf("unable to load txs from directory, %w", err)
100133
}
101134

135+
if err := signTxs(txs, keybase, genesis.ChainID, keyname, pass); err != nil {
136+
return fmt.Errorf("unable to sign txs, %w", err)
137+
}
138+
102139
parsedTxs = append(parsedTxs, txs...)
103140
}
104141

@@ -119,3 +156,25 @@ func execTxsAddPackages(
119156

120157
return nil
121158
}
159+
160+
func signTxs(txs []gnoland.TxWithMetadata, keybase keys.Keybase, chainID, keyname string, password string) error {
161+
for index, tx := range txs {
162+
// Here accountNumber and sequenceNumber are set to 0 because they are considered as 0 on genesis transactions.
163+
signBytes, err := tx.Tx.GetSignBytes(chainID, 0, 0)
164+
if err != nil {
165+
return fmt.Errorf("unable to load txs from directory, %w", err)
166+
}
167+
signature, publicKey, err := keybase.Sign(keyname, password, signBytes)
168+
if err != nil {
169+
return fmt.Errorf("unable sign tx %w", err)
170+
}
171+
txs[index].Tx.Signatures = []std.Signature{
172+
{
173+
PubKey: publicKey,
174+
Signature: signature,
175+
},
176+
}
177+
}
178+
179+
return nil
180+
}

0 commit comments

Comments
 (0)