27 | | - | func n (o,p) = if (isDefined(getBinary(this, o))) |
---|
28 | | - | then getBinaryValue(this, o) |
---|
29 | | - | else p |
---|
30 | | - | |
---|
31 | | - | |
---|
32 | | - | func q (r) = if (if ((r == h)) |
---|
33 | | - | then true |
---|
34 | | - | else (r == i)) |
---|
35 | | - | then true |
---|
36 | | - | else (r == j) |
---|
37 | | - | |
---|
38 | | - | |
---|
39 | | - | func s (t) = if (if (if ((size(t) >= g)) |
---|
40 | | - | then q(k(t, 0)) |
---|
41 | | - | else false) |
---|
42 | | - | then q(k(t, 1)) |
---|
43 | | - | else false) |
---|
44 | | - | then q(k(t, 2)) |
---|
45 | | - | else false |
---|
46 | | - | |
---|
47 | | - | |
---|
48 | | - | func u (v,w,u) = { |
---|
49 | | - | let x = k(v, u) |
---|
50 | | - | let y = k(w, u) |
---|
51 | | - | if ((x == y)) |
---|
52 | | - | then 0 |
---|
53 | | - | else if (if (if (if ((x == j)) |
---|
54 | | - | then (y == i) |
---|
55 | | - | else false) |
---|
56 | | - | then true |
---|
57 | | - | else if ((x == h)) |
---|
58 | | - | then (y == j) |
---|
59 | | - | else false) |
---|
60 | | - | then true |
---|
61 | | - | else if ((x == i)) |
---|
62 | | - | then (y == h) |
---|
63 | | - | else false) |
---|
64 | | - | then -1 |
---|
65 | | - | else 1 |
---|
66 | | - | } |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | func z (v,w) = ((u(v, w, 0) + u(v, w, 1)) + u(v, w, 2)) |
---|
70 | | - | |
---|
71 | | - | |
---|
72 | | - | func A (B,C) = DataEntry(B, (n(B, b) + C)) |
---|
73 | | - | |
---|
74 | | - | |
---|
75 | | - | @Callable(D) |
---|
76 | | - | func create (E) = { |
---|
77 | | - | let F = extract(D.payment) |
---|
78 | | - | if (isDefined(F.assetId)) |
---|
79 | | - | then throw("Payment should be in WAVES.") |
---|
80 | | - | else if ((F.amount != (1 * a))) |
---|
81 | | - | then throw("Amount should be 1 WAVE.") |
---|
82 | | - | else if ((size(E) != c)) |
---|
83 | | - | then throw("Invalid moves.") |
---|
84 | | - | else WriteSet([A(((toBase58String(D.callerPublicKey) + "_") + toBase58String(D.transactionId)), E)]) |
---|
85 | | - | } |
---|
86 | | - | |
---|
87 | | - | |
---|
88 | | - | |
---|
89 | | - | @Callable(D) |
---|
90 | | - | func join (B,t) = { |
---|
91 | | - | let F = extract(D.payment) |
---|
92 | | - | if (isDefined(F.assetId)) |
---|
93 | | - | then throw("Payment should be in WAVES.") |
---|
94 | | - | else if ((F.amount != (1 * a))) |
---|
95 | | - | then throw("Amount should be 1 WAVE.") |
---|
96 | | - | else if (!(isDefined(getBinary(this, B)))) |
---|
97 | | - | then throw("Fight is not found.") |
---|
98 | | - | else if ((size(getBinaryValue(this, B)) != c)) |
---|
99 | | - | then throw("Fight is already started.") |
---|
100 | | - | else if (!(s(t))) |
---|
101 | | - | then throw("Invalid moves.") |
---|
102 | | - | else WriteSet([A(B, ((toBytes(height) + D.callerPublicKey) + t))]) |
---|
103 | | - | } |
---|
104 | | - | |
---|
105 | | - | |
---|
106 | | - | |
---|
107 | | - | @Callable(D) |
---|
108 | | - | func complete (B,t) = if (!(isDefined(getBinary(this, B)))) |
---|
109 | | - | then throw("Fight is not found.") |
---|
110 | | - | else { |
---|
111 | | - | let G = getBinaryValue(this, B) |
---|
112 | | - | if ((size(G) == c)) |
---|
113 | | - | then throw("Fight is not started.") |
---|
114 | | - | else if ((size(G) > (((c + e) + d) + g))) |
---|
115 | | - | then throw("Fight is already finished.") |
---|
116 | | - | else { |
---|
117 | | - | let H = take(getBinaryValue(this, B), c) |
---|
118 | | - | if (if ((H != blake2b256(t))) |
---|
119 | | - | then true |
---|
120 | | - | else !(s(t))) |
---|
121 | | - | then throw("Invalid moves.") |
---|
122 | | - | else { |
---|
123 | | - | let I = takeRightBytes(dropRightBytes(G, g), d) |
---|
124 | | - | let J = z(take(t, g), takeRightBytes(G, g)) |
---|
125 | | - | ScriptResult(WriteSet([A(B, t)]), TransferSet(if ((J == 0)) |
---|
126 | | - | then [ScriptTransfer(D.caller, (1 * a), unit), ScriptTransfer(addressFromPublicKey(I), (1 * a), unit)] |
---|
127 | | - | else if ((0 > J)) |
---|
128 | | - | then [ScriptTransfer(D.caller, (2 * a), unit)] |
---|
129 | | - | else [ScriptTransfer(addressFromPublicKey(I), (2 * a), unit)])) |
---|
130 | | - | } |
---|
131 | | - | } |
---|
132 | | - | } |
---|
133 | | - | |
---|
134 | | - | |
---|
135 | | - | |
---|
136 | | - | @Callable(D) |
---|
137 | | - | func timeout (B) = if (!(isDefined(getBinary(this, B)))) |
---|
138 | | - | then throw("Fight is not found.") |
---|
139 | | - | else { |
---|
140 | | - | let G = getBinaryValue(this, B) |
---|
141 | | - | if ((size(G) == c)) |
---|
142 | | - | then throw("Fight is not started.") |
---|
143 | | - | else if ((size(G) > (((c + e) + d) + g))) |
---|
144 | | - | then throw("Fight is already finished.") |
---|
145 | | - | else { |
---|
146 | | - | let K = toInt(take(drop(G, c), e)) |
---|
147 | | - | if ((f > (height - K))) |
---|
148 | | - | then throw("Player1 still has a time to complete the fight.") |
---|
149 | | - | else { |
---|
150 | | - | let I = takeRightBytes(dropRightBytes(G, g), d) |
---|
151 | | - | ScriptResult(WriteSet([A(B, I)]), TransferSet([ScriptTransfer(addressFromPublicKey(I), (2 * a), unit)])) |
---|
152 | | - | } |
---|
153 | | - | } |
---|
154 | | - | } |
---|
| 6 | + | @Callable(a) |
---|
| 7 | + | func foo (b) = WriteSet([DataEntry("data", size(b))]) |
---|