forked from asuleymanov/steem-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathverify.go
More file actions
164 lines (147 loc) · 4.27 KB
/
verify.go
File metadata and controls
164 lines (147 loc) · 4.27 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package rpc
import (
// Stdlib
"fmt"
"log"
"strings"
"time"
// Vendor
"github.com/pkg/errors"
)
//VerifyVoterWeight check whether there is a voter on the list of those who have already voted for the weight of the vote.
func (client *Client) VerifyVoterWeight(author, permlink, voter string, weight int) bool {
ans, err := client.Database.GetActiveVotes(author, permlink)
if err != nil {
log.Println(errors.Wrapf(err, "Error Verify Voter: "))
return false
}
for _, v := range ans {
if v.Voter == voter && v.Percent == weight {
return true
}
}
return false
}
//VerifyVoter check whether there is a voter on the list of those who have already voted without taking into account the weight of the vote.
func (client *Client) VerifyVoter(author, permlink, voter string) bool {
ans, err := client.Database.GetActiveVotes(author, permlink)
if err != nil {
log.Println(errors.Wrapf(err, "Error Verify Voter: "))
return false
}
for _, v := range ans {
if v.Voter == voter {
return true
}
}
return false
}
//VerifyVotes check whether there are voted
func (client *Client) VerifyVotes(author, permlink string) bool {
ans, err := client.Database.GetActiveVotes(author, permlink)
if err != nil {
log.Println(errors.Wrapf(err, "Error Verify Votes: "))
return false
}
if len(ans) > 0 {
return true
}
return false
}
//VerifyComments check whether the entry in GOLOS is a comment.
func (client *Client) VerifyComments(author, permlink string) bool {
ans, err := client.Database.GetContentReplies(author, permlink)
if err != nil {
log.Println(errors.Wrapf(err, "Error Verify Comments: "))
return false
}
if len(ans) > 0 {
return true
}
return false
}
//VerifyReblogs сheck if the user made a repost entry in GOLOS
func (client *Client) VerifyReblogs(author, permlink, rebloger string) bool {
ans, err := client.Follow.GetRebloggedBy(author, permlink)
if err != nil {
log.Println(errors.Wrapf(err, "Error Verify Reblogs: "))
return false
}
for _, v := range ans {
if v == rebloger {
return true
}
}
return false
}
//VerifyFollow сheck if one user is signed for the second in GOLOS
func (client *Client) VerifyFollow(follower, following string) bool {
ans, err := client.Follow.GetFollowing(follower, following, "blog", 1)
if err != nil {
log.Println(errors.Wrapf(err, "Error Verify Follow: "))
return false
}
for _, v := range ans {
if (v.Follower == follower) && (v.Following == following) {
return true
}
}
return false
}
//VerifyPost сheck if there is an entry in GOLOS
func (client *Client) VerifyPost(author, permlink string) bool {
ans, err := client.Database.GetContent(author, permlink)
if err != nil {
log.Println(errors.Wrapf(err, "Error Verify Post: "))
return false
}
if (ans.Author == author) && (ans.Permlink == permlink) {
return true
}
return false
}
//VerifyDelegatePostingKeySign check whether the user has delegated the opportunity to use his post by using operations from a given user.
func (client *Client) VerifyDelegatePostingKeySign(fromUser, toUser string) bool {
acc, err := client.Database.GetAccounts([]string{fromUser})
if err != nil {
log.Println(errors.Wrapf(err, "Error Verify Delegate Vote Sign: "))
return false
} else if len(acc) == 1 {
for _, v := range acc[0].Posting.AccountAuths {
tu := strings.Split(strings.Replace(strings.Replace(fmt.Sprintf("%v", v), "[", "", -1), "]", "", -1), " ")
if tu[0] == toUser {
if tu[1] == fmt.Sprintf("%v", acc[0].Posting.WeightThreshold) {
return true
}
}
}
return false
} else {
return false
}
}
//VerifyFirstPost сheck whether the post of the user is his first post in GOLOS
func (client *Client) VerifyFirstPost(username string) bool {
d := time.Now()
cont, err := client.Database.GetDiscussionsByAuthorBeforeDate(username, "", d.Format("2006-01-02T00:00:00"), 100)
if err != nil {
log.Println(errors.Wrapf(err, "Error Verify First Post: "))
return false
}
if len(cont) > 1 {
return false
}
return true
}
//VerifyUser сheck if the user exists in GOLOS
func (client *Client) VerifyUser(username string) bool {
acc, err := client.Database.GetAccounts([]string{username})
if err != nil {
log.Println(errors.Wrapf(err, "Error Verify User: "))
return false
} else if len(acc) == 1 {
return true
} else {
return false
}
}