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