| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $nom_AA = 'Convocatories'; |
| 6 | |
| 7 | |
| 8 | |
| 9 | $_Portal = trigger.address; |
| 10 | if ( $_Portal != trigger.address ) bounce( 'Portal no reconegut' ); |
| 11 | |
| 12 | |
| 13 | |
| 14 | $args = trigger.data; |
| 15 | $adr__ = trigger.initial_address; |
| 16 | $_unitat = trigger.output[[ asset != base ]].asset; |
| 17 | $qt = 1; |
| 18 | |
| 19 | $proces = $args.proces; |
| 20 | $idprop = $args.idprop; |
| 21 | $dades = $args.dades otherwise {}; |
| 22 | |
| 23 | |
| 24 | |
| 25 | $__dada = $refval => |
| 26 | data_feed[[ oracles = $args._Registre, feed_name = $refval, ifnone = '' ]]; |
| 27 | |
| 28 | $__arg = $arg => |
| 29 | $args[ $arg ] otherwise |
| 30 | bounce( "Cal proporcionar el valor de: " || $arg ); |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | if ( !! $__dada( 'validacio_' || $idprop ) OR !! $__dada( 'refus_' || $idprop ) ) |
| 36 | bounce( 'La decisió sobre aquesta proposta ja ha estat presa' ); |
| 37 | |
| 38 | if ( ! $__dada( $idprop ) ) |
| 39 | bounce( 'No hi ha cap proposta amb aquesta id' ); |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | $convocatoria_efectuada = $__dada( 'convocatoria_' || $idprop ) otherwise ''; |
| 45 | |
| 46 | if ( $convocatoria_efectuada != '' ) |
| 47 | bounce( "La convocatoria d'aquesta proposta ja ha estat efectuada" ); |
| 48 | |
| 49 | $convocs_i = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]; |
| 50 | $nombre_isox = $__dada( 'ordinal_isox' ); |
| 51 | $selec_isox = []; |
| 52 | $llista_isox = []; |
| 53 | |
| 54 | $__ord_aleatori = ( $ord, $nombre, $seed ) => { |
| 55 | $num_aleatori = number_from_seed( ( $seed || $ord || $idprop ), 1000 ); |
| 56 | ceil( $num_aleatori / 1000 * $nombre ) |
| 57 | }; |
| 58 | |
| 59 | $__isox_aleatori = $x => { |
| 60 | $seed_isox = $llista_isox[0] otherwise $adr__ ; |
| 61 | $ordinal_aleatori = $__ord_aleatori( $x, $nombre_isox, $seed_isox ); |
| 62 | |
| 63 | $_isox = $__dada( 'isox_' || $ordinal_aleatori ); |
| 64 | $estat_isox = $__dada( 'isox_' || $_isox || '_estat' ) otherwise ''; |
| 65 | if( $estat_isox == 'habilitat' AND ! contains( $llista_isox[0], $_isox ) ) { |
| 66 | $selec_isox[] = $_isox; |
| 67 | $llista_isox_actual = $llista_isox[0] otherwise ''; |
| 68 | $llista_isox[0] = $_isox || ':' || $llista_isox_actual; |
| 69 | $dades[ 'convocatoria_' || $idprop || '_isox_' || $x ] = $_isox; |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | foreach( $convocs_i, 12, $__isox_aleatori ); |
| 74 | |
| 75 | $convocs_d = [ 1, 2, 3, 4, 5, 6 ]; |
| 76 | $nombre_entitats = $__dada( 'ordinal_entitat' ); |
| 77 | $selec_delegades = []; |
| 78 | $llista_entitats = []; |
| 79 | $llista_delegades = []; |
| 80 | |
| 81 | $__entitat_aleatoria = $x => { |
| 82 | $seed_entitats = $llista_entitats[0] otherwise $llista_isox[0] ; |
| 83 | $ord_entitat_aleatori = $__ord_aleatori( $x, $nombre_entitats, $seed_entitats ); |
| 84 | $ref_entitat = $__dada( 'entitat_' || $ord_entitat_aleatori ); |
| 85 | $estat_entitat = $__dada( $ref_entitat || '_estat' ) otherwise ''; |
| 86 | if( $estat_entitat == 'operatiu' AND ! contains( $llista_entitats[0], $ref_entitat ) ) { |
| 87 | $seed_delegades = $llista_delegades[0] otherwise $llista_entitats[0] ; |
| 88 | $ord_delegada_aleatori = $__ord_aleatori( $x, 3, $seed_delegades ); |
| 89 | $ref_delegada = $ref_entitat || '_delegada_' || $ord_delegada_aleatori; |
| 90 | $_delegada = $__dada( $ref_delegada ) otherwise ''; |
| 91 | $llista_entitats_actual = $llista_entitats[0] otherwise ''; |
| 92 | $llista_entitats[0] = $ref_entitat || ':' || $llista_entitats_actual; |
| 93 | if( $_delegada != '' AND ! contains( $llista_delegades[0], $_delegada ) ) { |
| 94 | $selec_delegades[] = $_delegada; |
| 95 | $llista_delegades_actual = $llista_delegades[0] otherwise ''; |
| 96 | $llista_delegades[0] = $_delegada || ':' || $llista_delegades_actual; |
| 97 | $dades[ 'convocatoria_' || $idprop || '_delegada_' || $x ] = $_delegada; |
| 98 | } |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | foreach( $convocs_d, 6, $__entitat_aleatoria ); |
| 103 | |
| 104 | $selec_valoradores = $selec_isox || $selec_delegades; |
| 105 | |
| 106 | $convocacions = []; |
| 107 | $__convocacions_seleccionades = $adr_valoradora => { |
| 108 | if( !! $adr_valoradora ) { |
| 109 | $convocacio = { |
| 110 | address : $adr_valoradora, |
| 111 | amount : $qt |
| 112 | }; |
| 113 | $convocacions[] = $convocacio; |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | foreach( $selec_valoradores, 18, $__convocacions_seleccionades ); |
| 118 | |
| 119 | $dades[ 'convocatoria_' || $idprop ] = timestamp; |
| 120 | |
| 121 | $registre = {}; |
| 122 | $registre.dades = $dades; |
| 123 | }", |
| 124 | "messages": [ |
| 125 | { |
| 126 | "init": "{ |
| 127 | $payload = |
| 128 | { |
| 129 | asset : $_unitat, |
| 130 | outputs : $convocacions |
| 131 | }; |
| 132 | }", |
| 133 | "app": "payment", |
| 134 | "payload": "{ $payload }" |
| 135 | }, |
| 136 | { |
| 137 | "app": "data", |
| 138 | "payload": "{ $registre }" |
| 139 | }, |
| 140 | { |
| 141 | "app": "payment", |
| 142 | "payload": { |
| 143 | "asset": "base", |
| 144 | "outputs": [ |
| 145 | { |
| 146 | "address": "{ $args._Registre }", |
| 147 | "amount": "{ $__dada( 'Provisio' ) }" |
| 148 | } |
| 149 | ] |
| 150 | } |
| 151 | }, |
| 152 | { |
| 153 | "app": "state", |
| 154 | "state": "{ |
| 155 | response[ 'Procés' ] = $proces; |
| 156 | response[ 'Proposta' ] = $idprop; |
| 157 | response[ 'Nombre Isox' ] = $nombre_isox; |
| 158 | response[ 'Nombre Entitats' ] = $nombre_entitats; |
| 159 | response[ 'Isox Convocades' ] = $llista_isox[0]; |
| 160 | response[ 'Entitats Convocades' ] = $llista_entitats[0]; |
| 161 | response[ 'Delegades Convocades' ] = $llista_delegades[0]; |
| 162 | }" |
| 163 | } |
| 164 | ] |
| 165 | } |
| 166 | ] |