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