| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $nom_AA = 'Portal'; |
| 6 | $versio = '0.1.2'; |
| 7 | |
| 8 | $_AUT_000 = 'XD7FVUM442NPIIMLRIT2FYWJEDQ4ILLJ'; |
| 9 | |
| 10 | |
| 11 | $adr__ = trigger.address; |
| 12 | $args = trigger.data; |
| 13 | $_unitat = trigger.output[[ asset != base ]].asset; |
| 14 | $qt = trigger.output[[ asset = $_unitat ]]; |
| 15 | |
| 16 | $generics = var[ 'generics' ] otherwise {}; |
| 17 | $ordinals = var[ 'ordinals' ] otherwise {}; |
| 18 | $refs_getons = var[ 'refs_getons' ] otherwise {}; |
| 19 | $ids_getons = var[ 'ids_getons' ] otherwise {}; |
| 20 | $versions = var[ 'versions' ] otherwise {}; |
| 21 | |
| 22 | $qt_registre_DAG = 3000; |
| 23 | |
| 24 | $_estels = $generics._Estels; |
| 25 | |
| 26 | |
| 27 | |
| 28 | $admin = $args.admin; |
| 29 | $proces = $args.proces; |
| 30 | $ref = $args.ref; |
| 31 | $idprop = $args.idprop; |
| 32 | |
| 33 | |
| 34 | |
| 35 | $_actuant_es_AUT_000 = $adr__ == $_AUT_000; |
| 36 | |
| 37 | $_actuant_es_AUT = |
| 38 | ! $generics |
| 39 | OR ( $generics._AUT_A AND $generics._AUT_A == $adr__ ) |
| 40 | OR ( $generics._AUT_B AND $generics._AUT_B == $adr__ ) |
| 41 | OR ( $generics._AUT_C AND $generics._AUT_C == $adr__ ) |
| 42 | OR ( $generics._AUT_0 AND $adr__ == $generics._AUT_0 ) |
| 43 | OR ( $_actuant_es_AUT_000 AND ! is_valid_address( $generics._AUT_0 ) ); |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | $__arg = $arg => |
| 49 | $args[ $arg ] otherwise |
| 50 | bounce( "Cal proporcionar el valor de: " || $arg ); |
| 51 | |
| 52 | $__dada = $refval => { |
| 53 | data_feed[[ oracles = $versions.Portal, feed_name = $refval, ifnone = false ]] |
| 54 | }; |
| 55 | |
| 56 | $__dada_Accions = $refval => { |
| 57 | data_feed[[ oracles = $versions.Accions, feed_name = $refval, ifnone = false ]] |
| 58 | }; |
| 59 | |
| 60 | $__dada_AA = $refval, $vers => { |
| 61 | data_feed[[ oracles = $vers, feed_name = $refval, ifnone = false ]] |
| 62 | }; |
| 63 | |
| 64 | $__ordinal = $rf => $ordinals[ $rf ] ? $ordinals[ $rf ] + 1 : 1; |
| 65 | |
| 66 | |
| 67 | |
| 68 | if ( $admin ) { |
| 69 | |
| 70 | if ( $args.admin_geto ) { |
| 71 | |
| 72 | $ref_geto = $__arg( 'ref_geto' ); |
| 73 | |
| 74 | |
| 75 | if ( ! $refs_getons[ $ref_geto ] ) |
| 76 | { bounce( 'Getó inexistent' ); } |
| 77 | |
| 78 | |
| 79 | $_AUT_0 = $__dada( $ref_geto || '_AUT_0' ); |
| 80 | $_actuant_es_AUT_geto = |
| 81 | $_actuant_es_AUT AND ! $_AUT_0 |
| 82 | OR $_actuant_es_AUT AND ! $proces == 'nou_geto' |
| 83 | OR $adr__ == $_AUT_0 |
| 84 | OR $adr__ == $__dada( $ref_geto || '_AUT_A' ) |
| 85 | OR $adr__ == $__dada( $ref_geto || '_AUT_B' ) |
| 86 | OR $adr__ == $__dada( $ref_geto || '_AUT_C' ); |
| 87 | |
| 88 | if ( ! $_actuant_es_AUT_geto ) |
| 89 | { bounce( 'No autoritzada per administrar el getó' ); } |
| 90 | |
| 91 | } else { |
| 92 | |
| 93 | if ( ! $_actuant_es_AUT ) |
| 94 | { bounce( 'No autoritzada' ); } |
| 95 | |
| 96 | |
| 97 | $_AUT_0_no_operatiu = ! $generics._AUT_0 OR $generics._AUT_0 == '...'; |
| 98 | $excepcio_inicial = $_actuant_es_AUT_000 AND $_AUT_0_no_operatiu; |
| 99 | $validacio_requerida = |
| 100 | ! $excepcio_inicial |
| 101 | AND $proces != 'copia_dades_portal' |
| 102 | AND $proces != 'generacio_getons'; |
| 103 | |
| 104 | if ( $validacio_requerida ) { |
| 105 | |
| 106 | if ( $args.operacio AND $args.operacio == 'confirmacio' ) { |
| 107 | |
| 108 | $temps_idprop = $__dada( $idprop ); |
| 109 | if ( ! is_integer( $temps_idprop ) ) |
| 110 | { bounce( "No hi ha cap proposta amb aquesta ref" ); } |
| 111 | |
| 112 | |
| 113 | if ( $__dada( $idprop || '_proposant' ) == $adr__ ) |
| 114 | { bounce( "El procés de confirmació l'ha d'endegar una altra AUT" ); } |
| 115 | |
| 116 | |
| 117 | if ( $generics.Lapse > timestamp - $temps_idprop ) |
| 118 | { bounce( "Encara no es pot confirmar la proposta" ); } |
| 119 | |
| 120 | |
| 121 | if ( ! $__dada_AA( 'validacio_' || $idprop, $versions.Validacions ) ) |
| 122 | { bounce( "La proposta encara no ha estat validada" ); } |
| 123 | |
| 124 | $operacio = 'confirmacio'; |
| 125 | |
| 126 | } else { |
| 127 | |
| 128 | $nou_ordinal = $__ordinal( $proces ); |
| 129 | $ordinals[ $proces ] = $nou_ordinal; |
| 130 | $nova_idprop = $proces || '_' || $nou_ordinal; |
| 131 | |
| 132 | $operacio = 'proposta'; |
| 133 | } |
| 134 | } else { $operacio = 'drecera'; } |
| 135 | } |
| 136 | } |
| 137 | }", |
| 138 | "messages": { |
| 139 | "cases": [ |
| 140 | { |
| 141 | "if": "{ $proces == 'acces_accions' }", |
| 142 | "init": "{ |
| 143 | $unitat_es_geto = $ids_getons[ $_unitat ]; |
| 144 | if ( $_unitat != $_estels |
| 145 | AND ( ! $unitat_es_geto OR $unitat_es_geto.estat != 'actiu' ) ) |
| 146 | { bounce( 'Getó inexistent o inactiu' ); } |
| 147 | |
| 148 | $ACC = $__arg( 'accio' ); |
| 149 | $refgeto = $unitat_es_geto ? $refs_getons[ $_unitat ] : 'estels'; |
| 150 | |
| 151 | |
| 152 | $__activada = ( $adrr, $reff ) => |
| 153 | ! $__dada_Accions( 'activacio_' || $adrr || '_en_' || $reff ) ? |
| 154 | bounce( 'Adreça no activada per a ' || $reff ) |
| 155 | : true; |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | if ( $unitat_es_geto ) { |
| 161 | $__activada( $adr__, 'estels' ); |
| 162 | if ( $ACC != 'Activacio' ) { |
| 163 | $__activada( $adr__, $refgeto ); |
| 164 | } |
| 165 | } |
| 166 | else if ( $ACC != 'Activacio' ) { |
| 167 | $__activada( $adr__, 'estels' ); |
| 168 | } |
| 169 | |
| 170 | |
| 171 | $__accRestringida = $acc => { |
| 172 | $refgeto == 'estels' ? |
| 173 | false : |
| 174 | $__dada_AA( $refgeto || '_' || $acc || 'ns_restringides', $versions.Getons ) |
| 175 | }; |
| 176 | |
| 177 | |
| 178 | $__capacitada = ( $acc, $adr ) => true; |
| 179 | |
| 180 | /* |
| 181 | $__capacitada = ( $acc, $adr ) => { |
| 182 | $capacitacio = $__dada_geto( 'capacitacio_' || $refgeto || '_' || $acc || '_' || $adr ); |
| 183 | $__accRestringida( $acc ) AND ! $capacitacio OR $capacitacio != 'capacitada' ? |
| 184 | bounce( 'Adreça no capacitada per a aquesta acció' ) : |
| 185 | true |
| 186 | }; |
| 187 | */ |
| 188 | |
| 189 | if ( $ACC == 'Transfer' ) { |
| 190 | $receptora = $__arg( 'receptora' ); |
| 191 | $receptora_activada = |
| 192 | $__activada( $receptora, 'estels' ) AND |
| 193 | $__activada( $receptora, $refgeto ); |
| 194 | $receptora_capacitada = |
| 195 | $unitat_es_geto ? |
| 196 | $__capacitada( 'recepcio', $receptora ) : |
| 197 | true; |
| 198 | $ref_subscripcio = 'subscripcio_' || $receptora || '_en_' || $refgeto; |
| 199 | $receptora_subscrita = is_integer( $__dada_Accions( $ref_subscripcio ) ); |
| 200 | $ref_renovacio = 'renovacio_' || $adr__ || '_en_' || $refgeto; |
| 201 | $cicle_renovacio = $__dada_Accions( $ref_renovacio || '_cicle' ); |
| 202 | $cicle_actual = $__dada_Accions( 'cicle_actual' ) otherwise 1; |
| 203 | $receptora_renovada = |
| 204 | is_integer( $cicle_renovacio ) AND |
| 205 | $cicle_renovacio == $cicle_actual; |
| 206 | if ( $receptora_subscrita AND $receptora_renovada ) { |
| 207 | $percent_derivacio = |
| 208 | $__dada_Accions( $ref_subscripcio || '_derivacio' ); |
| 209 | $derivacio = floor( $qt * $percent_derivacio / 100 ); |
| 210 | $total_particular = |
| 211 | $__dada( 'total_derivacions_' || $receptora || '_en_' || $refgeto ) + $derivacio; |
| 212 | $total_derivacions = |
| 213 | $__dada( 'total_derivacions_en_' || $refgeto ) + $derivacio; |
| 214 | $total_FOP = |
| 215 | $__dada( 'total_FOP_en_' || $refgeto ) + $derivacio; |
| 216 | $qt_accio = $qt - $derivacio; |
| 217 | } else { |
| 218 | $qt_accio = $qt; |
| 219 | } |
| 220 | } else { |
| 221 | $total_FOP = $__dada( 'total_FOP_en_' || $refgeto ) + $qt; |
| 222 | $qt_accio = $qt; |
| 223 | } |
| 224 | $total_unitat = $__dada( 'total_en_' || $refgeto ) + $qt; |
| 225 | $args.refgeto = $refgeto; |
| 226 | $args.qt_accio = $qt_accio; |
| 227 | }", |
| 228 | "messages": [ |
| 229 | { |
| 230 | "app": "data", |
| 231 | "payload": "{ $args }" |
| 232 | }, |
| 233 | { |
| 234 | "app": "payment", |
| 235 | "payload": { |
| 236 | "asset": "base", |
| 237 | "outputs": [ |
| 238 | { |
| 239 | "address": "{ $generics._Accions }", |
| 240 | "amount": "{ $qt_registre_DAG }" |
| 241 | } |
| 242 | ] |
| 243 | } |
| 244 | }, |
| 245 | { |
| 246 | "if": "{ $ACC == 'Transfer' }", |
| 247 | "app": "payment", |
| 248 | "payload": { |
| 249 | "asset": "{ $_unitat }", |
| 250 | "outputs": [ |
| 251 | { |
| 252 | "address": "{ $receptora }", |
| 253 | "amount": "{ $qt_accio }" |
| 254 | } |
| 255 | ] |
| 256 | } |
| 257 | }, |
| 258 | { |
| 259 | "if": "{ $derivacio }", |
| 260 | "app": "data_feed", |
| 261 | "payload": { |
| 262 | "{ 'total_derivacions_' || $receptora || '_en_' || $refgeto }": "{ $total_particular }", |
| 263 | "{ 'total_derivacions_en_' || $refgeto }": "{ $total_derivacions }", |
| 264 | "{ 'total_FOP_en_' || $refgeto }": "{ $total_FOP }", |
| 265 | "{ 'total_en_' || $refgeto }": "{ $total_unitat }" |
| 266 | } |
| 267 | }, |
| 268 | { |
| 269 | "if": "{ ! $receptora }", |
| 270 | "app": "data_feed", |
| 271 | "payload": { |
| 272 | "{ 'total_FOP_en_' || $refgeto }": "{ $total_FOP }", |
| 273 | "{ 'total_en_' || $refgeto }": "{ $total_unitat }" |
| 274 | } |
| 275 | }, |
| 276 | { |
| 277 | "app": "state", |
| 278 | "state": "{ |
| 279 | if ( $receptora ) { |
| 280 | response[ 'Transfer a' ] = |
| 281 | $receptora || " en " || $refgeto || " de " || $qt_accio || " " || $refgeto; |
| 282 | } |
| 283 | if ( $derivacio ) { |
| 284 | response[ 'Receptora deriva a FOP un ' || $percent_derivacio ] = $derivacio; |
| 285 | response[ 'Total Derivacions en ' || $refgeto ] = $total_derivacions; |
| 286 | response[ 'Total Derivacions de ' || $receptora || '_en_' || $refgeto ] = $total_particular; |
| 287 | } |
| 288 | if ( $receptora_subscrita AND ! $receptora_renovada ) { |
| 289 | response[ 'Atenció!' ] = "Adreça receptora subscrita però no renovada per al cicle actual"; |
| 290 | } |
| 291 | response[ 'Procés' ] = $proces; |
| 292 | }" |
| 293 | } |
| 294 | ] |
| 295 | }, |
| 296 | { |
| 297 | "if": "{ $admin AND $proces == 'inicialitzacio' }", |
| 298 | "messages": [ |
| 299 | { |
| 300 | "app": "state", |
| 301 | "state": "{ |
| 302 | $__resp = $r => { |
| 303 | $generics[ $r ] = |
| 304 | $args[ $r ] otherwise $generics[ $r ] otherwise '...'; |
| 305 | |
| 306 | }; |
| 307 | |
| 308 | $refs_generics = [ |
| 309 | '_Accions', '_Getons', '_Validacions', '_Validadores', |
| 310 | '_FRO', '_Estels', 'Interval', 'Lapse', |
| 311 | 'Import_Activacio', 'Import_Subscripcio', 'Import_Renovacio', |
| 312 | 'Taxa_Conversio', 'Factor_Conversio', 'Generacio_Minima', |
| 313 | 'Nombre_Delegades', 'Nombre_Aprovacions', 'Cicles_Diposit', |
| 314 | 'Diposit_Minim', '_AUT_0', '_AUT_A', '_AUT_B', '_AUT_C' |
| 315 | ]; |
| 316 | |
| 317 | $m = map( $refs_generics, 22, $__resp ); |
| 318 | |
| 319 | $versions.Portal = this_address; |
| 320 | $versions.Getons = $generics._Getons; |
| 321 | $versions.Accions = $generics._Accions; |
| 322 | $versions.Validacions = $generics._Validacions; |
| 323 | $versions.Validadores = $generics._Validadores; |
| 324 | |
| 325 | response[ 'Procés' ] = $proces; |
| 326 | response[ 'Operació' ] = $operacio; |
| 327 | var[ 'generics' ] = $generics; |
| 328 | var[ 'versions' ] = $versions; |
| 329 | var[ 'ordinals' ] = $ordinals; |
| 330 | }" |
| 331 | } |
| 332 | ] |
| 333 | }, |
| 334 | { |
| 335 | "if": "{ $admin AND $proces == 'copia_dades_portal' }", |
| 336 | "messages": [ |
| 337 | { |
| 338 | "app": "state", |
| 339 | "state": "{ |
| 340 | $__copia_dades = $r => { |
| 341 | var[ $r ] = var[ $args.val ][ $r ] otherwise {}; }; |
| 342 | |
| 343 | $blocs_dades = [ 'generics', 'ordinals', 'entitats', |
| 344 | 'refs_getons', 'ids_getons', 'versions' ]; |
| 345 | |
| 346 | $m = map( $blocs_dades, 6, $__copia_dades ); |
| 347 | |
| 348 | response[ 'Procés' ] = $proces; |
| 349 | }" |
| 350 | } |
| 351 | ] |
| 352 | }, |
| 353 | { |
| 354 | "if": "{ $admin AND $proces == 'esmena_generic' }", |
| 355 | "messages": [ |
| 356 | { |
| 357 | "if": "{ $operacio == 'proposta' }", |
| 358 | "app": "data_feed", |
| 359 | "payload": { |
| 360 | "{ $nova_idprop }": "{ timestamp }", |
| 361 | "{ $nova_idprop || '_ref' }": "{ $ref }", |
| 362 | "{ $nova_idprop || '_val' }": "{ $args.val }", |
| 363 | "{ $nova_idprop || '_proposant' }": "{ $adr__ }" |
| 364 | } |
| 365 | }, |
| 366 | { |
| 367 | "app": "state", |
| 368 | "state": "{ |
| 369 | if ( $operacio != 'proposta' ) { |
| 370 | $nova_ref = $__dada( $idprop || '_ref' ) otherwise $ref; |
| 371 | $nou_val = $__dada( $idprop || '_val' ) otherwise $args.val; |
| 372 | $generics[ $nova_ref ] = $nou_val; |
| 373 | $nom_aa = substring( $nova_ref, 1 ); |
| 374 | $AAs = 'Accions, Getons, Validacions, Validadores'; |
| 375 | if( contains( $AAs, $nom_aa ) ) { |
| 376 | $versions[ $nom_aa ] = $nou_val || ':' || $versions[ $nom_aa ]; |
| 377 | var[ 'versions' ] = $versions; |
| 378 | response[ 'Versions ' || $nom_aa ] = $versions[ $nom_aa ]; |
| 379 | } |
| 380 | } |
| 381 | response[ 'Nova ref' ] = $nova_ref; |
| 382 | response[ 'Nou valor' ] = $nou_val; |
| 383 | response[ 'Proposta' ] = $idprop; |
| 384 | response[ 'Procés' ] = $proces; |
| 385 | response[ 'Operació' ] = $operacio; |
| 386 | var[ 'generics' ] = $generics; |
| 387 | var[ 'ordinals' ] = $ordinals; |
| 388 | }" |
| 389 | } |
| 390 | ] |
| 391 | }, |
| 392 | { |
| 393 | "if": "{ $admin AND $proces == 'esmena_versions' }", |
| 394 | "messages": [ |
| 395 | { |
| 396 | "if": "{ $operacio == 'proposta' }", |
| 397 | "app": "data_feed", |
| 398 | "payload": { |
| 399 | "{ $nova_idprop }": "{ timestamp }", |
| 400 | "{ $nova_idprop || '_nom_aa' }": "{ $args.nom }", |
| 401 | "{ $nova_idprop || '_nou_valor' }": "{ $args.val }", |
| 402 | "{ $nova_idprop || '_proposant' }": "{ $adr__ }" |
| 403 | } |
| 404 | }, |
| 405 | { |
| 406 | "app": "state", |
| 407 | "state": "{ |
| 408 | if ( $operacio != 'proposta' ) { |
| 409 | $nom_aa = $__dada( $idprop || '_nom_aa' ) otherwise $args.nom; |
| 410 | $nou_valor = $__dada( $idprop || '_nou_valor' ) otherwise $args.val; |
| 411 | $afegiment = $nou_valor ? ( ':' || $nou_valor ) : ''; |
| 412 | $versions[ $nom_aa ] = $generics[ '_' || $args.nom ] || $afegiment; |
| 413 | var[ 'versions' ] = $versions; |
| 414 | response[ 'Versions ' || $nom_aa ] = $versions[ $nom_aa ]; |
| 415 | } |
| 416 | response[ 'Procés' ] = $proces; |
| 417 | response[ 'Operació' ] = $operacio; |
| 418 | var[ 'ordinals' ] = $ordinals; |
| 419 | }" |
| 420 | } |
| 421 | ] |
| 422 | }, |
| 423 | { |
| 424 | "if": "{ $admin AND $proces == 'assignacio' }", |
| 425 | "init": "{ |
| 426 | $unitat = $__dada( $idprop || '_unitat' ) otherwise $args.unitat; |
| 427 | $qt_assignacio = $__dada( $idprop || '_qt' ) otherwise $args.qt; |
| 428 | $receptora = $__dada( $idprop || '_receptora' ) otherwise $args.receptora; |
| 429 | }", |
| 430 | "messages": [ |
| 431 | { |
| 432 | "if": "{ $operacio != 'proposta' }", |
| 433 | "app": "payment", |
| 434 | "payload": { |
| 435 | "asset": "{ $unitat }", |
| 436 | "outputs": [ |
| 437 | { |
| 438 | "address": "{ $receptora }", |
| 439 | "amount": "{ $args.qt }" |
| 440 | } |
| 441 | ] |
| 442 | } |
| 443 | }, |
| 444 | { |
| 445 | "if": "{ $operacio == 'proposta' }", |
| 446 | "app": "data_feed", |
| 447 | "payload": { |
| 448 | "{ 'proposta_' || $nova_idprop }": "{ timestamp }" |
| 449 | } |
| 450 | }, |
| 451 | { |
| 452 | "if": "{ $operacio != 'confirmacio' }", |
| 453 | "app": "data_feed", |
| 454 | "payload": { |
| 455 | "{ $nova_idprop }": "{ timestamp }", |
| 456 | "{ $nova_idprop || '_ref' }": "{ $ref }", |
| 457 | "{ $nova_idprop || '_val' }": "{ $args.val }", |
| 458 | "{ $nova_idprop || '_proposant' }": "{ $adr__ }", |
| 459 | "{ $nova_idprop || '_receptora' }": "{ $receptora }", |
| 460 | "{ $nova_idprop || '_resolucio' }": "{ $args.resolucio }", |
| 461 | "{ $nova_idprop || '_requeriment' }": "{ $args.requeriment }", |
| 462 | "{ $nova_idprop || '_qt' }": "{ $qt }", |
| 463 | "{ $nova_idprop || '_unitat' }": "{ $unitat }" |
| 464 | } |
| 465 | }, |
| 466 | { |
| 467 | "if": "{ $operacio == 'confirmacio' OR $operacio == 'drecera' }", |
| 468 | "app": "data_feed", |
| 469 | "payload": { |
| 470 | "{ 'confirmacio_' || $nova_idprop }": "{ timestamp }" |
| 471 | } |
| 472 | }, |
| 473 | { |
| 474 | "app": "state", |
| 475 | "state": "{ |
| 476 | response[ 'Proposta' ] = $nova_idprop; |
| 477 | response[ 'Quantitat' ] = $qt_assignacio; |
| 478 | response[ 'Receptora' ] = $receptora; |
| 479 | response[ 'Unitat' ] = $unitat; |
| 480 | response[ 'Procés' ] = $proces; |
| 481 | response[ 'Operació' ] = $operacio; |
| 482 | var[ 'ordinals' ] = $ordinals; |
| 483 | }" |
| 484 | } |
| 485 | ] |
| 486 | }, |
| 487 | { |
| 488 | "if": "{ $proces == 'conversio' }", |
| 489 | "init": "{ |
| 490 | $qt_conversio = $__dada_Accions( $__arg( 'ref' ) || '_qt_conversio' ); |
| 491 | |
| 492 | if ( ! is_integer( $qt_conversio ) ) |
| 493 | { bounce( 'Dipòsit inexistent' ); } |
| 494 | |
| 495 | if ( $adr__ != $__dada_Accions( $ref || '_dipositant' ) ) |
| 496 | { bounce( "L'adreça receptora ha de ser la dipositant" ); } |
| 497 | |
| 498 | if ( is_integer( $__dada( 'conversio_' || $ref ) ) ) |
| 499 | { bounce( 'Aquest dipòsit ja ha estat convertit' ); } |
| 500 | |
| 501 | $cicle_conversio = $__dada_Accions( $ref || '_cicle_conversio' ); |
| 502 | if ( $cicle_conversio > $__dada_Accions( 'cicle_actual' ) ) |
| 503 | { bounce( "Encara no és l'hora" ); } |
| 504 | |
| 505 | $unitat = |
| 506 | $__dada_Accions( $ref || '_geto_diposit' ) == $_estels ? |
| 507 | "base" : |
| 508 | $_estels; |
| 509 | }", |
| 510 | "messages": [ |
| 511 | { |
| 512 | "app": "payment", |
| 513 | "payload": { |
| 514 | "asset": "{ $unitat }", |
| 515 | "outputs": [ |
| 516 | { |
| 517 | "address": "{ $adr__ }", |
| 518 | "amount": "{ $qt_conversio }" |
| 519 | } |
| 520 | ] |
| 521 | } |
| 522 | }, |
| 523 | { |
| 524 | "app": "data_feed", |
| 525 | "payload": { |
| 526 | "{ 'conversio_' || $ref }": "{ timestamp }", |
| 527 | "{ 'conversio_' || $ref || '_qt' }": "{ $qt }", |
| 528 | "{ 'conversio_' || $ref || '_unitat' }": "{ $unitat }" |
| 529 | } |
| 530 | }, |
| 531 | { |
| 532 | "app": "state", |
| 533 | "state": "{ |
| 534 | response[ 'Conversió realitzada' ] = $ref; |
| 535 | response[ 'Procés' ] = $proces; |
| 536 | }" |
| 537 | } |
| 538 | ] |
| 539 | }, |
| 540 | { |
| 541 | "if": "{ $proces == 'retribucio' }", |
| 542 | "init": "{ |
| 543 | if ( $ref == 'aportacio_activacio' ) { |
| 544 | $import = $__dada_Accions( 'activacio_' || $adr__ || '_en_estels_qt' ); |
| 545 | $escala = $__dada_Accions( 'activacio_' || $adr__ || '_en_estels_escala' ); |
| 546 | } else { |
| 547 | $import = $__dada_Accions( $ref ); |
| 548 | $escala = $__dada_Accions( $ref || '_escala' ); |
| 549 | |
| 550 | if ( ! is_integer( $import ) ) |
| 551 | { bounce( 'Contribucio inexistent' ); } |
| 552 | |
| 553 | if ( $adr__ != $__dada_Accions( $ref || '_contribuidora' ) ) |
| 554 | { bounce( "Només l'adreça contribuïdora pot rebre la retribució" ); } |
| 555 | } |
| 556 | |
| 557 | $escala_actual = $__dada_Accions( 'escala_actual' ) otherwise 1; |
| 558 | |
| 559 | $ref_retribucio = $__dada( 'retribucio_' || $ref || '_' || $escala_actual ); |
| 560 | |
| 561 | if ( is_integer( $ref_retribucio ) ) |
| 562 | { bounce( "aquesta ja ha estat retribuïda per a l'escala actual" ); } |
| 563 | |
| 564 | |
| 565 | if ( $escala_actual == $escala ) { bounce ( "Encara no és l'hora" ); } |
| 566 | |
| 567 | |
| 568 | $qt_retribucio = $import * ( $escala_actual - $escala ); |
| 569 | }", |
| 570 | "messages": [ |
| 571 | { |
| 572 | "app": "payment", |
| 573 | "payload": { |
| 574 | "asset": "{ $_estels }", |
| 575 | "outputs": [ |
| 576 | { |
| 577 | "address": "{ $adr__ }", |
| 578 | "amount": "{ $qt_retribucio }" |
| 579 | } |
| 580 | ] |
| 581 | } |
| 582 | }, |
| 583 | { |
| 584 | "app": "data_feed", |
| 585 | "payload": { |
| 586 | "{ 'retribucio_' || $ref }": "{ timestamp }", |
| 587 | "{ 'retribucio_' || $ref || '_qt' }": "{ $qt_retribucio }", |
| 588 | "{ 'retribucio_' || $ref || '_receptora' }": "{ $adr__ }" |
| 589 | } |
| 590 | }, |
| 591 | { |
| 592 | "app": "state", |
| 593 | "state": "{ |
| 594 | response[ 'Retribució realitzada' ] = $ref_retribucio; |
| 595 | response[ 'Procés' ] = $proces; |
| 596 | }" |
| 597 | } |
| 598 | ] |
| 599 | }, |
| 600 | { |
| 601 | "if": "{ $admin AND $proces == 'convocatoria_validadores' }", |
| 602 | "messages": [ |
| 603 | { |
| 604 | "app": "data", |
| 605 | "payload": "{ $args }" |
| 606 | }, |
| 607 | { |
| 608 | "app": "payment", |
| 609 | "payload": { |
| 610 | "asset": "base", |
| 611 | "outputs": [ |
| 612 | { |
| 613 | "address": "{ $generics._Validacions }", |
| 614 | "amount": "{ $qt_registre_DAG }" |
| 615 | } |
| 616 | ] |
| 617 | } |
| 618 | } |
| 619 | ] |
| 620 | }, |
| 621 | { |
| 622 | "if": "{ $proces == 'decisio_validacio' }", |
| 623 | "messages": [ |
| 624 | { |
| 625 | "app": "data", |
| 626 | "payload": "{ $args }" |
| 627 | }, |
| 628 | { |
| 629 | "app": "payment", |
| 630 | "payload": { |
| 631 | "asset": "base", |
| 632 | "outputs": [ |
| 633 | { |
| 634 | "address": "{ $generics._Validacions }", |
| 635 | "amount": "{ $qt_registre_DAG }" |
| 636 | } |
| 637 | ] |
| 638 | } |
| 639 | } |
| 640 | ] |
| 641 | }, |
| 642 | { |
| 643 | "if": "{ $proces == 'validacio_directa_TEST' AND $_actuant_es_AUT }", |
| 644 | "messages": [ |
| 645 | { |
| 646 | "app": "data", |
| 647 | "payload": "{ $args }" |
| 648 | }, |
| 649 | { |
| 650 | "app": "payment", |
| 651 | "payload": { |
| 652 | "asset": "base", |
| 653 | "outputs": [ |
| 654 | { |
| 655 | "address": "{ $generics._Validacions }", |
| 656 | "amount": "{ $qt_registre_DAG }" |
| 657 | } |
| 658 | ] |
| 659 | } |
| 660 | } |
| 661 | ] |
| 662 | }, |
| 663 | { |
| 664 | "if": "{ $admin AND $args.admin_entitats }", |
| 665 | "messages": [ |
| 666 | { |
| 667 | "if": "{ $operacio == 'proposta' }", |
| 668 | "app": "data_feed", |
| 669 | "payload": { |
| 670 | "{ $nova_idprop }": "{ timestamp }", |
| 671 | "{ $nova_idprop || '_adr' }": "{ $args.adr }", |
| 672 | "{ $nova_idprop || '_nom' }": "{ $args.nom }", |
| 673 | "{ $nova_idprop || '_estat' }": "{ $args.estat }" |
| 674 | } |
| 675 | }, |
| 676 | { |
| 677 | "app": "state", |
| 678 | "state": "{ |
| 679 | $entitats = var[ 'entitats' ] otherwise {}; |
| 680 | $estat_prop = $__dada( $idprop || '_estat' ); |
| 681 | |
| 682 | if ( $proces == 'nova_entitat' ) { |
| 683 | if ( $entitats[ $args.adr ] ) |
| 684 | { bounce( "Ja hi ha una entitat amb aquesta adreça" ); } |
| 685 | |
| 686 | if ( $entitats[ $args.adr ].nom == $args.nom ) |
| 687 | { bounce( "Ja hi ha una entitat amb aquest nom" ); } |
| 688 | |
| 689 | if ( $operacio != 'proposta' ) { |
| 690 | $adr_entitat = $args.adr otherwise $__dada( $idprop || '_adr' ); |
| 691 | $entitats[ $adr_entitat ] = { |
| 692 | nom: $args.nom otherwise $__dada( $idprop || '_nom' ), |
| 693 | estat: $args.estat otherwise $estat_prop, |
| 694 | }; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | if ( $proces == 'nou_estat_entitat' ) { |
| 699 | if ( ! $entitats[ $args.adr ] ) |
| 700 | { bounce( "No hi ha cap entitat amb aquesta adreça" ); } |
| 701 | |
| 702 | if ( $operacio != 'proposta' ) { |
| 703 | $entitats[ $args.adr ].estat = |
| 704 | $args.estat otherwise $estat_prop; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | var[ 'entitats' ] = $entitats; |
| 709 | var[ 'ordinals' ] = $ordinals; |
| 710 | response[ 'Procés' ] = $proces; |
| 711 | response[ 'Operació' ] = $operacio; |
| 712 | }" |
| 713 | } |
| 714 | ] |
| 715 | }, |
| 716 | { |
| 717 | "if": "{ $admin AND $proces == 'implementacio_geto' }", |
| 718 | "init": "{ |
| 719 | $reff_geto = $__arg( 'ref_geto' ); |
| 720 | |
| 721 | |
| 722 | if ( $__dada_AA( $reff_geto || '_confirmant', $versions.Getons ) ) |
| 723 | { bounce( 'Proposta pendent de confirmació' ); } |
| 724 | |
| 725 | }", |
| 726 | "messages": [ |
| 727 | { |
| 728 | "if": "{ $operacio == 'proposta' }", |
| 729 | "app": "data_feed", |
| 730 | "payload": { |
| 731 | "{ $nova_idprop }": "{ timestamp }", |
| 732 | "{ $nova_idprop || '_ref' }": "{ $reff_geto }" |
| 733 | } |
| 734 | }, |
| 735 | { |
| 736 | "if": "{ $operacio != 'proposta' }", |
| 737 | "app": "asset", |
| 738 | "payload": { |
| 739 | "cap": "{ $args.cap otherwise 1e9 }", |
| 740 | "is_private": false, |
| 741 | "is_transferrable": true, |
| 742 | "auto_destroy": "{ !! $args.auto_destroy }", |
| 743 | "fixed_denominations": false, |
| 744 | "issued_by_definer_only": true, |
| 745 | "cosigned_by_definer": false, |
| 746 | "spender_attested": false |
| 747 | } |
| 748 | }, |
| 749 | { |
| 750 | "if": "{ $operacio != 'proposta' }", |
| 751 | "app": "state", |
| 752 | "state": "{ |
| 753 | $refs_getons[ response_unit ] = $reff_geto; |
| 754 | $ids_getons[ $reff_geto ] = response_unit; |
| 755 | var[ 'ids_getons' ] = $ids_getons; |
| 756 | var[ 'refs_getons' ] = $refs_getons; |
| 757 | response[ 'Procés' ] = $proces; |
| 758 | response[ 'Operació' ] = $operacio; |
| 759 | }" |
| 760 | } |
| 761 | ] |
| 762 | }, |
| 763 | { |
| 764 | "if": "{ $admin AND $proces == 'baixa_geto' }", |
| 765 | "init": "{ |
| 766 | $reff_geto = $__arg( 'ref_geto' ); |
| 767 | |
| 768 | if ( ! $refs_getons[ $reff_geto ] ) |
| 769 | { bounce( 'Getó inexistent' ); } |
| 770 | }", |
| 771 | "messages": [ |
| 772 | { |
| 773 | "if": "{ $operacio == 'proposta' }", |
| 774 | "app": "data_feed", |
| 775 | "payload": { |
| 776 | "{ $nova_idprop }": "{ timestamp }", |
| 777 | "{ $nova_idprop || '_geto' }": "{ $reff_geto }" |
| 778 | } |
| 779 | }, |
| 780 | { |
| 781 | "if": "{ $operacio != 'proposta' }", |
| 782 | "app": "state", |
| 783 | "state": "{ |
| 784 | delete( $ids_getons, $reff_geto ); |
| 785 | delete( $refs_getons, $refs_getons[ $reff_geto ] ); |
| 786 | var[ 'refs_getons' ] = $refs_getons; |
| 787 | var[ 'ids_getons' ] = $ids_getons; |
| 788 | response[ 'Procés' ] = $proces; |
| 789 | response[ 'Operació' ] = $operacio; |
| 790 | }" |
| 791 | } |
| 792 | ] |
| 793 | }, |
| 794 | { |
| 795 | "if": "{ $args.admin_geto }", |
| 796 | "init": "{ |
| 797 | $args.operacio = $operacio; |
| 798 | $args.idprop = $nova_idprop; |
| 799 | $args.nougeto = $proces == 'nou_geto' ? 'geto_' || $__ordinal( 'geto' ) : ''; |
| 800 | }", |
| 801 | "messages": [ |
| 802 | { |
| 803 | "if": "{ $proces == 'emissio_getons' }", |
| 804 | "init": "{ |
| 805 | if ( $_unitat != $_estels ) |
| 806 | { bounce( 'Cal aportar-hi estels' ); } |
| 807 | |
| 808 | if ( $qt < $generics.Generacio_Minima ) |
| 809 | { bounce( 'Cal aportar-hi si més no ' |
| 810 | || $generics.Generacio_Minima || ' estels' ); } |
| 811 | }", |
| 812 | "app": "payment", |
| 813 | "payload": { |
| 814 | "asset": "{ $ids_getons[ $ref_geto ] }", |
| 815 | "outputs": [ |
| 816 | { |
| 817 | "address": "{ $__dada_AA( $ref_geto || '_FOP', $versions.Getons ) }", |
| 818 | "amount": "{ $qt * $__dada_AA( $ref_geto || 'factor_conversio', $versions.Getons ) }" |
| 819 | } |
| 820 | ] |
| 821 | } |
| 822 | }, |
| 823 | { |
| 824 | "app": "data", |
| 825 | "payload": "{ $args }" |
| 826 | }, |
| 827 | { |
| 828 | "app": "payment", |
| 829 | "payload": { |
| 830 | "asset": "base", |
| 831 | "outputs": [ |
| 832 | { |
| 833 | "address": "{ $generics._Getons }", |
| 834 | "amount": "{ $qt_registre_DAG }" |
| 835 | } |
| 836 | ] |
| 837 | } |
| 838 | } |
| 839 | ] |
| 840 | } |
| 841 | ] |
| 842 | } |
| 843 | } |
| 844 | ] |