SC CODE: // "DERODECK" Smart Contract in DVM-BASIC
Function Initialize() Uint64
10 VERSION("1.0.0")
20 STORE("owner", SIGNER())
30 STORE("post_seq", 0)
40 RETURN 0
End Function
Function CreatePost(content String, hashtag String) Uint64
10 DIM pid as Uint64
20 DIM ts as Uint64
30 DIM idstr as String
40 IF STRLEN(content) == 0 THEN GOTO 210
50 IF STRLEN(content) >= 512 THEN GOTO 210
60 IF STRLEN(hashtag) >= 64 THEN GOTO 210
70 LET pid = LOAD("post_seq") + 1
80 STORE("post_seq", pid)
90 LET idstr = ITOA(pid)
100 STORE("post:"+idstr+":author", SIGNER())
110 STORE("post:"+idstr+":content", content)
120 STORE("post:"+idstr+":likes", 0)
130 STORE("post:"+idstr+":retweetOf", "")
140 STORE("post:"+idstr+":hashtag", hashtag)
150 STORE("post:"+idstr+":ts", BLOCK_TIMESTAMP())
155 DIM tagcntkey as String
156 DIM tagitemkey as String
157 DIM tagcount as Uint64
160 LET tagcntkey = "tag:"+hashtag+":count"
170 IF EXISTS(tagcntkey) == 1 THEN GOTO 190
180 STORE(tagcntkey, 0)
190 LET tagcount = LOAD(tagcntkey) + 1
195 STORE(tagcntkey, tagcount)
196 LET tagitemkey = "tag:"+hashtag+":item:"+ITOA(tagcount)
197 STORE(tagitemkey, idstr)
210 RETURN 0
End Function
Function LikePost(post_id Uint64) Uint64
10 DIM idstr as String
20 DIM likekey as String
30 LET idstr = ITOA(post_id)
40 IF EXISTS("post:"+idstr+":author") == 1 THEN GOTO 60
50 RETURN 1
60 LET likekey = "liked:"+idstr+":"+SIGNER()
70 IF EXISTS(likekey) == 1 THEN GOTO 120
80 STORE(likekey, 1)
90 STORE("post:"+idstr+":likes", LOAD("post:"+idstr+":likes") + 1)
120 RETURN 0
End Function
Function RetweetPost(post_id Uint64, comment String, hashtag String) Uint64
10 DIM pid as Uint64
20 DIM idstr as String
30 DIM new_idstr as String
40 IF STRLEN(comment) >= 512 THEN GOTO 180
50 IF STRLEN(hashtag) >= 64 THEN GOTO 180
60 LET idstr = ITOA(post_id)
70 IF EXISTS("post:"+idstr+":author") == 1 THEN GOTO 90
80 RETURN 1
90 LET pid = LOAD("post_seq") + 1
100 STORE("post_seq", pid)
110 LET new_idstr = ITOA(pid)
120 STORE("post:"+new_idstr+":author", SIGNER())
130 STORE("post:"+new_idstr+":content", comment)
140 STORE("post:"+new_idstr+":likes", 0)
150 STORE("post:"+new_idstr+":retweetOf", idstr)
160 STORE("post:"+new_idstr+":hashtag", hashtag)
170 STORE("post:"+new_idstr+":ts", BLOCK_TIMESTAMP())
175 DIM tagcntkey as String
176 DIM tagitemkey as String
177 DIM tagcount as Uint64
178 LET tagcntkey = "tag:"+hashtag+":count"
179 IF EXISTS(tagcntkey) == 1 THEN GOTO 183
180 STORE(tagcntkey, 0)
183 LET tagcount = LOAD(tagcntkey) + 1
184 STORE(tagcntkey, tagcount)
185 LET tagitemkey = "tag:"+hashtag+":item:"+ITOA(tagcount)
186 STORE(tagitemkey, new_idstr)
200 RETURN 0
End Function
Function SetBio(bio String) Uint64
10 IF STRLEN(bio) >= 512 THEN GOTO 30
20 STORE("bio:"+SIGNER(), bio)
30 RETURN 0
End Function
Function TransferOwnership(newowner String) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("tmpowner", ADDRESS_RAW(newowner))
40 RETURN 0
End Function
Function ClaimOwnership() Uint64
10 IF LOAD("tmpowner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("owner", SIGNER())
40 RETURN 0
End Function
Function Withdraw(amount Uint64) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 SEND_DERO_TO_ADDRESS(SIGNER(), amount)
40 RETURN 0
End Function
Function UpdateCode(code String) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 UPDATE_SC_CODE(code)
40 RETURN 0
End Function |
| SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'// "DERODECK" Smart Contract in DVM-BASIC
Function Initialize() Uint64
10 VERSION("1.0.0")
20 STORE("owner", SIGNER())
30 STORE("post_seq", 0)
40 RETURN 0
End Function
Function CreatePost(content String, hashtag String) Uint64
10 DIM pid as Uint64
20 DIM ts as Uint64
30 DIM idstr as String
40 IF STRLEN(content) == 0 THEN GOTO 210
50 IF STRLEN(content) >= 512 THEN GOTO 210
60 IF STRLEN(hashtag) >= 64 THEN GOTO 210
70 LET pid = LOAD("post_seq") + 1
80 STORE("post_seq", pid)
90 LET idstr = ITOA(pid)
100 STORE("post:"+idstr+":author", SIGNER())
110 STORE("post:"+idstr+":content", content)
120 STORE("post:"+idstr+":likes", 0)
130 STORE("post:"+idstr+":retweetOf", "")
140 STORE("post:"+idstr+":hashtag", hashtag)
150 STORE("post:"+idstr+":ts", BLOCK_TIMESTAMP())
155 DIM tagcntkey as String
156 DIM tagitemkey as String
157 DIM tagcount as Uint64
160 LET tagcntkey = "tag:"+hashtag+":count"
170 IF EXISTS(tagcntkey) == 1 THEN GOTO 190
180 STORE(tagcntkey, 0)
190 LET tagcount = LOAD(tagcntkey) + 1
195 STORE(tagcntkey, tagcount)
196 LET tagitemkey = "tag:"+hashtag+":item:"+ITOA(tagcount)
197 STORE(tagitemkey, idstr)
210 RETURN 0
End Function
Function LikePost(post_id Uint64) Uint64
10 DIM idstr as String
20 DIM likekey as String
30 LET idstr = ITOA(post_id)
40 IF EXISTS("post:"+idstr+":author") == 1 THEN GOTO 60
50 RETURN 1
60 LET likekey = "liked:"+idstr+":"+SIGNER()
70 IF EXISTS(likekey) == 1 THEN GOTO 120
80 STORE(likekey, 1)
90 STORE("post:"+idstr+":likes", LOAD("post:"+idstr+":likes") + 1)
120 RETURN 0
End Function
Function RetweetPost(post_id Uint64, comment String, hashtag String) Uint64
10 DIM pid as Uint64
20 DIM idstr as String
30 DIM new_idstr as String
40 IF STRLEN(comment) >= 512 THEN GOTO 180
50 IF STRLEN(hashtag) >= 64 THEN GOTO 180
60 LET idstr = ITOA(post_id)
70 IF EXISTS("post:"+idstr+":author") == 1 THEN GOTO 90
80 RETURN 1
90 LET pid = LOAD("post_seq") + 1
100 STORE("post_seq", pid)
110 LET new_idstr = ITOA(pid)
120 STORE("post:"+new_idstr+":author", SIGNER())
130 STORE("post:"+new_idstr+":content", comment)
140 STORE("post:"+new_idstr+":likes", 0)
150 STORE("post:"+new_idstr+":retweetOf", idstr)
160 STORE("post:"+new_idstr+":hashtag", hashtag)
170 STORE("post:"+new_idstr+":ts", BLOCK_TIMESTAMP())
175 DIM tagcntkey as String
176 DIM tagitemkey as String
177 DIM tagcount as Uint64
178 LET tagcntkey = "tag:"+hashtag+":count"
179 IF EXISTS(tagcntkey) == 1 THEN GOTO 183
180 STORE(tagcntkey, 0)
183 LET tagcount = LOAD(tagcntkey) + 1
184 STORE(tagcntkey, tagcount)
185 LET tagitemkey = "tag:"+hashtag+":item:"+ITOA(tagcount)
186 STORE(tagitemkey, new_idstr)
200 RETURN 0
End Function
Function SetBio(bio String) Uint64
10 IF STRLEN(bio) >= 512 THEN GOTO 30
20 STORE("bio:"+SIGNER(), bio)
30 RETURN 0
End Function
Function TransferOwnership(newowner String) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("tmpowner", ADDRESS_RAW(newowner))
40 RETURN 0
End Function
Function ClaimOwnership() Uint64
10 IF LOAD("tmpowner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("owner", SIGNER())
40 RETURN 0
End Function
Function Withdraw(amount Uint64) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 SEND_DERO_TO_ADDRESS(SIGNER(), amount)
40 RETURN 0
End Function
Function UpdateCode(code String) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 UPDATE_SC_CODE(code)
40 RETURN 0
End Function'] |