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