Skip to content

Commit

Permalink
feat: add slides for Nebular Summit 2024 (#54)
Browse files Browse the repository at this point in the history
* feat: add slides for Nebular Summit 2024

Signed-off-by: moul <[email protected]>

* chore: add carbon-now

Signed-off-by: moul <[email protected]>

* chore: update carbon config

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* feat: add counter & hello

Signed-off-by: gfanton <[email protected]>

* feat: add guest and mini users

Signed-off-by: gfanton <[email protected]>

* feat: add tamagochi + board

Signed-off-by: gfanton <[email protected]>

* fix: fix board ex

Signed-off-by: gfanton <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* feat: add blog

Signed-off-by: gfanton <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* fix: admin blog

Signed-off-by: gfanton <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* feat: bar20 mini

Signed-off-by: gfanton <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

* chore: fixup

Signed-off-by: moul <[email protected]>

---------

Signed-off-by: moul <[email protected]>
Signed-off-by: gfanton <[email protected]>
Co-authored-by: gfanton <[email protected]>
  • Loading branch information
moul and gfanton authored Jul 13, 2024
1 parent cbd06fc commit 1cea4d8
Show file tree
Hide file tree
Showing 40 changed files with 846 additions and 3 deletions.
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ module github.com/gnolang/workshops

go 1.20

require golang.org/x/tools v0.9.1
require (
github.com/soypat/go-presentx v1.1.0
golang.org/x/tools v0.9.1
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/soypat/rebed v0.2.2 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
26 changes: 26 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
github.com/soypat/go-presentx v1.1.0 h1:M4COCoEyOUgx1NwDuEf/t6CstIs1TwKDQrthA/LYAmI=
github.com/soypat/go-presentx v1.1.0/go.mod h1:DIDpYQh+AY+gLseYAh2w0lq7i//TLn9dX7Yh5JzVfg4=
github.com/soypat/rebed v0.2.2 h1:SGQStt1jkwA/hzvqxZlvt5PzH/jzhz2/5ivzcHXpPms=
github.com/soypat/rebed v0.2.2/go.mod h1:tP1Sb7HyBNHG23LZGltBh1FL0pJOdNO1bT0EBqJOVyA=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201109182053-3db8fd265862/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo=
golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Empty file.
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions presentations/2024-07-13--nebular--manfred/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
run:
cd ..; go run golang.org/x/tools/cmd/present -http 0.0.0.0:3999 # -base ../..

runx:
cd ..; go run github.com/soypat/go-presentx -http 0.0.0.0:3999
2 changes: 2 additions & 0 deletions presentations/2024-07-13--nebular--manfred/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Slides: https://gnolang.github.io/workshops/presentations/2024-07-13--nebular--manfred/presentation.slide.html#1
Tweet: XXX
1 change: 1 addition & 0 deletions presentations/2024-07-13--nebular--manfred/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.png
15 changes: 15 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SOURCES := $(shell find . -name '*.gno')
PNGS := $(SOURCES:.gno=.png)

.PHONY: all
all: $(PNGS)

.SECONDEXPANSION:
%.png: $$(wildcard %.gno)
carbon-now --config carbon-now.json --save-as $(basename $@) $<

clean:
rm *.png

install:
yarn global add carbon-now-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package async_closure
84 changes: 84 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/atomicswap.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package atomicswap

// Swap represents an atomic swap contract.
type Swap struct {
sender std.Address
recipient std.Address
hashlock string
timelock time.Time
claimed bool
refunded bool
amountStr string
sendFn func(to std.Address)
}

func newSwap(
sender std.Address,
recipient std.Address,
hashlock string,
timelock time.Time,
amountStr string,
sendFn func(std.Address),
) *Swap {
require(time.Now().Before(timelock), "timelock must be in the future")
require(hashlock != "", "hashlock must not be empty")
return &Swap{
recipient: recipient,
sender: sender,
hashlock: hashlock,
timelock: timelock,
claimed: false,
refunded: false,
sendFn: sendFn,
amountStr: amountStr,
}
}

// Claim allows the recipient to claim the funds if they provide the correct preimage.
func (s *Swap) Claim(preimage string) {
require(!s.claimed, "already claimed")
require(!s.refunded, "already refunded")
require(std.PrevRealm().Addr() == s.recipient, "unauthorized")

hashlock := sha256.Sum256([]byte(preimage))
hashlockHex := hex.EncodeToString(hashlock[:])
require(hashlockHex == s.hashlock, "invalid preimage")

s.claimed = true
s.sendFn(s.recipient)
}

// Refund allows the sender to refund the funds after the timelock has expired.
func (s *Swap) Refund() {
require(!s.claimed, "already claimed")
require(!s.refunded, "already refunded")
require(std.PrevRealm().Addr() == s.sender, "unauthorized")
require(time.Now().After(s.timelock), "timelock not expired")

s.refunded = true
s.sendFn(s.sender)
}

func NewCustomCoinSwap(recipient std.Address, hashlock string, timelock time.Time) (int, *Swap) {
sender := std.PrevRealm().Addr()
sent := std.GetOrigSend()
require(len(sent) != 0, "at least one coin needs to be sent")
sendFn := func(to std.Address) {
banker := std.GetBanker(std.BankerTypeRealmSend)
banker.SendCoins(std.GetOrigPkgAddr(), to, sent)
}
amountStr := sent.String()
swap := newSwap(sender, recipient, hashlock, timelock, amountStr, sendFn)
counter++
id := strconv.Itoa(counter)
swaps.Set(id, swap)
return counter, swap
}

func Claim(id int, secret string) {
swaps.Get(id).Claim(secret)
}

func Refund(id int) {
swaps.Get(id).Refund(secret)
}
19 changes: 19 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/bar20.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package bar20

import "gno.land/r/demo/grc20reg"

var Bank, adm = grc20.NewBank("Bar", "BAR", 4)

var UserBanker = grc20.PrevRealmBanker(Bank)

func init() {
grc20reg.Register(Bank, "")
}

func Faucet() string {
caller := std.GetOrignCaller()
if err := adm.Mint(caller, 1_000_000); err != nil {
return "error: " + err.Error()
}
return "OK"
}
19 changes: 19 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/blog_admin.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package blog

type Post struct{}

var (
adminAuthor string = std.GetOrginCaller() // Set deployer as admin
postid int
posts []Post
)

func Post(name, body string) Post {
// Assert caller is admin
caller := std.GetOrigCaller()
if caller != adminAuthor {
panic("unauthorized")
}

// Add post ...
}
21 changes: 21 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/blog_post.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package blog

import "time"

type Post struct {
id int
Date time.Time
Name string
Comments []Post
}

var postid int

var posts []Post

func Post(name, body string) Post {
post := Post{postid, time.Now(), name, body}
posts = append(posts, post)
postid++
return post
}
18 changes: 18 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/board_comment.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package board

type Post struct{}

type Board struct{}

func (b *Board) Post(name, body string) Post

func (b *Board) Comment(id string, body string) {
if id < 0 || id >= len(b.posts) {
panic("invalid id")
}
caller := std.GetOrigCaller()

post := &b.posts[id]
comment := Post{len(post.Comment), caller, "", body}
post.Comment = append(post.Comment, post)
}
19 changes: 19 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/board_post.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package board

type Post struct {
id int
Author std.Address
Name string
Comments []Post
}

type Board struct {
posts []Post
}

func (b *Board) Post(name, body string) Post {
caller := std.GetOrigCaller()
post := Post{len(b.posts), caller, name, body}
b.posts = append(b.posts, post)
return post
}
21 changes: 21 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/carbon-now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"latest-preset": {
"t": "blackboard",
"bg": "rgba(100,245,145,1)",
"wc": false,
"fm": "Hack",
"fs": "15px",
"ln": false,
"ds": false,
"dsyoff": "20px",
"dsblur": "68px",
"wa": true,
"lh": "133%",
"pv": "0px",
"ph": "0px",
"si": false,
"wm": false,
"es": "4x",
"type": "png"
}
}
Empty file.
11 changes: 11 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/counter.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package counter

var Counter int

func Inc() {
Counter += 1
}

func Render(path string) string {
return "My Super Counter: " + Counter
}
22 changes: 22 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/counter_2.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package counter

import "std"

var (
Counter int
LastCaller std.Address
)

func Inc() int {
return addToCounter(amount)
}

func Add(amount int) int {
return addToCounter(amount)
}

func addToCounter(amount int) int {
Counter += amount
LastCaller = std.GetOrigCaller()
return Counter
}
16 changes: 16 additions & 0 deletions presentations/2024-07-13--nebular--manfred/code/dao.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dao

// Voter defines the needed methods for a voting system
type Voter interface {
// IsAccepted indicates if the voting process had been accepted
IsAccepted(voters []std.Address) bool

// IsFinished indicates if the voting process is finished
IsFinished(voters []std.Address) bool

// Vote adds a new vote to the voting system
Vote(voters []std.Address, caller std.Address, flag string)

// Status returns a human friendly string describing how the voting process is going
Status(voters []std.Address) string
}
Loading

0 comments on commit 1cea4d8

Please sign in to comment.