Skip to content

Commit

Permalink
Merge branch 'master' into dev/aeddi/gnokms-gnokey-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddi committed Feb 19, 2025
2 parents 030a273 + ec696d4 commit 0fc3dd3
Show file tree
Hide file tree
Showing 29 changed files with 1,629 additions and 158 deletions.
66 changes: 66 additions & 0 deletions .github/goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ builds:
goarch:
- amd64
- arm64
- id: gnodev
dir: ./contribs/gnodev/cmd/gnodev
binary: gnodev
ldflags:
# using hardcoded ldflag
- -X github.com/gnolang/gno/gnovm/pkg/gnoenv._GNOROOT=/gnoroot
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
# Gno Contribs
# NOTE: Contribs binary will be added in a single docker image below: gnocontribs
- id: gnobro
Expand Down Expand Up @@ -307,6 +321,48 @@ dockers:
ids:
- gnofaucet

# gnodev
- use: buildx
dockerfile: Dockerfile.release
goos: linux
goarch: amd64
image_templates:
- "ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Version }}-amd64"
- "ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Env.TAG_VERSION }}-amd64"
build_flag_templates:
- "--target=gnodev"
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}/gnodev"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
ids:
- gnodev
extra_files:
- examples
- gno.land/genesis/genesis_balances.txt
- gno.land/genesis/genesis_txs.jsonl
- use: buildx
dockerfile: Dockerfile.release
goos: linux
goarch: arm64
image_templates:
- "ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Version }}-arm64v8"
- "ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Env.TAG_VERSION }}-arm64v8"
build_flag_templates:
- "--target=gnodev"
- "--platform=linux/arm64/v8"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}/gnodev"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
ids:
- gnodev
extra_files:
- examples
- gno.land/genesis/genesis_balances.txt
- gno.land/genesis/genesis_txs.jsonl

# gnocontribs
- use: buildx
dockerfile: Dockerfile.release
Expand Down Expand Up @@ -406,6 +462,16 @@ docker_manifests:
- ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-amd64
- ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-arm64v8

# gnodev
- name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Version }}
image_templates:
- ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Version }}-amd64
- ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Version }}-arm64v8
- name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Env.TAG_VERSION }}
image_templates:
- ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Env.TAG_VERSION }}-amd64
- ghcr.io/gnolang/{{ .ProjectName }}/gnodev:{{ .Env.TAG_VERSION }}-arm64v8

# gnocontribs
- name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }}
image_templates:
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ COPY ./gnofaucet /usr/bin/gnofaucet
EXPOSE 5050
ENTRYPOINT [ "/usr/bin/gnofaucet" ]

#
## ghcr.io/gnolang/gno/gnodev
FROM base as gnodev

COPY ./gnodev /usr/bin/gnodev
COPY ./examples /gnoroot/examples/
COPY ./gno.land/genesis/genesis_balances.txt /gnoroot/gno.land/genesis/genesis_balances.txt
COPY ./gno.land/genesis/genesis_txs.jsonl /gnoroot/gno.land/genesis/genesis_txs.jsonl
# gnoweb exposed by default
EXPOSE 8888
ENTRYPOINT [ "/usr/bin/gnodev" ]

#
## ghcr.io/gnolang/gno
FROM base as gno
Expand Down
93 changes: 30 additions & 63 deletions examples/gno.land/r/leon/config/config.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ package config
import (
"errors"
"std"
"strconv"
"strings"
"time"

"gno.land/p/demo/avl"
p "gno.land/p/demo/avl/pager"
"gno.land/p/demo/ownable"
"gno.land/p/demo/ufmt"
"gno.land/p/moul/md"
"gno.land/p/moul/realmpath"
"gno.land/p/demo/seqid"
)

var (
cfgID seqid.ID
configs = avl.NewTree()
pager = p.NewPager(configs, 10, false)
banner = "---\n[[Leon's Home page]](/r/leon/home) | [[GitHub: @leohhhn]](https://github.com/leohhhn)\n\n---"

absPath = strings.TrimPrefix(std.CurrentRealm().PkgPath(), std.GetChainDomain())

// SafeObjects
Expand All @@ -29,6 +25,8 @@ var (
)

type Config struct {
id seqid.ID
name string
lines string
updated time.Time
}
Expand All @@ -38,81 +36,50 @@ func AddConfig(name, lines string) {
panic(ErrUnauthorized)
}

configs.Set(name, Config{
id := cfgID.Next()
configs.Set(id.String(), Config{
id: id,
name: name,
lines: lines,
updated: time.Now(),
}) // no overwrite check
})
}

func RemoveConfig(name string) {
func EditConfig(id string, name, lines string) {
if !IsAuthorized(std.PrevRealm().Addr()) {
panic(ErrUnauthorized)
}

if _, ok := configs.Remove(name); !ok {
panic("no config with that name")
raw, ok := configs.Remove(id)
if !ok {
panic("no config with that id")
}

conf := raw.(Config)
// Overwrites data
conf.lines = lines
conf.name = name
conf.updated = time.Now()
}

func UpdateBanner(newBanner string) {
func RemoveConfig(id string) {
if !IsAuthorized(std.PrevRealm().Addr()) {
panic(ErrUnauthorized)
}

banner = newBanner
}

func IsAuthorized(addr std.Address) bool {
return addr == OwnableMain.Owner() || addr == OwnableBackup.Owner()
}

func Banner() string {
return banner
}

func Render(path string) (out string) {
req := realmpath.Parse(path)
if req.Path == "" {
out += md.H1("Leon's config package")

out += ufmt.Sprintf("Leon's main address: %s\n\n", OwnableMain.Owner().String())
out += ufmt.Sprintf("Leon's backup address: %s\n\n", OwnableBackup.Owner().String())

out += md.H2("Leon's configs")

if configs.Size() == 0 {
out += "No configs yet :c\n\n"
}

page := pager.MustGetPageByPath(path)
for _, item := range page.Items {
out += ufmt.Sprintf("- [%s](%s:%s)\n\n", item.Key, absPath, item.Key)
}

out += page.Picker()
out += "\n\n"
out += "Page " + strconv.Itoa(page.PageNumber) + " of " + strconv.Itoa(page.TotalPages) + "\n\n"

out += Banner()

return out
if _, ok := configs.Remove(id); !ok {
panic("no config with that id")
}

return renderConfPage(req.Path)
}

func renderConfPage(confName string) (out string) {
raw, ok := configs.Get(confName)
if !ok {
out += md.H1("404")
out += "That config does not exist :/"
return out
func UpdateBanner(newBanner string) {
if !IsAuthorized(std.PrevRealm().Addr()) {
panic(ErrUnauthorized)
}

conf := raw.(Config)
out += md.H1(confName)
out += ufmt.Sprintf("```\n%s\n```\n\n", conf.lines)
out += ufmt.Sprintf("_Last updated on %s_", conf.updated.Format("02 Jan, 2006"))
banner = newBanner
}

return out
func IsAuthorized(addr std.Address) bool {
return addr == OwnableMain.Owner() || addr == OwnableBackup.Owner()
}
69 changes: 69 additions & 0 deletions examples/gno.land/r/leon/config/render.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package config

import (
"strconv"

p "gno.land/p/demo/avl/pager"
"gno.land/p/demo/ufmt"
"gno.land/p/moul/md"
"gno.land/p/moul/realmpath"
"gno.land/p/moul/txlink"
)

var (
banner = "---\n[[Leon's Home page]](/r/leon/home) | [[Leon's snippets]](/r/leon/config) | [[GitHub: @leohhhn]](https://github.com/leohhhn)\n\n---"
pager = p.NewPager(configs, 10, true)
)

func Banner() string {
return banner
}

func Render(path string) (out string) {
req := realmpath.Parse(path)
if req.Path == "" {
out += md.H1("Leon's configs & snippets")

out += ufmt.Sprintf("Leon's main address: %s\n\n", OwnableMain.Owner().String())
out += ufmt.Sprintf("Leon's backup address: %s\n\n", OwnableBackup.Owner().String())

out += md.H2("Snippets")

if configs.Size() == 0 {
out += "No configs yet :c\n\n"
} else {
page := pager.MustGetPageByPath(path)
for _, item := range page.Items {
out += ufmt.Sprintf("- [%s](%s:%s)\n\n", item.Value.(Config).name, absPath, item.Key)
}

out += page.Picker()
out += "\n\n"
out += "Page " + strconv.Itoa(page.PageNumber) + " of " + strconv.Itoa(page.TotalPages) + "\n\n"
}

out += Banner()

return out
}

return renderConfPage(req.Path)
}

func renderConfPage(id string) (out string) {
raw, ok := configs.Get(id)
if !ok {
out += md.H1("404")
out += "That config does not exist :/"
return out
}

conf := raw.(Config)
out += md.H1(conf.name)
out += ufmt.Sprintf("```\n%s\n```\n\n", conf.lines)
out += ufmt.Sprintf("_Last updated on %s_\n\n", conf.updated.Format("02 Jan, 2006"))
out += md.HorizontalRule()
out += ufmt.Sprintf("[[EDIT]](%s) - [[DELETE]](%s)", txlink.Call("EditConfig", "id", conf.id.String()), txlink.Call("RemoveConfig", "id", conf.id.String()))

return out
}
3 changes: 1 addition & 2 deletions gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func TestBuiltinIdentifiersShadowing(t *testing.T) {
"println",
"recover",
"nil",
"bigint",
"bool",
"byte",
"float32",
Expand Down Expand Up @@ -247,7 +246,7 @@ func main() {
},
{
`package test
func main() {
const f = float64(1.0)
println(int64(f))
Expand Down
8 changes: 4 additions & 4 deletions gnovm/pkg/gnolang/gonative.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,9 @@ func gno2GoType(t Type) reflect.Type {
return reflect.TypeOf(float32(0))
case Float64Type:
return reflect.TypeOf(float64(0))
case BigintType, UntypedBigintType:
case UntypedBigintType:
panic("not yet implemented")
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
panic("not yet implemented")
default:
panic("should not happen")
Expand Down Expand Up @@ -887,9 +887,9 @@ func gno2GoTypeMatches(t Type, rt reflect.Type) (result bool) {
return rt.Kind() == reflect.Float32
case Float64Type:
return rt.Kind() == reflect.Float64
case BigintType, UntypedBigintType:
case UntypedBigintType:
panic("not yet implemented")
case BigdecType, UntypedBigdecType:
case UntypedBigdecType:
panic("not yet implemented")
default:
panic("should not happen")
Expand Down
20 changes: 19 additions & 1 deletion gnovm/pkg/gnolang/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2119,12 +2119,28 @@ func (x *PackageNode) SetBody(b Body) {
// such as those for *DeclaredType methods or *StructType fields,
// see tests/selector_test.go.
type ValuePath struct {
Type VPType // see VPType* consts.
Type VPType // see VPType* consts.
// Warning: Use SetDepth() to set Depth.
Depth uint8 // see doc for ValuePath.
Index uint16 // index of value, field, or method.
Name Name // name of value, field, or method.
}

// Maximum depth of a ValuePath.
const MaxValuePathDepth = 127

func (vp ValuePath) validateDepth() {
if vp.Depth > MaxValuePathDepth {
panic(fmt.Sprintf("exceeded maximum %s depth (%d)", vp.Type, MaxValuePathDepth))
}
}

func (vp *ValuePath) SetDepth(d uint8) {
vp.Depth = d

vp.validateDepth()
}

type VPType uint8

const (
Expand Down Expand Up @@ -2203,6 +2219,8 @@ func NewValuePathNative(n Name) ValuePath {
}

func (vp ValuePath) Validate() {
vp.validateDepth()

switch vp.Type {
case VPUverse:
if vp.Depth != 0 {
Expand Down
Loading

0 comments on commit 0fc3dd3

Please sign in to comment.