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

Develop contract + testing social feed #1

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6b210f7
wip: init + testing social feed
hthieu1110 Jul 3, 2023
7562657
feat: add tests
hthieu1110 Jul 4, 2023
8f67fcb
wip: try to output object to strinng
hthieu1110 Jul 4, 2023
3f5d519
wip: stringify objects
Jul 5, 2023
72eb493
feat: user binutils to convert data to buffer
hthieu1110 Jul 5, 2023
121faab
feat: add binutils
hthieu1110 Jul 5, 2023
5dc2d12
Merge branch 'feat/add-socia-feed-realm' of github.com:TERITORI/gno i…
hthieu1110 Jul 5, 2023
87cf403
wip: encoding reactions
Jul 6, 2023
7c1f7a2
feat: add GetPost by id
hthieu1110 Jul 6, 2023
fc909b0
wip: handle subposts
hthieu1110 Jul 10, 2023
e2a6a60
feat: add pagination for query posts/comments
Jul 10, 2023
736143e
feat: handle pginnations for posts
hthieu1110 Jul 10, 2023
c683cd3
chore: remove uneeded files
hthieu1110 Jul 10, 2023
c6ea0c6
Merge remote-tracking branch 'origin' into feat/add-socia-feed-realm
hthieu1110 Aug 3, 2023
18d7e3b
fix: remove unneeded AssertOrig
hthieu1110 Aug 3, 2023
b48e66d
feat: add render + remove check for origCaller
hthieu1110 Aug 5, 2023
6fb95d7
feat: add extra binutils
hthieu1110 Aug 5, 2023
dc88135
feat: add extra binutils
hthieu1110 Aug 5, 2023
a440d7f
chore: update module name
hthieu1110 Aug 5, 2023
5adb1a9
chore: update module name
hthieu1110 Aug 5, 2023
20481ba
feat: handle all categories
hthieu1110 Aug 8, 2023
030a5fb
feat: update social_feeds_v4
hthieu1110 Aug 8, 2023
5f05ad7
chore: optimize test code
hthieu1110 Aug 12, 2023
0f93a72
Add TipPost + tests
hthieu1110 Aug 12, 2023
480ebcc
Add filter by user + test
hthieu1110 Aug 12, 2023
e681af4
feat: add migration to social_feeds
hthieu1110 Aug 13, 2023
03e03a9
wip: add flag
hthieu1110 Aug 14, 2023
c662f34
wip: add flags
hthieu1110 Aug 14, 2023
2e93a46
wip
hthieu1110 Aug 15, 2023
208face
wip: add missinng files
hthieu1110 Aug 15, 2023
f9ffa3c
fix: test bank send
hthieu1110 Aug 15, 2023
d282920
chore: change branch
hthieu1110 Aug 16, 2023
cefd249
wip: handle flag posts
hthieu1110 Aug 17, 2023
cecc1fd
wip: handle flag post + temporary fix filter hidden posts due to Get…
hthieu1110 Aug 18, 2023
5871be5
feat: add hiddenPostsForUser
hthieu1110 Aug 18, 2023
56df907
chore: add daodao pkg
hthieu1110 Aug 21, 2023
1301aeb
Merge remote-tracking branch 'origin/master' into feat/add-socia-feed…
hthieu1110 Aug 21, 2023
a6b3eb1
chore: add files for daodao plg
hthieu1110 Aug 21, 2023
af44d23
chore: add needed utils
hthieu1110 Aug 21, 2023
c5b3f9f
wip: add flag post
hthieu1110 Aug 21, 2023
ea6a39b
feat: done flag post + exec
hthieu1110 Aug 22, 2023
95285aa
chore: rename social_feeds_v5
hthieu1110 Aug 22, 2023
749b9b2
feat: deploy all updated versions
hthieu1110 Aug 22, 2023
86d82b0
fix: add missing pkg to gno.mod
hthieu1110 Sep 5, 2023
c9502dd
fix: fix pagination when querying posts
hthieu1110 Sep 5, 2023
5af5dbe
feat: add test for query out of range
hthieu1110 Sep 5, 2023
f645019
wip: migrate
hthieu1110 Sep 6, 2023
a45fd60
wip
hthieu1110 Sep 6, 2023
80c5aad
feat: done migration + wip: testing migration
hthieu1110 Sep 8, 2023
0f72bcd
feat: handle comments by parentID instead of comments array
hthieu1110 Sep 8, 2023
8948048
feat: use json encoding + adjust tests
hthieu1110 Sep 8, 2023
fcad5c5
feat: done migration JSON
hthieu1110 Sep 8, 2023
7371b6f
fix: optimize char used for metadata
hthieu1110 Sep 8, 2023
8800438
feat: add social_feeds_v8 + social_feeds_dao_v2
hthieu1110 Sep 9, 2023
ddd6f11
fix unicode pkg
hthieu1110 Sep 11, 2023
758edfc
fix: parserString
hthieu1110 Sep 11, 2023
8a20006
update gno pkg with updated ujson
hthieu1110 Sep 11, 2023
af6c3dc
update feeds with update string parsed
hthieu1110 Sep 11, 2023
3ea5128
update teritori group name
hthieu1110 Sep 14, 2023
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
42 changes: 42 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,45 @@ clean:
GOFMT_FLAGS ?= -w
fmt:
go run -modfile ../misc/devdeps/go.mod mvdan.cc/gofumpt $(GOFMT_FLAGS) `find . -name "*.gno"`

.PHONY: create.pkg
create.pkg:
gnokey maketx addpkg \
-deposit="1ugnot" \
-gas-fee="1ugnot" \
-gas-wanted="5000000" \
-broadcast="true" \
-pkgdir="." \
-pkgpath="gno.land/r/demo/social_feeds_v3" \
-chainid "teritori-1" \
-remote "https://testnet.gno.teritori.com:26657" \
test1

.PHONY: create.feed
create.feed:
gnokey maketx call \
-pkgpath "gno.land/r/demo/social_feeds_v4" \
-func "CreateFeed" \
-gas-fee 1000000ugnot \
-gas-wanted 3000000 \
-send "" \
-broadcast \
-args "teritori" \
-chainid "teritori-1" \
-remote "https://testnet.gno.teritori.com:26657" \
test1

.PHONE: create.post
create.post:
gnokey maketx call \
-pkgpath "gno.land/r/demo/social_feeds_v3" \
-func "CreatePost" \
-gas-fee 1000000ugnot \
-gas-wanted 2000000 \
-send "" \
-broadcast \
-args "1" \
-args "0" \
-args "2" \
-args '{"gifs": [], "files": [], "title": "", "message": "Hello world !", "hashtags": [], "mentions": [], "createdAt": "2023-08-03T01:39:45.522Z", "updatedAt": "2023-08-03T01:39:45.522Z"}' \
test1
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
70 changes: 70 additions & 0 deletions examples/gno.land/p/demo/daodao/core_v6/dao_core.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package core

import (
"std"
"strings"

dao_interfaces "gno.land/p/demo/daodao/interfaces_v6"
"gno.land/p/demo/markdown_utils"
)

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

type IDAOCore interface {
AddProposalModule(proposalMod dao_interfaces.IProposalModule)

VotingModule() dao_interfaces.IVotingModule
ProposalModules() []dao_interfaces.IProposalModule

Render(path string) string
}

type daoCore struct {
IDAOCore

votingModule dao_interfaces.IVotingModule
proposalModules []dao_interfaces.IProposalModule
}

func NewDAOCore(
votingModule dao_interfaces.IVotingModule,
proposalModules []dao_interfaces.IProposalModule,
) IDAOCore {
return &daoCore{
votingModule: votingModule,
proposalModules: proposalModules,
}
}

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

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

func (d *daoCore) AddProposalModule(proposalMod dao_interfaces.IProposalModule) {
d.proposalModules = append(d.proposalModules, proposalMod)
}

func (d *daoCore) Render(path string) string {
s := "# DAO Core\n"
s += "This is a port of [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 {
s += markdown_utils.Indent(propMod.Render(path)) + "\n"
}
return s
}

func GetProposalModule(core IDAOCore, moduleIndex int) dao_interfaces.IProposalModule {
if moduleIndex < 0 {
panic("Module index must be >= 0")
}
mods := core.ProposalModules()
if moduleIndex >= len(mods) {
panic("invalid module index")
}
return mods[moduleIndex]
}
6 changes: 6 additions & 0 deletions examples/gno.land/p/demo/daodao/core_v6/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/p/demo/daodao/core_v6

require (
"gno.land/p/demo/daodao/interfaces_v6" v0.0.0-latest
"gno.land/p/demo/markdown_utils" v0.0.0-latest
)
172 changes: 172 additions & 0 deletions examples/gno.land/p/demo/daodao/interfaces_v6/dao_interfaces.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package dao_interfaces

import (
"std"
"strconv"

"gno.land/p/demo/avl"
"gno.land/p/demo/jsonutil_v4"
)

type IVotingModule interface {
VotingPower(addr std.Address) uint64
TotalPower() uint64
Render(path string) string
}

type Ballot struct {
Power uint64
Vote Vote
Rationale string
}

func (b Ballot) ToJSON() string {
return jsonutil.FormatObject([]jsonutil.KeyValue{
{Key: "power", Value: b.Power},
{Key: "vote", Value: b.Vote},
{Key: "rationale", Value: b.Rationale},
})
}

type Votes struct {
Yes uint64
No uint64
Abstain uint64
}

func (v *Votes) Add(vote Vote, power uint64) {
switch vote {
case VoteYes:
v.Yes += power
case VoteNo:
v.No += power
case VoteAbstain:
v.Abstain += power
default:
panic("unknown vote kind")
}
}

func (v *Votes) Remove(vote Vote, power uint64) {
switch vote {
case VoteYes:
v.Yes -= power
case VoteNo:
v.No -= power
case VoteAbstain:
v.Abstain -= power
default:
panic("unknown vote kind")
}
}

func (v *Votes) Total() uint64 {
return v.Yes + v.No + v.Abstain
}

func (v Votes) ToJSON() string {
return jsonutil.FormatObject([]jsonutil.KeyValue{
{Key: "yes", Value: v.Yes},
{Key: "no", Value: v.No},
{Key: "abstain", Value: v.Abstain},
})
}

type Proposal struct {
ID int
Title string
Description string
Proposer std.Address
Messages []ExecutableMessage
Ballots *avl.Tree // dev
// Ballots *avl.MutTree // test3
Votes Votes
Status ProposalStatus
}

var _ jsonutil.JSONAble = (*Proposal)(nil)

func (p Proposal) ToJSON() string {
return jsonutil.FormatObject([]jsonutil.KeyValue{
{Key: "id", Value: p.ID},
{Key: "title", Value: p.Title},
{Key: "description", Value: p.Description},
{Key: "proposer", Value: p.Proposer},
{Key: "messages", Value: jsonutil.FormatSlice(p.Messages), Raw: true},
{Key: "ballots", Value: p.Ballots},
{Key: "votes", Value: p.Votes},
{Key: "status", Value: p.Status},
})
}

type ProposalStatus int

const (
ProposalStatusOpen ProposalStatus = iota
ProposalStatusPassed
ProposalStatusExecuted
)

func (p ProposalStatus) ToJSON() string {
return jsonutil.FormatString(p.String())
}

func (p ProposalStatus) String() string {
switch p {
case ProposalStatusOpen:
return "Open"
case ProposalStatusPassed:
return "Passed"
case ProposalStatusExecuted:
return "Executed"
default:
return "Unknown(" + strconv.Itoa(int(p)) + ")"
}
}

type Vote int

const (
VoteYes Vote = iota
VoteNo
VoteAbstain
)

func (v Vote) ToJSON() string {
return jsonutil.FormatString(v.String())
}

func (v Vote) String() string {
switch v {
case VoteYes:
return "Yes"
case VoteNo:
return "No"
case VoteAbstain:
return "Abstain"
default:
return "Unknown(" + strconv.Itoa(int(v)) + ")"
}
}

type IProposalModule interface {
Propose(
title string,
description string,
actions []ExecutableMessage,
)
Vote(proposalId int, vote Vote, rationale string)
Execute(proposalId int)
Threshold() Threshold

Proposals() []Proposal
GetBallot(proposalId int, addr std.Address) Ballot

Render(path string) string
}

type ExecutableMessage interface {
String() string
Binary() []byte
Type() string
}
Loading