Skip to content

Commit

Permalink
Merge branch 'master' into docs/gnokey-tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
leohhhn authored Sep 5, 2024
2 parents e24eabd + c1a3341 commit d3126bd
Show file tree
Hide file tree
Showing 35 changed files with 2,158 additions and 436 deletions.
6 changes: 4 additions & 2 deletions contribs/gnodev/pkg/dev/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ func (n *Node) rebuildNode(ctx context.Context, genesis gnoland.GnoGenesisState)

// Setup node config
nodeConfig := newNodeConfig(n.config.TMConfig, n.config.ChainID, genesis)
nodeConfig.GenesisTxHandler = n.genesisTxHandler
nodeConfig.GenesisTxResultHandler = n.genesisTxResultHandler
// 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

// recoverFromError handles panics and converts them to errors.
Expand Down Expand Up @@ -512,7 +514,7 @@ func (n *Node) rebuildNode(ctx context.Context, genesis gnoland.GnoGenesisState)
return nil
}

func (n *Node) genesisTxHandler(ctx sdk.Context, tx std.Tx, res sdk.Result) {
func (n *Node) genesisTxResultHandler(ctx sdk.Context, tx std.Tx, res sdk.Result) {
if !res.IsErr() {
return
}
Expand Down
65 changes: 65 additions & 0 deletions examples/gno.land/r/leon/config/config.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package config

import (
"errors"
"std"
)

var (
main std.Address // leon's main address
backup std.Address // backup address
)

func init() {
main = "g125em6arxsnj49vx35f0n0z34putv5ty3376fg5"
}

func Address() std.Address {
return main
}

func Backup() std.Address {
return backup
}

func SetAddress(a std.Address) error {
if !a.IsValid() {
return errors.New("config: invalid address")
}

if err := checkAuthorized(); err != nil {
return err
}

main = a
return nil
}

func SetBackup(a std.Address) error {
if !a.IsValid() {
return errors.New("config: invalid address")
}

if err := checkAuthorized(); err != nil {
return err
}

backup = a
return nil
}

func checkAuthorized() error {
caller := std.PrevRealm().Addr()
if caller != main || caller != backup {
return errors.New("config: unauthorized")
}

return nil
}

func AssertAuthorized() {
caller := std.PrevRealm().Addr()
if caller != main || caller != backup {
panic("config: unauthorized")
}
}
1 change: 1 addition & 0 deletions examples/gno.land/r/leon/config/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/leon/config
8 changes: 8 additions & 0 deletions examples/gno.land/r/leon/home/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module gno.land/r/leon/home

require (
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/r/demo/art/gnoface v0.0.0-latest
gno.land/r/demo/art/millipede v0.0.0-latest
gno.land/r/leon/config v0.0.0-latest
)
121 changes: 121 additions & 0 deletions examples/gno.land/r/leon/home/home.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package home

import (
"std"
"strconv"

"gno.land/p/demo/ufmt"

"gno.land/r/demo/art/gnoface"
"gno.land/r/demo/art/millipede"
"gno.land/r/leon/config"
)

var (
pfp string // link to profile picture
pfpCaption string // profile picture caption
abtMe [2]string
)

func init() {
pfp = "https://i.imgflip.com/91vskx.jpg"
pfpCaption = "[My favourite painting & pfp](https://en.wikipedia.org/wiki/Wanderer_above_the_Sea_of_Fog)"
abtMe = [2]string{
`### About me
Hi, I'm Leon, a DevRel Engineer at gno.land. I am a tech enthusiast,
life-long learner, and sharer of knowledge.`,
`### Contributions
My contributions to gno.land can mainly be found
[here](https://github.com/gnolang/gno/issues?q=sort:updated-desc+author:leohhhn).
TODO import r/gh
`,
}
}

func UpdatePFP(url, caption string) {
config.AssertAuthorized()
pfp = url
pfpCaption = caption
}

func UpdateAboutMe(col1, col2 string) {
config.AssertAuthorized()
abtMe[0] = col1
abtMe[1] = col2
}

func Render(path string) string {
out := "# Leon's Homepage\n\n"

out += renderAboutMe()
out += renderBlogPosts()
out += "\n\n"
out += renderArt()

return out
}

func renderBlogPosts() string {
out := ""
//out += "## Leon's Blog Posts"

// todo fetch blog posts authored by @leohhhn
// and render them
return out
}

func renderAboutMe() string {
out := "<div class='columns-3'>"

out += "<div>\n\n"
out += ufmt.Sprintf("![my profile pic](%s)\n\n%s\n\n", pfp, pfpCaption)
out += "</div>\n\n"

out += "<div>\n\n"
out += abtMe[0] + "\n\n"
out += "</div>\n\n"

out += "<div>\n\n"
out += abtMe[1] + "\n\n"
out += "</div>\n\n"

out += "</div><!-- /columns-3 -->\n\n"

return out
}

func renderArt() string {
out := `<div class="jumbotron">` + "\n\n"
out += "# Gno Art\n\n"

out += "<div class='columns-3'>"

out += renderGnoFace()
out += renderMillipede()
out += "Empty spot :/"

out += "</div><!-- /columns-3 -->\n\n"

out += "This art is dynamic; it will change with every new block.\n\n"
out += `</div><!-- /jumbotron -->` + "\n"

return out
}

func renderGnoFace() string {
out := "<div>\n\n"
out += gnoface.Render(strconv.Itoa(int(std.GetHeight())))
out += "</div>\n\n"

return out
}

func renderMillipede() string {
out := "<div>\n\n"
out += "Millipede\n\n"
out += "```\n" + millipede.Draw(int(std.GetHeight())%10+1) + "```\n"
out += "</div>\n\n"

return out
}
1 change: 0 additions & 1 deletion gno.land/cmd/gnoland/testdata/issue_2283_cacheTypes.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,3 @@ import (
func Call(s string) {
base64.StdEncoding.DecodeString("hey")
}

202 changes: 202 additions & 0 deletions gno.land/cmd/gnoland/testdata/restart_missing_type.txtar

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions gno.land/cmd/gnoland/testdata/restart_nonval.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This txtar tests for starting up a non-validator node; then also restarting it.
loadpkg gno.land/p/demo/avl

gnoland start -non-validator
gnoland restart
Loading

0 comments on commit d3126bd

Please sign in to comment.