SC CODE: Function Initialize() Uint64
10 IF EXISTS("contract_version") == 1 THEN GOTO 900
20 STORE("contract_version", 1)
30 STORE("total_publishes", 0)
40 STORE("name_0", "")
41 STORE("score_0", 0)
42 STORE("addr_0", "")
43 STORE("time_0", 0)
50 STORE("name_1", "")
51 STORE("score_1", 0)
52 STORE("addr_1", "")
53 STORE("time_1", 0)
60 STORE("name_2", "")
61 STORE("score_2", 0)
62 STORE("addr_2", "")
63 STORE("time_2", 0)
70 STORE("name_3", "")
71 STORE("score_3", 0)
72 STORE("addr_3", "")
73 STORE("time_3", 0)
80 STORE("name_4", "")
81 STORE("score_4", 0)
82 STORE("addr_4", "")
83 STORE("time_4", 0)
900 RETURN 0
End Function
Function TestStore() Uint64
10 STORE("last_test", "ok")
20 STORE("last_test_height", BLOCK_HEIGHT())
30 RETURN 0
End Function
Function Publish(pseudo String, score Uint64) Uint64
10 IF STRLEN(pseudo) < 1 THEN GOTO 900
20 IF STRLEN(pseudo) > 16 THEN GOTO 900
30 IF score == 0 THEN GOTO 900
40 DIM s0 as Uint64
41 DIM s1 as Uint64
42 DIM s2 as Uint64
43 DIM s3 as Uint64
44 DIM s4 as Uint64
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 DIM min_slot as Uint64
61 DIM min_score as Uint64
70 LET min_slot = 0
71 LET min_score = s0
80 IF s1 >= min_score THEN GOTO 90
81 LET min_slot = 1
82 LET min_score = s1
90 IF s2 >= min_score THEN GOTO 100
91 LET min_slot = 2
92 LET min_score = s2
100 IF s3 >= min_score THEN GOTO 110
101 LET min_slot = 3
102 LET min_score = s3
110 IF s4 >= min_score THEN GOTO 200
111 LET min_slot = 4
112 LET min_score = s4
200 IF score <= min_score THEN GOTO 910
210 IF min_slot == 0 THEN GOTO 300
211 IF min_slot == 1 THEN GOTO 400
212 IF min_slot == 2 THEN GOTO 500
213 IF min_slot == 3 THEN GOTO 600
214 IF min_slot == 4 THEN GOTO 700
300 STORE("name_0", pseudo)
301 STORE("score_0", score)
302 STORE("addr_0", SIGNER())
303 STORE("time_0", BLOCK_HEIGHT())
304 GOTO 800
400 STORE("name_1", pseudo)
401 STORE("score_1", score)
402 STORE("addr_1", SIGNER())
403 STORE("time_1", BLOCK_HEIGHT())
404 GOTO 800
500 STORE("name_2", pseudo)
501 STORE("score_2", score)
502 STORE("addr_2", SIGNER())
503 STORE("time_2", BLOCK_HEIGHT())
504 GOTO 800
600 STORE("name_3", pseudo)
601 STORE("score_3", score)
602 STORE("addr_3", SIGNER())
603 STORE("time_3", BLOCK_HEIGHT())
604 GOTO 800
700 STORE("name_4", pseudo)
701 STORE("score_4", score)
702 STORE("addr_4", SIGNER())
703 STORE("time_4", BLOCK_HEIGHT())
704 GOTO 800
800 STORE("total_publishes", LOAD("total_publishes") + 1)
801 RETURN 0
900 RETURN 1
910 RETURN 2
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", 1)
30 STORE("total_publishes", 0)
40 STORE("name_0", "")
41 STORE("score_0", 0)
42 STORE("addr_0", "")
43 STORE("time_0", 0)
50 STORE("name_1", "")
51 STORE("score_1", 0)
52 STORE("addr_1", "")
53 STORE("time_1", 0)
60 STORE("name_2", "")
61 STORE("score_2", 0)
62 STORE("addr_2", "")
63 STORE("time_2", 0)
70 STORE("name_3", "")
71 STORE("score_3", 0)
72 STORE("addr_3", "")
73 STORE("time_3", 0)
80 STORE("name_4", "")
81 STORE("score_4", 0)
82 STORE("addr_4", "")
83 STORE("time_4", 0)
900 RETURN 0
End Function
Function TestStore() Uint64
10 STORE("last_test", "ok")
20 STORE("last_test_height", BLOCK_HEIGHT())
30 RETURN 0
End Function
Function Publish(pseudo String, score Uint64) Uint64
10 IF STRLEN(pseudo) < 1 THEN GOTO 900
20 IF STRLEN(pseudo) > 16 THEN GOTO 900
30 IF score == 0 THEN GOTO 900
40 DIM s0 as Uint64
41 DIM s1 as Uint64
42 DIM s2 as Uint64
43 DIM s3 as Uint64
44 DIM s4 as Uint64
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 DIM min_slot as Uint64
61 DIM min_score as Uint64
70 LET min_slot = 0
71 LET min_score = s0
80 IF s1 >= min_score THEN GOTO 90
81 LET min_slot = 1
82 LET min_score = s1
90 IF s2 >= min_score THEN GOTO 100
91 LET min_slot = 2
92 LET min_score = s2
100 IF s3 >= min_score THEN GOTO 110
101 LET min_slot = 3
102 LET min_score = s3
110 IF s4 >= min_score THEN GOTO 200
111 LET min_slot = 4
112 LET min_score = s4
200 IF score <= min_score THEN GOTO 910
210 IF min_slot == 0 THEN GOTO 300
211 IF min_slot == 1 THEN GOTO 400
212 IF min_slot == 2 THEN GOTO 500
213 IF min_slot == 3 THEN GOTO 600
214 IF min_slot == 4 THEN GOTO 700
300 STORE("name_0", pseudo)
301 STORE("score_0", score)
302 STORE("addr_0", SIGNER())
303 STORE("time_0", BLOCK_HEIGHT())
304 GOTO 800
400 STORE("name_1", pseudo)
401 STORE("score_1", score)
402 STORE("addr_1", SIGNER())
403 STORE("time_1", BLOCK_HEIGHT())
404 GOTO 800
500 STORE("name_2", pseudo)
501 STORE("score_2", score)
502 STORE("addr_2", SIGNER())
503 STORE("time_2", BLOCK_HEIGHT())
504 GOTO 800
600 STORE("name_3", pseudo)
601 STORE("score_3", score)
602 STORE("addr_3", SIGNER())
603 STORE("time_3", BLOCK_HEIGHT())
604 GOTO 800
700 STORE("name_4", pseudo)
701 STORE("score_4", score)
702 STORE("addr_4", SIGNER())
703 STORE("time_4", BLOCK_HEIGHT())
704 GOTO 800
800 STORE("total_publishes", LOAD("total_publishes") + 1)
801 RETURN 0
900 RETURN 1
910 RETURN 2
End Function
'] |