-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/nft-p2e
- Loading branch information
Showing
70 changed files
with
5,994 additions
and
359 deletions.
There are no files selected for viewing
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,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 |
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,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 |
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 |
---|---|---|
|
@@ -14,6 +14,8 @@ web-build/ | |
/android | ||
/app-build/ | ||
|
||
gnobuild/ | ||
|
||
# macOS | ||
.DS_Store | ||
|
||
|
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
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
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 @@ | ||
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 | ||
} |
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 @@ | ||
module gno.land/p/demo/teritori/binutils |
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,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++ | ||
} |
Oops, something went wrong.