| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ \r |
| 8 | \r |
| 9 | $nom_AA = 'Compensacions';\r |
| 10 | $versio = '3';\r |
| 11 | \r |
| 12 | $AA_PF = trigger.data.AA_PF;\r |
| 13 | $adr__ = trigger.initial_address;\r |
| 14 | $qt = trigger.output[[asset=base]] - 10000; |
| 15 | $receptora = trigger.data.receptora;\r |
| 16 | \r |
| 17 | $unitat = var[ $AA_PF ][ 'unitat' ]; \r |
| 18 | $AA_Transfers = var[ $AA_PF ][ '_AA_Transfers' ];\r |
| 19 | $AA_Subscripcions = var[ $AA_PF ][ '_AA_Subscripcions' ];\r |
| 20 | $AA_Renovacions = var[ $AA_PF ][ '_AA_Renovacions' ];\r |
| 21 | $adr_FOP = var[ $AA_PF ][ '_FOP' ]; \r |
| 22 | \r |
| 23 | |
| 24 | $subscripcio = var[ $AA_Subscripcions ][ 'subscripcio_' || $receptora ]; \r |
| 25 | if ( ! $subscripcio ) \r |
| 26 | { bounce ( $nom_AA || ": L'adreça receptora no està subscrita per rebre compensacions." ); }\r |
| 27 | \r |
| 28 | |
| 29 | $cicle_subscripcio = $subscripcio.cicle;\r |
| 30 | \r |
| 31 | $cicle_actual = var[ $AA_Transfers ][ 'cicle_actual'];\r |
| 32 | $cicle_renovat = var[ $AA_Renovacions ][ 'cicle_' || $receptora ];\r |
| 33 | \r |
| 34 | if ( $cicle_actual > $cicle_subscripcio ){\r |
| 35 | $resp = $nom_AA || ": L'adreça receptora no ha renovat la subscripció per rebre compensacions.";\r |
| 36 | if ( ! $cicle_renovat ) { bounce ( $resp ); }\r |
| 37 | if ( $cicle_actual > $cicle_renovat ) { bounce ( $resp ); }\r |
| 38 | }\r |
| 39 | \r |
| 40 | $derivacio = $qt * $subscripcio.aFOP / 100; \r |
| 41 | \r |
| 42 | }", |
| 43 | "messages": [ |
| 44 | { |
| 45 | "app": "payment", |
| 46 | "payload": { |
| 47 | "asset": "{ $unitat }", |
| 48 | "outputs": [ |
| 49 | { |
| 50 | "address": "{ $receptora }", |
| 51 | "amount": "{ $qt - $derivacio }" |
| 52 | }, |
| 53 | { |
| 54 | "address": "{ $adr_FOP }", |
| 55 | "amount": "{ $derivacio }" |
| 56 | } |
| 57 | ] |
| 58 | } |
| 59 | }, |
| 60 | { |
| 61 | "app": "state", |
| 62 | "state": "{\r |
| 63 | \r |
| 64 | var[ 'total_Compensacions' ] += $qt;\r |
| 65 | var[ 'total_Compensacions_de_' || $adr__ ] += $qt;\r |
| 66 | var[ 'total_Compensacions_a_' || $receptora ] += $qt;\r |
| 67 | var[ 'total_Compensacions_de_' || $adr__ || '_a_' || $receptora ] += $qt;\r |
| 68 | \r |
| 69 | response[ 'Total Compensacions ' ] = var[ 'total_Compensacions' ];\r |
| 70 | response[ 'Total Compensacions ' || ' de ' || $adr__ ] = var[ 'total_Compensacions_de_' || $adr__ ];\r |
| 71 | response[ 'Total Compensacions ' || ' a ' || $receptora ] = var[ 'total_Compensacions_a_' || $receptora ];\r |
| 72 | response[ 'Total Compensacions ' || ' de ' || $adr__ || ' a ' || $receptora ] = var[ 'total_Compensacions_de_' || $adr__ || '_a_' || $receptora ];\r |
| 73 | \r |
| 74 | var[ 'total_Derivacions' ] += $qt;\r |
| 75 | var[ 'total_Derivacions_de_' || $receptora ] += $qt;\r |
| 76 | \r |
| 77 | response[ 'Total Derivacions ' ] = var[ 'total_Derivacions' ];\r |
| 78 | response[ 'Total Derivacions ' || ' de ' || $receptora ] = var[ 'total_Derivacions_de_' || $receptora ];\r |
| 79 | \r |
| 80 | }" |
| 81 | } |
| 82 | ] |
| 83 | } |
| 84 | ] |