Skip to content

Commit

Permalink
Merge branch 'main' into fix/nft-p2e
Browse files Browse the repository at this point in the history
  • Loading branch information
n0izn0iz authored Jul 4, 2024
2 parents b6c5a4f + f7cded0 commit 8b4e36a
Show file tree
Hide file tree
Showing 70 changed files with 5,994 additions and 359 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/gno-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Gno Lint

on:
push:
branches:
- main
pull_request:
merge_group:

jobs:
go:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: "1.22"
- name: Clean gno
run: make clean-gno

- name: Clone gno
run: make clone-gno

- name: Build GnoVM
run: make build-gno

- name: Lint gno
run: make lint-gno
30 changes: 30 additions & 0 deletions .github/workflows/gno-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Gno Test

on:
push:
branches:
- main
pull_request:
merge_group:

jobs:
go:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: "1.22"

- name: Clean gno
run: make clean-gno

- name: Clone gno
run: make clone-gno

- name: Build GnoVM
run: make build-gno

- name: Test gno
run: make test-gno
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ web-build/
/android
/app-build/

gnobuild/

# macOS
.DS_Store

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
diff --git a/bin/provider/jsonrpc/jsonrpc.d.ts b/bin/provider/jsonrpc/jsonrpc.d.ts
index 434273193c4f38a5eefaa9d43b3114bc44e5fd0e..69f2922f8fd30cd56021db887619fab0f012935c 100644
index 3b50e8ec390e5e344ef81d928aea8976c4020cb6..759408444a434f801c540c2f95923ab7aff46c35 100644
--- a/bin/provider/jsonrpc/jsonrpc.d.ts
+++ b/bin/provider/jsonrpc/jsonrpc.d.ts
@@ -23,5 +23,5 @@ export declare class JSONRPCProvider implements Provider {
getAccountNumber(address: string, height?: number): Promise<number>;
getStatus(): Promise<Status>;
sendTransaction(tx: string): Promise<string>;
@@ -25,5 +25,5 @@ export declare class JSONRPCProvider implements Provider {
sendTransaction<K extends keyof BroadcastTransactionMap>(tx: string, endpoint: K): Promise<BroadcastTransactionMap[K]['result']>;
private broadcastTxSync;
private broadcastTxCommit;
- waitForTransaction(hash: string, fromHeight?: number, timeout?: number): Promise<Tx>;
+ waitForTransaction(hash: string, fromHeight?: number, timeout?: number): Promise<{tx: Tx, height: number, index: number}>;
}
diff --git a/bin/provider/provider.d.ts b/bin/provider/provider.d.ts
index a5b37aacb3b9c47bec2a4bc6fe1bb7f653656ee5..d9aa2d8a703c9c40d58695643e3718b2c82aaf5a 100644
index 4fcb051ea4dd924bfbdfcf3ca697982a3504d88f..4908d25744a3b06194263e2bdd54c7bee058a6df 100644
--- a/bin/provider/provider.d.ts
+++ b/bin/provider/provider.d.ts
@@ -82,5 +82,5 @@ export interface Provider {
@@ -84,5 +84,5 @@ export interface Provider {
* @param {number} [fromHeight=latest] The block height used to begin the search
* @param {number} [timeout=15000] Optional wait timeout in MS
*/
Expand Down Expand Up @@ -44,13 +44,13 @@ index 82a13a73ec49ed3970dc0567bac5b4bfc4fa8c41..b860d1d4d4d45dd24073a3a3aba665be
}
_b.label = 4;
diff --git a/bin/provider/websocket/ws.d.ts b/bin/provider/websocket/ws.d.ts
index a373b6af1d5cb158d4c129199e565b9fe16f5548..05e8cc7c9a7fd7d89154a1f4a0441f1133ff742f 100644
index 1a41dcc96ba11d576d8a56c84ccd826764299a12..6e7c65aac957ab7f95ffcee66ffd70b5fd15507a 100644
--- a/bin/provider/websocket/ws.d.ts
+++ b/bin/provider/websocket/ws.d.ts
@@ -51,5 +51,5 @@ export declare class WSProvider implements Provider {
getAccountNumber(address: string, height?: number): Promise<number>;
getStatus(): Promise<Status>;
sendTransaction(tx: string): Promise<string>;
@@ -53,5 +53,5 @@ export declare class WSProvider implements Provider {
sendTransaction<K extends keyof BroadcastTransactionMap>(tx: string, endpoint: K): Promise<BroadcastTransactionMap[K]['result']>;
private broadcastTxSync;
private broadcastTxCommit;
- waitForTransaction(hash: string, fromHeight?: number, timeout?: number): Promise<Tx>;
+ waitForTransaction(hash: string, fromHeight?: number, timeout?: number): Promise<{tx: Tx, height: number, index: number}>;
}
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,20 @@ generate.internal-contracts-clients: node_modules
|| exit 1 ;\
npx tsx packages/scripts/makeTypescriptIndex $${outdir} || exit 1 ; \
done


clone-gno:
cd gnobuild && git clone https://github.com/gnolang/gno.git
cp -r ./gno/p ./gnobuild/gno/examples/gno.land/p/demo/teritori

build-gno:
cd gnobuild/gno/gnovm && make build

lint-gno:
./gnobuild/gno/gnovm/build/gno lint ./gno/. -v

test-gno:
./gnobuild/gno/gnovm/build/gno test ./gno/... -v

clean-gno:
rm -rf gnobuild
mkdir gnobuild
34 changes: 34 additions & 0 deletions gno/p/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 gno/p/binutils/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/teritori/binutils
183 changes: 183 additions & 0 deletions gno/p/dao_core/dao_core.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package core

import (
"std"

dao_interfaces "gno.land/p/demo/teritori/dao_interfaces"
"gno.land/p/demo/teritori/markdown_utils"
)

// TODO: add wrapper message handler to handle multiple proposal modules messages

type daoCore struct {
dao_interfaces.IDAOCore

votingModule dao_interfaces.IVotingModule
proposalModules []dao_interfaces.ActivableProposalModule
activeProposalModuleCount int
realm std.Realm
registry *dao_interfaces.MessagesRegistry
}

func NewDAOCore(
votingModuleFactory dao_interfaces.VotingModuleFactory,
proposalModulesFactories []dao_interfaces.ProposalModuleFactory,
messageHandlersFactories []dao_interfaces.MessageHandlerFactory,
) dao_interfaces.IDAOCore {
if votingModuleFactory == nil {
panic("Missing voting module factory")
}

if len(proposalModulesFactories) == 0 {
panic("No proposal modules factories")
}

core := &daoCore{
realm: std.CurrentRealm(),
activeProposalModuleCount: len(proposalModulesFactories),
registry: dao_interfaces.NewMessagesRegistry(),
proposalModules: make([]dao_interfaces.ActivableProposalModule, len(proposalModulesFactories)),
}

core.votingModule = votingModuleFactory(core)
if core.votingModule == nil {
panic("voting module factory returned nil")
}

for i, modFactory := range proposalModulesFactories {
mod := modFactory(core)
if mod == nil {
panic("proposal module factory returned nil")
}
core.proposalModules[i] = dao_interfaces.ActivableProposalModule{
Enabled: true,
Module: mod,
}
}

// this registry is specific to gno since we can't do dynamic calls
core.registry.Register(NewUpdateVotingModuleMessageHandler(core))
core.registry.Register(NewUpdateProposalModulesMessageHandler(core))
for _, handlerFactory := range messageHandlersFactories {
handler := handlerFactory(core)
if handler == nil {
panic("message handler factory returned nil")
}
core.registry.Register(handler)
}

return core
}

// mutations

func (d *daoCore) UpdateVotingModule(newVotingModule dao_interfaces.IVotingModule) {
if std.CurrentRealm().Addr() != d.realm.Addr() { // not sure this check necessary since the ownership system should protect against mutation from other realms
panic(ErrUnauthorized)
}

// FIXME: check da0-da0 implem
d.votingModule = newVotingModule
}

func (d *daoCore) UpdateProposalModules(toAdd []dao_interfaces.IProposalModule, toDisable []int) {
if std.CurrentRealm().Addr() != d.realm.Addr() { // not sure this check necessary since the ownership system should protect against mutation from other realms
panic(ErrUnauthorized)
}

for _, module := range toAdd {
d.addProposalModule(module)
}

for _, moduleIndex := range toDisable {
module := GetProposalModule(d, moduleIndex)

if !module.Enabled {
panic(ErrModuleAlreadyDisabled)
}
module.Enabled = false

d.activeProposalModuleCount--
if d.activeProposalModuleCount == 0 {
panic("no active proposal modules") // this -> `panic(ErrNoActiveProposalModules)` triggers `panic: reflect: reflect.Value.SetString using value obtained using unexported field`
}
}
}

// queries

func (d *daoCore) ProposalModules() []dao_interfaces.ActivableProposalModule {
return d.proposalModules
}

func (d *daoCore) VotingModule() dao_interfaces.IVotingModule {
return d.votingModule
}

func (d *daoCore) VotingPowerAtHeight(address std.Address, height int64) uint64 {
return d.VotingModule().VotingPowerAtHeight(address, height)
}

func (d *daoCore) ActiveProposalModuleCount() int {
return d.activeProposalModuleCount
}

func (d *daoCore) Render(path string) string {
s := "# DAO Core\n"
s += "This is an attempt at porting [DA0-DA0 contracts](https://github.com/DA0-DA0/dao-contracts)\n"
s += markdown_utils.Indent(d.votingModule.Render(path)) + "\n"
for _, propMod := range d.proposalModules {
if !propMod.Enabled {
continue
}
s += markdown_utils.Indent(propMod.Module.Render(path)) + "\n"
}
return s
}

func (d *daoCore) Registry() *dao_interfaces.MessagesRegistry {
return d.registry
}

// TODO: move this helper in dao interfaces

func GetProposalModule(core dao_interfaces.IDAOCore, moduleIndex int) *dao_interfaces.ActivableProposalModule {
if moduleIndex < 0 {
panic("module index must be >= 0")
}
mods := core.ProposalModules()
if moduleIndex >= len(mods) {
panic("invalid module index")
}
return &mods[moduleIndex]
}

// internal

func (d *daoCore) executeMsgs(msgs []dao_interfaces.ExecutableMessage) {
for _, msg := range msgs {
d.registry.Execute(msg)
}
}

func (d *daoCore) addProposalModule(proposalMod dao_interfaces.IProposalModule) {
for _, mod := range d.proposalModules {
if mod.Module != proposalMod {
continue
}

if mod.Enabled {
panic(ErrModuleAlreadyAdded)
}
mod.Enabled = true
d.activeProposalModuleCount++
return
}

d.proposalModules = append(d.proposalModules, dao_interfaces.ActivableProposalModule{
Enabled: true,
Module: proposalMod,
})

d.activeProposalModuleCount++
}
Loading

0 comments on commit 8b4e36a

Please sign in to comment.