| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $owner = "MYESSCFGDERS3YIEGNZDOG2BI5HKQHLU"; |
| 6 | }", |
| 7 | "messages": { |
| 8 | "cases": [ |
| 9 | { |
| 10 | "if": "{ trigger.data.create }", |
| 11 | "init": "{ |
| 12 | $guarantee_subject_name = trigger.data.create; |
| 13 | $other_party = trigger.data.other_party otherwise bounce ("need 'other_party' address!"); |
| 14 | }", |
| 15 | "messages": [ |
| 16 | { |
| 17 | "app": "state", |
| 18 | "state": "{ |
| 19 | var[$guarantee_subject_name||"_party1"] = trigger.address; |
| 20 | var[$guarantee_subject_name||"_party2"] = $other_party; |
| 21 | var[$guarantee_subject_name||"_balance"] = trigger.output[[asset=base]]; |
| 22 | |
| 23 | var[$blocked_balance] += trigger.output[[asset=base]]; |
| 24 | |
| 25 | response['message'] = "Done! Later, the parties will have to agree on how to spread the balance ("||trigger.output[[asset=base]]||") by sending the 'amount' they allow the other party to receive, if the sum of the 2 amounts is equal to the balance then the payment will be executed."; |
| 26 | }" |
| 27 | } |
| 28 | ] |
| 29 | }, |
| 30 | { |
| 31 | "if": "{ trigger.data.name }", |
| 32 | "init": "{ |
| 33 | $name = trigger.data.name; |
| 34 | $balance = var[$name||"_balance"] otherwise bounce ("Guarantee name do not exist!"); |
| 35 | $amount = trigger.data.amount otherwise bounce ("Need the 'amount' you allow the other party to receive!"); |
| 36 | if ($amount > $balance) bounce ("The amount is bigger than the full balance!"); |
| 37 | |
| 38 | if (var[$name||"_party1"] == trigger.address) |
| 39 | { |
| 40 | $proposition1 = $amount; |
| 41 | $proposition2 = var[$name||"_proposition2"] otherwise $balance; |
| 42 | } |
| 43 | if (var[$name||"_party2"] == trigger.address) |
| 44 | { |
| 45 | $proposition1 = var[$name||"_proposition1"] otherwise $balance; |
| 46 | $proposition2 = $amount; |
| 47 | } |
| 48 | |
| 49 | if (!($proposition1)) bounce ("You are not part of the agreement!"); |
| 50 | |
| 51 | $agreement_found = ($amount + $deblocked_by_other) == $balance; |
| 52 | }", |
| 53 | "messages": [ |
| 54 | { |
| 55 | "if": "{ $agreement_found }", |
| 56 | "app": "payment", |
| 57 | "payload": { |
| 58 | "asset": "base", |
| 59 | "outputs": [ |
| 60 | { |
| 61 | "address": "{var[$name||"_party1"]}", |
| 62 | "amount": "{ $proposition2 - 500 }" |
| 63 | }, |
| 64 | { |
| 65 | "address": "{var[$name||"_party2"]}", |
| 66 | "amount": "{ $proposition1 - 500 }" |
| 67 | }, |
| 68 | { |
| 69 | "address": "{trigger.address}", |
| 70 | "amount": "{ trigger.output[[asset=base]]-2000 }" |
| 71 | } |
| 72 | ] |
| 73 | } |
| 74 | }, |
| 75 | { |
| 76 | "app": "state", |
| 77 | "state": "{ |
| 78 | if ($agreement_found) |
| 79 | { |
| 80 | var[$name||"_party1"] = false; |
| 81 | var[$name||"_party2"] = false; |
| 82 | var[$name||"_balance"] = false; |
| 83 | var[$name||"_proposition1"] = false; |
| 84 | var[$name||"_proposition2"] = false; |
| 85 | |
| 86 | var[$blocked_balance] -= ($proposition1 + $proposition2 - 1000); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | if (var[$name||"_party1"] == trigger.address) |
| 91 | var[$name||"_proposition1"] = $amount; |
| 92 | else |
| 93 | var[$name||"_proposition2"] = $amount; |
| 94 | } |
| 95 | }" |
| 96 | } |
| 97 | ] |
| 98 | }, |
| 99 | { |
| 100 | "init": "{ |
| 101 | if (trigger.address != $owner) |
| 102 | bounce ("you need to read the doc!"); |
| 103 | }", |
| 104 | "messages": [ |
| 105 | { |
| 106 | "if": "{ $agreement_found }", |
| 107 | "app": "payment", |
| 108 | "payload": { |
| 109 | "asset": "base", |
| 110 | "outputs": [ |
| 111 | { |
| 112 | "address": "{$owner}", |
| 113 | "amount": "{ balance[base] - var[$blocked_balance] - 600 }" |
| 114 | } |
| 115 | ] |
| 116 | } |
| 117 | } |
| 118 | ] |
| 119 | } |
| 120 | ] |
| 121 | } |
| 122 | } |
| 123 | ] |