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

feat: add social_feed #1232

Merged
merged 12 commits into from
Jul 4, 2024
Merged
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
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
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
Loading