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

ERC721 posts #338

Merged
merged 6 commits into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added ERC721 fields to post
  • Loading branch information
shanev committed Mar 13, 2021
commit d631d6cfbef1dd29966ba98bacb88c9c19c55f82
18 changes: 18 additions & 0 deletions proto/stargaze/curating/v1beta1/curating.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ message Post {
(gogoproto.moretags) = "yaml:\"total_amount\"",
(gogoproto.jsontag) = "total_amount"
];
string chain_id = 11 [
(gogoproto.customname) = "ChainID",
(gogoproto.moretags) = "yaml:\"chain_id\"",
(gogoproto.jsontag) = "chain_id",
(gogoproto.nullable) = true
];
string owner = 12 [ (gogoproto.moretags) = "yaml:\"owner\"" ];
string contract_address = 13
[ (gogoproto.moretags) = "yaml:\"contract_address\"" ];
string metadata = 14 [ (gogoproto.moretags) = "yaml:\"metadata\"" ];
bool locked = 15 [ (gogoproto.moretags) = "yaml:\"locked\"" ];
string parent_id = 16 [
(gogoproto.customname) = "ParentID",
(gogoproto.customtype) = "PostID",
(gogoproto.moretags) = "yaml:\"parent_id\"",
(gogoproto.jsontag) = "parent_id",
(gogoproto.nullable) = true
];
}

message Upvote {
Expand Down
16 changes: 16 additions & 0 deletions proto/stargaze/curating/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ message MsgPost {
string reward_account = 4
[ (gogoproto.moretags) = "yaml:\"reward_account\"" ];
string body = 5 [ (gogoproto.moretags) = "yaml:\"body\"" ];
string chain_id = 6 [
(gogoproto.customname) = "ChainID",
(gogoproto.moretags) = "yaml:\"chain_id\"",
(gogoproto.jsontag) = "chain_id",
(gogoproto.nullable) = true
];
string contract_address = 7
[ (gogoproto.moretags) = "yaml:\"contract_address\"" ];
string metadata = 8 [ (gogoproto.moretags) = "yaml:\"metadata\"" ];
string parent_id = 9 [
(gogoproto.customname) = "ParentID",
(gogoproto.customtype) = "PostID",
(gogoproto.moretags) = "yaml:\"parent_id\"",
(gogoproto.jsontag) = "parent_id",
(gogoproto.nullable) = true
];
}

message MsgUpvote {
Expand Down
22 changes: 17 additions & 5 deletions x/curating/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ func setup(t *testing.T) (*simapp.SimApp, sdk.Context) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], addrs[0])
err = app.CuratingKeeper.CreatePost(
ctx,
vendorID,
&postID,
bodyHash,
body,
addrs[0],
addrs[0],
"chain id",
nil,
"metadata",
nil,
)
require.NoError(t, err)

_, found, err := app.CuratingKeeper.GetPost(ctx, vendorID, postID)
Expand Down Expand Up @@ -159,12 +171,12 @@ func TestEndBlocker_RemoveFromExpiredQueue(t *testing.T) {

postID, err := types.PostIDFromString("777")
require.NoError(t, err)
_, err = app.CuratingKeeper.CreatePost(ctx, uint32(1), &postID, bodyHash, body, addrs[0], addrs[0])
_, err = app.CuratingKeeper.CreatePost(ctx, uint32(1), postID, bodyHash, body, addrs[0], addrs[0], "", nil, "", nil)
require.NoError(t, err)

postID, err = types.PostIDFromString("888")
require.NoError(t, err)
_, err = app.CuratingKeeper.CreatePost(ctx, uint32(1), &postID, bodyHash, body, addrs[0], addrs[0])
_, err = app.CuratingKeeper.CreatePost(ctx, uint32(1), &postID, bodyHash, body, addrs[0], addrs[0], "", nil, "", nil)
require.NoError(t, err)

// force 2 different keys in the iterator underlying store
Expand All @@ -173,7 +185,7 @@ func TestEndBlocker_RemoveFromExpiredQueue(t *testing.T) {

postID, err = types.PostIDFromString("999")
require.NoError(t, err)
_, err = app.CuratingKeeper.CreatePost(ctx.WithBlockHeader(b), uint32(1), &postID, bodyHash, body, addrs[0], addrs[0])
_, err = app.CuratingKeeper.CreatePost(ctx.WithBlockHeader(b), uint32(1), &postID, bodyHash, body, addrs[0], addrs[0], "", nil, "", nil)
require.NoError(t, err)

// fast-forward blocktime to simulate end of curation window
Expand Down Expand Up @@ -217,7 +229,7 @@ func TestEndblocker_BurnCoinsFromVotingPool(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[1], addrs[1])
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[1], addrs[1], "", nil, "", nil)
require.NoError(t, err)

// amt = 1
Expand Down
21 changes: 15 additions & 6 deletions x/curating/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ func TestPost(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], addrs[0])
_, err = app.CuratingKeeper.CreatePost(
ctx,
vendorID,
&postID,
bodyHash,
body,
addrs[0],
addrs[0],
"chain_id", nil, "metadata", nil,
)
require.NoError(t, err)

_, found, err := app.CuratingKeeper.GetPost(ctx, vendorID, postID)
Expand All @@ -38,7 +47,7 @@ func TestPost(t *testing.T) {
vps := app.CuratingKeeper.GetCurationQueueTimeSlice(ctx, ctx.BlockTime())
require.NotNil(t, vps)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], addrs[0])
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], addrs[0], "", nil, "", nil)
require.Equal(t, types.ErrDuplicatePost, err)
}

Expand All @@ -56,7 +65,7 @@ func TestPost_EmptyCreator(t *testing.T) {
require.NoError(t, err)

addrs := simapp.AddTestAddrsIncremental(app, ctx, 3, sdk.NewInt(1000000))
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, nil, addrs[1])
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, nil, addrs[1], "", nil, "", nil)
require.NoError(t, err)

_, found, err := app.CuratingKeeper.GetPost(ctx, vendorID, postID)
Expand Down Expand Up @@ -87,7 +96,7 @@ func TestPost_EmptyRewardAccount(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], nil)
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], nil, "", nil, "", nil)
require.NoError(t, err)

_, found, err := app.CuratingKeeper.GetPost(ctx, vendorID, postID)
Expand Down Expand Up @@ -115,7 +124,7 @@ func TestPost_WithRewardAccount(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], addrs[1])
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], addrs[1], "", nil, "", nil)
require.NoError(t, err)

_, found, err := app.CuratingKeeper.GetPost(ctx, vendorID, postID)
Expand Down Expand Up @@ -146,7 +155,7 @@ func TestDeletePost(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], addrs[1])
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], addrs[1], "", nil, "", nil)
require.NoError(t, err)

_, found, err := app.CuratingKeeper.GetPost(ctx, vendorID, postID)
Expand Down
15 changes: 13 additions & 2 deletions x/curating/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,19 @@ func (k msgServer) Post(goCtx context.Context, msg *types.MsgPost) (*types.MsgPo
return nil, err
}

post, err := k.CreatePost(
ctx, msg.VendorID, &postID, bodyHash, msg.Body, creator, rewardAccount)
post, err = k.CreatePost(
ctx,
msg.VendorID,
&postID,
bodyHash,
msg.Body,
creator,
rewardAccount,
msg.ChainID,
creator, // owner = creator intially
msg.Metadata,
msg.ParentID,
)
if err != nil {
return nil, err
}
Expand Down
44 changes: 42 additions & 2 deletions x/curating/keeper/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ func (k Keeper) GetPost(

// CreatePost registers a post on-chain and starts the curation period.
// It can be called from CreateUpvote() when a post doesn't exist yet.
func (k Keeper) CreatePost(ctx sdk.Context, vendorID uint32, postID *types.PostID,
bodyHash types.BodyHash, body string, creator, rewardAccount sdk.AccAddress) (post types.Post, err error) {
func (k Keeper) CreatePost(
ctx sdk.Context,
vendorID uint32,
postID *types.PostID,
bodyHash types.BodyHash,
body string,
creator, rewardAccount sdk.AccAddress,
chainID string,
contractAddress sdk.AccAddress,
metadata string,
parentID *types.PostID,
) (post types.Post, err error) {

err = k.validateVendorID(ctx, vendorID)
if err != nil {
Expand All @@ -56,6 +66,21 @@ func (k Keeper) CreatePost(ctx sdk.Context, vendorID uint32, postID *types.PostI

curationWindow := k.GetParams(ctx).CurationWindow
curationEndTime := ctx.BlockTime().Add(curationWindow)
post := types.NewPost(
vendorID,
postID,
bodyHash,
body,
creator,
rewardAccount,
curationEndTime,
chainID,
creator,
contractAddress,
metadata,
false,
parentID,
)

if postID != nil {
_, found, err := k.GetPost(ctx, vendorID, *postID)
Expand Down Expand Up @@ -91,9 +116,24 @@ func (k Keeper) CreatePost(ctx sdk.Context, vendorID uint32, postID *types.PostI
sdk.NewAttribute(types.AttributeKeyBody, body),
sdk.NewAttribute(types.AttributeCurationEndTime, curationEndTime.Format(time.RFC3339)),
sdk.NewAttribute(types.AttributeKeyVoteDenom, types.DefaultVoteDenom),
sdk.NewAttribute(types.AttributeKeyChainID, chainID),
sdk.NewAttribute(types.AttributeKeyContractAddress, contractAddress.String()),
sdk.NewAttribute(types.AttributeKeyMetadata, metadata),
sdk.NewAttribute(types.AttributeKeyLocked, "false"),
),
})

if parentID != nil {
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypePost,
sdk.NewAttribute(types.AttributeKeyVendorID, fmt.Sprintf("%d", vendorID)),
sdk.NewAttribute(types.AttributeKeyPostID, postID.String()),
sdk.NewAttribute(types.AttributeKeyParentID, parentID.String()),
),
})
}

return post, nil
}

Expand Down
5 changes: 3 additions & 2 deletions x/curating/keeper/post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestCreatePost(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], addrs[0])
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[0], addrs[0], "", nil, "", nil)
require.NoError(t, err)

post, found, err := app.CuratingKeeper.GetPost(ctx, vendorID, postID)
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestCreateVendor0Post(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, nil, bodyHash, body, addrs[0], addrs[0])
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, nil, bodyHash, body, addrs[0], addrs[0], "", nil, "", nil)
require.NoError(t, err)

post, found, err := app.CuratingKeeper.GetPost(ctx, vendorID, postID)
Expand All @@ -96,6 +96,7 @@ func TestCreateVendor0Post(t *testing.T) {
// add another post
postID, err = types.PostIDFromString("2")
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, nil, bodyHash, body, addrs[0], addrs[0])
err = app.CuratingKeeper.CreatePost(ctx, vendorID, postID, bodyHash, body, addrs[0], addrs[0], "", nil, "", nil)
require.NoError(t, err)

// fast forward block time
Expand Down
14 changes: 13 additions & 1 deletion x/curating/keeper/upvote.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,19 @@ func (k Keeper) CreateUpvote(
if !found {
// no deposit is locked
// this curator gets both creator + curator rewards (sent to reward_account)
_, err = k.CreatePost(ctx, vendorID, &postID, types.BodyHash{}, "", nil, rewardAccount)
_, err = k.CreatePost(
ctx,
vendorID,
&postID,
types.BodyHash{},
"",
nil,
rewardAccount,
"",
nil,
"",
nil,
)
if err != nil {
return err
}
Expand Down
10 changes: 7 additions & 3 deletions x/curating/keeper/upvote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func TestCreateUpvote_ExistingPost(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

<<<<<<< HEAD
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[1], addrs[1])
=======
err = app.CuratingKeeper.CreatePost(ctx, vendorID, postID, bodyHash, body, addrs[1], addrs[1], "", nil, "", nil)
>>>>>>> a3cf992 (Added ERC721 fields to post)
require.NoError(t, err)

err = app.CuratingKeeper.CreateUpvote(ctx, vendorID, postID, addrs[0], addrs[0], 5)
Expand Down Expand Up @@ -98,7 +102,7 @@ func TestCreateUpvote_ExpiredPost(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[1], addrs[1])
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[1], addrs[1], "", nil, "", nil)
require.NoError(t, err)

ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Hour*24*3 + 1))
Expand All @@ -123,7 +127,7 @@ func TestMultipleUpvotes(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[1], addrs[1])
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, postID, bodyHash, body, addrs[1], addrs[1], "", nil, "", nil)
require.NoError(t, err)

// amt = 1
Expand Down Expand Up @@ -164,7 +168,7 @@ func TestCreateUpvote_ExistingUpvote(t *testing.T) {
bodyHash, err := types.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, addrs[1], addrs[1])
_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, postID, bodyHash, body, addrs[1], addrs[1], "", nil, "", nil)
require.NoError(t, err)

err = app.CuratingKeeper.CreateUpvote(ctx, vendorID, postID, addrs[0], addrs[0], 5)
Expand Down
5 changes: 5 additions & 0 deletions x/curating/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const (
AttributeKeyVoteDenom = "vote_denom"
AttributeKeyProtocolRewardType = "reward_type"
AttributeKeyRewardAmount = "reward_amount"
AttributeKeyChainID = "chain_id"
AttributeKeyContractAddress = "contract_address"
AttributeKeyMetadata = "metadata"
AttributeKeyParentID = "parent_id"
AttributeKeyLocked = "locked"

AttributeValueCategory = ModuleName
)
10 changes: 9 additions & 1 deletion x/curating/types/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ type CuratingQueue []VPPair
// NewPost allocates and returns a new `Post` struct
func NewPost(
vendorID uint32, postID PostID, bodyHash BodyHash, body string, creator,
rewardAccount sdk.AccAddress, curatingEndTime time.Time) Post {
rewardAccount sdk.AccAddress, curatingEndTime time.Time,
chainID string, owner sdk.AccAddress, contractAddress sdk.AccAddress,
metaData string, locked bool, parentID *PostID) Post {

return Post{
VendorID: vendorID,
Expand All @@ -131,6 +133,12 @@ func NewPost(
CuratingEndTime: curatingEndTime,
TotalVotes: 0,
TotalAmount: sdk.Coin{},
ChainID: chainID,
Owner: owner.String(),
ContractAddress: contractAddress.String(),
Metadata: metaData,
Locked: locked,
ParentID: parentID,
}
}

Expand Down
14 changes: 13 additions & 1 deletion x/stake/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,19 @@ func TestPerformStakeAndUnstake(t *testing.T) {
bodyHash, err := curatingtypes.BodyHashFromString(body)
require.NoError(t, err)

_, err = app.CuratingKeeper.CreatePost(ctx, vendorID, &postID, bodyHash, body, delAddr, delAddr)
_, err = app.CuratingKeeper.CreatePost(
ctx,
vendorID,
&postID,
bodyHash,
body,
delAddr,
delAddr,
"",
nil,
"",
nil,
)
require.NoError(t, err)

staking.EndBlocker(ctx, app.StakingKeeper)
Expand Down