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