forked from go-steem/rpc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.go
145 lines (129 loc) · 5.4 KB
/
data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package database
import (
// Stdlib
"encoding/json"
"strconv"
"strings"
// RPC
"github.com/go-steem/rpc/types"
)
type Config struct {
SteemitBlockchainHardforkVersion string `json:"STEEMIT_BLOCKCHAIN_HARDFORK_VERSION"`
SteemitBlockchainVersion string `json:"STEEMIT_BLOCKCHAIN_VERSION"`
SteemitBlockInterval uint `json:"STEEMIT_BLOCK_INTERVAL"`
}
type DynamicGlobalProperties struct {
Time *types.Time `json:"time"`
TotalPow *types.Int `json:"total_pow"`
NumPowWitnesses *types.Int `json:"num_pow_witnesses"`
CurrentReserveRatio *types.Int `json:"current_reserve_ratio"`
ID *types.ID `json:"id"`
CurrentSupply string `json:"current_supply"`
CurrentSBDSupply string `json:"current_sbd_supply"`
MaximumBlockSize *types.Int `json:"maximum_block_size"`
RecentSlotsFilled *types.Int `json:"recent_slots_filled"`
CurrentWitness string `json:"current_witness"`
TotalRewardShares2 *types.Int `json:"total_reward_shares2"`
AverageBlockSize *types.Int `json:"average_block_size"`
CurrentAslot *types.Int `json:"current_aslot"`
LastIrreversibleBlockNum uint32 `json:"last_irreversible_block_num"`
TotalVestingShares string `json:"total_vesting_shares"`
TotalVersingFundSteem string `json:"total_vesting_fund_steem"`
HeadBlockID string `json:"head_block_id"`
HeadBlockNumber types.UInt32 `json:"head_block_number"`
VirtualSupply string `json:"virtual_supply"`
ConfidentialSupply string `json:"confidential_supply"`
ConfidentialSBDSupply string `json:"confidential_sbd_supply"`
TotalRewardFundSteem string `json:"total_reward_fund_steem"`
TotalActivityFundSteem string `json:"total_activity_fund_steem"`
TotalActivityFundShares *types.Int `json:"total_activity_fund_shares"`
SBDInterestRate *types.Int `json:"sbd_interest_rate"`
MaxVirtualBandwidth *types.Int `json:"max_virtual_bandwidth"`
}
type Block struct {
Number uint32 `json:"-"`
Timestamp *types.Time `json:"timestamp"`
Witness string `json:"witness"`
WitnessSignature string `json:"witness_signature"`
TransactionMerkleRoot string `json:"transaction_merkle_root"`
Previous string `json:"previous"`
Extensions [][]interface{} `json:"extensions"`
Transactions []*types.Transaction `json:"transactions"`
}
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 *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"`
Rshares *types.Int `json:"rshares"`
Percent *types.Int `json:"percent"`
Time *types.Time `json:"time"`
}