-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,524 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.PHONY: clean | ||
clean: | ||
rm -rf */gno.me | ||
rm -rf */cmd/*/gno.me |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module github.com/deelawn/gno-workshop | ||
|
||
go 1.21.2 | ||
|
||
require github.com/gnolang/gno v0.0.0-00010101000000-000000000000 | ||
|
||
require ( | ||
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect | ||
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect | ||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect | ||
github.com/cockroachdb/apd/v3 v3.2.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect | ||
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 // indirect | ||
github.com/go-logr/logr v1.4.1 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/gorilla/websocket v1.5.1 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect | ||
github.com/libp2p/go-buffer-pool v0.1.0 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rs/xid v1.5.0 // indirect | ||
github.com/stretchr/testify v1.9.0 // indirect | ||
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect | ||
go.opentelemetry.io/otel v1.25.0 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.25.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.25.0 // indirect | ||
go.opentelemetry.io/otel/sdk v1.25.0 // indirect | ||
go.opentelemetry.io/otel/sdk/metric v1.25.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.25.0 // indirect | ||
go.opentelemetry.io/proto/otlp v1.1.0 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
golang.org/x/crypto v0.21.0 // indirect | ||
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect | ||
golang.org/x/mod v0.16.0 // indirect | ||
golang.org/x/net v0.23.0 // indirect | ||
golang.org/x/sys v0.18.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
golang.org/x/tools v0.19.0 // indirect | ||
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect | ||
google.golang.org/grpc v1.63.0 // indirect | ||
google.golang.org/protobuf v1.33.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) | ||
|
||
// replace github.com/gnolang/gno => github.com/deelawn/gno v0.0.4-workshop | ||
replace github.com/gnolang/gno => ../gnoland/fork/gno |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Phase 1 | ||
|
||
## Goal | ||
Embed a Gno VM inside a Go application. | ||
|
||
## Instructions | ||
- The included `hello.gno` file is a Gno application with a `main` function. | ||
- The `main.go` file has code that embeds a Gno VM and runs Gno code provided from `stdin`. | ||
- Run the program to interpret `hello.gno` by issuing the command `cat hello.gno | go run main.go`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
func main() { | ||
println("hello") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/gnolang/gno/gno.me/gno" | ||
) | ||
|
||
func main() { | ||
vm, _ := gno.NewVM() | ||
input, err := io.ReadAll(os.Stdin) | ||
if err != nil { | ||
panic("failed to read input") | ||
} | ||
|
||
res, err := vm.Run(context.Background(), string(input)) | ||
if err != nil { | ||
fmt.Println("run error:", err.Error()) | ||
return | ||
} | ||
|
||
fmt.Println("result:", res) | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
presentations/2024-05-23--belgrade--dylan/phase-2/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Phase 2 | ||
|
||
## Goal | ||
Embed a Gno VM in a CLI application, create a Gno application, and interact with it by calling functions. | ||
|
||
## Instructions | ||
- The `adder.gno` application is included here along with the Go app, `main.go` | ||
- Run `go run main.go create -file adder.gno` to create the `adder` app. | ||
- Run `go run main.go call -app adder -func Add -args 2` to add 2 to the application's running total | ||
- Run `go run main.go call -app adder -func Value` to obtain the `adder` app's current value via its `Value` function |
11 changes: 11 additions & 0 deletions
11
presentations/2024-05-23--belgrade--dylan/phase-2/adder.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package adder | ||
|
||
var value int | ||
|
||
func Add(n int) { | ||
value += n | ||
} | ||
|
||
func Value() int { | ||
return value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/gnolang/gno/gno.me/gno" | ||
) | ||
|
||
var ( | ||
// call flags | ||
callSet = flag.NewFlagSet("call", flag.ExitOnError) | ||
callApp = callSet.String("app", "", "app to call") | ||
callFunc = callSet.String("func", "", "function to call") | ||
callIsPkg = callSet.Bool("pkg", false, "is package") | ||
|
||
// create flags | ||
createSet = flag.NewFlagSet("create", flag.ExitOnError) | ||
createIsPkg = createSet.Bool("pkg", false, "is package") | ||
createFile = createSet.String("file", "", "name of the .gno file") | ||
) | ||
|
||
type sliceFlag []string | ||
|
||
func (s *sliceFlag) Set(value string) error { | ||
*s = append(*s, value) | ||
return nil | ||
} | ||
|
||
func (s *sliceFlag) String() string { | ||
return strings.Join(*s, ",") | ||
} | ||
|
||
func main() { | ||
vm, _ := gno.NewVM() | ||
|
||
var callArgs sliceFlag | ||
callSet.Var(&callArgs, "args", "arguments to call function with") | ||
|
||
if len(os.Args) < 2 { | ||
flag.Usage() | ||
os.Exit(1) | ||
} | ||
|
||
var ( | ||
result string | ||
err error | ||
) | ||
|
||
switch os.Args[1] { | ||
case "call": | ||
callSet.Parse(os.Args[2:]) | ||
result, _, err = vm.Call(context.Background(), *callApp, *callIsPkg, *callFunc, callArgs...) | ||
case "create": | ||
createSet.Parse(os.Args[2:]) | ||
var code []byte | ||
code, err = os.ReadFile(*createFile) | ||
if err != nil { | ||
panic("failed to read file") | ||
} | ||
|
||
_, err = vm.Create(context.Background(), string(code), *createIsPkg, false) | ||
} | ||
|
||
if err != nil { | ||
fmt.Println("error:", err.Error()) | ||
return | ||
} | ||
|
||
if result == "" { | ||
result = "OK" | ||
} | ||
|
||
fmt.Println("result:", result) | ||
} |
11 changes: 11 additions & 0 deletions
11
presentations/2024-05-23--belgrade--dylan/phase-3/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Phase 3 | ||
|
||
## Goal | ||
Create an app via a web UI and render the app in the browser. | ||
|
||
## Instructions | ||
- Run `go run main.go` | ||
- Navigate to `localhost:4591/installer` | ||
- Copy the code from `myname.gno` and past it into the text box on the web page. | ||
- Click submit to create the application. | ||
- Append your name to `localhost:4591/myname:` and navigate to that address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gnolang/gno/gno.me/apps" | ||
"github.com/gnolang/gno/gno.me/gno" | ||
"github.com/gnolang/gno/gno.me/http" | ||
) | ||
|
||
const port = "4591" | ||
|
||
func main() { | ||
vm, firstStartup := gno.NewVM() | ||
if firstStartup { | ||
if err := apps.CreatePort(vm); err != nil { // installer dependency | ||
fmt.Println("could not create port app: " + err.Error()) | ||
return | ||
} | ||
|
||
if err := apps.CreateInstaller(vm); err != nil { | ||
fmt.Println("could not create installer app: " + err.Error()) | ||
return | ||
} | ||
} | ||
|
||
server := http.NewServer(vm, port) | ||
fmt.Println("Server started on port " + port) | ||
fmt.Println("Visit http://localhost:" + port + "/installer") | ||
if err := server.ListenAndServe(); err != nil { | ||
panic("could not start server: " + err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package myname | ||
|
||
func Render(arg string) string { | ||
return "Hi, my name is " + arg | ||
} |
14 changes: 14 additions & 0 deletions
14
presentations/2024-05-23--belgrade--dylan/phase-4/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Phase 4 | ||
|
||
## Goal | ||
Allow a user to remotely install an application from another user. | ||
|
||
## Instructions | ||
- Open two terminal windows, one for each the `cmd/alice` and `cmd/bob` directories | ||
- In each directory, run `go run main.go` | ||
- Alice is running on port 4591, Bob on 4592 | ||
- Install an app on Alice's VM by navigating to `localhost:4591/installer`, pasting the code from `myname.gno` from phase 4, and submitting. | ||
- Navigate to `localhost:4591/myname:Alice` to ensure that the app was installed. | ||
- Now navigate to `localhost:4592/remoteinstaller` on Bob's machine. | ||
- Type in Alice's address, `localhost:4591`, and the name of the app to install on Bob's VM, `myname` | ||
- Navigate to `localhost:4592/myname` to confirm the installation succeeded. |
36 changes: 36 additions & 0 deletions
36
presentations/2024-05-23--belgrade--dylan/phase-4/cmd/alice/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/gnolang/gno/gno.me/server" | ||
) | ||
|
||
const port = "4591" | ||
|
||
func main() { | ||
gnoServer := server.Start(port, "") | ||
|
||
// Create a channel to receive signals. | ||
sigs := make(chan os.Signal, 1) | ||
done := make(chan struct{}) | ||
|
||
// Register a signal handler. | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
// Start a goroutine to handle signals. | ||
go func() { | ||
<-sigs | ||
fmt.Println("Shutting down server...") | ||
gnoServer.Stop() | ||
close(done) | ||
}() | ||
|
||
fmt.Println("Server started on port " + port) | ||
fmt.Println("Visit http://localhost:" + port + "/installer") | ||
|
||
<-done | ||
} |
36 changes: 36 additions & 0 deletions
36
presentations/2024-05-23--belgrade--dylan/phase-4/cmd/bob/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/gnolang/gno/gno.me/server" | ||
) | ||
|
||
const port = "4592" | ||
|
||
func main() { | ||
gnoServer := server.Start(port, "") | ||
|
||
// Create a channel to receive signals. | ||
sigs := make(chan os.Signal, 1) | ||
done := make(chan struct{}) | ||
|
||
// Register a signal handler. | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
// Start a goroutine to handle signals. | ||
go func() { | ||
<-sigs | ||
fmt.Println("Shutting down server...") | ||
gnoServer.Stop() | ||
close(done) | ||
}() | ||
|
||
fmt.Println("Server started on port " + port) | ||
fmt.Println("Visit http://localhost:" + port + "/remote-installer") | ||
|
||
<-done | ||
} |
11 changes: 11 additions & 0 deletions
11
presentations/2024-05-23--belgrade--dylan/phase-5/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Phase 5 | ||
|
||
## Goal | ||
Install an app that other users can install. Sync the app data to all users' machines. | ||
|
||
## Instructions | ||
- Open two terminal windows, one for each the `cmd/alice` and `cmd/bob` directories | ||
- In each directory, run `go run main.go` | ||
- Alice is running on port 4591, Bob on 4592 | ||
- Open the provided postman collection and execute the requests in order OR run the provided `run_all.sh` file | ||
- Running the postman collection, one request at a time and navigating to `localhost:<port>/postit` on each of the users' machines, allows you to see how each request is updating, and then syncing, the state. |
Binary file added
BIN
+1.28 MB
presentations/2024-05-23--belgrade--dylan/phase-5/cmd/alice/gno.me/gno.me.db/000007.log
Binary file not shown.
Binary file added
BIN
+2.02 MB
presentations/2024-05-23--belgrade--dylan/phase-5/cmd/alice/gno.me/gno.me.db/000009.ldb
Binary file not shown.
Binary file added
BIN
+982 KB
presentations/2024-05-23--belgrade--dylan/phase-5/cmd/alice/gno.me/gno.me.db/000010.ldb
Binary file not shown.
1 change: 1 addition & 0 deletions
1
presentations/2024-05-23--belgrade--dylan/phase-5/cmd/alice/gno.me/gno.me.db/CURRENT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MANIFEST-000000 |
Empty file.
34 changes: 34 additions & 0 deletions
34
presentations/2024-05-23--belgrade--dylan/phase-5/cmd/alice/gno.me/gno.me.db/LOG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
=============== May 28, 2024 (PDT) =============== | ||
06:54:37.005053 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed | ||
06:54:37.067111 db@open opening | ||
06:54:37.068561 version@stat F·[] S·0B[] Sc·[] | ||
06:54:37.089002 db@janitor F·2 G·0 | ||
06:54:37.089065 db@open done T·21.879138ms | ||
06:54:37.643179 memdb@flush N·7644 S·3MiB | ||
06:54:37.685601 memdb@flush created L0@3 N·7644 S·994KiB "s/1,v3":"vminit,v1" | ||
06:54:37.685702 version@stat F·[1] S·994KiB[994KiB] Sc·[0.25] | ||
06:54:37.723547 memdb@flush committed F·1 T·80.253591ms | ||
06:54:37.724382 journal@remove removed @1 | ||
06:54:38.197763 memdb@flush N·6050 S·3MiB | ||
06:54:38.226077 memdb@flush created L0@5 N·6050 S·778KiB "s/_..a:1,v13650":"s/_..nge,v13466" | ||
06:54:38.226146 version@stat F·[2] S·1MiB[1MiB] Sc·[0.50] | ||
06:54:38.245589 memdb@flush committed F·1 T·47.761802ms | ||
06:54:38.246605 journal@remove removed @2 | ||
06:54:38.668148 table@compaction L0·2 -> L1·0 S·1MiB Q·16458 | ||
06:54:38.717169 table@build created L1@6 N·13642 S·1MiB "s/1,v3":"vminit,v1" | ||
06:54:38.717296 version@stat F·[0 1] S·1MiB[0B 1MiB] Sc·[0.00 0.02] | ||
06:54:38.736837 table@compaction committed F-1 S+11KiB Ke·0 D·52 T·68.635839ms | ||
06:54:38.737297 table@remove removed @5 | ||
06:54:38.737549 table@remove removed @3 | ||
06:54:38.978399 memdb@flush N·5007 S·3MiB | ||
06:54:39.017137 memdb@flush created L0@8 N·5007 S·1MiB "s/10,v14877":"s/latest,v14384" | ||
06:54:39.017412 version@stat F·[1 1] S·3MiB[1MiB 1MiB] Sc·[0.25 0.02] | ||
06:54:39.055930 memdb@flush committed F·1 T·77.460675ms | ||
06:54:39.058280 journal@remove removed @4 | ||
06:54:39.147515 table@compaction L0·1 -> L1·1 S·3MiB Q·20990 | ||
06:54:39.192477 table@build created L1@9 N·9983 S·2MiB "s/1,v3":"s/_..486,v849" | ||
06:54:39.228060 table@build created L1@10 N·6592 S·981KiB "s/_..487,v850":"vminit,v1" | ||
06:54:39.228158 version@stat F·[0 2] S·2MiB[0B 2MiB] Sc·[0.00 0.03] | ||
06:54:39.268591 table@compaction committed F~ S-97KiB Ke·0 D·2074 T·120.982514ms | ||
06:54:39.269293 table@remove removed @8 | ||
06:54:39.269798 table@remove removed @6 |
Binary file added
BIN
+535 Bytes
presentations/2024-05-23--belgrade--dylan/phase-5/cmd/alice/gno.me/gno.me.db/MANIFEST-000000
Binary file not shown.
Oops, something went wrong.