tx · GZtrLmwpweSUDTLzjPPuKXa8M8dQXoQUWpcnJChWEkaF

3N9tKixzqTYWnEXQxrDQ5pBTGvQd6sFsvmV:  -0.05000000 Waves

2024.10.28 10:20 [3346414] smart account 3N9tKixzqTYWnEXQxrDQ5pBTGvQd6sFsvmV > SELF 0.00000000 Waves

{ "type": 13, "id": "GZtrLmwpweSUDTLzjPPuKXa8M8dQXoQUWpcnJChWEkaF", "fee": 5000000, "feeAssetId": null, "timestamp": 1730100027208, "version": 2, "chainId": 84, "sender": "3N9tKixzqTYWnEXQxrDQ5pBTGvQd6sFsvmV", "senderPublicKey": "DS6HkopS9zypvxX6VhkdNvv6v4wcPZuChRvTwKJeacxE", "proofs": [ "64mJrgSznUpGLdYK33sKKVj7M6tqAc6y2CmuWCHdJNJWo91QT7DRPosTsfGEBZbE7cB6cPepLLSFgh8nvNznpv9u" ], "script": "base64:BgIbCAISBAoCCAgSBQoDCAgIEgQKAggIEgQKAggIDAARQUlfVE9LRU5fQVNTRVRfSUQBIJPhcjhxBJtq6JpjHwQkt2RTlyw+vGYLg3SvaLskjeJCAAtTVEFUVVNfT1BFTgIEb3BlbgASU1RBVFVTX0NIRUNLRURfT1VUAgtjaGVja2VkX291dAALU1RBVFVTX0RPTkUCBGRvbmUADkNIRUNLRURfT1VUX0JZAhBfY2hlY2tlZF9vdXRfYnlfABNTSU1QTEVfQ0hBVEdQVF9UQVNLAhNzaW1wbGVfQ2hhdEdQVF90YXNrABBDSEVDS19PVVRfSEVJR0hUAhJfY2hlY2tfb3V0X2hlaWdodF8AD1JFR0lTVEVSX0hFSUdIVAIRX3JlZ2lzdGVyX2hlaWdodF8ADUNPTU1JVF9IRUlHSFQCD19jb21taXRfaGVpZ2h0XwEPY2FuQmVDaGVja2VkT3V0AgZ0YXNrSWQEdHlwZQQGc3RhdHVzCQCdCAIFBHRoaXMJAKwCAgkArAICBQZ0YXNrSWQCCF9zdGF0dXNfBQR0eXBlCQAAAgUGc3RhdHVzBQtTVEFUVVN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GlzIG5vdCBlcXVhbCB0byBpdHNlbGYuCQDMCAIJAQtTdHJpbmdFbnRyeQIJAKwCAgkArAICBQZ0YXNrSWQCCF9zdGF0dXNfBQR0eXBlBQtTVEFUVVNfRE9ORQkAzAgCCQELU3RyaW5nRW50cnkCCQCsAgIJAKwCAgUGdGFza0lkAghfcmVzdWx0XwUEdHlwZQUIcmVzcG9uc2UJAMwIAgkBDEludGVnZXJFbnRyeQIJAKwCAgkArAICBQZ0YXNrSWQFDUNPTU1JVF9IRUlHSFQFBHR5cGUFBmhlaWdodAkAzAgCCQEMSW50ZWdlckVudHJ5AgkArAICCQCsAgIFBnRhc2tJZAISX2NvbW1pdF90aW1lc3RhbXBfBQR0eXBlBQl0aW1lc3RhbXAJAMwIAgkBC0RlbGV0ZUVudHJ5AQkArAICCQCsAgIJAKwCAgkArAICCQCsAgICD2NoZWNrZWRfb3V0X2J5XwUPY2FsbGVyUHVibGljS2V5AgFfBQR0eXBlAgFfBQZ0YXNrSWQFA25pbAECdHgBBnZlcmlmeQAJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAIBQJ0eA9zZW5kZXJQdWJsaWNLZXkmP4uL", "height": 3346414, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8FfhZKXNXG9SNHYDcsrANSKfKaSobwU281H5wQXSCBMo Next: none Diff:
OldNewDifferences
1-{-# STDLIB_VERSION 5 #-}
1+{-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let BAI_CONTRACT_PUBLIC_KEY = base58'DS6HkopS9zypvxX6VhkdNvv6v4wcPZuChRvTwKJeacxE'
4+let AI_TOKEN_ASSET_ID = base58'AxGKQRxKo4F2EbhrRq6N2tdLsxtMnpzQsS4QemV6V1W1'
55
6-let BAI_CONTRACT = "3N9tKixzqTYWnEXQxrDQ5pBTGvQd6sFsvmV"
6+let STATUS_OPEN = "open"
77
8-let BAI_ASSET_ID = base58'AxGKQRxKo4F2EbhrRq6N2tdLsxtMnpzQsS4QemV6V1W1'
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+
941
1042 @Callable(i)
11-func getAnswerForChat (chatId,cid) = {
43+func registerTask (description,type) = {
1244 let numberOfPayments = size(i.payments)
1345 if ((numberOfPayments != 1))
1446 then throw("Payment necessary!")
1547 else {
48+ let callerPublicKey = toBase58String(i.callerPublicKey)
49+ let txId = toBase58String(i.transactionId)
1650 let payment = i.payments[0]
1751 let fee = payment.amount
1852 let feeAssetId = payment.assetId
19- let minFee = match getInteger(Address(fromBase58String(BAI_CONTRACT)), "price_fullchatgpt") {
53+ let taskId = ((txId + "_") + callerPublicKey)
54+ let timestamp = lastBlock.timestamp
55+ let minFee = getPriceForType(type)
56+ let daoUserValue = match getInteger(this, ("dao_user_" + callerPublicKey)) {
2057 case n: Int =>
21- n
58+ (n + fee)
2259 case _ =>
23- 0
60+ fee
2461 }
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(Address(fromBase58String(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- }
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)]
4575 }
4676 }
4777
4878
4979
5080 @Callable(i)
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- }
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+ }
69155
70156
71157 @Verifier(tx)
Full:
OldNewDifferences
1-{-# STDLIB_VERSION 5 #-}
1+{-# STDLIB_VERSION 6 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let BAI_CONTRACT_PUBLIC_KEY = base58'DS6HkopS9zypvxX6VhkdNvv6v4wcPZuChRvTwKJeacxE'
4+let AI_TOKEN_ASSET_ID = base58'AxGKQRxKo4F2EbhrRq6N2tdLsxtMnpzQsS4QemV6V1W1'
55
6-let BAI_CONTRACT = "3N9tKixzqTYWnEXQxrDQ5pBTGvQd6sFsvmV"
6+let STATUS_OPEN = "open"
77
8-let BAI_ASSET_ID = base58'AxGKQRxKo4F2EbhrRq6N2tdLsxtMnpzQsS4QemV6V1W1'
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+
941
1042 @Callable(i)
11-func getAnswerForChat (chatId,cid) = {
43+func registerTask (description,type) = {
1244 let numberOfPayments = size(i.payments)
1345 if ((numberOfPayments != 1))
1446 then throw("Payment necessary!")
1547 else {
48+ let callerPublicKey = toBase58String(i.callerPublicKey)
49+ let txId = toBase58String(i.transactionId)
1650 let payment = i.payments[0]
1751 let fee = payment.amount
1852 let feeAssetId = payment.assetId
19- let minFee = match getInteger(Address(fromBase58String(BAI_CONTRACT)), "price_fullchatgpt") {
53+ let taskId = ((txId + "_") + callerPublicKey)
54+ let timestamp = lastBlock.timestamp
55+ let minFee = getPriceForType(type)
56+ let daoUserValue = match getInteger(this, ("dao_user_" + callerPublicKey)) {
2057 case n: Int =>
21- n
58+ (n + fee)
2259 case _ =>
23- 0
60+ fee
2461 }
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(Address(fromBase58String(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- }
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)]
4575 }
4676 }
4777
4878
4979
5080 @Callable(i)
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- }
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+ }
69155
70156
71157 @Verifier(tx)
72158 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
73159

github/deemru/w8io/026f985 
27.85 ms