19 | | - | func parseJson (json) = { |
---|
20 | | - | let modifiedJson = drop(json, 1) |
---|
21 | | - | let modifiedJson2 = dropRight(modifiedJson, 1) |
---|
22 | | - | let split1 = split(modifiedJson2, ",") |
---|
23 | | - | let keyValue1 = split(split1[0], ":") |
---|
24 | | - | let key1 = removeMarks(keyValue1[0]) |
---|
25 | | - | let value1 = removeMarks(keyValue1[1]) |
---|
26 | | - | let keyValue2 = split(split1[1], ":") |
---|
27 | | - | let key2 = removeMarks(keyValue2[0]) |
---|
28 | | - | let value2 = removeMarks(keyValue2[1]) |
---|
29 | | - | let keyValue3 = split(split1[2], ":") |
---|
30 | | - | let key3 = removeMarks(keyValue3[0]) |
---|
31 | | - | let value3 = removeMarks(keyValue3[1]) |
---|
32 | | - | $Tuple3([key1, value1], [key2, value2], [key3, value3]) |
---|
33 | | - | } |
---|
34 | | - | |
---|
35 | | - | |
---|
36 | | - | @Callable(i) |
---|
37 | | - | func registerData (clientInput,opponentInput,id,oppAddress,lgtCond) = { |
---|
38 | | - | let searchForExistingData = match getString(id) { |
---|
39 | | - | case s: String => |
---|
40 | | - | s |
---|
41 | | - | case _ => |
---|
42 | | - | "no Data exists" |
---|
43 | | - | } |
---|
44 | | - | if ((searchForExistingData != "no Data exists")) |
---|
45 | | - | then throw("There is already existing Data for this case!") |
---|
46 | | - | else { |
---|
47 | | - | let parameters = [id, TYPE, "evaluatedDataCallback"] |
---|
48 | | - | let client = toString(i.caller) |
---|
49 | | - | let txId = toBase58String(i.transactionId) |
---|
50 | | - | let invokeTask = invoke(Address(fromBase58String(BAI_ADDRESS)), "registerTaskCallback", parameters, [AttachedPayment(AI_TOKEN_ASSET_ID, BAI_FEE)]) |
---|
51 | | - | [StringEntry(id, txId), IntegerEntry((((id + "_") + client) + "_age"), clientInput[0]), IntegerEntry((((id + "_") + client) + "_sex"), clientInput[1]), IntegerEntry((((id + "_") + client) + "_damage"), clientInput[2]), IntegerEntry((((id + "_") + client) + "_fac1"), clientInput[3]), IntegerEntry((((id + "_") + client) + "_fac2"), clientInput[4]), IntegerEntry((((id + "_") + client) + "_fac3"), clientInput[5]), IntegerEntry((((id + "_") + client) + "_fac4"), clientInput[6]), IntegerEntry((((id + "_") + client) + "_vio1"), clientInput[7]), IntegerEntry((((id + "_") + client) + "_vio2"), clientInput[8]), IntegerEntry((((id + "_") + client) + "_vio3"), clientInput[9]), IntegerEntry((((id + "_") + client) + "_vio4"), clientInput[10]), IntegerEntry((((id + "_") + client) + "_cost"), clientInput[11]), IntegerEntry((((id + "_") + oppAddress) + "_age"), opponentInput[0]), IntegerEntry((((id + "_") + oppAddress) + "_sex"), opponentInput[1]), IntegerEntry((((id + "_") + oppAddress) + "_damage"), opponentInput[2]), IntegerEntry((((id + "_") + oppAddress) + "_fac1"), opponentInput[3]), IntegerEntry((((id + "_") + oppAddress) + "_fac2"), opponentInput[4]), IntegerEntry((((id + "_") + oppAddress) + "_fac3"), opponentInput[5]), IntegerEntry((((id + "_") + oppAddress) + "_fac4"), opponentInput[6]), IntegerEntry((((id + "_") + oppAddress) + "_vio1"), opponentInput[7]), IntegerEntry((((id + "_") + oppAddress) + "_vio2"), opponentInput[8]), IntegerEntry((((id + "_") + oppAddress) + "_vio3"), opponentInput[9]), IntegerEntry((((id + "_") + oppAddress) + "_vio4"), opponentInput[10]), IntegerEntry((((id + "_") + oppAddress) + "_cost"), opponentInput[11]), IntegerEntry((id + "_lgt"), lgtCond), StringEntry((id + "_status"), "open"), StringEntry((id + "_sender"), client)] |
---|
52 | | - | } |
---|
53 | | - | } |
---|
54 | | - | |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | @Callable(i) |
---|
58 | | - | func evaluatedDataCallback (response) = { |
---|
59 | | - | let txId = toBase58String(i.transactionId) |
---|
60 | | - | let parsedJson = parseJson(response) |
---|
61 | | - | let crashId = parsedJson._1[1] |
---|
62 | | - | let innocentAddress = parsedJson._2[1] |
---|
63 | | - | let guiltyAddress = parsedJson._3[1] |
---|
64 | | - | let RegisterTxId = match getString(crashId) { |
---|
65 | | - | case s: String => |
---|
66 | | - | s |
---|
67 | | - | case _ => |
---|
68 | | - | "no Data exists" |
---|
69 | | - | } |
---|
70 | | - | if ((RegisterTxId == "no Data exists")) |
---|
71 | | - | then throw("There is no Data for this crashId!") |
---|
72 | | - | else { |
---|
73 | | - | let status = match getString((crashId + "_status")) { |
---|
74 | | - | case s: String => |
---|
75 | | - | s |
---|
76 | | - | case _ => |
---|
77 | | - | "no Data exists" |
---|
78 | | - | } |
---|
79 | | - | if ((status == "no Data exists")) |
---|
80 | | - | then throw("There is no status for this case!") |
---|
81 | | - | else if ((status == "closed")) |
---|
82 | | - | then throw("A case should not be evaluated twice!") |
---|
83 | | - | else { |
---|
84 | | - | let costEstimationOfInnocentPerson = match getInteger((((RegisterTxId + "_") + innocentAddress) + "_cost")) { |
---|
85 | | - | case s: Int => |
---|
86 | | - | s |
---|
87 | | - | case _ => |
---|
88 | | - | "No data Found" |
---|
89 | | - | } |
---|
90 | | - | if ((costEstimationOfInnocentPerson == "No data Found")) |
---|
91 | | - | then throw("There is no data for this address!") |
---|
92 | | - | else if ((costEstimationOfInnocentPerson == -1)) |
---|
93 | | - | then [StringEntry((crashId + "_eval"), txId), StringEntry((crashId + "_innocent_address"), innocentAddress), StringEntry((crashId + "_guilty_address"), guiltyAddress), StringEntry((crashId + "_status"), "evaluated")] |
---|
94 | | - | else [StringEntry((crashId + "_eval"), txId), StringEntry((crashId + "_innocent_address"), innocentAddress), StringEntry((crashId + "_guilty_address"), guiltyAddress), StringEntry((crashId + "_status"), "closed"), ScriptTransfer(Address(fromBase58String(innocentAddress)), 100000000, unit)] |
---|
95 | | - | } |
---|
96 | | - | } |
---|
97 | | - | } |
---|
98 | | - | |
---|
99 | | - | |
---|
100 | | - | |
---|
101 | | - | @Callable(i) |
---|
102 | | - | func evaluatedData (prediction_id,per_one_address,per_two_address,guilty_person_address) = { |
---|
103 | | - | let txId = toBase58String(i.transactionId) |
---|
104 | | - | [StringEntry(prediction_id, txId), StringEntry((txId + "_guilty"), guilty_person_address)] |
---|
105 | | - | } |
---|
106 | | - | |
---|
107 | | - | |
---|
108 | | - | |
---|
109 | | - | @Callable(i) |
---|
110 | | - | func requestPayout (pred_txId,amount,id) = { |
---|
111 | | - | let client = toString(i.caller) |
---|
112 | | - | let txId = toBase58String(i.transactionId) |
---|
113 | | - | [StringEntry((id + "_request_payout"), txId), IntegerEntry((txId + "_amount"), amount), StringEntry((txId + "_prediction_id"), pred_txId)] |
---|
114 | | - | } |
---|
115 | | - | |
---|
116 | | - | |
---|
117 | | - | @Verifier(tx) |
---|
118 | | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|