Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some notes for n0izn0iz #6

Open
wants to merge 7 commits into
base: da0-da0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions IDEA.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
create interface packages

type TheInterface interface {
Whatever()
}

create a realm for each of these interface package with funcs

func Register(v TheInferface)

implementerRealm := std.PrevRealm()
tree.Set(implementerRealm, v)

func Get(address std.Address) TheInterface

return tree.Get(address)


when you implement an interface in a new realm

var implem = newImplem()

func init() {
the_interface_realm.Register(implem)
}

when you want to consume the interface via realm ref (package path or address) in some realm created before the implem

func DoSomething(realmRef Realm) {
the_interface_realm.Get(realmRef).Whatever()
}
34 changes: 34 additions & 0 deletions examples/gno.land/p/demo/binutils/binutils.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package binutils

import (
"encoding/binary"
"errors"
)

var ErrInvalidLengthPrefixedString = errors.New("invalid length-prefixed string")

func EncodeLengthPrefixedStringUint16BE(s string) []byte {
b := make([]byte, 2+len(s))
binary.BigEndian.PutUint16(b, uint16(len(s)))
copy(b[2:], s)
return b
}

func DecodeLengthPrefixedStringUint16BE(b []byte) (string, []byte, error) {
if len(b) < 2 {
return "", nil, ErrInvalidLengthPrefixedString
}
l := binary.BigEndian.Uint16(b)
if len(b) < 2+int(l) {
return "", nil, ErrInvalidLengthPrefixedString
}
return string(b[2 : 2+l]), b[l+2:], nil
}

func MustDecodeLengthPrefixedStringUint16BE(b []byte) (string, []byte) {
s, r, err := DecodeLengthPrefixedStringUint16BE(b)
if err != nil {
panic(err)
}
return s, r
}
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/binutils/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/binutils
30 changes: 30 additions & 0 deletions examples/gno.land/p/demo/cpavl/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
pkgpath=p/demo/cpavl
pkguri=gno.land/$(pkgpath)
pkgsrc=.

chainid=dev
gnoland=localhost:26657
gnoweb=http://localhost:8888
wallet=onblock-test

#chainid=test3
#gnoland=test3.gno.land:36657
#gnoweb=https://test3.gno.land
#wallet=dev

.PHONY: deploy.package
deploy.pkg:
gnokey maketx addpkg \
-deposit="1ugnot" \
-gas-fee="1ugnot" \
-gas-wanted="5000000" \
-broadcast="true" \
-remote="$(gnoland)" \
-chainid="$(chainid)" \
-pkgdir="./$(pkgsrc)" \
-pkgpath="$(pkguri)" \
$(wallet)

.PHONY: open.pkg
open.pkg:
open "$(gnoweb)/$(pkgpath)"
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/cpavl/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/cpavl
Loading