10 | | - | let d = "done" |
---|
11 | | - | |
---|
12 | | - | let e = "_checked_out_by_" |
---|
13 | | - | |
---|
14 | | - | let f = "simple_ChatGPT_task" |
---|
15 | | - | |
---|
16 | | - | let g = "_check_out_height_" |
---|
17 | | - | |
---|
18 | | - | let h = "_register_height_" |
---|
19 | | - | |
---|
20 | | - | let i = "_commit_height_" |
---|
21 | | - | |
---|
22 | | - | func j (k,l) = { |
---|
23 | | - | let m = getString(this, ((k + "_status_") + l)) |
---|
24 | | - | (m == b) |
---|
25 | | - | } |
---|
26 | | - | |
---|
27 | | - | |
---|
28 | | - | func n (k,o,l) = { |
---|
29 | | - | let p = getString(this, ((k + e) + l)) |
---|
30 | | - | (p == o) |
---|
31 | | - | } |
---|
32 | | - | |
---|
33 | | - | |
---|
34 | | - | func q (l) = { |
---|
35 | | - | let r = getInteger(this, ("price_" + l)) |
---|
36 | | - | if ($isInstanceOf(r, "Int")) |
---|
37 | | - | then { |
---|
38 | | - | let s = r |
---|
39 | | - | s |
---|
40 | | - | } |
---|
41 | | - | else -1 |
---|
42 | | - | } |
---|
43 | | - | |
---|
44 | | - | |
---|
45 | | - | @Callable(s) |
---|
46 | | - | func registerTask (t,l) = { |
---|
47 | | - | let u = size(s.payments) |
---|
48 | | - | if ((u != 1)) |
---|
| 10 | + | @Callable(d) |
---|
| 11 | + | func getAnswerForChat (e,f) = { |
---|
| 12 | + | let g = size(d.payments) |
---|
| 13 | + | if ((g != 1)) |
---|
68 | | - | let E = { |
---|
69 | | - | let r = getInteger(this, "dao_sum") |
---|
70 | | - | if ($isInstanceOf(r, "Int")) |
---|
71 | | - | then { |
---|
72 | | - | let D = r |
---|
73 | | - | (D + y) |
---|
74 | | - | } |
---|
75 | | - | else y |
---|
76 | | - | } |
---|
77 | | - | if ((z != a)) |
---|
78 | | - | then throw("Payment only possible in the AI Token!") |
---|
79 | | - | else if ((B == -1)) |
---|
80 | | - | then throw("Task type not supported!") |
---|
81 | | - | else if ((B > y)) |
---|
82 | | - | then throw((("Payment needs to be at least " + toString(B)) + " BAI Token!")) |
---|
83 | | - | else [StringEntry(((k + "_description_") + l), t), StringEntry(((w + "_initializer_") + l), v), StringEntry(((k + "_status_") + l), b), StringEntry((k + "_type"), l), IntegerEntry(((k + h) + l), height), IntegerEntry(((k + "_register_timestamp_") + l), A), BooleanEntry(((("open_" + l) + "_") + k), true), IntegerEntry("dao_sum", E), IntegerEntry(("dao_user_" + v), C)] |
---|
| 28 | + | if (if ((j != c)) |
---|
| 29 | + | then true |
---|
| 30 | + | else (k > i)) |
---|
| 31 | + | then throw("Payment of the minimal BAI amount necessary!") |
---|
| 32 | + | else { |
---|
| 33 | + | let n = toBase58String(d.callerPublicKey) |
---|
| 34 | + | let o = toString(lastBlock.timestamp) |
---|
| 35 | + | let p = invoke(b, "registerTaskCallback", [f, "fullchatgpt", "callback"], [AttachedPayment(c, 10000000)]) |
---|
| 36 | + | if ((p == p)) |
---|
| 37 | + | then { |
---|
| 38 | + | let q = { |
---|
| 39 | + | let l = p |
---|
| 40 | + | if ($isInstanceOf(l, "String")) |
---|
| 41 | + | then { |
---|
| 42 | + | let r = l |
---|
| 43 | + | r |
---|
| 44 | + | } |
---|
| 45 | + | else throw("Unknown task id!") |
---|
| 46 | + | } |
---|
| 47 | + | [StringEntry((e + "_latest"), f), StringEntry((e + "_status"), "waiting"), StringEntry(q, e), StringEntry(((n + "_") + e), ((((f + "_") + o) + "_") + "waiting")), StringEntry((e + "_initiator"), n)] |
---|
| 48 | + | } |
---|
| 49 | + | else throw("Strict value is not equal to itself.") |
---|
| 50 | + | } |
---|
89 | | - | @Callable(s) |
---|
90 | | - | func registerTaskCallback (t,l,F) = { |
---|
91 | | - | let u = size(s.payments) |
---|
92 | | - | if ((u != 1)) |
---|
93 | | - | then throw("Payment necessary!") |
---|
94 | | - | else { |
---|
95 | | - | let v = toBase58String(s.callerPublicKey) |
---|
96 | | - | let G = toString(s.caller) |
---|
97 | | - | let w = toBase58String(s.transactionId) |
---|
98 | | - | let x = s.payments[0] |
---|
99 | | - | let y = x.amount |
---|
100 | | - | let z = x.assetId |
---|
101 | | - | let k = ((w + "_") + v) |
---|
102 | | - | let A = lastBlock.timestamp |
---|
103 | | - | let B = q(l) |
---|
104 | | - | if ((z != a)) |
---|
105 | | - | then throw("Payment only possible in the AI Token!") |
---|
106 | | - | else if ((B == -1)) |
---|
107 | | - | then throw("Task type not supported!") |
---|
108 | | - | else if ((B > y)) |
---|
109 | | - | then throw((("Payment needs to be at least " + toString(B)) + " BAI Token!")) |
---|
110 | | - | else $Tuple2([StringEntry(((k + "_description_") + l), t), StringEntry(((w + "_initializer_") + l), v), StringEntry(((k + "_callback_") + l), F), StringEntry(((k + "_caller_") + l), G), StringEntry(((k + "_status_") + l), b), StringEntry((k + "_type"), l), IntegerEntry(((k + h) + l), height), IntegerEntry(((k + "_register_timestamp_") + l), A), BooleanEntry(((("open_" + l) + "_") + k), true), StringEntry(((("callback_accounting_" + w) + "_") + toString(height)), k)], k) |
---|
| 56 | + | @Callable(d) |
---|
| 57 | + | func callback (q,f) = if ((d.callerPublicKey != a)) |
---|
| 58 | + | then throw("Only BAI Contract is allowed to call the callback!") |
---|
| 59 | + | else { |
---|
| 60 | + | let e = { |
---|
| 61 | + | let l = getString(q) |
---|
| 62 | + | if ($isInstanceOf(l, "String")) |
---|
| 63 | + | then { |
---|
| 64 | + | let r = l |
---|
| 65 | + | r |
---|
| 66 | + | } |
---|
| 67 | + | else throw("Chat ID for task id not found!") |
---|
112 | | - | } |
---|
| 69 | + | let n = { |
---|
| 70 | + | let l = getString((e + "_initiator")) |
---|
| 71 | + | if ($isInstanceOf(l, "String")) |
---|
| 72 | + | then { |
---|
| 73 | + | let r = l |
---|
| 74 | + | r |
---|
| 75 | + | } |
---|
| 76 | + | else throw("No initiator found!") |
---|
| 77 | + | } |
---|
| 78 | + | let o = toString(lastBlock.timestamp) |
---|
| 79 | + | [StringEntry((e + "_latest"), f), StringEntry((e + "_status"), "done"), StringEntry(((n + "_") + e), ((((f + "_") + o) + "_") + "done")), StringEntry("caller", toBase58String(d.callerPublicKey))] |
---|
| 80 | + | } |
---|
115 | | - | |
---|
116 | | - | @Callable(s) |
---|
117 | | - | func checkoutTask (k,l) = { |
---|
118 | | - | let v = toBase58String(s.callerPublicKey) |
---|
119 | | - | let H = j(k, l) |
---|
120 | | - | let A = lastBlock.timestamp |
---|
121 | | - | if (!(H)) |
---|
122 | | - | then throw("Task not open for checkout!") |
---|
123 | | - | else [StringEntry(((k + e) + l), v), StringEntry(((k + "_status_") + l), c), IntegerEntry(((k + g) + l), height), IntegerEntry(((k + "_check_out_timestamp_") + l), A), BooleanEntry(((((("checked_out_by_" + v) + "_") + l) + "_") + k), true), DeleteEntry(((("open_" + l) + "_") + k))] |
---|
124 | | - | } |
---|
125 | | - | |
---|
126 | | - | |
---|
127 | | - | |
---|
128 | | - | @Callable(s) |
---|
129 | | - | func commitTask (k,I) = { |
---|
130 | | - | let v = toBase58String(s.callerPublicKey) |
---|
131 | | - | let l = { |
---|
132 | | - | let r = getString((k + "_type")) |
---|
133 | | - | if ($isInstanceOf(r, "String")) |
---|
134 | | - | then { |
---|
135 | | - | let J = r |
---|
136 | | - | J |
---|
137 | | - | } |
---|
138 | | - | else "not set" |
---|
139 | | - | } |
---|
140 | | - | let K = n(k, v, l) |
---|
141 | | - | let A = lastBlock.timestamp |
---|
142 | | - | let F = { |
---|
143 | | - | let r = getString(((k + "_callback_") + l)) |
---|
144 | | - | if ($isInstanceOf(r, "String")) |
---|
145 | | - | then { |
---|
146 | | - | let J = r |
---|
147 | | - | J |
---|
148 | | - | } |
---|
149 | | - | else "no callback" |
---|
150 | | - | } |
---|
151 | | - | let G = { |
---|
152 | | - | let r = getString(((k + "_caller_") + l)) |
---|
153 | | - | if ($isInstanceOf(r, "String")) |
---|
154 | | - | then { |
---|
155 | | - | let J = r |
---|
156 | | - | J |
---|
157 | | - | } |
---|
158 | | - | else "no callback" |
---|
159 | | - | } |
---|
160 | | - | if (!(K)) |
---|
161 | | - | then throw("Task may only be submitted by the agent who checked the task out!") |
---|
162 | | - | else if ((l == "not set")) |
---|
163 | | - | then throw("Can not identify type of task id") |
---|
164 | | - | else if ((F != "no callback")) |
---|
165 | | - | then { |
---|
166 | | - | let L = invoke(Address(fromBase58String(G)), F, [k, I], nil) |
---|
167 | | - | if ((L == L)) |
---|
168 | | - | then [StringEntry(((k + "_status_") + l), d), StringEntry(((k + "_result_") + l), I), IntegerEntry(((k + i) + l), height), IntegerEntry(((k + "_commit_timestamp_") + l), A), DeleteEntry(((((("checked_out_by_" + v) + "_") + l) + "_") + k))] |
---|
169 | | - | else throw("Strict value is not equal to itself.") |
---|
170 | | - | } |
---|
171 | | - | else [StringEntry(((k + "_status_") + l), d), StringEntry(((k + "_result_") + l), I), IntegerEntry(((k + i) + l), height), IntegerEntry(((k + "_commit_timestamp_") + l), A), DeleteEntry(((((("checked_out_by_" + v) + "_") + l) + "_") + k))] |
---|
172 | | - | } |
---|
173 | | - | |
---|
174 | | - | |
---|
175 | | - | @Verifier(M) |
---|
176 | | - | func N () = sigVerify(M.bodyBytes, M.proofs[0], M.senderPublicKey) |
---|
| 83 | + | @Verifier(s) |
---|
| 84 | + | func t () = sigVerify(s.bodyBytes, s.proofs[0], s.senderPublicKey) |
---|