Skip to content

Commit 477520c

Browse files
committed
Change Pull -> Push
1 parent 85cebe0 commit 477520c

File tree

13 files changed

+230
-63
lines changed

13 files changed

+230
-63
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module gno.land/p/demo/teritori/worx
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package worx
2+
3+
import "std"
4+
5+
6+
type Worx struct {
7+
Hours int
8+
Metadata string
9+
Address std.Address
10+
Points int
11+
Timestamp int64
12+
}
13+
14+
func NewWorx(hours int, metadata string, addr std.Address, points int, timestamp int64) *Worx{
15+
return &Worx{
16+
Hours: hours,
17+
Metadata: metadata,
18+
Address: addr,
19+
Points: points,
20+
Timestamp: timestamp,
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package worx
2+
3+
type WorxKeeper struct {
4+
worxs []*Worx
5+
}
6+
7+
func (keeper *WorxKeeper) Store(worx *Worx) {
8+
keeper.worxs = append(keeper.worxs, worx)
9+
}
10+
11+
func (keeper *WorxKeeper) Get() []*Worx {
12+
return keeper.worxs
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module gno.land/r/demo/teritori/social_follow
2+
3+
require (
4+
gno.land/p/demo/avl v0.0.0-latest
5+
gno.land/p/demo/testutils v0.0.0-latest
6+
)

examples/gno.land/r/demo/teritori/worx_aggregator/providers/profile.gno renamed to examples/gno.land/r/demo/teritori/providers/profile.gno

File renamed without changes.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package provider
2+
3+
import (
4+
"std"
5+
"gno.land/p/demo/avl"
6+
"gno.land/p/demo/ufmt"
7+
"gno.land/r/demo/teritori/registry"
8+
)
9+
10+
var profiles avl.Tree
11+
12+
func init() {
13+
registry.Register("profiles", RegisterHandler)
14+
}
15+
16+
17+
func Get(dataName string, addr std.Address) interface{} {
18+
if dataName != "profile"{
19+
panic("invalid dataname")
20+
}
21+
profile:=getProfile(addr)
22+
23+
return profile.ToString()
24+
}
25+
26+
func SupportedTypes() interface{}{
27+
return []interface{}{"profile"}
28+
}
29+
30+
func UpsertProfile(field string, value string){
31+
caller := std.GetOrigCaller()
32+
profile := getProfile(caller)
33+
profile.SetField(field, value)
34+
profiles.Set(caller.String(), profile)
35+
}
36+
37+
38+
func getProfile(addr std.Address ) *Profile {
39+
profile, found:=profiles.Get(addr.String())
40+
if !found{
41+
return &Profile{}
42+
}
43+
44+
return profile.(*Profile)
45+
}
46+
47+
func RegisterHandler(functionName string, args ...interface{}) interface{} {
48+
switch functionName {
49+
case "get":
50+
if len(args) != 2{
51+
panic("invalid number of arguments")
52+
}
53+
dataname := args[0].(string)
54+
address := args[1].(std.Address)
55+
return Get(dataname,address)
56+
case "supportedTypes":
57+
if len(args) != 0{
58+
panic("invalid number of arguments")
59+
}
60+
dataname := args[0].(string)
61+
address := args[1].(std.Address)
62+
return SupportedTypes()
63+
default:
64+
panic("invalid function name")
65+
}
66+
}

examples/gno.land/r/demo/teritori/worx_aggregator/providers/profiles_test.gno renamed to examples/gno.land/r/demo/teritori/providers/profiles_test.gno

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,14 @@ func TestGetProfile(t *testing.T) {
2020
if !strings.Contains(result,"name: Gopher"){
2121
t.Error("Bad")
2222
}
23+
}
24+
25+
func TestRegisterHandler(t *testing.T) {
26+
user1 := testutils.TestAddress("user1")
27+
std.TestSetOrigCaller(user1)
28+
supportedTypes := RegisterHandler("supportedTypes")
29+
if len(supportedTypes) != 1{
30+
t.Error("Supported types is wrong")
31+
}
32+
}
2333

24-
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package provider
2+
3+
import (
4+
"std"
5+
"gno.land/r/demo/teritori/worx_aggregator"
6+
"gno.land/p/demo/rand"
7+
)
8+
9+
var admin std.Address
10+
11+
func init() {
12+
admin = std.GetOrigCaller()
13+
}
14+
15+
func RandWorx(addr std.Address){
16+
r := rand.New()
17+
worx_aggregator.Push(r.Intn(25), "", addr, r.Intn(100), std.GetHeight())
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package registry
2+
3+
import (
4+
"gno.land/p/demo/avl"
5+
"std"
6+
)
7+
8+
var callbacks avl.Tree
9+
type FunctionCB func(functionName string, args ...interface{}) interface{}
10+
11+
func Register(id string, callback FunctionCB){
12+
_,exists:=callbacks.Get(id)
13+
if exists{
14+
panic("A callback already exists for the id")
15+
}
16+
17+
callbacks.Set(id, callback)
18+
}
19+
20+
func Exec(id string, functionName string, args ...interface{}) interface{} {
21+
cb, ok:= callbacks.Get(id)
22+
if !ok{
23+
panic("Callback not found")
24+
}
25+
function := cb.(FunctionCB)
26+
return function(functionName, args)
27+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package registry
2+
3+
import (
4+
"std"
5+
"testing"
6+
7+
"gno.land/p/demo/avl"
8+
"gno.land/p/demo/testutils"
9+
"strings"
10+
)
11+
12+
func TestGetProfile(t *testing.T) {
13+
user1 := testutils.TestAddress("user1")
14+
std.TestSetOrigCaller(user1)
15+
functionID:="SOMEID"
16+
var cb functionCB = func(args ...interface{})[]interface{}{
17+
//t.Errorf("dataType",dataType)
18+
return nil
19+
}
20+
Register(functionID, cb)
21+
Exec(functionID)
22+
}

0 commit comments

Comments
 (0)