Skip to content

Commit

Permalink
Merge branch 'master' into feat/312
Browse files Browse the repository at this point in the history
  • Loading branch information
omarsy authored Dec 17, 2024
2 parents c0808ea + 9f181d1 commit 08dba29
Show file tree
Hide file tree
Showing 165 changed files with 5,487 additions and 4,871 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/gnoland.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,25 @@ jobs:
tests-extra-args: "-coverpkg=github.com/gnolang/gno/gno.land/..."
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}

gnoweb_generate:
strategy:
fail-fast: false
matrix:
go-version: ["1.22.x"]
# unittests: TODO: matrix with contracts
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- uses: actions/setup-node@v4
with:
node-version: lts/Jod # (22.x) https://github.com/nodejs/Release
- uses: actions/checkout@v4
- run: |
make -C gno.land/pkg/gnoweb fclean generate
# Check if there are changes after running generate.gnoweb
git diff --exit-code || \
(echo "\`gnoweb generate\` out of date, please run \`make gnoweb.generate\` within './gno.land'" && exit 1)
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ ENTRYPOINT ["/usr/bin/gno"]
# gnoweb
FROM base AS gnoweb
COPY --from=build-gno /gnoroot/build/gnoweb /usr/bin/gnoweb
COPY --from=build-gno /opt/gno/src/gno.land/cmd/gnoweb /opt/gno/src/gnoweb
EXPOSE 8888
ENTRYPOINT ["/usr/bin/gnoweb"]

Expand Down
48 changes: 31 additions & 17 deletions contribs/gnodev/cmd/gnodev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ type devCfg struct {
txsFile string

// Web Configuration
noWeb bool
webHTML bool
webListenerAddr string
webRemoteHelperAddr string
webWithHTML bool

// Node Configuration
minimal bool
Expand Down Expand Up @@ -123,6 +124,20 @@ func (c *devCfg) RegisterFlags(fs *flag.FlagSet) {
"gno root directory",
)

fs.BoolVar(
&c.noWeb,
"no-web",
defaultDevOptions.noWeb,
"disable gnoweb",
)

fs.BoolVar(
&c.webHTML,
"web-html",
defaultDevOptions.webHTML,
"gnoweb: enable unsafe HTML parsing in markdown rendering",
)

fs.StringVar(
&c.webListenerAddr,
"web-listener",
Expand All @@ -137,13 +152,6 @@ func (c *devCfg) RegisterFlags(fs *flag.FlagSet) {
"gnoweb: web server help page's remote addr (default to <node-rpc-listener>)",
)

fs.BoolVar(
&c.webWithHTML,
"web-with-html",
defaultDevOptions.webWithHTML,
"gnoweb: enable HTML parsing in markdown rendering",
)

fs.StringVar(
&c.nodeRPCListenerAddr,
"node-rpc-listener",
Expand Down Expand Up @@ -323,7 +331,10 @@ func execDev(cfg *devCfg, args []string, io commands.IO) (err error) {
defer server.Close()

// Setup gnoweb
webhandler := setupGnoWebServer(logger.WithGroup(WebLogName), cfg, devNode)
webhandler, err := setupGnoWebServer(logger.WithGroup(WebLogName), cfg, devNode)
if err != nil {
return fmt.Errorf("unable to setup gnoweb server: %w", err)
}

// Setup unsafe APIs if enabled
if cfg.unsafeAPI {
Expand Down Expand Up @@ -351,14 +362,17 @@ func execDev(cfg *devCfg, args []string, io commands.IO) (err error) {
mux.Handle("/", webhandler)
}

go func() {
err := server.ListenAndServe()
cancel(err)
}()
// Serve gnoweb
if !cfg.noWeb {
go func() {
err := server.ListenAndServe()
cancel(err)
}()

logger.WithGroup(WebLogName).
Info("gnoweb started",
"lisn", fmt.Sprintf("http://%s", server.Addr))
logger.WithGroup(WebLogName).
Info("gnoweb started",
"lisn", fmt.Sprintf("http://%s", server.Addr))
}

watcher, err := watcher.NewPackageWatcher(loggerEvents, emitterServer)
if err != nil {
Expand All @@ -377,7 +391,7 @@ func execDev(cfg *devCfg, args []string, io commands.IO) (err error) {
return runEventLoop(ctx, logger, book, rt, devNode, watcher)
}

var helper string = `For more in-depth documentation, visit the GNO Tooling CLI documentation:
var helper string = `For more in-depth documentation, visit the GNO Tooling CLI documentation:
https://docs.gno.land/gno-tooling/cli/gno-tooling-gnodev
P Previous TX - Go to the previous tx
Expand Down
29 changes: 18 additions & 11 deletions contribs/gnodev/cmd/gnodev/setup_web.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log/slog"
"net/http"

Expand All @@ -9,19 +10,25 @@ import (
)

// setupGnowebServer initializes and starts the Gnoweb server.
func setupGnoWebServer(logger *slog.Logger, cfg *devCfg, dnode *gnodev.Node) http.Handler {
webConfig := gnoweb.NewDefaultConfig()
func setupGnoWebServer(logger *slog.Logger, cfg *devCfg, dnode *gnodev.Node) (http.Handler, error) {
if cfg.noWeb {
return http.HandlerFunc(http.NotFound), nil
}

remote := dnode.GetRemoteAddress()

webConfig.HelpChainID = cfg.chainId
webConfig.RemoteAddr = dnode.GetRemoteAddress()
webConfig.HelpRemote = cfg.webRemoteHelperAddr
webConfig.WithHTML = cfg.webWithHTML
appcfg := gnoweb.NewDefaultAppConfig()
appcfg.UnsafeHTML = cfg.webHTML
appcfg.NodeRemote = remote
appcfg.ChainID = cfg.chainId
if cfg.webRemoteHelperAddr != "" {
appcfg.RemoteHelp = cfg.webRemoteHelperAddr
}

// If `HelpRemote` is empty default it to `RemoteAddr`
if webConfig.HelpRemote == "" {
webConfig.HelpRemote = webConfig.RemoteAddr
router, err := gnoweb.NewRouter(logger, appcfg)
if err != nil {
return nil, fmt.Errorf("unable to create router app: %w", err)
}

app := gnoweb.MakeApp(logger, webConfig)
return app.Router
return router, nil
}
10 changes: 3 additions & 7 deletions contribs/gnodev/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (

require (
dario.cat/mergo v1.0.1 // indirect
github.com/alecthomas/chroma/v2 v2.8.0 // indirect
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
Expand All @@ -48,7 +48,7 @@ require (
github.com/creack/pty v1.1.21 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand All @@ -57,10 +57,6 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/gotuna/gotuna v0.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
Expand All @@ -81,7 +77,7 @@ require (
github.com/rs/xid v1.6.0 // 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.5.4 // indirect
github.com/yuin/goldmark v1.7.2 // indirect
github.com/yuin/goldmark-emoji v1.0.2 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
Expand Down
28 changes: 10 additions & 18 deletions contribs/gnodev/go.sum

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

1 change: 1 addition & 0 deletions examples/gno.land/p/n2p5/loci/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/n2p5/loci
44 changes: 44 additions & 0 deletions examples/gno.land/p/n2p5/loci/loci.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// loci is a single purpose datastore keyed by the caller's address. It has two
// functions: Set and Get. loci is plural for locus, which is a central or core
// place where something is found or from which it originates. In this case,
// it's a simple key-value store where an address (the key) can store exactly
// one value (in the form of a byte slice). Only the caller can set the value
// for their address, but anyone can retrieve the value for any address.
package loci

import (
"std"

"gno.land/p/demo/avl"
)

// LociStore is a simple key-value store that uses
// an AVL tree to store the data.
type LociStore struct {
internal *avl.Tree
}

// New creates a reference to a new LociStore.
func New() *LociStore {
return &LociStore{
internal: avl.NewTree(),
}
}

// Set stores a byte slice in the AVL tree using the `std.PrevRealm().Addr()`
// string as the key.
func (s *LociStore) Set(value []byte) {
key := string(std.PrevRealm().Addr())
s.internal.Set(key, value)
}

// Get retrieves a byte slice from the AVL tree using the provided address.
// The return values are the byte slice value and a boolean indicating
// whether the value exists.
func (s *LociStore) Get(addr std.Address) []byte {
value, exists := s.internal.Get(string(addr))
if !exists {
return nil
}
return value.([]byte)
}
84 changes: 84 additions & 0 deletions examples/gno.land/p/n2p5/loci/loci_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package loci

import (
"std"
"testing"

"gno.land/p/demo/testutils"
)

func TestLociStore(t *testing.T) {
t.Parallel()

u1 := testutils.TestAddress("u1")
u2 := testutils.TestAddress("u1")

t.Run("TestSet", func(t *testing.T) {
t.Parallel()
store := New()
u1 := testutils.TestAddress("u1")

m1 := []byte("hello")
m2 := []byte("world")
std.TestSetOrigCaller(u1)

// Ensure that the value is nil before setting it.
r1 := store.Get(u1)
if r1 != nil {
t.Errorf("expected value to be nil, got '%s'", r1)
}
store.Set(m1)
// Ensure that the value is correct after setting it.
r2 := store.Get(u1)
if string(r2) != "hello" {
t.Errorf("expected value to be 'hello', got '%s'", r2)
}
store.Set(m2)
// Ensure that the value is correct after overwriting it.
r3 := store.Get(u1)
if string(r3) != "world" {
t.Errorf("expected value to be 'world', got '%s'", r3)
}
})
t.Run("TestGet", func(t *testing.T) {
t.Parallel()
store := New()
u1 := testutils.TestAddress("u1")
u2 := testutils.TestAddress("u2")
u3 := testutils.TestAddress("u3")
u4 := testutils.TestAddress("u4")

m1 := []byte("hello")
m2 := []byte("world")
m3 := []byte("goodbye")

std.TestSetOrigCaller(u1)
store.Set(m1)
std.TestSetOrigCaller(u2)
store.Set(m2)
std.TestSetOrigCaller(u3)
store.Set(m3)

// Ensure that the value is correct after setting it.
r0 := store.Get(u4)
if r0 != nil {
t.Errorf("expected value to be nil, got '%s'", r0)
}
// Ensure that the value is correct after setting it.
r1 := store.Get(u1)
if string(r1) != "hello" {
t.Errorf("expected value to be 'hello', got '%s'", r1)
}
// Ensure that the value is correct after setting it.
r2 := store.Get(u2)
if string(r2) != "world" {
t.Errorf("expected value to be 'world', got '%s'", r2)
}
// Ensure that the value is correct after setting it.
r3 := store.Get(u3)
if string(r3) != "goodbye" {
t.Errorf("expected value to be 'goodbye', got '%s'", r3)
}
})

}
Loading

0 comments on commit 08dba29

Please sign in to comment.