SC CODE: Function Initialize() Uint64
10 IF EXISTS("contract_version") == 1 THEN GOTO 900
20 STORE("contract_version", 2)
21 STORE("owner", SIGNER())
22 STORE("total_publishes", 0)
30 STORE("name_0", "")
31 STORE("score_0", 0)
32 STORE("addr_0", "")
33 STORE("time_0", 0)
40 STORE("name_1", "")
41 STORE("score_1", 0)
42 STORE("addr_1", "")
43 STORE("time_1", 0)
50 STORE("name_2", "")
51 STORE("score_2", 0)
52 STORE("addr_2", "")
53 STORE("time_2", 0)
60 STORE("name_3", "")
61 STORE("score_3", 0)
62 STORE("addr_3", "")
63 STORE("time_3", 0)
70 STORE("name_4", "")
71 STORE("score_4", 0)
72 STORE("addr_4", "")
73 STORE("time_4", 0)
900 RETURN 0
End Function
Function Publish(pseudo String, score Uint64) Uint64
10 DIM s0, s1, s2, s3, s4 as Uint64
11 DIM min_slot, min_score, height, last_block as Uint64
12 DIM signer_raw, last_key as String
20 IF DEROVALUE() < 1000 THEN GOTO 900
21 SEND_DERO_TO_ADDRESS(LOAD("owner"), DEROVALUE())
22 IF score == 0 THEN GOTO 900
23 IF score >= 2000 THEN GOTO 900
24 IF STRLEN(pseudo) < 1 THEN GOTO 900
25 IF STRLEN(pseudo) > 16 THEN GOTO 900
30 LET signer_raw = SIGNER()
31 LET last_key = "last_publish:" + signer_raw
32 LET height = BLOCK_HEIGHT()
40 IF EXISTS(last_key) == 0 THEN GOTO 50
41 LET last_block = LOAD(last_key)
42 IF height - last_block < 100 THEN GOTO 920
50 LET s0 = LOAD("score_0")
51 LET s1 = LOAD("score_1")
52 LET s2 = LOAD("score_2")
53 LET s3 = LOAD("score_3")
54 LET s4 = LOAD("score_4")
60 LET min_slot = 0
61 LET min_score = s0
70 IF s1 >= min_score THEN GOTO 80
71 LET min_slot = 1
72 LET min_score = s1
80 IF s2 >= min_score THEN GOTO 90
81 LET min_slot = 2
82 LET min_score = s2
90 IF s3 >= min_score THEN GOTO 100
91 LET min_slot = 3
92 LET min_score = s3
100 IF s4 >= min_score THEN GOTO 110
101 LET min_slot = 4
102 LET min_score = s4
110 IF score <= min_score THEN GOTO 910
120 IF min_slot == 0 THEN GOTO 200
121 IF min_slot == 1 THEN GOTO 300
122 IF min_slot == 2 THEN GOTO 400
123 IF min_slot == 3 THEN GOTO 500
124 IF min_slot == 4 THEN GOTO 600
200 STORE("name_0", pseudo)
201 STORE("score_0", score)
202 STORE("addr_0", signer_raw)
203 STORE("time_0", height)
204 GOTO 800
300 STORE("name_1", pseudo)
301 STORE("score_1", score)
302 STORE("addr_1", signer_raw)
303 STORE("time_1", height)
304 GOTO 800
400 STORE("name_2", pseudo)
401 STORE("score_2", score)
402 STORE("addr_2", signer_raw)
403 STORE("time_2", height)
404 GOTO 800
500 STORE("name_3", pseudo)
501 STORE("score_3", score)
502 STORE("addr_3", signer_raw)
503 STORE("time_3", height)
504 GOTO 800
600 STORE("name_4", pseudo)
601 STORE("score_4", score)
602 STORE("addr_4", signer_raw)
603 STORE("time_4", height)
604 GOTO 800
800 STORE("total_publishes", LOAD("total_publishes") + 1)
801 STORE(last_key, height)
802 RETURN 0
900 RETURN 1
910 RETURN 2
920 RETURN 3
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:'Function Initialize() Uint64
10 IF EXISTS("contract_version") == 1 THEN GOTO 900
20 STORE("contract_version", 2)
21 STORE("owner", SIGNER())
22 STORE("total_publishes", 0)
30 STORE("name_0", "")
31 STORE("score_0", 0)
32 STORE("addr_0", "")
33 STORE("time_0", 0)
40 STORE("name_1", "")
41 STORE("score_1", 0)
42 STORE("addr_1", "")
43 STORE("time_1", 0)
50 STORE("name_2", "")
51 STORE("score_2", 0)
52 STORE("addr_2", "")
53 STORE("time_2", 0)
60 STORE("name_3", "")
61 STORE("score_3", 0)
62 STORE("addr_3", "")
63 STORE("time_3", 0)
70 STORE("name_4", "")
71 STORE("score_4", 0)
72 STORE("addr_4", "")
73 STORE("time_4", 0)
900 RETURN 0
End Function
Function Publish(pseudo String, score Uint64) Uint64
10 DIM s0, s1, s2, s3, s4 as Uint64
11 DIM min_slot, min_score, height, last_block as Uint64
12 DIM signer_raw, last_key as String
20 IF DEROVALUE() < 1000 THEN GOTO 900
21 SEND_DERO_TO_ADDRESS(LOAD("owner"), DEROVALUE())
22 IF score == 0 THEN GOTO 900
23 IF score >= 2000 THEN GOTO 900
24 IF STRLEN(pseudo) < 1 THEN GOTO 900
25 IF STRLEN(pseudo) > 16 THEN GOTO 900
30 LET signer_raw = SIGNER()
31 LET last_key = "last_publish:" + signer_raw
32 LET height = BLOCK_HEIGHT()
40 IF EXISTS(last_key) == 0 THEN GOTO 50
41 LET last_block = LOAD(last_key)
42 IF height - last_block < 100 THEN GOTO 920
50 LET s0 = LOAD("score_0")
51 LET s1 = LOAD("score_1")
52 LET s2 = LOAD("score_2")
53 LET s3 = LOAD("score_3")
54 LET s4 = LOAD("score_4")
60 LET min_slot = 0
61 LET min_score = s0
70 IF s1 >= min_score THEN GOTO 80
71 LET min_slot = 1
72 LET min_score = s1
80 IF s2 >= min_score THEN GOTO 90
81 LET min_slot = 2
82 LET min_score = s2
90 IF s3 >= min_score THEN GOTO 100
91 LET min_slot = 3
92 LET min_score = s3
100 IF s4 >= min_score THEN GOTO 110
101 LET min_slot = 4
102 LET min_score = s4
110 IF score <= min_score THEN GOTO 910
120 IF min_slot == 0 THEN GOTO 200
121 IF min_slot == 1 THEN GOTO 300
122 IF min_slot == 2 THEN GOTO 400
123 IF min_slot == 3 THEN GOTO 500
124 IF min_slot == 4 THEN GOTO 600
200 STORE("name_0", pseudo)
201 STORE("score_0", score)
202 STORE("addr_0", signer_raw)
203 STORE("time_0", height)
204 GOTO 800
300 STORE("name_1", pseudo)
301 STORE("score_1", score)
302 STORE("addr_1", signer_raw)
303 STORE("time_1", height)
304 GOTO 800
400 STORE("name_2", pseudo)
401 STORE("score_2", score)
402 STORE("addr_2", signer_raw)
403 STORE("time_2", height)
404 GOTO 800
500 STORE("name_3", pseudo)
501 STORE("score_3", score)
502 STORE("addr_3", signer_raw)
503 STORE("time_3", height)
504 GOTO 800
600 STORE("name_4", pseudo)
601 STORE("score_4", score)
602 STORE("addr_4", signer_raw)
603 STORE("time_4", height)
604 GOTO 800
800 STORE("total_publishes", LOAD("total_publishes") + 1)
801 STORE(last_key, height)
802 RETURN 0
900 RETURN 1
910 RETURN 2
920 RETURN 3
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
'] |