| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{\r |
| 5 | $nom_AA = 'Accions';\r |
| 6 | |
| 7 | $_Portal_original = trigger.address; |
| 8 | \r |
| 9 | $_Portal_actual = var[ 'portal_actual' ] otherwise $_Portal_original;\r |
| 10 | \r |
| 11 | if ( $_Portal_actual != trigger.address )\r |
| 12 | {\r |
| 13 | $versions_Portal = var[ $_Portal_actual ][ 'versions' ];\r |
| 14 | $_Portal = substring( $versions_Portal.Portal, 0, 32 );\r |
| 15 | if ( $_Portal != trigger.address )\r |
| 16 | { bounce ( 'Portal no reconegut' ); }\r |
| 17 | } else {\r |
| 18 | $_Portal = $_Portal_actual;\r |
| 19 | }\r |
| 20 | \r |
| 21 | |
| 22 | $args = trigger.data;\r |
| 23 | $adr__ = trigger.initial_address;\r |
| 24 | $idgeto = trigger.output[[ asset != base ]].asset;\r |
| 25 | \r |
| 26 | $definidors = var[ $_Portal ][ 'definidors' ];\r |
| 27 | $versions = var[ $_Portal ][ 'versions' ] otherwise {};\r |
| 28 | $versions.Portal = $versions.Portal otherwise $_Portal;\r |
| 29 | $versions.Accions = $versions.Accions otherwise this_address;\r |
| 30 | $versions.Getons = $versions.Getons otherwise $definidors._Getons;\r |
| 31 | $refs_getons = var[ $_Portal ][ 'refs_getons' ];\r |
| 32 | $refgeto = $args.refgeto;\r |
| 33 | \r |
| 34 | \r |
| 35 | |
| 36 | \r |
| 37 | |
| 38 | $__arg = $arg =>\r |
| 39 | $args[ $arg ] otherwise\r |
| 40 | bounce( "Cal proporcionar el valor de: " || $arg );\r |
| 41 | \r |
| 42 | $__dada = $refval => {\r |
| 43 | data_feed[[ oracles = $versions.Accions, feed_name = $refval, ifnone = false ]]\r |
| 44 | };\r |
| 45 | \r |
| 46 | $__dada_geto = $refval => {\r |
| 47 | data_feed[[ oracles = $versions.Getons, feed_name = $refval, ifnone = false ]]\r |
| 48 | };\r |
| 49 | \r |
| 50 | $__dada_portal = $refval => {\r |
| 51 | data_feed[[ oracles = $versions.Portal, feed_name = $refval, ifnone = false ]]\r |
| 52 | };\r |
| 53 | \r |
| 54 | $__param = $refparam => {\r |
| 55 | $refgeto == 'estels'?\r |
| 56 | $definidors[ $refparam ] :\r |
| 57 | $__dada_geto( $refgeto || '_' || $refparam )\r |
| 58 | };\r |
| 59 | \r |
| 60 | |
| 61 | $__activada = ( $adr, $ref ) => \r |
| 62 | ! $__dada( 'activacio_' || $adr || '_en_' || $ref ) ?\r |
| 63 | bounce( 'Adreça no activada per a ' || $ref )\r |
| 64 | : true;\r |
| 65 | \r |
| 66 | |
| 67 | $__qtSuficient = $ref, $q =>\r |
| 68 | $__param( $ref ) > $q ?\r |
| 69 | bounce( "L'" || $ref || " és de " || $__param( $ref ) )\r |
| 70 | : true;\r |
| 71 | \r |
| 72 | |
| 73 | $__subscrita = $adr =>\r |
| 74 | ! $__dada( 'subscripcio_' || $adr || '_en_' || $refgeto ) ?\r |
| 75 | bounce( "Adreça no subscrita per a " || $refgeto ) \r |
| 76 | : true;\r |
| 77 | \r |
| 78 | |
| 79 | $__renovada = $adr => {\r |
| 80 | $cicle_renovat = $__dada( 'renovacio_' || $adr || '_en_' || $refgeto || '_cicle' );\r |
| 81 | $cicle_renovat >= $__dada( 'cicle_actual' ) ?\r |
| 82 | true :\r |
| 83 | bounce( "Subscripció de l'adreça " || $adr || " no renovada en " || $refgeto\r |
| 84 | || " per al cicle actual: " || $__dada( 'cicle_actual' ) )\r |
| 85 | };\r |
| 86 | \r |
| 87 | \r |
| 88 | |
| 89 | $ACC = $__arg( 'accio' );\r |
| 90 | $qt = $__arg( 'qt_accio' );\r |
| 91 | $cicle_actual = $__dada( 'cicle_actual' ) otherwise 1;\r |
| 92 | $escala_actual = $__dada( 'escala_actual' ) otherwise 1;\r |
| 93 | \r |
| 94 | \r |
| 95 | |
| 96 | |
| 97 | $ref_avis = $refgeto || '_avis_' || $adr__;\r |
| 98 | $rebot = $__dada_geto( $ref_avis || '_rebot' );\r |
| 99 | $temps_avis = $__dada_geto( $ref_avis );\r |
| 100 | $avis_es_actual =\r |
| 101 | is_integer( $temps_avis ) AND\r |
| 102 | $temps_avis + ( $definidors.Lapse * 2 ) < timestamp;\r |
| 103 | \r |
| 104 | if ( $avis_es_actual AND $rebot )\r |
| 105 | { bounce ( $__dada_geto( $ref_avis || '_text' ) ); }\r |
| 106 | \r |
| 107 | \r |
| 108 | |
| 109 | $secc_ref = $ACC == 'Diposit' ? 'diposits' : to_lower( $ACC ) || 'ns';\r |
| 110 | $ref_total = 'total_' || $secc_ref || '_en_' || $refgeto;\r |
| 111 | $total_acc = $__dada( $ref_total ) otherwise 0;\r |
| 112 | \r |
| 113 | \r |
| 114 | |
| 115 | if ( $ACC == 'Activacio' ) {\r |
| 116 | $ref_Activacio = 'activacio_' || $adr__ || '_en_' || $refgeto;\r |
| 117 | \r |
| 118 | if ( is_integer( $__dada( $ref_Activacio ) ) )\r |
| 119 | { bounce( 'Adreça ja activada' ); }\r |
| 120 | \r |
| 121 | $condicions =\r |
| 122 | $__qtSuficient( 'Import_Activacio', $qt )\r |
| 123 | AND $__arg( 'nom' );\r |
| 124 | }\r |
| 125 | \r |
| 126 | \r |
| 127 | |
| 128 | if ( $ACC == 'Subscripcio' ) {\r |
| 129 | $ref_subscripcio = 'subscripcio_' || $adr__ || '_en_' || $refgeto;\r |
| 130 | $ref_renovacio = 'renovacio_' || $adr__ || '_en_' || $refgeto;\r |
| 131 | \r |
| 132 | if ( is_integer( $__dada( $ref_subscripcio ) ) )\r |
| 133 | { bounce( 'Adreça ja subscrita' ); }\r |
| 134 | \r |
| 135 | $condicions =\r |
| 136 | $__qtSuficient( 'Import_Subscripcio', $qt )\r |
| 137 | AND $__arg( 'nom' )\r |
| 138 | AND $__arg( 'derivacio' );\r |
| 139 | }\r |
| 140 | \r |
| 141 | \r |
| 142 | |
| 143 | if ( $ACC == 'Renovacio' ) {\r |
| 144 | $ref_renovacio = 'renovacio_' || $adr__ || '_en_' || $refgeto;\r |
| 145 | $cicle_renovat = $__dada( $ref_renovacio || '_cicle' ) otherwise 1;\r |
| 146 | \r |
| 147 | if ( $cicle_actual == $cicle_renovat )\r |
| 148 | { bounce( 'Cicle actual ( ' || $cicle_actual || ' ) ja renovat' ); }\r |
| 149 | \r |
| 150 | $condicions =\r |
| 151 | $__subscrita( $adr__ )\r |
| 152 | AND $__qtSuficient( 'Import_Renovacio', $qt );\r |
| 153 | }\r |
| 154 | \r |
| 155 | \r |
| 156 | |
| 157 | if ( $ACC == 'Diposit' ) {\r |
| 158 | $ref_diposit = 'diposit_' || timestamp || '_en_' || $refgeto;\r |
| 159 | \r |
| 160 | if ( $qt < $__param( 'Diposit_Minim' ) )\r |
| 161 | { bounce( 'El dipòsit mínim és de ' || $__param( 'Diposit_Minim' ) ); }\r |
| 162 | \r |
| 163 | $condicions =\r |
| 164 | $__subscrita( $adr__ )\r |
| 165 | AND $__renovada( $adr__ );\r |
| 166 | \r |
| 167 | $taxa_conversio = $__param( 'Taxa_Conversio' );\r |
| 168 | $cicles_diposit = $__param( 'Cicles_Diposit' );\r |
| 169 | $cicle_conversio = $cicle_actual + $cicles_diposit;\r |
| 170 | $taxa = round( $qt * $taxa_conversio / 100, 0 );\r |
| 171 | $qt_conversio = $qt - $taxa;\r |
| 172 | }\r |
| 173 | \r |
| 174 | \r |
| 175 | |
| 176 | if ( $ACC == 'Contribucio' )\r |
| 177 | {\r |
| 178 | $ref_contribucio = 'contribucio_' || timestamp;\r |
| 179 | }\r |
| 180 | \r |
| 181 | \r |
| 182 | |
| 183 | if ( $ACC == 'Transfer' )\r |
| 184 | {\r |
| 185 | $data_cicle_actual = $__dada( 'data_cicle_actual' ) otherwise timestamp;\r |
| 186 | $salt_cicle = timestamp - $data_cicle_actual > $definidors.Interval;\r |
| 187 | $nou_cicle =\r |
| 188 | ! $__dada( 'cicle_actual' ) ?\r |
| 189 | 1 :\r |
| 190 | $salt_cicle ?\r |
| 191 | $cicle_actual + 1 :\r |
| 192 | $cicle_actual;\r |
| 193 | \r |
| 194 | $total_FOP = $__dada_portal( 'total_FOP_en_estels' ) otherwise 0;\r |
| 195 | $nova_escala = length( $total_FOP );\r |
| 196 | $salt_escala =\r |
| 197 | ! $__dada( 'cicle_actual' )\r |
| 198 | AND ! $salt_cicle\r |
| 199 | AND ( $nova_escala > $escala_actual );\r |
| 200 | }\r |
| 201 | \r |
| 202 | }", |
| 203 | "messages": [ |
| 204 | { |
| 205 | "if": "{ $ACC == 'Transfer' AND $salt_escala }", |
| 206 | "app": "data_feed", |
| 207 | "payload": { |
| 208 | "{ 'escala_actual' }": "{ $nova_escala }", |
| 209 | "{ 'data_escala_' || $nova_escala }": "{ timestamp }", |
| 210 | "{ 'cicle_escala_' || $nova_escala }": "{ $cicle_actual }" |
| 211 | } |
| 212 | }, |
| 213 | { |
| 214 | "if": "{ $ACC == 'Transfer' AND ( $salt_cicle OR ! $__dada( 'cicle_actual' ) ) }", |
| 215 | "app": "data_feed", |
| 216 | "payload": { |
| 217 | "{ 'cicle_actual' }": "{ $nou_cicle }", |
| 218 | "{ 'data_cicle_actual' }": "{ timestamp }", |
| 219 | "{ 'escala_cicle_actual' }": "{ $escala_actual }", |
| 220 | "{ 'data_cicle_' || $nou_cicle }": "{ timestamp }", |
| 221 | "{ 'escala_cicle_' || $nou_cicle }": "{ $escala_actual }" |
| 222 | } |
| 223 | }, |
| 224 | { |
| 225 | "if": "{ $ACC == 'Activacio' }", |
| 226 | "app": "data_feed", |
| 227 | "payload": { |
| 228 | "{ $ref_total }": "{ $total_acc + $qt }", |
| 229 | "{ $ref_Activacio }": "{ timestamp }", |
| 230 | "{ $ref_Activacio || '_nom' }": "{ $args.nom }", |
| 231 | "{ $ref_Activacio || '_qt' }": "{ $qt }", |
| 232 | "{ $ref_Activacio || '_cicle' }": "{ $cicle_actual }", |
| 233 | "{ $ref_Activacio || '_escala' }": "{ $refgeto == 'estels' ? $escala_actual : 100 }" |
| 234 | } |
| 235 | }, |
| 236 | { |
| 237 | "if": "{ $ACC == 'Subscripcio' }", |
| 238 | "app": "data_feed", |
| 239 | "payload": { |
| 240 | "{ $ref_total }": "{ $total_acc + $qt }", |
| 241 | "{ $ref_subscripcio }": "{ timestamp }", |
| 242 | "{ $ref_subscripcio || '_nom' }": "{ $args.nom }", |
| 243 | "{ $ref_subscripcio || '_cicle' }": "{ $cicle_actual }", |
| 244 | "{ $ref_subscripcio || '_derivacio' }": "{ $args.derivacio }", |
| 245 | "{ $ref_renovacio }": "{ timestamp }", |
| 246 | "{ $ref_renovacio || '_cicle' }": "{ $cicle_actual }" |
| 247 | } |
| 248 | }, |
| 249 | { |
| 250 | "if": "{ $ACC == 'Renovacio' }", |
| 251 | "app": "data_feed", |
| 252 | "payload": { |
| 253 | "{ $ref_total }": "{ $total_acc + $qt }", |
| 254 | "{ $ref_renovacio }": "{ timestamp }", |
| 255 | "{ $ref_renovacio || '_cicle' }": "{ $cicle_actual }" |
| 256 | } |
| 257 | }, |
| 258 | { |
| 259 | "if": "{ $ACC == 'Diposit' }", |
| 260 | "app": "data_feed", |
| 261 | "payload": { |
| 262 | "{ $ref_total }": "{ $total_acc + $qt }", |
| 263 | "{ $ref_diposit }": "{ $qt }", |
| 264 | "{ $ref_diposit || '_dipositant' }": "{ $adr__ }", |
| 265 | "{ $ref_diposit || '_qt_conversio' }": "{ $qt_conversio }", |
| 266 | "{ $ref_diposit || '_cicle_conversio' }": "{ $taxa_conversio }", |
| 267 | "{ $ref_diposit || '_taxa' }": "{ $taxa_conversio }", |
| 268 | "{ $ref_diposit || '_cicle' }": "{ $cicle_actual }", |
| 269 | "{ $ref_diposit || '_geto_diposit' }": "{ $refgeto }" |
| 270 | } |
| 271 | }, |
| 272 | { |
| 273 | "if": "{ $ACC == 'Contribucio' }", |
| 274 | "app": "data_feed", |
| 275 | "payload": { |
| 276 | "{ $ref_total }": "{ $total_acc + $qt }", |
| 277 | "{ $ref_contribucio }": "{ $qt }", |
| 278 | "{ $ref_contribucio || '_contribuidora' }": "{ $adr__ }", |
| 279 | "{ $ref_contribucio || '_cicle' }": "{ $cicle_actual }", |
| 280 | "{ $ref_contribucio || '_escala' }": "{ $escala_actual }" |
| 281 | } |
| 282 | }, |
| 283 | { |
| 284 | "app": "state", |
| 285 | "state": "{\r |
| 286 | \r |
| 287 | |
| 288 | |
| 289 | if ( $avis_es_actual )\r |
| 290 | { response[ 'AVÍS !' ] = $__dada_geto( $ref_avis || '_text' ); }\r |
| 291 | \r |
| 292 | |
| 293 | if ( $ACC == 'Activacio' ) {\r |
| 294 | response[ 'Activació' ] =\r |
| 295 | "Amb nom: " || $args.nom || " de l'adr " || $adr__ || " per operar amb " || $refgeto;\r |
| 296 | }\r |
| 297 | \r |
| 298 | |
| 299 | if ( $ACC == 'Subscripcio' ) {\r |
| 300 | response[ 'Subscripció' ] =\r |
| 301 | "Amb nom: " || $args.nom || " de l'adr " || $adr__ ||\r |
| 302 | " per al cicle " || $cicle_actual || " per operar amb " || $refgeto;\r |
| 303 | }\r |
| 304 | \r |
| 305 | |
| 306 | if ( $ACC == 'Renovacio' ) {\r |
| 307 | response[ 'Renovació' ] =\r |
| 308 | "De la subscripció per al cicle " || $cicle_actual\r |
| 309 | || " de l'adr " || $adr__ || " en " || $refgeto;\r |
| 310 | }\r |
| 311 | \r |
| 312 | |
| 313 | if ( $ACC == 'Diposit' ) {\r |
| 314 | response[ 'Dipòsit' ] = $ref_diposit;\r |
| 315 | response[ 'Dipositant' ] = $adr__;\r |
| 316 | response[ 'Qt dipòsit' ] = $qt;\r |
| 317 | response[ 'Qt conversió' ] = $qt_conversio;\r |
| 318 | response[ 'Taxa' ] = $taxa_conversio;\r |
| 319 | response[ 'Data dipòsit' ] = timestamp_to_string( timestamp, 'date' );\r |
| 320 | response[ 'Hora dipòsit' ] = timestamp_to_string( timestamp, 'time' );\r |
| 321 | response[ 'Cicle dipòsit' ] = $cicle_actual;\r |
| 322 | response[ 'Cicle conversió' ] = $cicle_actual + $cicle_conversio;\r |
| 323 | }\r |
| 324 | \r |
| 325 | |
| 326 | if ( $ACC == 'Contribucio' ) {\r |
| 327 | response[ 'Contribució' ] = $ref_contribucio;\r |
| 328 | response[ 'Contribuïdora' ] = $adr__;\r |
| 329 | response[ 'Quantitat' ] = $qt;\r |
| 330 | response[ 'Escala actual' ] = $nova_escala;\r |
| 331 | }\r |
| 332 | \r |
| 333 | |
| 334 | \r |
| 335 | response[ 'Cicle actual' ] =\r |
| 336 | $salt_cicle ? 'Nou cicle: ' || $nou_cicle : $cicle_actual;\r |
| 337 | response[ 'Escala actual' ] =\r |
| 338 | $salt_escala ? 'Nova Escala: ' || $nova_escala : $escala_actual;\r |
| 339 | response[ 'Acció realitzada' ] = $ACC;\r |
| 340 | \r |
| 341 | |
| 342 | if ( $_Portal != $_Portal_actual ) {\r |
| 343 | var[ 'anterior_portal' ] = var[ 'portal_actual' ];\r |
| 344 | var[ 'portal_actual' ] = $_Portal;\r |
| 345 | response[ 'Nou portal actual' ] = $_Portal;\r |
| 346 | }\r |
| 347 | }" |
| 348 | } |
| 349 | ] |
| 350 | } |
| 351 | ] |