Skip to content

Commit

Permalink
Revert "Add CommentOperation.JsonMetadata"
Browse files Browse the repository at this point in the history
This reverts commit efaa109.
  • Loading branch information
tchap committed Aug 17, 2017
1 parent efaa109 commit 57b3a4f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 88 deletions.
105 changes: 78 additions & 27 deletions apis/database/data.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package database

import (
// Stdlib
"encoding/json"
"strconv"
"strings"

// RPC
"github.com/go-steem/rpc/types"
)
Expand Down Expand Up @@ -52,39 +57,85 @@ type Block struct {
}

type Content struct {
Id *types.ID `json:"id"`
RootTitle string `json:"root_title"`
Active *types.Time `json:"active"`
AbsRshares *types.Int `json:"abs_rshares"`
PendingPayoutValue string `json:"pending_payout_value"`
TotalPendingPayoutValue string `json:"total_pending_payout_value"`
Category string `json:"category"`
Title string `json:"title"`
LastUpdate *types.Time `json:"last_update"`
Stats string `json:"stats"`
Body string `json:"body"`
Created *types.Time `json:"created"`
Replies []*Content `json:"replies"`
Permlink string `json:"permlink"`
JsonMetadata *types.ContentMetadata `json:"json_metadata"`
Children *types.Int `json:"children"`
NetRshares *types.Int `json:"net_rshares"`
URL string `json:"url"`
ActiveVotes []*VoteState `json:"active_votes"`
ParentPermlink string `json:"parent_permlink"`
CashoutTime *types.Time `json:"cashout_time"`
TotalPayoutValue string `json:"total_payout_value"`
ParentAuthor string `json:"parent_author"`
ChildrenRshares2 *types.Int `json:"children_rshares2"`
Author string `json:"author"`
Depth *types.Int `json:"depth"`
TotalVoteWeight *types.Int `json:"total_vote_weight"`
Id *types.ID `json:"id"`
RootTitle string `json:"root_title"`
Active *types.Time `json:"active"`
AbsRshares *types.Int `json:"abs_rshares"`
PendingPayoutValue string `json:"pending_payout_value"`
TotalPendingPayoutValue string `json:"total_pending_payout_value"`
Category string `json:"category"`
Title string `json:"title"`
LastUpdate *types.Time `json:"last_update"`
Stats string `json:"stats"`
Body string `json:"body"`
Created *types.Time `json:"created"`
Replies []*Content `json:"replies"`
Permlink string `json:"permlink"`
JsonMetadata *ContentMetadata `json:"json_metadata"`
Children *types.Int `json:"children"`
NetRshares *types.Int `json:"net_rshares"`
URL string `json:"url"`
ActiveVotes []*VoteState `json:"active_votes"`
ParentPermlink string `json:"parent_permlink"`
CashoutTime *types.Time `json:"cashout_time"`
TotalPayoutValue string `json:"total_payout_value"`
ParentAuthor string `json:"parent_author"`
ChildrenRshares2 *types.Int `json:"children_rshares2"`
Author string `json:"author"`
Depth *types.Int `json:"depth"`
TotalVoteWeight *types.Int `json:"total_vote_weight"`
}

func (content *Content) IsStory() bool {
return content.ParentAuthor == ""
}

type ContentMetadata struct {
Flag bool
Users []string
Tags []string
Image []string
}

type ContentMetadataRaw struct {
Users types.StringSlice `json:"users"`
Tags types.StringSlice `json:"tags"`
Image types.StringSlice `json:"image"`
}

func (metadata *ContentMetadata) UnmarshalJSON(data []byte) error {
unquoted, err := strconv.Unquote(string(data))
if err != nil {
return err
}

switch unquoted {
case "true":
metadata.Flag = true
return nil
case "false":
metadata.Flag = false
return nil
}

if len(unquoted) == 0 {
var value ContentMetadata
metadata = &value
return nil
}

var raw ContentMetadataRaw
if err := json.NewDecoder(strings.NewReader(unquoted)).Decode(&raw); err != nil {
return err
}

metadata.Users = raw.Users
metadata.Tags = raw.Tags
metadata.Image = raw.Image

return nil
}

type VoteState struct {
Voter string `json:"voter"`
Weight *types.Int `json:"weight"`
Expand Down
67 changes: 6 additions & 61 deletions types/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package types
import (
// Stdlib
"encoding/json"
"strconv"
"strings"

// RPC
"github.com/go-steem/rpc/encoding/transaction"
Expand Down Expand Up @@ -289,13 +287,12 @@ func (op *AccountWitnessProxyOperation) Data() interface{} {
// In case Title is filled in and ParentAuthor is empty, it is a new post.
// The post category can be read from ParentPermlink.
type CommentOperation struct {
Author string `json:"author"`
Title string `json:"title"`
Permlink string `json:"permlink"`
ParentAuthor string `json:"parent_author"`
ParentPermlink string `json:"parent_permlink"`
Body string `json:"body"`
JsonMetadata *ContentMetadata `json:"json_metadata"`
Author string `json:"author"`
Title string `json:"title"`
Permlink string `json:"permlink"`
ParentAuthor string `json:"parent_author"`
ParentPermlink string `json:"parent_permlink"`
Body string `json:"body"`
}

func (op *CommentOperation) Type() OpType {
Expand All @@ -310,58 +307,6 @@ func (op *CommentOperation) IsStoryOperation() bool {
return op.ParentAuthor == ""
}

type ContentMetadata struct {
Flag bool
Users []string
Tags []string
Image []string
App string
Format string
}

type ContentMetadataRaw struct {
Users StringSlice `json:"users"`
Tags StringSlice `json:"tags"`
Image StringSlice `json:"image"`
App string `json:"app"`
Format string `json:"format"`
}

func (metadata *ContentMetadata) UnmarshalJSON(data []byte) error {
unquoted, err := strconv.Unquote(string(data))
if err != nil {
return err
}

switch unquoted {
case "true":
metadata.Flag = true
return nil
case "false":
metadata.Flag = false
return nil
}

if len(unquoted) == 0 {
var value ContentMetadata
metadata = &value
return nil
}

var raw ContentMetadataRaw
if err := json.NewDecoder(strings.NewReader(unquoted)).Decode(&raw); err != nil {
return err
}

metadata.Users = raw.Users
metadata.Tags = raw.Tags
metadata.Image = raw.Image
metadata.App = raw.App
metadata.Format = raw.Format

return nil
}

// FC_REFLECT( steemit::chain::vote_operation,
// (voter)
// (author)
Expand Down

0 comments on commit 57b3a4f

Please sign in to comment.