tx · DwHkFLxNsAVbSrHcoLTHD2XBxAJnuVUaeVi8iiL3kvA1

3N9tKixzqTYWnEXQxrDQ5pBTGvQd6sFsvmV:  -0.05000000 Waves

2024.10.28 10:17 [3346410] smart account 3N9tKixzqTYWnEXQxrDQ5pBTGvQd6sFsvmV > SELF 0.00000000 Waves

{ "type": 13, "id": "DwHkFLxNsAVbSrHcoLTHD2XBxAJnuVUaeVi8iiL3kvA1", "fee": 5000000, "feeAssetId": null, "timestamp": 1730099881834, "version": 2, "chainId": 84, "sender": "3N9tKixzqTYWnEXQxrDQ5pBTGvQd6sFsvmV", "senderPublicKey": "DS6HkopS9zypvxX6VhkdNvv6v4wcPZuChRvTwKJeacxE", "proofs": [ "5skE7Fk9Pc1zjgK8XuEyVSYcrhmPTXZYTwN5vprVc2uoVH3j1zPaUqQG5cNPCooeeSCY6YjHiiFSijqQFEkUyg9r" ], "script": "base64:AAIFAAAAAAAAAA4IAhIECgIICBIECgIICAAAAAMAAAAAF0JBSV9DT05UUkFDVF9QVUJMSUNfS0VZAQAAACC4ub5WQ6dKmSY4XOD0ENHA5nSTpo3ZXmT/mOT2RZ2+BwAAAAAMQkFJX0NPTlRSQUNUCQEAAAAUYWRkcmVzc0Zyb21QdWJsaWNLZXkAAAABBQAAABdCQUlfQ09OVFJBQ1RfUFVCTElDX0tFWQAAAAAMQkFJX0FTU0VUX0lEAQAAACCT4XI4cQSbauiaYx8EJLdkU5csPrxmC4N0r2i7JI3iQgAAAAIAAAABaQEAAAAQZ2V0QW5zd2VyRm9yQ2hhdAAAAAIAAAAGY2hhdElkAAAAA2NpZAQAAAAQbnVtYmVyT2ZQYXltZW50cwkAAZAAAAABCAUAAAABaQAAAAhwYXltZW50cwMJAQAAAAIhPQAAAAIFAAAAEG51bWJlck9mUGF5bWVudHMAAAAAAAAAAAEJAAACAAAAAQIAAAASUGF5bWVudCBuZWNlc3NhcnkhBAAAAAdwYXltZW50CQABkQAAAAIIBQAAAAFpAAAACHBheW1lbnRzAAA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UAAAAGY2hhdElkAgAAAApfaW5pdGlhdG9yAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAXMFAAAAByRtYXRjaDAFAAAAAXMJAAACAAAAAQIAAAATTm8gaW5pdGlhdG9yIGZvdW5kIQQAAAAJdGltZXN0YW1wCQABpAAAAAEIBQAAAAlsYXN0QmxvY2sAAAAJdGltZXN0YW1wCQAETAAAAAIJAQAAAAtTdHJpbmdFbnRyeQAAAAIJAAEsAAAAAgUAAAAGY2hhdElkAgAAAAdfbGF0ZXN0BQAAAANjaWQJAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgkAASwAAAACBQAAAAZjaGF0SWQCAAAAB19zdGF0dXMCAAAABGRvbmUJAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgkAASwAAAACCQABLAAAAAIFAAAACXB1YmxpY0tleQIAAAABXwUAAAAGY2hhdElkCQABLAAAAAIJAAEsAAAAAgkAASwAAAACCQABLAAAAAIFAAAAA2NpZAIAAAABXwUAAAAJdGltZXN0YW1wAgAAAAFfAgAAAARkb25lCQAETAAAAAIJAQAAAAtTdHJpbmdFbnRyeQAAAAICAAAABmNhbGxlcgkAAlgAAAABCAUAAAABaQAAAA9jYWxsZXJQdWJsaWNLZXkFAAAAA25pbAAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAACAUAAAACdHgAAAAPc2VuZGVyUHVibGljS2V5EZD+xA==", "height": 3346410, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3X47SC5puiDbDG9fY1MKzSrqJwhB5pd9h61SfSfxpsPK Next: 8FfhZKXNXG9SNHYDcsrANSKfKaSobwU281H5wQXSCBMo Diff:
OldNewDifferences
1-{-# STDLIB_VERSION 6 #-}
1+{-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let AI_TOKEN_ASSET_ID = base58'AxGKQRxKo4F2EbhrRq6N2tdLsxtMnpzQsS4QemV6V1W1'
4+let BAI_CONTRACT_PUBLIC_KEY = base58'DS6HkopS9zypvxX6VhkdNvv6v4wcPZuChRvTwKJeacxE'
55
6-let STATUS_OPEN = "open"
6+let BAI_CONTRACT = addressFromPublicKey(BAI_CONTRACT_PUBLIC_KEY)
77
8-let STATUS_CHECKED_OUT = "checked_out"
9-
10-let STATUS_DONE = "done"
11-
12-let CHECKED_OUT_BY = "_checked_out_by_"
13-
14-let SIMPLE_CHATGPT_TASK = "simple_ChatGPT_task"
15-
16-let CHECK_OUT_HEIGHT = "_check_out_height_"
17-
18-let REGISTER_HEIGHT = "_register_height_"
19-
20-let COMMIT_HEIGHT = "_commit_height_"
21-
22-func canBeCheckedOut (taskId,type) = {
23- let status = getString(this, ((taskId + "_status_") + type))
24- (status == STATUS_OPEN)
25- }
26-
27-
28-func isCorrectAgent (taskId,agentId,type) = {
29- let checkoutAgentId = getString(this, ((taskId + CHECKED_OUT_BY) + type))
30- (checkoutAgentId == agentId)
31- }
32-
33-
34-func getPriceForType (type) = match getInteger(this, ("price_" + type)) {
35- case i: Int =>
36- i
37- case _ =>
38- -1
39-}
40-
8+let BAI_ASSET_ID = base58'AxGKQRxKo4F2EbhrRq6N2tdLsxtMnpzQsS4QemV6V1W1'
419
4210 @Callable(i)
43-func registerTask (description,type) = {
11+func getAnswerForChat (chatId,cid) = {
4412 let numberOfPayments = size(i.payments)
4513 if ((numberOfPayments != 1))
4614 then throw("Payment necessary!")
4715 else {
48- let callerPublicKey = toBase58String(i.callerPublicKey)
49- let txId = toBase58String(i.transactionId)
5016 let payment = i.payments[0]
5117 let fee = payment.amount
5218 let feeAssetId = payment.assetId
53- let taskId = ((txId + "_") + callerPublicKey)
54- let timestamp = lastBlock.timestamp
55- let minFee = getPriceForType(type)
56- let daoUserValue = match getInteger(this, ("dao_user_" + callerPublicKey)) {
19+ let minFee = match getInteger(BAI_CONTRACT, "price_fullchatgpt") {
5720 case n: Int =>
58- (n + fee)
21+ n
5922 case _ =>
60- fee
23+ 0
6124 }
62- let daoSum = match getInteger(this, "dao_sum") {
63- case n: Int =>
64- (n + fee)
65- case _ =>
66- fee
67- }
68- if ((feeAssetId != AI_TOKEN_ASSET_ID))
69- then throw("Payment only possible in the AI Token!")
70- else if ((minFee == -1))
71- then throw("Task type not supported!")
72- else if ((minFee > fee))
73- then throw((("Payment needs to be at least " + toString(minFee)) + " BAI Token!"))
74- else [StringEntry(((taskId + "_description_") + type), description), StringEntry(((txId + "_initializer_") + type), callerPublicKey), StringEntry(((taskId + "_status_") + type), STATUS_OPEN), StringEntry((taskId + "_type"), type), IntegerEntry(((taskId + REGISTER_HEIGHT) + type), height), IntegerEntry(((taskId + "_register_timestamp_") + type), timestamp), BooleanEntry(((("open_" + type) + "_") + taskId), true), IntegerEntry("dao_sum", daoSum), IntegerEntry(("dao_user_" + callerPublicKey), daoUserValue)]
25+ if (if ((feeAssetId != BAI_ASSET_ID))
26+ then true
27+ else (minFee > fee))
28+ then throw("Payment of the minimal BAI amount necessary!")
29+ else {
30+ let publicKey = toBase58String(i.callerPublicKey)
31+ let timestamp = toString(lastBlock.timestamp)
32+ let result = invoke(BAI_CONTRACT, "registerTaskCallback", [cid, "fullchatgpt", "callback"], [AttachedPayment(BAI_ASSET_ID, 10000000)])
33+ if ((result == result))
34+ then {
35+ let taskId = match result {
36+ case s: String =>
37+ s
38+ case _ =>
39+ throw("Unknown task id!")
40+ }
41+[StringEntry((chatId + "_latest"), cid), StringEntry((chatId + "_status"), "waiting"), StringEntry(taskId, chatId), StringEntry(((publicKey + "_") + chatId), ((((cid + "_") + timestamp) + "_") + "waiting")), StringEntry((chatId + "_initiator"), publicKey)]
42+ }
43+ else throw("Strict value is not equal to itself.")
44+ }
7545 }
7646 }
7747
7848
7949
8050 @Callable(i)
81-func registerTaskCallback (description,type,callback) = {
82- let numberOfPayments = size(i.payments)
83- if ((numberOfPayments != 1))
84- then throw("Payment necessary!")
85- else {
86- let callerPublicKey = toBase58String(i.callerPublicKey)
87- let caller = toString(i.caller)
88- let txId = toBase58String(i.transactionId)
89- let payment = i.payments[0]
90- let fee = payment.amount
91- let feeAssetId = payment.assetId
92- let taskId = ((txId + "_") + callerPublicKey)
93- let timestamp = lastBlock.timestamp
94- let minFee = getPriceForType(type)
95- if ((feeAssetId != AI_TOKEN_ASSET_ID))
96- then throw("Payment only possible in the AI Token!")
97- else if ((minFee == -1))
98- then throw("Task type not supported!")
99- else if ((minFee > fee))
100- then throw((("Payment needs to be at least " + toString(minFee)) + " BAI Token!"))
101- else $Tuple2([StringEntry(((taskId + "_description_") + type), description), StringEntry(((txId + "_initializer_") + type), callerPublicKey), StringEntry(((taskId + "_callback_") + type), callback), StringEntry(((taskId + "_caller_") + type), caller), StringEntry(((taskId + "_status_") + type), STATUS_OPEN), StringEntry((taskId + "_type"), type), IntegerEntry(((taskId + REGISTER_HEIGHT) + type), height), IntegerEntry(((taskId + "_register_timestamp_") + type), timestamp), BooleanEntry(((("open_" + type) + "_") + taskId), true), StringEntry(((("callback_accounting_" + txId) + "_") + toString(height)), taskId)], taskId)
102- }
103- }
104-
105-
106-
107-@Callable(i)
108-func checkoutTask (taskId,type) = {
109- let callerPublicKey = toBase58String(i.callerPublicKey)
110- let taskStillOpen = canBeCheckedOut(taskId, type)
111- let timestamp = lastBlock.timestamp
112- if (!(taskStillOpen))
113- then throw("Task not open for checkout!")
114- else [StringEntry(((taskId + CHECKED_OUT_BY) + type), callerPublicKey), StringEntry(((taskId + "_status_") + type), STATUS_CHECKED_OUT), IntegerEntry(((taskId + CHECK_OUT_HEIGHT) + type), height), IntegerEntry(((taskId + "_check_out_timestamp_") + type), timestamp), BooleanEntry(((((("checked_out_by_" + callerPublicKey) + "_") + type) + "_") + taskId), true), DeleteEntry(((("open_" + type) + "_") + taskId))]
115- }
116-
117-
118-
119-@Callable(i)
120-func commitTask (taskId,response) = {
121- let callerPublicKey = toBase58String(i.callerPublicKey)
122- let type = match getString((taskId + "_type")) {
123- case s: String =>
124- s
125- case _ =>
126- "not set"
127- }
128- let correctAgent = isCorrectAgent(taskId, callerPublicKey, type)
129- let timestamp = lastBlock.timestamp
130- let callback = match getString(((taskId + "_callback_") + type)) {
131- case s: String =>
132- s
133- case _ =>
134- "no callback"
135- }
136- let caller = match getString(((taskId + "_caller_") + type)) {
137- case s: String =>
138- s
139- case _ =>
140- "no callback"
141- }
142- if (!(correctAgent))
143- then throw("Task may only be submitted by the agent who checked the task out!")
144- else if ((type == "not set"))
145- then throw("Can not identify type of task id")
146- else if ((callback != "no callback"))
147- then {
148- let result = invoke(Address(fromBase58String(caller)), callback, [taskId, response], nil)
149- if ((result == result))
150- then [StringEntry(((taskId + "_status_") + type), STATUS_DONE), StringEntry(((taskId + "_result_") + type), response), IntegerEntry(((taskId + COMMIT_HEIGHT) + type), height), IntegerEntry(((taskId + "_commit_timestamp_") + type), timestamp), DeleteEntry(((((("checked_out_by_" + callerPublicKey) + "_") + type) + "_") + taskId))]
151- else throw("Strict value is not equal to itself.")
152- }
153- else [StringEntry(((taskId + "_status_") + type), STATUS_DONE), StringEntry(((taskId + "_result_") + type), response), IntegerEntry(((taskId + COMMIT_HEIGHT) + type), height), IntegerEntry(((taskId + "_commit_timestamp_") + type), timestamp), DeleteEntry(((((("checked_out_by_" + callerPublicKey) + "_") + type) + "_") + taskId))]
154- }
51+func callback (taskId,cid) = if ((i.callerPublicKey != BAI_CONTRACT_PUBLIC_KEY))
52+ then throw("Only BAI Contract is allowed to call the callback!")
53+ else {
54+ let chatId = match getString(taskId) {
55+ case s: String =>
56+ s
57+ case _ =>
58+ throw("Chat ID for task id not found!")
59+ }
60+ let publicKey = match getString((chatId + "_initiator")) {
61+ case s: String =>
62+ s
63+ case _ =>
64+ throw("No initiator found!")
65+ }
66+ let timestamp = toString(lastBlock.timestamp)
67+[StringEntry((chatId + "_latest"), cid), StringEntry((chatId + "_status"), "done"), StringEntry(((publicKey + "_") + chatId), ((((cid + "_") + timestamp) + "_") + "done")), StringEntry("caller", toBase58String(i.callerPublicKey))]
68+ }
15569
15670
15771 @Verifier(tx)
Full:
OldNewDifferences
1-{-# STDLIB_VERSION 6 #-}
1+{-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let AI_TOKEN_ASSET_ID = base58'AxGKQRxKo4F2EbhrRq6N2tdLsxtMnpzQsS4QemV6V1W1'
4+let BAI_CONTRACT_PUBLIC_KEY = base58'DS6HkopS9zypvxX6VhkdNvv6v4wcPZuChRvTwKJeacxE'
55
6-let STATUS_OPEN = "open"
6+let BAI_CONTRACT = addressFromPublicKey(BAI_CONTRACT_PUBLIC_KEY)
77
8-let STATUS_CHECKED_OUT = "checked_out"
9-
10-let STATUS_DONE = "done"
11-
12-let CHECKED_OUT_BY = "_checked_out_by_"
13-
14-let SIMPLE_CHATGPT_TASK = "simple_ChatGPT_task"
15-
16-let CHECK_OUT_HEIGHT = "_check_out_height_"
17-
18-let REGISTER_HEIGHT = "_register_height_"
19-
20-let COMMIT_HEIGHT = "_commit_height_"
21-
22-func canBeCheckedOut (taskId,type) = {
23- let status = getString(this, ((taskId + "_status_") + type))
24- (status == STATUS_OPEN)
25- }
26-
27-
28-func isCorrectAgent (taskId,agentId,type) = {
29- let checkoutAgentId = getString(this, ((taskId + CHECKED_OUT_BY) + type))
30- (checkoutAgentId == agentId)
31- }
32-
33-
34-func getPriceForType (type) = match getInteger(this, ("price_" + type)) {
35- case i: Int =>
36- i
37- case _ =>
38- -1
39-}
40-
8+let BAI_ASSET_ID = base58'AxGKQRxKo4F2EbhrRq6N2tdLsxtMnpzQsS4QemV6V1W1'
419
4210 @Callable(i)
43-func registerTask (description,type) = {
11+func getAnswerForChat (chatId,cid) = {
4412 let numberOfPayments = size(i.payments)
4513 if ((numberOfPayments != 1))
4614 then throw("Payment necessary!")
4715 else {
48- let callerPublicKey = toBase58String(i.callerPublicKey)
49- let txId = toBase58String(i.transactionId)
5016 let payment = i.payments[0]
5117 let fee = payment.amount
5218 let feeAssetId = payment.assetId
53- let taskId = ((txId + "_") + callerPublicKey)
54- let timestamp = lastBlock.timestamp
55- let minFee = getPriceForType(type)
56- let daoUserValue = match getInteger(this, ("dao_user_" + callerPublicKey)) {
19+ let minFee = match getInteger(BAI_CONTRACT, "price_fullchatgpt") {
5720 case n: Int =>
58- (n + fee)
21+ n
5922 case _ =>
60- fee
23+ 0
6124 }
62- let daoSum = match getInteger(this, "dao_sum") {
63- case n: Int =>
64- (n + fee)
65- case _ =>
66- fee
67- }
68- if ((feeAssetId != AI_TOKEN_ASSET_ID))
69- then throw("Payment only possible in the AI Token!")
70- else if ((minFee == -1))
71- then throw("Task type not supported!")
72- else if ((minFee > fee))
73- then throw((("Payment needs to be at least " + toString(minFee)) + " BAI Token!"))
74- else [StringEntry(((taskId + "_description_") + type), description), StringEntry(((txId + "_initializer_") + type), callerPublicKey), StringEntry(((taskId + "_status_") + type), STATUS_OPEN), StringEntry((taskId + "_type"), type), IntegerEntry(((taskId + REGISTER_HEIGHT) + type), height), IntegerEntry(((taskId + "_register_timestamp_") + type), timestamp), BooleanEntry(((("open_" + type) + "_") + taskId), true), IntegerEntry("dao_sum", daoSum), IntegerEntry(("dao_user_" + callerPublicKey), daoUserValue)]
25+ if (if ((feeAssetId != BAI_ASSET_ID))
26+ then true
27+ else (minFee > fee))
28+ then throw("Payment of the minimal BAI amount necessary!")
29+ else {
30+ let publicKey = toBase58String(i.callerPublicKey)
31+ let timestamp = toString(lastBlock.timestamp)
32+ let result = invoke(BAI_CONTRACT, "registerTaskCallback", [cid, "fullchatgpt", "callback"], [AttachedPayment(BAI_ASSET_ID, 10000000)])
33+ if ((result == result))
34+ then {
35+ let taskId = match result {
36+ case s: String =>
37+ s
38+ case _ =>
39+ throw("Unknown task id!")
40+ }
41+[StringEntry((chatId + "_latest"), cid), StringEntry((chatId + "_status"), "waiting"), StringEntry(taskId, chatId), StringEntry(((publicKey + "_") + chatId), ((((cid + "_") + timestamp) + "_") + "waiting")), StringEntry((chatId + "_initiator"), publicKey)]
42+ }
43+ else throw("Strict value is not equal to itself.")
44+ }
7545 }
7646 }
7747
7848
7949
8050 @Callable(i)
81-func registerTaskCallback (description,type,callback) = {
82- let numberOfPayments = size(i.payments)
83- if ((numberOfPayments != 1))
84- then throw("Payment necessary!")
85- else {
86- let callerPublicKey = toBase58String(i.callerPublicKey)
87- let caller = toString(i.caller)
88- let txId = toBase58String(i.transactionId)
89- let payment = i.payments[0]
90- let fee = payment.amount
91- let feeAssetId = payment.assetId
92- let taskId = ((txId + "_") + callerPublicKey)
93- let timestamp = lastBlock.timestamp
94- let minFee = getPriceForType(type)
95- if ((feeAssetId != AI_TOKEN_ASSET_ID))
96- then throw("Payment only possible in the AI Token!")
97- else if ((minFee == -1))
98- then throw("Task type not supported!")
99- else if ((minFee > fee))
100- then throw((("Payment needs to be at least " + toString(minFee)) + " BAI Token!"))
101- else $Tuple2([StringEntry(((taskId + "_description_") + type), description), StringEntry(((txId + "_initializer_") + type), callerPublicKey), StringEntry(((taskId + "_callback_") + type), callback), StringEntry(((taskId + "_caller_") + type), caller), StringEntry(((taskId + "_status_") + type), STATUS_OPEN), StringEntry((taskId + "_type"), type), IntegerEntry(((taskId + REGISTER_HEIGHT) + type), height), IntegerEntry(((taskId + "_register_timestamp_") + type), timestamp), BooleanEntry(((("open_" + type) + "_") + taskId), true), StringEntry(((("callback_accounting_" + txId) + "_") + toString(height)), taskId)], taskId)
102- }
103- }
104-
105-
106-
107-@Callable(i)
108-func checkoutTask (taskId,type) = {
109- let callerPublicKey = toBase58String(i.callerPublicKey)
110- let taskStillOpen = canBeCheckedOut(taskId, type)
111- let timestamp = lastBlock.timestamp
112- if (!(taskStillOpen))
113- then throw("Task not open for checkout!")
114- else [StringEntry(((taskId + CHECKED_OUT_BY) + type), callerPublicKey), StringEntry(((taskId + "_status_") + type), STATUS_CHECKED_OUT), IntegerEntry(((taskId + CHECK_OUT_HEIGHT) + type), height), IntegerEntry(((taskId + "_check_out_timestamp_") + type), timestamp), BooleanEntry(((((("checked_out_by_" + callerPublicKey) + "_") + type) + "_") + taskId), true), DeleteEntry(((("open_" + type) + "_") + taskId))]
115- }
116-
117-
118-
119-@Callable(i)
120-func commitTask (taskId,response) = {
121- let callerPublicKey = toBase58String(i.callerPublicKey)
122- let type = match getString((taskId + "_type")) {
123- case s: String =>
124- s
125- case _ =>
126- "not set"
127- }
128- let correctAgent = isCorrectAgent(taskId, callerPublicKey, type)
129- let timestamp = lastBlock.timestamp
130- let callback = match getString(((taskId + "_callback_") + type)) {
131- case s: String =>
132- s
133- case _ =>
134- "no callback"
135- }
136- let caller = match getString(((taskId + "_caller_") + type)) {
137- case s: String =>
138- s
139- case _ =>
140- "no callback"
141- }
142- if (!(correctAgent))
143- then throw("Task may only be submitted by the agent who checked the task out!")
144- else if ((type == "not set"))
145- then throw("Can not identify type of task id")
146- else if ((callback != "no callback"))
147- then {
148- let result = invoke(Address(fromBase58String(caller)), callback, [taskId, response], nil)
149- if ((result == result))
150- then [StringEntry(((taskId + "_status_") + type), STATUS_DONE), StringEntry(((taskId + "_result_") + type), response), IntegerEntry(((taskId + COMMIT_HEIGHT) + type), height), IntegerEntry(((taskId + "_commit_timestamp_") + type), timestamp), DeleteEntry(((((("checked_out_by_" + callerPublicKey) + "_") + type) + "_") + taskId))]
151- else throw("Strict value is not equal to itself.")
152- }
153- else [StringEntry(((taskId + "_status_") + type), STATUS_DONE), StringEntry(((taskId + "_result_") + type), response), IntegerEntry(((taskId + COMMIT_HEIGHT) + type), height), IntegerEntry(((taskId + "_commit_timestamp_") + type), timestamp), DeleteEntry(((((("checked_out_by_" + callerPublicKey) + "_") + type) + "_") + taskId))]
154- }
51+func callback (taskId,cid) = if ((i.callerPublicKey != BAI_CONTRACT_PUBLIC_KEY))
52+ then throw("Only BAI Contract is allowed to call the callback!")
53+ else {
54+ let chatId = match getString(taskId) {
55+ case s: String =>
56+ s
57+ case _ =>
58+ throw("Chat ID for task id not found!")
59+ }
60+ let publicKey = match getString((chatId + "_initiator")) {
61+ case s: String =>
62+ s
63+ case _ =>
64+ throw("No initiator found!")
65+ }
66+ let timestamp = toString(lastBlock.timestamp)
67+[StringEntry((chatId + "_latest"), cid), StringEntry((chatId + "_status"), "done"), StringEntry(((publicKey + "_") + chatId), ((((cid + "_") + timestamp) + "_") + "done")), StringEntry("caller", toBase58String(i.callerPublicKey))]
68+ }
15569
15670
15771 @Verifier(tx)
15872 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
15973

github/deemru/w8io/026f985 
25.19 ms