| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $nom_AA = 'Validacions'; |
| 6 | $darrera_versio = '0000000000'; |
| 7 | |
| 8 | $_Portal_original = trigger.address; |
| 9 | |
| 10 | $_Portal = var[ 'nou_portal' ] otherwise $_Portal_original; |
| 11 | |
| 12 | if ( $_Portal != trigger.address ) |
| 13 | { bounce ( 'Portal no habilitat' ); } |
| 14 | |
| 15 | |
| 16 | $args = trigger.data; |
| 17 | $adr__ = trigger.initial_address; |
| 18 | $_unitat = trigger.output[[ asset != base ]].asset; |
| 19 | $qt = 10; |
| 20 | |
| 21 | $proces = $args.proces; |
| 22 | $idprop = $args.idprop; |
| 23 | |
| 24 | $generics = var[ $_Portal ][ 'generics' ]; |
| 25 | $entitats = var[ $_Portal ][ 'entitats' ]; |
| 26 | $versions = var[ $_Portal ][ 'versions_validacions' ]; |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | $__arg = $arg => |
| 32 | $args[ $arg ] otherwise |
| 33 | bounce( "Cal proporcionar el valor de: " || $arg ); |
| 34 | |
| 35 | $__dada = $refval => { |
| 36 | data_feed[[ oracles = $versions, feed_name = $refval, ifnone = false ]] |
| 37 | }; |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | if ( $__dada( 'validacio_' || $idprop ) ) |
| 43 | { bounce( 'Ja validada' ); } |
| 44 | |
| 45 | |
| 46 | if ( ! $__dada( $idprop ) ) |
| 47 | { bounce( 'No hi ha cap proposta amb aquesta id' ); } |
| 48 | |
| 49 | |
| 50 | |
| 51 | if ( $proces == 'convocatoria_validadores' ) { |
| 52 | $convocs = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; |
| 53 | |
| 54 | $nombre_isox = $__dada( 'darrer_isox' ); |
| 55 | $ordinal_base = number_from_seed( timestamp, $nombre_isox ); |
| 56 | |
| 57 | $__isox_aleatori = $x => { |
| 58 | $ord_isox_aleatori = |
| 59 | $ordinal_base + $x > $nombre_isox ? |
| 60 | $ordinal_base + $x - $nombre_isox : |
| 61 | $ordinal_base + $x; |
| 62 | |
| 63 | $isox_seleccionat = $__dada( 'isox_' || $ord_isox_aleatori ); |
| 64 | $isox_seleccionat AND $__dada( 'isox_' || $ord_isox_aleatori ) == 'habilitat' ? |
| 65 | $isox_seleccionat : '' |
| 66 | }; |
| 67 | |
| 68 | $preseleccio_isox = map( $convocs, 8, $__isox_aleatori ); |
| 69 | |
| 70 | $seleccio_isox = |
| 71 | array_length( $preseleccio_isox ) < 10 ? |
| 72 | $preseleccio_isox : |
| 73 | $preseleccio_isox || map( $convocs, 10, $__isox_aleatori ); |
| 74 | |
| 75 | $__entitat_aleatoria = $x => { |
| 76 | $ord_entitat_aleatoria = |
| 77 | number_from_seed( timestamp, array_length( $entitats ) ); |
| 78 | $entitat_seleccionada = $entitats[ $ord_entitat_aleatoria ]; |
| 79 | $entitats[ $entitat_seleccionada ].estat == 'habilitada' ? |
| 80 | $entitat_seleccionada : '' |
| 81 | }; |
| 82 | |
| 83 | $preseleccio_entitats = map( $convocs, 10, $__entitat_aleatoria ); |
| 84 | |
| 85 | $seleccio_entitats = |
| 86 | array_length( $preseleccio_entitats ) < 10 ? |
| 87 | $preseleccio_entitats : |
| 88 | $preseleccio_entitats || map( $convocs, 10, $__entitat_aleatoria ); |
| 89 | |
| 90 | $__delegada_aleatoria = $x => { |
| 91 | $ord_delegada_aleatoria = |
| 92 | number_from_seed( timestamp, $generics.Nombre_Delegades ); |
| 93 | $seleccio_entitats[ $ord_delegada_aleatoria ] |
| 94 | }; |
| 95 | |
| 96 | $seleccio_delegades = map( $seleccio_entitats, 12, $__delegada_aleatoria ); |
| 97 | |
| 98 | $nova_convocatoria = { |
| 99 | isox: $seleccio_isox, |
| 100 | delegades: $seleccio_delegades, |
| 101 | temps: timestamp |
| 102 | }; |
| 103 | } |
| 104 | |
| 105 | if ( $proces == 'decisio_validacio' ) { |
| 106 | |
| 107 | $convocatoria = var[ 'convocatoria_' || $idprop ]; |
| 108 | $validacio = $__dada( 'validacio_' || $idprop ); |
| 109 | $deliberacio = var[ 'deliberacio_' || $idprop ]; |
| 110 | $refus = $__dada( 'refus_' || $idprop ); |
| 111 | |
| 112 | |
| 113 | if ( ! $convocatoria ) |
| 114 | { bounce( 'No hi ha cap convocatoria amb aquesta id' ); } |
| 115 | |
| 116 | |
| 117 | if ( $validacio OR $refus ) |
| 118 | { bounce( 'Aquesta proposta ja ha estat tractada' ); } |
| 119 | |
| 120 | $_isox = $convocatoria.isox[ $adr__ ] ? $adr__ : false; |
| 121 | $_delegada = $convocatoria.delegades[ $adr__ ] ? $adr__ : false; |
| 122 | |
| 123 | |
| 124 | if ( ! $_isox AND ! $_delegada ) |
| 125 | { bounce( 'Adreça no convocada' ); } |
| 126 | |
| 127 | |
| 128 | if ( |
| 129 | $deliberacio.isox.aprovacions[ $adr__ ] OR |
| 130 | $deliberacio.delegades.aprovacions[ $adr__ ] ) |
| 131 | { bounce( "Ja hi consta una decisió d'aquesta adreça per a aquesta proposta" ); } |
| 132 | |
| 133 | $grup = $_isox ? 'isox' : $_delegada ? 'delegades' : bounce( 'error' ); |
| 134 | |
| 135 | |
| 136 | if ( $deliberacio[ $grup ].refusada OR $deliberacio[ $grup ].aprovada ) |
| 137 | { bounce( 'Deliberacio de ' || $grup || ' ja enllestida' ); } |
| 138 | |
| 139 | if ( $__arg( 'decisio' ) == 'refusada' ) { |
| 140 | $deliberacio[ $grup ].refus = $adr__; |
| 141 | $deliberacio[ $grup ].refusada = timestamp; |
| 142 | $validacio_refusada = true; |
| 143 | } |
| 144 | |
| 145 | if ( $__arg( 'decisio' ) == 'aprovada' ) { |
| 146 | $deliberacio[ $grup ].aprovacions[] = $adr__; |
| 147 | $resp = 'aprovada per' || $adr__; |
| 148 | |
| 149 | $nombre_aprovacions = $deliberacio[ $grup ].aprovacions; |
| 150 | if ( array_length( $nombre_aprovacions == $generics.Nombre_Aprovacions ) ) { |
| 151 | $deliberacio[ $grup ].aprovada = timestamp; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | if ( $deliberacio.isox.aprovada AND $deliberacio.delegades.aprovada ) { |
| 156 | $validacio_aprovada = true; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | |
| 161 | if ( $proces == 'validacio_directa_TEST' ) { |
| 162 | $validacio_aprovada = true; |
| 163 | } |
| 164 | |
| 165 | }", |
| 166 | "messages": [ |
| 167 | { |
| 168 | "app": "data", |
| 169 | "payload": "{ $args }" |
| 170 | }, |
| 171 | { |
| 172 | "if": "{ $proces == 'convocatoria_validadores' }", |
| 173 | "app": "payment", |
| 174 | "payload": { |
| 175 | "asset": "{ $_unitat }", |
| 176 | "outputs": [ |
| 177 | { |
| 178 | "if": "{ $seleccio_isox[0] }", |
| 179 | "address": "{ $seleccio_isox[0] }", |
| 180 | "amount": "{ $qt }" |
| 181 | }, |
| 182 | { |
| 183 | "if": "{ $seleccio_isox[1] }", |
| 184 | "address": "{ $seleccio_isox[1] }", |
| 185 | "amount": "{ $qt }" |
| 186 | }, |
| 187 | { |
| 188 | "if": "{ $seleccio_isox[2] }", |
| 189 | "address": "{ $seleccio_isox[2] }", |
| 190 | "amount": "{ $qt }" |
| 191 | }, |
| 192 | { |
| 193 | "if": "{ $seleccio_isox[3] }", |
| 194 | "address": "{ $seleccio_isox[3] }", |
| 195 | "amount": "{ $qt }" |
| 196 | }, |
| 197 | { |
| 198 | "if": "{ $seleccio_isox[4] }", |
| 199 | "address": "{ $seleccio_isox[4] }", |
| 200 | "amount": "{ $qt }" |
| 201 | }, |
| 202 | { |
| 203 | "if": "{ $seleccio_isox[5] }", |
| 204 | "address": "{ $seleccio_isox[5] }", |
| 205 | "amount": "{ $qt }" |
| 206 | }, |
| 207 | { |
| 208 | "if": "{ $seleccio_isox[6] }", |
| 209 | "address": "{ $seleccio_isox[6] }", |
| 210 | "amount": "{ $qt }" |
| 211 | }, |
| 212 | { |
| 213 | "if": "{ $seleccio_isox[7] }", |
| 214 | "address": "{ $seleccio_isox[7] }", |
| 215 | "amount": "{ $qt }" |
| 216 | }, |
| 217 | { |
| 218 | "if": "{ $seleccio_isox[8] }", |
| 219 | "address": "{ $seleccio_isox[8] }", |
| 220 | "amount": "{ $qt }" |
| 221 | }, |
| 222 | { |
| 223 | "if": "{ $seleccio_isox[9] }", |
| 224 | "address": "{ $seleccio_isox[9] }", |
| 225 | "amount": "{ $qt }" |
| 226 | } |
| 227 | ] |
| 228 | } |
| 229 | }, |
| 230 | { |
| 231 | "if": "{ $validacio_aprovada }", |
| 232 | "app": "data_feed", |
| 233 | "payload": { |
| 234 | "{ 'validacio_' || $idprop }": "{ timestamp }" |
| 235 | } |
| 236 | }, |
| 237 | { |
| 238 | "if": "{ $validacio_refusada }", |
| 239 | "app": "data_feed", |
| 240 | "payload": { |
| 241 | "{ 'refus_' || $idprop }": "{ timestamp }" |
| 242 | } |
| 243 | }, |
| 244 | { |
| 245 | "app": "state", |
| 246 | "state": "{ |
| 247 | response[ 'Procés' ] = $proces; |
| 248 | response[ 'Proposta' ] = $idprop; |
| 249 | |
| 250 | if ( $nova_convocatoria ) { |
| 251 | var[ 'convocatoria_' || $idprop ] = $nova_convocatoria; |
| 252 | } |
| 253 | |
| 254 | if ( $proces == 'decisio_validacio' ) { |
| 255 | response[ 'Validació' ] = |
| 256 | $__arg( 'decisio' ) || ' per ' || $adr__; |
| 257 | |
| 258 | if ( $deliberacio[ $grup ].aprovada ) { |
| 259 | response[ 'Validació' ] = ' aprovada per ' || $grup; |
| 260 | } |
| 261 | |
| 262 | if ( $deliberacio.isox.aprovada AND $deliberacio.delegades.aprovada ) { |
| 263 | response[ 'Validació' ] = 'aprovada'; |
| 264 | } |
| 265 | |
| 266 | var[ 'deliberacio_' || $idprop ] = $deliberacio; |
| 267 | } |
| 268 | |
| 269 | |
| 270 | if ( $args.nou_portal ) { |
| 271 | var[ 'anterior_portal' ] = var[ 'nou_portal' ]; |
| 272 | var[ 'nou_portal' ] = $args.nou_portal; |
| 273 | response[ 'Nou portal de _Validacions ' ] = $args.nou_portal; |
| 274 | } |
| 275 | }" |
| 276 | } |
| 277 | ] |
| 278 | } |
| 279 | ] |