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