| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $nom_AA = 'Validacions'; |
| 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 | if ( $proces == 'convocatoria_validadores' ) { |
| 44 | |
| 45 | |
| 46 | $convocatoria_efectuada = $__dada( 'convocatoria_' || $idprop ) otherwise ''; |
| 47 | |
| 48 | if ( $convocatoria_efectuada != '' ) |
| 49 | bounce( "La convocatoria d'aquesta proposta ja ha estat efectuada" ); |
| 50 | |
| 51 | $convocs_i = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; |
| 52 | $nombre_isox = $__dada( 'ordinal_isox' ); |
| 53 | $selec_isox = []; |
| 54 | $llista_isox = []; |
| 55 | |
| 56 | $__ord_aleatori = ( $ord, $nombre, $seed ) => { |
| 57 | $num_aleatori = number_from_seed( ( $seed || $ord || $idprop ), 1000 ); |
| 58 | ceil( $num_aleatori / 1000 * $nombre ) |
| 59 | }; |
| 60 | |
| 61 | $__isox_aleatori = $x => { |
| 62 | $seed_isox = $llista_isox[0] otherwise $adr__ ; |
| 63 | $ordinal_aleatori = $__ord_aleatori( $x, $nombre_isox, $seed_isox ); |
| 64 | |
| 65 | $_isox = $__dada( 'isox_' || $ordinal_aleatori ); |
| 66 | $estat_isox = $__dada( 'isox_' || $_isox || '_estat' ) otherwise ''; |
| 67 | if( $estat_isox == 'habilitat' AND ! contains( $llista_isox[0], $_isox ) ) { |
| 68 | $selec_isox[] = $_isox; |
| 69 | $llista_isox_actual = $llista_isox[0] otherwise ''; |
| 70 | $llista_isox[0] = $_isox || ':' || $llista_isox_actual; |
| 71 | $dades[ 'convocatoria_' || $idprop || '_validadora_isox_' || $x ] = $_isox; |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | foreach( $convocs_i, 8, $__isox_aleatori ); |
| 76 | |
| 77 | $convocs_d = [ 1, 2, 3, 4 ]; |
| 78 | $nombre_entitats = $__dada( 'ordinal_Entitat' ); |
| 79 | $selec_delegades = []; |
| 80 | $llista_entitats = []; |
| 81 | $llista_delegades = []; |
| 82 | |
| 83 | $__entitat_aleatoria = $x => { |
| 84 | $seed_entitats = $llista_entitats[0] otherwise $llista_isox[0] ; |
| 85 | $ord_entitat_aleatori = $__ord_aleatori( $x, $nombre_entitats, $seed_entitats ); |
| 86 | $ref_entitat = $__dada( 'Entitat_' || $ord_entitat_aleatori ); |
| 87 | $estat_entitat = $__dada( $ref_entitat || '_estat' ) otherwise ''; |
| 88 | if( $estat_entitat == 'operatiu' AND ! contains( $llista_entitats[0], $ref_entitat ) ) { |
| 89 | $seed_delegades = $llista_delegades[0] otherwise $llista_entitats[0] ; |
| 90 | $ord_delegada_aleatori = $__ord_aleatori( $x, 3, $seed_delegades ); |
| 91 | $ref_delegada = $ref_entitat || '_delegada_' || $ord_delegada_aleatori; |
| 92 | $_delegada = $__dada( $ref_delegada ) otherwise ''; |
| 93 | $llista_entitats_actual = $llista_entitats[0] otherwise ''; |
| 94 | $llista_entitats[0] = $ref_entitat || ':' || $llista_entitats_actual; |
| 95 | if( $_delegada != '' AND ! contains( $llista_delegades[0], $_delegada ) ) { |
| 96 | $selec_delegades[] = $_delegada; |
| 97 | $llista_delegades_actual = $llista_delegades[0] otherwise ''; |
| 98 | $llista_delegades[0] = $_delegada || ':' || $llista_delegades_actual; |
| 99 | $dades[ 'convocatoria_' || $idprop || '_validadora_delegada_' || $x ] = $_delegada; |
| 100 | } |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | foreach( $convocs_d, 4, $__entitat_aleatoria ); |
| 105 | |
| 106 | $selec_valoradores = $selec_isox || $selec_delegades; |
| 107 | |
| 108 | $convocacions = []; |
| 109 | $__convocacions_seleccionades = $adr_valoradora => { |
| 110 | if( !! $adr_valoradora ) { |
| 111 | $convocacio = { |
| 112 | address : $adr_valoradora, |
| 113 | amount : $qt |
| 114 | }; |
| 115 | $convocacions[] = $convocacio; |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | foreach( $selec_valoradores, 16, $__convocacions_seleccionades ); |
| 120 | |
| 121 | $dades[ 'convocatoria_' || $idprop ] = timestamp; |
| 122 | } |
| 123 | |
| 124 | if ( $proces == 'decisio_validacio' ) { |
| 125 | $convocatoria = $__dada( 'convocatoria_' || $idprop ); |
| 126 | $convocs = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; |
| 127 | |
| 128 | |
| 129 | if ( ! $convocatoria ) |
| 130 | bounce( 'No hi ha cap convocatoria amb aquesta id' ); |
| 131 | |
| 132 | $_isox_convocada = []; |
| 133 | $semiref_isox = 'convocatoria_' || $idprop || '_validadora_isox_'; |
| 134 | $__troba_convocatoria_isox = $o => { |
| 135 | $adr_convo = $__dada( $semiref_isox || $o ) otherwise ''; |
| 136 | if ( $adr_convo == $adr__ ) |
| 137 | $_isox_convocada[0] = $o; |
| 138 | }; |
| 139 | |
| 140 | foreach( $convocs, 8, $__troba_convocatoria_isox ); |
| 141 | |
| 142 | $_delegada_convocada = []; |
| 143 | $semiref_delegada = 'convocatoria_' || $idprop || '_validadora_delegada_'; |
| 144 | $__troba_convocatoria_delegada = $o => { |
| 145 | $adr_convo = $__dada( $semiref_delegada || $o ) otherwise ''; |
| 146 | if ( $adr_convo == $adr__ ) |
| 147 | $_delegada_convocada[0] = $o; |
| 148 | }; |
| 149 | |
| 150 | foreach( $convocs, 8, $__troba_convocatoria_delegada ); |
| 151 | |
| 152 | |
| 153 | |
| 154 | if ( ! $_isox_convocada[0] AND ! $_delegada_convocada[0] ) |
| 155 | bounce( 'Adreça no convocada' ); |
| 156 | |
| 157 | if ( !! $_isox_convocada[0] ) $grup = 'isox'; |
| 158 | |
| 159 | if ( !! $_delegada_convocada[0] ) $grup = 'delegs'; |
| 160 | |
| 161 | $secc_ref_decisio = $idprop || '_' || $grup; |
| 162 | |
| 163 | if ( !! $__dada( $secc_ref_decisio || '_' || $adr__ ) ) |
| 164 | bounce( "Ja hi consta una decisió d'aquesta adreça per a aquesta proposta" ); |
| 165 | |
| 166 | |
| 167 | $decisio_grup = $__dada( $secc_ref_decisio ); |
| 168 | if ( !! $decisio_grup ) |
| 169 | bounce( 'Decisió del grup ' || $grup || ' ja pronunciada: ' || $decisio_grup ); |
| 170 | |
| 171 | if ( $__arg( 'decisio' ) == 'refusada' ) { |
| 172 | $dades[ $secc_ref_decisio || '_' || $adr__ ] = 'refusada'; |
| 173 | $dades[ $secc_ref_decisio ] = 'refusada'; |
| 174 | $dades[ 'refus_' || $idprop ] = timestamp; |
| 175 | $dades[ 'refus_' || $idprop || '_grup' ] = $grup; |
| 176 | } |
| 177 | |
| 178 | if ( $__arg( 'decisio' ) == 'aprovada' ) { |
| 179 | $ref_nombre_aprovacions = 'nombre_aprovacions_' || $grup || '_' || $idprop; |
| 180 | $nombre_aprovacions = $__dada( $ref_nombre_aprovacions ) otherwise 0; |
| 181 | $dades[ $secc_ref_decisio || '_' || $adr__ ] = 'aprovada'; |
| 182 | $dades[ $ref_nombre_aprovacions ] = $nombre_aprovacions + 1; |
| 183 | |
| 184 | |
| 185 | $nombre_aprovacions_minim = 3; |
| 186 | |
| 187 | if ( $nombre_aprovacions_minim == $nombre_aprovacions + 1 ) { |
| 188 | $dades[ $secc_ref_decisio ] = 'aprovada'; |
| 189 | |
| 190 | $alter_grup = $grup == 'isox' ? 'delegs' : 'isox'; |
| 191 | $decisio_altre_grup = |
| 192 | $__dada( $idprop || '_' || $alter_grup ) otherwise ''; |
| 193 | |
| 194 | if ( $decisio_altre_grup == 'aprovada' ) |
| 195 | $dades[ 'validacio_' || $idprop ] = timestamp; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | |
| 201 | if ( $proces == 'validacio_directa_TEST' ) |
| 202 | $dades[ 'validacio_' || $idprop ] = timestamp; |
| 203 | |
| 204 | $registre = {}; |
| 205 | $registre.dades = $dades; |
| 206 | }", |
| 207 | "messages": [ |
| 208 | { |
| 209 | "if": "{ $proces == 'convocatoria_validadores' }", |
| 210 | "init": "{ |
| 211 | $payload = |
| 212 | { |
| 213 | asset : $_unitat, |
| 214 | outputs : $convocacions |
| 215 | }; |
| 216 | }", |
| 217 | "app": "payment", |
| 218 | "payload": "{ $payload }" |
| 219 | }, |
| 220 | { |
| 221 | "app": "data", |
| 222 | "payload": "{ $registre }" |
| 223 | }, |
| 224 | { |
| 225 | "app": "payment", |
| 226 | "payload": { |
| 227 | "asset": "base", |
| 228 | "outputs": [ |
| 229 | { |
| 230 | "address": "{ $args._Registre }", |
| 231 | "amount": "{ $__dada( 'Provisio' ) }" |
| 232 | } |
| 233 | ] |
| 234 | } |
| 235 | }, |
| 236 | { |
| 237 | "app": "state", |
| 238 | "state": "{ |
| 239 | response[ 'Procés' ] = $proces; |
| 240 | response[ 'Proposta' ] = $idprop; |
| 241 | |
| 242 | if ( $proces == 'convocatoria_validadores' ) { |
| 243 | response[ 'Nombre Isox' ] = $nombre_isox; |
| 244 | response[ 'Nombre Entitats' ] = $nombre_entitats; |
| 245 | response[ 'Isox Convocades' ] = $llista_isox[0]; |
| 246 | response[ 'Entitats Convocades' ] = $llista_entitats[0]; |
| 247 | response[ 'Delegades Convocades' ] = $llista_delegades[0]; |
| 248 | } |
| 249 | |
| 250 | if ( $proces == 'decisio_validacio' ) { |
| 251 | response[ 'Validació' ] = |
| 252 | $__arg( 'decisio' ) || ' per ' || $adr__; |
| 253 | |
| 254 | $decisio_presa = $dades[ $secc_ref_decisio ] otherwise ''; |
| 255 | if ( $decisio_presa != '' ) |
| 256 | response[ 'Validació' ] = $decisio_presa || ' per grup ' || $grup; |
| 257 | |
| 258 | if ( !! $dades[ 'validacio_' || $idprop ] ) |
| 259 | response[ 'Validació' ] = 'aprovada'; |
| 260 | |
| 261 | if ( !! $dades[ 'refus_' || $idprop ] ) |
| 262 | response[ 'Validació' ] = 'refusada'; |
| 263 | } |
| 264 | }" |
| 265 | } |
| 266 | ] |
| 267 | } |
| 268 | ] |