| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 25000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $nom_AA = 'Portal'; |
| 9 | $_AUT_000 = 'XD7FVUM442NPIIMLRIT2FYWJEDQ4ILLJ'; |
| 10 | |
| 11 | |
| 12 | $adr__ = trigger.address; |
| 13 | $args = trigger.data; |
| 14 | $_unitat = trigger.output[[ asset != base ]].asset; |
| 15 | $qt = trigger.output[[ asset = $_unitat ]]; |
| 16 | $noms = var[ 'noms' ] otherwise {}; |
| 17 | $versions = var[ 'versions' ] otherwise {}; |
| 18 | $getons_provisionals = var[ 'getons_provisionals' ] otherwise {}; |
| 19 | $dades = {}; |
| 20 | |
| 21 | |
| 22 | $admin = $args.admin; |
| 23 | $proces = $args.proces; |
| 24 | $ref = $args.ref; |
| 25 | $val = $args.val; |
| 26 | $idprop = $args.idprop; |
| 27 | $nom = $args.nom; |
| 28 | $adr = $args.adr; |
| 29 | $estat = $args.estat; |
| 30 | $qt_args = $args.qt; |
| 31 | |
| 32 | |
| 33 | $versions_Portal = $versions.Portal otherwise this_address; |
| 34 | $__dada_port = $refval => |
| 35 | data_feed[[ oracles = $versions_Portal, feed_name = $refval, ifnone = false ]]; |
| 36 | |
| 37 | $_Registre = $__dada_port( '_Registre' ) otherwise $args._Registre; |
| 38 | $versions_Registre = $versions.Registre otherwise $_Registre; |
| 39 | $__dada_acc = $refval => |
| 40 | data_feed[[ oracles = $versions_Registre, feed_name = $refval, ifnone = false ]]; |
| 41 | |
| 42 | $_Accions = $__dada_port( '_Accions' ) otherwise $args._Accions; |
| 43 | $versions_Accions = $versions.Accions otherwise $_Accions; |
| 44 | $__dada_acc22222 = $refval => |
| 45 | data_feed[[ oracles = $versions_Accions, feed_name = $refval, ifnone = false ]]; |
| 46 | |
| 47 | $_Validacions = $__dada_port( '_Validacions' ) otherwise $args._Validacions; |
| 48 | $versions_Validacions = $versions.Validacions otherwise $_Validacions; |
| 49 | $__dada_val = $refval => |
| 50 | data_feed[[ oracles = $versions_Validacions, feed_name = $refval, ifnone = false ]]; |
| 51 | |
| 52 | $_Getons = $__dada_port( '_Getons' ) otherwise $args._Getons; |
| 53 | $versions_Getons = $versions.Getons otherwise $_Getons; |
| 54 | $__dada_get = $refval => |
| 55 | data_feed[[ oracles = $versions_Getons, feed_name = $refval, ifnone = false ]]; |
| 56 | |
| 57 | |
| 58 | $__arg = $arg => |
| 59 | $args[ $arg ] otherwise |
| 60 | bounce( "Cal proporcionar el valor de: " || $arg ); |
| 61 | |
| 62 | |
| 63 | $__ordinal = $rf => { |
| 64 | $ord = $__dada_port( 'ordinal_' || $rf ); |
| 65 | $ord ? $ord + 1 : 1 |
| 66 | }; |
| 67 | |
| 68 | |
| 69 | $__provisio = $rf => { |
| 70 | $prov = $__dada_port( 'Provisio' ); |
| 71 | $romanent_minim = $__dada_port( 'Romanent_Minim' ); |
| 72 | $romanent = balance[ $rf ][ base ]; |
| 73 | $romanent > $romanent_minim ? |
| 74 | $prov : |
| 75 | $prov * 10 |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | |
| 80 | $actuant_es_AUT_000 = $adr__ == $_AUT_000; |
| 81 | $_AUT_0 = $__dada_port( '_AUT_0' ); |
| 82 | $actuant_es_AUT = |
| 83 | ( $actuant_es_AUT_000 AND ! $_AUT_0 ) |
| 84 | OR $adr__ == $__dada_port( '_AUT_A' ) |
| 85 | OR $adr__ == $__dada_port( '_AUT_B' ) |
| 86 | OR $adr__ == $__dada_port( '_AUT_C' ) |
| 87 | OR $adr__ == $_AUT_0; |
| 88 | |
| 89 | |
| 90 | |
| 91 | if ( $admin ) { |
| 92 | |
| 93 | if ( ! $actuant_es_AUT ) bounce( 'No autoritzada' ); |
| 94 | |
| 95 | |
| 96 | $excepcio_inicial = |
| 97 | ( $actuant_es_AUT_000 AND ! $_AUT_0 ) |
| 98 | OR $proces == 'copia_dades_portal'; |
| 99 | |
| 100 | if ( ! $excepcio_inicial ) { |
| 101 | if ( !! $args.operacio AND $args.operacio == 'confirmacio' ) { |
| 102 | |
| 103 | $temps_idprop = $__dada_port( $idprop ); |
| 104 | if ( ! $temps_idprop ) bounce( "No hi ha cap proposta amb aquesta ref" ); |
| 105 | |
| 106 | |
| 107 | if ( $__dada_port( $idprop || '_proposant' ) == $adr__ ) |
| 108 | bounce( "El procés de confirmació l'ha d'endegar una altra AUT" ); |
| 109 | |
| 110 | |
| 111 | if ( $__dada_port( 'Lapse' ) > timestamp - $temps_idprop ) |
| 112 | bounce( "Encara no es pot confirmar la proposta" ); |
| 113 | |
| 114 | |
| 115 | if ( ! $__dada_val( 'validacio_' || $idprop ) ) |
| 116 | bounce( "La proposta encara no ha estat validada" ); |
| 117 | |
| 118 | $dades[ 'confirmacio_' || $idprop ] = timestamp; |
| 119 | $dades[ 'confirmacio_' || $idprop || '_confirmant' ] = $adr__; |
| 120 | $operacio = 'confirmacio'; |
| 121 | } else { |
| 122 | $ord_prop = $__ordinal( $proces ); |
| 123 | $nova_idprop = 'proposta_' || $proces || '_' || $ord_prop; |
| 124 | $dades[ 'ordinal_' || $proces ] = $ord_prop; |
| 125 | $dades[ $nova_idprop ] = timestamp; |
| 126 | $dades[ $nova_idprop || '_proposant' ] = $adr__; |
| 127 | $operacio = 'proposta'; |
| 128 | } |
| 129 | } else { |
| 130 | $ord_prop = $__ordinal( $proces ); |
| 131 | $nova_iddrec = 'drecera_' || $proces || '_' || $ord_prop; |
| 132 | $dades[ 'ordinal_' || $proces ] = $ord_prop; |
| 133 | $dades[ $nova_iddrec ] = timestamp; |
| 134 | $dades[ $nova_iddrec || '_actuant' ] = $adr__; |
| 135 | $operacio = 'drecera'; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | |
| 140 | |
| 141 | $_estels = $__dada_port( '_Estels' ); |
| 142 | |
| 143 | if ( $proces != 'inicialitzacio' AND $proces != 'copia_dades_portal' ) { |
| 144 | $cicle_actual = |
| 145 | 1 + floor( ( timestamp - $__dada_port( 'Origen' ) ) / $__dada_port( 'Interval' ) ); |
| 146 | $nova_escala = length( $__dada_acc( 'total_FOP_en_estels' ) otherwise 1 ); |
| 147 | $escala_actual = $__dada_port( 'escala_actual' ); |
| 148 | $data_escala_actual = $__dada_port( 'data_escala_actual' ); |
| 149 | if ( $nova_escala > $escala_actual ) { |
| 150 | $dades[ 'escala_actual' ] = $nova_escala; |
| 151 | $dades[ 'data_escala_actual' ] = timestamp; |
| 152 | $interval_escala = 1000; |
| 153 | } else $interval_escala = timestamp - $data_escala_actual + 1000; |
| 154 | } |
| 155 | }", |
| 156 | "messages": { |
| 157 | "cases": [ |
| 158 | { |
| 159 | "if": "{ $proces == 'acces_accions' }", |
| 160 | "init": "{ |
| 161 | $unitat_es_geto = !! $__dada_get( 'refgeto_' || $_unitat ); |
| 162 | if ( $_unitat != $_estels |
| 163 | AND ( ! $unitat_es_geto OR $unitat_es_geto.estat != 'actiu' ) ) |
| 164 | bounce( 'Getó inexistent o inactiu' ); |
| 165 | |
| 166 | $ACC = $__arg( 'accio' ); |
| 167 | $refgeto = |
| 168 | $unitat_es_geto ? |
| 169 | $__dada_get( 'refgeto_' || $_unitat ) : |
| 170 | 'estels'; |
| 171 | |
| 172 | |
| 173 | $__activada = ( $adrr, $reff ) => |
| 174 | !! $__dada_acc( 'activacio_' || $adrr || '_en_' || $reff ) ? |
| 175 | true : |
| 176 | bounce( 'Adreça no activada per a ' || $reff ); |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | if ( $unitat_es_geto ) { |
| 182 | $__activada( $adr__, 'estels' ); |
| 183 | if ( $ACC != 'Activacio' ) |
| 184 | $__activada( $adr__, $refgeto ); |
| 185 | } |
| 186 | else if ( $ACC != 'Activacio' ) |
| 187 | $__activada( $adr__, 'estels' ); |
| 188 | |
| 189 | |
| 190 | $__accRestringida = $acc => { |
| 191 | $refgeto == 'estels' ? |
| 192 | false : |
| 193 | $__dada_get( $refgeto || '_' || $acc || 'ns_restringides' ) |
| 194 | }; |
| 195 | |
| 196 | |
| 197 | $__capacitada = ( $acc, $adrr ) => true; |
| 198 | |
| 199 | /* |
| 200 | $__capacitada = ( $acc, $adrr ) => { |
| 201 | $capacitacio = $__dada_geto( 'capacitacio_' || $refgeto || '_' || $acc || '_' || $adrr ); |
| 202 | $__accRestringida( $acc ) AND ! $capacitacio OR $capacitacio != 'capacitada' ? |
| 203 | bounce( 'Adreça no capacitada per a aquesta acció' ) : |
| 204 | true |
| 205 | }; |
| 206 | */ |
| 207 | |
| 208 | |
| 209 | if ( $ACC == 'Contribucio' AND $refgeto != 'estels' ) |
| 210 | bounce( 'Les contribucions només es poden fer en estels' ); |
| 211 | |
| 212 | if ( $ACC == 'Transfer' ) { |
| 213 | $receptora = $__arg( 'receptora' ); |
| 214 | $receptora_activada = |
| 215 | $__activada( $receptora, 'estels' ) AND |
| 216 | $__activada( $receptora, $refgeto ); |
| 217 | $receptora_capacitada = |
| 218 | $unitat_es_geto ? |
| 219 | $__capacitada( 'recepcio', $receptora ) : |
| 220 | true; |
| 221 | $ref_subscripcio = 'subscripcio_' || $receptora || '_en_' || $refgeto; |
| 222 | $receptora_subscrita = !! $__dada_acc( $ref_subscripcio ); |
| 223 | $ref_renovacio = 'renovacio_' || $receptora || '_en_' || $refgeto; |
| 224 | $cicle_renovacio = $__dada_acc( $ref_renovacio || '_cicle' ); |
| 225 | $receptora_renovada = |
| 226 | !! $cicle_renovacio AND |
| 227 | $cicle_renovacio == $cicle_actual; |
| 228 | if ( $receptora_subscrita AND $receptora_renovada ) { |
| 229 | $percent_derivacio = $__dada_acc( $ref_subscripcio || '_derivacio' ); |
| 230 | $args.qt_derivacio = floor( $qt * $percent_derivacio / 100 ); |
| 231 | $qt_accio = $qt - $args.qt_derivacio; |
| 232 | $args.amb_derivacio = true; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | $args.cicle_actual = $cicle_actual; |
| 237 | $args.escala_actual = $escala_actual; |
| 238 | $args.interval_escala = $interval_escala; |
| 239 | $args.refgeto = $refgeto; |
| 240 | $args.qt_accio = $qt_accio otherwise $qt; |
| 241 | }", |
| 242 | "messages": [ |
| 243 | { |
| 244 | "app": "data_feed", |
| 245 | "payload": "{ $dades }" |
| 246 | }, |
| 247 | { |
| 248 | "app": "data", |
| 249 | "payload": "{ $args }" |
| 250 | }, |
| 251 | { |
| 252 | "app": "payment", |
| 253 | "payload": { |
| 254 | "asset": "base", |
| 255 | "outputs": [ |
| 256 | { |
| 257 | "address": "{ $_Accions }", |
| 258 | "amount": "{ $__provisio( $_Accions ) }" |
| 259 | } |
| 260 | ] |
| 261 | } |
| 262 | }, |
| 263 | { |
| 264 | "if": "{ $ACC == 'Transfer' }", |
| 265 | "app": "payment", |
| 266 | "payload": { |
| 267 | "asset": "{ $_unitat }", |
| 268 | "outputs": [ |
| 269 | { |
| 270 | "address": "{ $receptora }", |
| 271 | "amount": "{ $args.qt_accio }" |
| 272 | } |
| 273 | ] |
| 274 | } |
| 275 | }, |
| 276 | { |
| 277 | "app": "state", |
| 278 | "state": "{ |
| 279 | if ( !! $receptora ) |
| 280 | response[ 'Transfer a' ] = |
| 281 | $receptora || " de " || $args.qt_accio || " " || $refgeto; |
| 282 | if ( $receptora_subscrita AND ! $receptora_renovada ) |
| 283 | response[ 'Atenció!' ] = |
| 284 | "Adreça receptora subscrita però no renovada per al cicle actual: " || |
| 285 | " No comporta cap mena de derivació!"; |
| 286 | response[ 'Procés' ] = $proces; |
| 287 | response[ 'Romanent en bytes' ] = balance[ base ] || ' bytes'; |
| 288 | response[ 'Romanent en estels' ] = balance[ $_estels ] || ' estels'; |
| 289 | }" |
| 290 | } |
| 291 | ] |
| 292 | }, |
| 293 | { |
| 294 | "if": "{ $admin AND $proces == 'inicialitzacio' }", |
| 295 | "init": "{ |
| 296 | $__definidors = $r => { |
| 297 | $dades[ $r ] = $args[ $r ]; |
| 298 | |
| 299 | }; |
| 300 | |
| 301 | $refs_definidors = [ |
| 302 | '_Accions', '_Registre', '_Getons', |
| 303 | '_Validacions', '_Validadores', |
| 304 | '_FRO', '_Estels', '_AUT_A', '_AUT_B' |
| 305 | ]; |
| 306 | |
| 307 | $m = map( $refs_definidors, 9, $__definidors ); |
| 308 | |
| 309 | $dades.Origen = timestamp; |
| 310 | $dades.Interval = 1200; |
| 311 | |
| 312 | |
| 313 | $dades.Lapse = 800; |
| 314 | $dades.Import_Activacio = 20; |
| 315 | $dades.Import_Subscripcio = 50; |
| 316 | $dades.Import_Renovacio = 30; |
| 317 | $dades.Taxa_Conversio = 4; |
| 318 | $dades.Factor_Conversio = 10; |
| 319 | $dades.Compensacio_Interficie = 10; |
| 320 | $dades.Compensacio_Promocio = 20; |
| 321 | $dades.Generacio_Minima = 1000; |
| 322 | $dades.Nombre_Delegades = 5; |
| 323 | $dades.Nombre_Aprovacions = 5; |
| 324 | $dades.Cicles_Diposit = 3; |
| 325 | $dades.Diposit_Minim = 100; |
| 326 | $dades.Provisio = 2000; |
| 327 | $dades.Romanent_Minim = 10000; |
| 328 | $dades.escala_actual = 1; |
| 329 | $dades.data_escala_actual = timestamp; |
| 330 | }", |
| 331 | "messages": [ |
| 332 | { |
| 333 | "app": "data_feed", |
| 334 | "payload": "{ $dades }" |
| 335 | }, |
| 336 | { |
| 337 | "app": "state", |
| 338 | "state": "{ |
| 339 | $versions.Portal = this_address; |
| 340 | $versions.Accions = $dades._Accions; |
| 341 | $versions.Registre = $dades._Registre; |
| 342 | $versions.Getons = $dades._Getons; |
| 343 | $versions.Validacions = $dades._Validacions; |
| 344 | $versions.Validadores = $dades._Validadores; |
| 345 | var[ 'versions' ] = $versions; |
| 346 | response[ 'Procés' ] = $proces; |
| 347 | response[ 'Operació' ] = $operacio; |
| 348 | }" |
| 349 | } |
| 350 | ] |
| 351 | }, |
| 352 | { |
| 353 | "if": "{ $admin AND $proces == 'esmena_definidor' }", |
| 354 | "init": "{ |
| 355 | if ( $operacio == 'proposta' ) { |
| 356 | $dades[ $nova_idprop || '_ref' ] = $ref; |
| 357 | $dades[ $nova_idprop || '_val' ] = $val; |
| 358 | } else { |
| 359 | $nova_ref = $__dada_port( $idprop || '_ref' ) otherwise $ref; |
| 360 | $nou_val = $__dada_port( $idprop || '_val' ) otherwise $val; |
| 361 | $dades[ $nova_ref ] = $nou_val; |
| 362 | } |
| 363 | }", |
| 364 | "messages": [ |
| 365 | { |
| 366 | "app": "data_feed", |
| 367 | "payload": "{ $dades }" |
| 368 | }, |
| 369 | { |
| 370 | "app": "state", |
| 371 | "state": "{ |
| 372 | if ( $operacio != 'proposta' ) { |
| 373 | $nom_aa = substring( $nova_ref, 1 ); |
| 374 | $AAs = 'Accions, Getons, Validacions, Validadores'; |
| 375 | if( contains( $AAs, $nom_aa ) ) { |
| 376 | $versions_aa = $versions[ $nom_aa ]; |
| 377 | $_aa = $nou_val; |
| 378 | if ( ! is_aa( $_aa ) ) bounce( 'No és un AA' ); |
| 379 | delete( $versions_aa, $_aa ); |
| 380 | $versions[ $nom_aa ] = $_aa || ' : ' || $versions_aa; |
| 381 | var[ 'versions' ] = $versions; |
| 382 | response[ 'Versions ' || $nom_aa ] = $versions[ $nom_aa ]; |
| 383 | } |
| 384 | } |
| 385 | response[ 'Nova ref' ] = $nova_ref otherwise $ref; |
| 386 | response[ 'Nou valor' ] = $nou_val otherwise $val; |
| 387 | response[ 'Proposta' ] = |
| 388 | $nova_idprop otherwise $idprop otherwise 'drecera'; |
| 389 | response[ 'Procés' ] = $proces; |
| 390 | response[ 'Operació' ] = $operacio; |
| 391 | }" |
| 392 | } |
| 393 | ] |
| 394 | }, |
| 395 | { |
| 396 | "if": "{ $admin AND $proces == 'copia_dades_portal' }", |
| 397 | "messages": [ |
| 398 | { |
| 399 | "app": "state", |
| 400 | "state": "{ |
| 401 | $versions_actual = var[ $args.adr ][ 'versions' ]; |
| 402 | $versions.Portal = this_address || ' : ' || $versions_actual[ 'Portal' ]; |
| 403 | $versions_accions = replace( $versions_actual[ 'Accions' ], $_Accions, '' ); |
| 404 | $versions.Accions = |
| 405 | $versions_accions ? |
| 406 | $_Accions || ' : ' || $versions_accions: |
| 407 | $_Accions; |
| 408 | $versions_validacions = replace( $versions_actual[ 'Validacions' ], $_Validacions, '' ); |
| 409 | $versions.Validacions = |
| 410 | $versions_validacions ? |
| 411 | $_Validacions || ' : ' || $versions_validacions: |
| 412 | $_Validacions; |
| 413 | $versions_getons = replace( $versions_actual[ 'Getons' ], $_Getons, '' ); |
| 414 | $versions.Getons = |
| 415 | $versions_getons ? |
| 416 | $_Getons || ' : ' || $versions_getons: |
| 417 | $_Getons; |
| 418 | var[ 'versions' ] = $versions; |
| 419 | var[ 'noms' ] = var[ $args.adr ][ 'noms' ] otherwise {}; |
| 420 | var[ 'getons_provisionals' ] = var[ $args.adr ][ 'getons_provisionals' ] otherwise {}; |
| 421 | response[ 'versions Portal' ] = $versions.Portal; |
| 422 | response[ 'versions Accions' ] = $versions.Accions; |
| 423 | response[ 'versions Validacions' ] = $versions.Validacions; |
| 424 | response[ 'versions Getons' ] = $versions.Getons; |
| 425 | response[ 'Procés' ] = $proces; |
| 426 | }" |
| 427 | } |
| 428 | ] |
| 429 | }, |
| 430 | { |
| 431 | "if": "{ |
| 432 | $proces == 'assignacio' OR $proces == 'conversio' OR $proces == 'retribucio' |
| 433 | }", |
| 434 | "init": "{ |
| 435 | if ( $admin AND $proces == 'assignacio' ) { |
| 436 | |
| 437 | $ref_assignacio = 'assignacio_' || $args.requeriment; |
| 438 | $destinataria = $args.destinataria; |
| 439 | $qt_assignacio = $__dada_port( $idprop || '_qt' ) otherwise $qt_args; |
| 440 | |
| 441 | if ( $operacio == 'proposta' ) { |
| 442 | $dades[ $nova_idprop || '_destinataria' ] = $destinataria; |
| 443 | $dades[ $nova_idprop || '_resolucio' ] = $args.resolucio; |
| 444 | $dades[ $nova_idprop || '_requeriment' ] = $args.requeriment; |
| 445 | $dades[ $nova_idprop || '_qt' ] = $qt_args; |
| 446 | $dades[ $nova_idprop || '_unitat' ] = $args.unitat; |
| 447 | } else { |
| 448 | $unitat = $__dada_port( $idprop || '_unitat' ) otherwise $args.unitat; |
| 449 | $dades[ $ref_assignacio || '_unitat' ] = $unitat; |
| 450 | $dades[ $ref_assignacio || '_destinataria' ] = |
| 451 | $__dada_port( $idprop || '_destinataria' ) otherwise $destinataria; |
| 452 | $dades[ $ref_assignacio || '_resolucio' ] = |
| 453 | $__dada_port( $idprop || '_resolucio' ) otherwise $args.resolucio; |
| 454 | $dades[ $ref_assignacio || '_requeriment' ] = |
| 455 | $__dada_port( $idprop || '_requeriment' ) otherwise $args.requeriment; |
| 456 | $dades[ $ref_assignacio || '_qt' ] = $qt_assignacio; |
| 457 | |
| 458 | $total_assignacions = $__dada_port( 'total_assignacions' ) otherwise 0; |
| 459 | $dades[ 'total_assignacions' ] = $total_assignacions + $qt_assignacio; |
| 460 | } |
| 461 | $payment = [ $unitat, $destinataria, $qt_args ]; |
| 462 | $realitzable = $operacio != 'proposta'; |
| 463 | } |
| 464 | |
| 465 | if ( $proces == 'conversio' ) { |
| 466 | $qt_dipositada = $__dada_acc( $__arg( 'ref' ) ); |
| 467 | $qt_conversio = $__dada_acc( $ref || '_qt_conversio' ); |
| 468 | $geto_diposit = $__dada_acc( $ref || '_geto_diposit' ); |
| 469 | $cicle_conversio = $__dada_acc( $ref || '_cicle_conversio' ); |
| 470 | $cicle_renovat = $__dada_acc( 'renovacio_' || $adr__ || '_en_' || $geto_diposit || '_cicle' ); |
| 471 | $unitat = $geto_diposit == $_estels ? "base" : $_estels; |
| 472 | $ref_conversio = 'conversio_' || $ref; |
| 473 | |
| 474 | if ( ! $qt_conversio ) bounce( 'Dipòsit inexistent' ); |
| 475 | |
| 476 | if ( $adr__ != $__dada_acc( $ref || '_dipositant' ) ) |
| 477 | bounce( "L'adreça receptora ha de ser la dipositant" ); |
| 478 | |
| 479 | if ( !! $__dada_port( $ref_conversio || '_data' ) ) |
| 480 | bounce( 'Aquest dipòsit ja ha estat convertit' ); |
| 481 | |
| 482 | if ( $cicle_conversio > $cicle_actual ) |
| 483 | bounce( "Encara no és l'hora" ); |
| 484 | |
| 485 | if ( $cicle_renovat < $cicle_actual ) |
| 486 | bounce( "No renovada en " || $geto_diposit || " per al cicle actual: " || $cicle_actual ); |
| 487 | |
| 488 | $dades[ $ref_conversio || '_data' ] = timestamp; |
| 489 | $dades[ $ref_conversio || '_qt' ] = $qt_conversio; |
| 490 | $dades[ $ref_conversio || '_unitat' ] = $unitat; |
| 491 | |
| 492 | $ref_total_conversions = 'total_conversions_' || $geto_diposit; |
| 493 | $total_conversions = $__dada_port( $ref_total_conversions ) otherwise 0; |
| 494 | $dades[ $ref_total_conversions ] = $total_conversions + $qt_dipositada; |
| 495 | |
| 496 | $ref_total_taxes = 'total_taxes_' || $geto_diposit; |
| 497 | $total_taxes = $__dada_port( $ref_total_taxes ) otherwise 0; |
| 498 | $dades[ $ref_total_taxes ] = $total_taxes + $qt_dipositada - $qt_conversio; |
| 499 | |
| 500 | $payment = [ $unitat, $adr__, $qt_conversio ]; |
| 501 | $realitzable = true; |
| 502 | } |
| 503 | |
| 504 | if ( $proces == 'retribucio' ) { |
| 505 | if ( $ref == 'aportacio_activacio' ) { |
| 506 | $import = $__dada_acc( 'activacio_' || $adr__ || '_en_estels_qt' ); |
| 507 | $escala = $__dada_acc( 'activacio_' || $adr__ || '_en_estels_escala' ); |
| 508 | $interval = $__dada_acc( 'activacio_' || $adr__ || '_en_estels_interval' ); |
| 509 | |
| 510 | if ( ! $import ) bounce( 'Activació inexistent' ); |
| 511 | |
| 512 | } else { |
| 513 | $import = $__dada_acc( $ref ); |
| 514 | $escala = $__dada_acc( $ref || '_escala' ); |
| 515 | $interval = $__dada_acc( $ref || '_interval' ); |
| 516 | |
| 517 | if ( ! $import ) bounce( 'Contribució inexistent' ); |
| 518 | |
| 519 | if ( $adr__ != $__dada_acc( $ref || '_contribuidora' ) ) |
| 520 | bounce( "Només l'adreça contribuïdora pot rebre la retribució" ); |
| 521 | } |
| 522 | |
| 523 | $ref_retribucio = 'retribucio_' || $ref || '_escala_' || $escala_actual; |
| 524 | $retribucio = $__dada_port( $ref_retribucio ); |
| 525 | |
| 526 | if ( !! $retribucio ) |
| 527 | bounce( "Ja ha estat retribuïda per a l'escala actual" ); |
| 528 | |
| 529 | |
| 530 | if ( $escala_actual == $escala ) |
| 531 | bounce ( "Cal que es produeixi un salt d'escala" ); |
| 532 | |
| 533 | |
| 534 | |
| 535 | $diferencia_intervals = $interval_escala - $interval; |
| 536 | if ( $diferencia_intervals < 0 ) |
| 537 | bounce ( "Encara no és l'hora. Falten: " || $diferencia_intervals || 'segons' ); |
| 538 | |
| 539 | |
| 540 | $qt_retribucio = $import * ( $escala_actual - $escala ); |
| 541 | |
| 542 | $dades[ $ref_retribucio || '_data' ] = timestamp; |
| 543 | $dades[ $ref_retribucio || '_qt' ] = $qt_retribucio; |
| 544 | $dades[ $ref_retribucio || '_destinataria' ] = $adr__; |
| 545 | |
| 546 | $total_retribucions = $__dada_port( 'total_retribucions' ) otherwise 0; |
| 547 | $dades[ 'total_retribucions' ] = $total_retribucions + $qt_retribucio; |
| 548 | |
| 549 | $payment = [ $_estels, $adr__, $qt_retribucio ]; |
| 550 | $realitzable = true; |
| 551 | } |
| 552 | }", |
| 553 | "messages": [ |
| 554 | { |
| 555 | "if": "{ $realitzable }", |
| 556 | "app": "payment", |
| 557 | "payload": { |
| 558 | "asset": "{ $payment[0] }", |
| 559 | "outputs": [ |
| 560 | { |
| 561 | "address": "{ $payment[1] }", |
| 562 | "amount": "{ $payment[2] }" |
| 563 | } |
| 564 | ] |
| 565 | } |
| 566 | }, |
| 567 | { |
| 568 | "app": "data_feed", |
| 569 | "payload": "{ $dades }" |
| 570 | }, |
| 571 | { |
| 572 | "app": "state", |
| 573 | "state": "{ |
| 574 | if ( $proces == 'assignacio' ) { |
| 575 | response[ 'Proposta' ] = |
| 576 | $nova_idprop otherwise $ref otherwise 'drecera'; |
| 577 | response[ 'Quantitat' ] = $qt_args; |
| 578 | response[ 'Operació' ] = $operacio; |
| 579 | } |
| 580 | if ( $proces == 'retribucio' ) { |
| 581 | response[ 'Escala Actual' ] = $escala_actual; |
| 582 | } |
| 583 | response[ 'Destinataria' ] = $destinataria; |
| 584 | response[ 'Unitat' ] = $unitat; |
| 585 | response[ 'Ref procés' ] = |
| 586 | $ref_assignacio otherwise $ref_conversio otherwise $ref_retribucio; |
| 587 | response[ 'Procés' ] = $proces; |
| 588 | }" |
| 589 | } |
| 590 | ] |
| 591 | }, |
| 592 | { |
| 593 | "if": "{ |
| 594 | $admin AND |
| 595 | ( |
| 596 | $proces == 'convocatoria_validadores' OR |
| 597 | $proces == 'decisio_validacio' OR |
| 598 | $proces == 'validacio_directa_TEST' AND $actuant_es_AUT |
| 599 | ) |
| 600 | }", |
| 601 | "messages": [ |
| 602 | { |
| 603 | "app": "data", |
| 604 | "payload": "{ $args }" |
| 605 | }, |
| 606 | { |
| 607 | "app": "payment", |
| 608 | "payload": { |
| 609 | "asset": "base", |
| 610 | "outputs": [ |
| 611 | { |
| 612 | "address": "{ $_Validacions }", |
| 613 | "amount": "{ $__provisio( $_Validacions ) }" |
| 614 | } |
| 615 | ] |
| 616 | } |
| 617 | } |
| 618 | ] |
| 619 | }, |
| 620 | { |
| 621 | "if": "{ $admin AND $args.admin_vincles }", |
| 622 | "init": "{ |
| 623 | $tipus_vincle = $__dada_port( $idprop || '_tipus' ) otherwise $__arg( 'tipus' ); |
| 624 | $_vincle = $__dada_port( $idprop || '_adr' ) otherwise $__arg( 'adr' ); |
| 625 | $nom_vincle = $__dada_port( $idprop || '_nom' ) otherwise $__arg( 'nom' ); |
| 626 | $llista_noms = $noms[ $tipus_vincle ] otherwise ''; |
| 627 | $ref_vincle = $tipus_vincle || '_' || $_vincle; |
| 628 | $registrat = !! $__dada_port( $ref_vincle ); |
| 629 | |
| 630 | if ( $proces == 'nou_vincle' ) { |
| 631 | if ( $registrat ) |
| 632 | bounce( "Ja n'hi ha un amb aquesta adreça" ); |
| 633 | |
| 634 | if ( contains( $llista_noms, $nom_vincle ) ) |
| 635 | bounce( "Ja n'hi ha un amb aquest nom" ); |
| 636 | |
| 637 | if ( $operacio == 'proposta' ) { |
| 638 | $dades[ $nova_idprop || '_adr' ] = $adr; |
| 639 | $dades[ $nova_idprop || '_nom' ] = $nom; |
| 640 | } else { |
| 641 | $dades[ $ref_vincle || '_adr' ] = $_vincle; |
| 642 | $dades[ $ref_vincle || '_nom' ] = $nom_vincle; |
| 643 | $dades[ $ref_vincle || '_estat' ] = 'operatiu'; |
| 644 | if ( $tipus_vincle == 'entitat' ) |
| 645 | $dades[ 'ordinal_entitat_' || $__ordinal( 'entitat' ) ] = $ref_vincle; |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | if ( $proces == 'nou_estat_vincle' ) { |
| 650 | if ( ! $registrat ) |
| 651 | bounce( "No n'hi ha cap amb aquesta adreça" ); |
| 652 | |
| 653 | if ( $operacio == 'proposta' ) { |
| 654 | $dades[ $nova_idprop || '_adr' ] = $adr; |
| 655 | $dades[ $nova_idprop || '_estat' ] = $estat; |
| 656 | } else { |
| 657 | $nou_estat = $__dada_port( $idprop || '_estat' ) otherwise $estat; |
| 658 | $dades[ $ref_vincle || '_estat' ] = $nou_estat; |
| 659 | |
| 660 | if ( $nou_estat == 'opereatiu' ) |
| 661 | $noms[ $tipus_vincle ] = ': ' || $nom_vincle || ' ' || $noms; |
| 662 | else |
| 663 | $fes = replace( $noms, ( ': ' || $nom_vincle ), '' ); |
| 664 | } |
| 665 | } |
| 666 | }", |
| 667 | "messages": [ |
| 668 | { |
| 669 | "app": "data_feed", |
| 670 | "payload": "{ $dades }" |
| 671 | }, |
| 672 | { |
| 673 | "app": "state", |
| 674 | "state": "{ |
| 675 | var[ 'noms' ] = $noms; |
| 676 | if ( !! $nou_estat ) |
| 677 | response[ 'Nou estat entitat ' || $ref_vincle ] = $nou_estat; |
| 678 | response[ 'Proposta' ] = $nova_idprop otherwise $ref otherwise 'drecera'; |
| 679 | response[ 'Procés' ] = $proces; |
| 680 | response[ 'Operació' ] = $operacio; |
| 681 | }" |
| 682 | } |
| 683 | ] |
| 684 | } |
| 685 | ] |
| 686 | } |
| 687 | } |
| 688 | ] |