| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{\r |
| 5 | $_Registre = 'IW6DOUEPGHGQGTKLU6W6I2ILKZ562N6R';\r |
| 6 | \r |
| 7 | |
| 8 | $args = trigger.data;\r |
| 9 | $adr__ = trigger.initial_address;\r |
| 10 | $idgeto = trigger.output[[ asset != base ]].asset;\r |
| 11 | $qt_rebuda = trigger.output[[ asset = $idgeto ]];\r |
| 12 | $dades = $args.dades otherwise {};\r |
| 13 | \r |
| 14 | |
| 15 | $__dada = $refdada =>\r |
| 16 | data_feed [[\r |
| 17 | oracles = $_Registre,\r |
| 18 | feed_name = $refdada,\r |
| 19 | ifnone = 0\r |
| 20 | ]];\r |
| 21 | \r |
| 22 | if ( $__dada( '_Portal' ) != trigger.address )\r |
| 23 | bounce( 'Portal no reconegut' );\r |
| 24 | \r |
| 25 | |
| 26 | $proces = $args.proces;\r |
| 27 | $operacio = $args.operacio;\r |
| 28 | $idprop = $args.idprop;\r |
| 29 | $nova_idprop = $args.nova_idprop;\r |
| 30 | $ref = $args.ref;\r |
| 31 | $val = $args.val;\r |
| 32 | \r |
| 33 | |
| 34 | $__arg = $arg =>\r |
| 35 | $args[ $arg ] otherwise\r |
| 36 | bounce( "Cal proporcionar el valor de: " || $arg );\r |
| 37 | \r |
| 38 | $geto = $__arg( 'geto' );\r |
| 39 | \r |
| 40 | if ( $proces == 'nou_definidor_geto' ) {\r |
| 41 | $definidors_esmenables =\r |
| 42 | 'taxa_conversio, derivacio, import_activacio, ' ||\r |
| 43 | 'import_subscripcio, import_renovacio, ' ||\r |
| 44 | 'cicles_diposit, _AUT_A, _AUT_B, _AUT_C';\r |
| 45 | \r |
| 46 | if ( $operacio == 'proposta' ) {\r |
| 47 | $refdef = $ref otherwise 'cap';\r |
| 48 | if ( ! contains( $definidors_esmenables, $refdef ) )\r |
| 49 | bounce( 'Definidor inexistent o no esmenable' );\r |
| 50 | \r |
| 51 | if ( $__dada( $geto || '_redefinible') < 1 )\r |
| 52 | bounce( "Els valors definidors d'aquest getó no són esmenables" );\r |
| 53 | \r |
| 54 | $dades[ $nova_idprop || '_geto' ] = $geto;\r |
| 55 | $dades[ $nova_idprop || '_ref' ] = $__arg( 'ref' );\r |
| 56 | $dades[ $nova_idprop || '_val' ] = $__arg( 'val' );\r |
| 57 | }\r |
| 58 | if ( $operacio == 'confirmacio' ) {\r |
| 59 | $refg = $__dada( $idprop || '_geto' );\r |
| 60 | $refdef = $__dada( $idprop || '_ref' );\r |
| 61 | $dades[ $refg || '_' || $refdef ] = $__dada( $idprop || '_val' );\r |
| 62 | }\r |
| 63 | if ( $operacio == 'drecera' ) {\r |
| 64 | $dades[ $geto || '_' || $__arg( 'ref' ) ] = $__arg( 'val' );\r |
| 65 | }\r |
| 66 | }\r |
| 67 | \r |
| 68 | if ( $proces == 'capacitacio' ) {\r |
| 69 | $accio_restringida =\r |
| 70 | $__dada( $geto || '_' || to_lower ( $__arg( 'accio' ) ) || 'ns_restringides') \r |
| 71 | otherwise -1;\r |
| 72 | \r |
| 73 | if ( $accio_restringida < 1 )\r |
| 74 | bounce( 'Acció no restringible per a aquest getó' );\r |
| 75 | \r |
| 76 | $geto_capacitacio = $__dada( $idprop || '_geto' ) otherwise $geto;\r |
| 77 | $accio_capacitacio = $__dada( $idprop || '_accio' ) otherwise $__arg( 'accio' );\r |
| 78 | $adr_capacitacio = $__dada( $idprop || '_adr' ) otherwise $__arg( 'adr' );\r |
| 79 | $estat_capacitacio = $__dada( $idprop || '_estat' ) otherwise $__arg( 'estat' );\r |
| 80 | \r |
| 81 | if ( $operacio == 'proposta' ) {\r |
| 82 | $dades[ $nova_idprop || '_geto' ] = $geto_capacitacio;\r |
| 83 | $dades[ $nova_idprop || '_accio' ] = $accio_capacitacio;\r |
| 84 | $dades[ $nova_idprop || '_capacitada' ] = $adr_capacitacio;\r |
| 85 | $dades[ $nova_idprop || '_estat' ] = $estat_capacitacio;\r |
| 86 | }\r |
| 87 | if ( $operacio == 'confirmacio' OR $operacio == 'drecera' ) {\r |
| 88 | $ordinal_capacitacio = $__dada( 'ordinal_capacitacio_' || $geto ) + 1;\r |
| 89 | $ord_capacitacio = 'capacitacio_' || $ordinal_capacitacio;\r |
| 90 | $ref_capacitacio =\r |
| 91 | $geto_capacitacio || '_' || $accio_capacitacio || '_' || $adr_capacitacio;\r |
| 92 | $dades[ $ref_capacitacio ] = $ord_capacitacio;\r |
| 93 | $dades[ $ord_capacitacio || '_estat' ] = $estat_capacitacio;\r |
| 94 | $dades[ 'ordinal_capacitacio_' || $geto ] = $ordinal_capacitacio;\r |
| 95 | }\r |
| 96 | }\r |
| 97 | \r |
| 98 | if ( $proces == 'atribucio' ) {\r |
| 99 | $rebedora = $__dada( $idprop || '_rebedora' ) otherwise $args.rebedora;\r |
| 100 | $qt = $__dada( $idprop || '_qt' ) otherwise $args.qt;\r |
| 101 | $requeriment = $__dada( $idprop || '_requeriment' ) otherwise $args.requeriment;\r |
| 102 | $ref_atribucio = 'atribucio_'|| $geto || '_' || $requeriment;\r |
| 103 | \r |
| 104 | if ( $__dada( $geto || '_atribucions_permeses' ) != 1 )\r |
| 105 | bounce( 'Atribucions no permeses amb ' || $geto );\r |
| 106 | \r |
| 107 | if ( ! $__dada( 'activacio_Estels_' || $rebedora ) )\r |
| 108 | bounce( 'Rebedora no activada' );\r |
| 109 | \r |
| 110 | if ( ! $__dada( 'activacio_' || $geto || '_' || $rebedora ) )\r |
| 111 | bounce( 'Rebedora no activada per operar amb ' || $geto );\r |
| 112 | \r |
| 113 | if ( !! $__dada( $ref_atribucio ) )\r |
| 114 | bounce( 'Aquesta atribució ja ha estat realitzada' );\r |
| 115 | \r |
| 116 | if ( $operacio == 'proposta' ) {\r |
| 117 | $dades[ $nova_idprop || '_rebedora' ] = $rebedora;\r |
| 118 | $dades[ $nova_idprop || '_requeriment' ] = $requeriment;\r |
| 119 | $dades[ $nova_idprop || '_qt' ] = $args.qt;\r |
| 120 | $dades[ $nova_idprop || '_geto' ] = $geto;\r |
| 121 | }\r |
| 122 | \r |
| 123 | if ( $operacio == 'confirmacio' OR $operacio == 'drecera' ) {\r |
| 124 | $ordinal_atribucio = $__dada( 'ordinal_atribucio_' || $geto ) + 1;\r |
| 125 | $ord_atribucio = 'atribucio_' || $geto || '_' || $ordinal_atribucio;\r |
| 126 | $total_atribucions = $__dada( 'total_atribucions_' || $geto ) otherwise 0;\r |
| 127 | $_Capsa = $__dada( $geto || '__Capsa' );\r |
| 128 | \r |
| 129 | $dades[ $ref_atribucio ] = $ord_atribucio;\r |
| 130 | $dades[ $ord_atribucio || '_data' ] = timestamp;\r |
| 131 | $dades[ $ord_atribucio || '_geto' ] = $geto;\r |
| 132 | $dades[ $ord_atribucio || '_rebedora' ] = $rebedora;\r |
| 133 | $dades[ $ord_atribucio || '_requeriment' ] = $requeriment;\r |
| 134 | $dades[ $ord_atribucio || '_qt' ] = $qt;\r |
| 135 | $dades[ 'ordinal_atribucio_' || $geto ] = $ordinal_atribucio;\r |
| 136 | $dades[ 'total_atribucions_' || $geto ] =\r |
| 137 | $total_atribucions + $qt;\r |
| 138 | \r |
| 139 | $args.qt = $qt;\r |
| 140 | $args.rebedora = $rebedora;\r |
| 141 | $args.sentit = 'sortida';\r |
| 142 | }\r |
| 143 | }\r |
| 144 | \r |
| 145 | $registre = {};\r |
| 146 | $registre.dades = $dades;\r |
| 147 | }", |
| 148 | "messages": [ |
| 149 | { |
| 150 | "app": "data", |
| 151 | "payload": "{ $registre || $args }" |
| 152 | }, |
| 153 | { |
| 154 | "if": "{ $proces != 'atribucio' OR $operacio == 'proposta' }", |
| 155 | "app": "payment", |
| 156 | "payload": { |
| 157 | "asset": "base", |
| 158 | "outputs": [ |
| 159 | { |
| 160 | "address": "{ $_Registre }", |
| 161 | "amount": "{ $__dada( 'Provisio' ) }" |
| 162 | } |
| 163 | ] |
| 164 | } |
| 165 | }, |
| 166 | { |
| 167 | "if": "{\r |
| 168 | $proces == 'atribucio'\r |
| 169 | AND ( $operacio == 'confirmacio' OR $operacio == 'drecera' )\r |
| 170 | AND $idgeto != 'none' |
| 171 | }", |
| 172 | "app": "payment", |
| 173 | "payload": { |
| 174 | "asset": "base", |
| 175 | "outputs": [ |
| 176 | { |
| 177 | "address": "{ $_Registre }", |
| 178 | "amount": "{ $__dada( 'Provisio' ) }" |
| 179 | }, |
| 180 | { |
| 181 | "address": "{ $_Capsa }", |
| 182 | "amount": "{ $args.provisio_Capsa }" |
| 183 | } |
| 184 | ] |
| 185 | } |
| 186 | }, |
| 187 | { |
| 188 | "if": "{\r |
| 189 | $proces == 'atribucio'\r |
| 190 | AND ( $operacio == 'confirmacio' OR $operacio == 'drecera' )\r |
| 191 | AND $idgeto != 'none'\r |
| 192 | }", |
| 193 | "app": "payment", |
| 194 | "payload": { |
| 195 | "asset": "{ $idgeto }", |
| 196 | "outputs": [ |
| 197 | { |
| 198 | "address": "{ $_Capsa }", |
| 199 | "amount": "{ $qt_rebuda }" |
| 200 | } |
| 201 | ] |
| 202 | } |
| 203 | }, |
| 204 | { |
| 205 | "app": "state", |
| 206 | "state": "{\r |
| 207 | response[ 'proces' ] = $proces;\r |
| 208 | response[ 'operacio' ] = $operacio;\r |
| 209 | response[ 'Proposta' ] =\r |
| 210 | $nova_idprop otherwise $ref otherwise 'drecera';\r |
| 211 | \r |
| 212 | if ( $proces == 'atribucio' ) {\r |
| 213 | response[ 'Quantitat' ] = $qt || ' ' || $geto;\r |
| 214 | response[ 'Rebedora' ] = $rebedora;\r |
| 215 | }\r |
| 216 | }" |
| 217 | } |
| 218 | ] |
| 219 | } |
| 220 | ] |