| 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 | $propostes = var[ $_Portal ][ 'propostes' ]; |
| 26 | $entitats = var[ $_Portal ][ 'entitats' ]; |
| 27 | |
| 28 | $validacions = var[ 'validacions' ] otherwise {}; |
| 29 | $convocatories = var[ 'convocatories' ] otherwise {}; |
| 30 | $deliberacions = var[ 'deliberacions' ] otherwise {}; |
| 31 | $refusos = var[ 'refusos' ] otherwise {}; |
| 32 | |
| 33 | $_validadores = $generics._Validadores; |
| 34 | $validadores = var[ $_validadores ][ 'Validadores' ]; |
| 35 | $isox = $validadores.isox; |
| 36 | $delegades = $validadores.delegades; |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | $__arg = $arg => |
| 42 | $args[ $arg ] otherwise |
| 43 | bounce( "Cal proporcionar el valor de: " || $arg ); |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | if ( $validacions[ $idprop ] ) |
| 49 | { bounce( 'Ja validada' ); } |
| 50 | |
| 51 | |
| 52 | $proposta = $propostes[ $idprop ]; |
| 53 | if ( ! $proposta ) |
| 54 | { bounce( 'No hi ha cap proposta amb aquesta id' ); } |
| 55 | |
| 56 | |
| 57 | if ( $proces == 'convocatoria_validadores' ) { |
| 58 | $convocs = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]; |
| 59 | |
| 60 | $__isox_aleatori = $x => { |
| 61 | $ord_isox_aleatori = number_from_seed( timestamp, array_length( $isox ) ); |
| 62 | $isox_seleccionat = $isox[ $ord_isox_aleatori ]; |
| 63 | $isox_seleccionat AND $isox_seleccionat.estat == 'habilitat' ? |
| 64 | $isox_seleccionat : '' |
| 65 | }; |
| 66 | |
| 67 | $preseleccio_isox = map( $convocs, 12, $__isox_aleatori ); |
| 68 | |
| 69 | $seleccio_isox = |
| 70 | array_length( $preseleccio_isox ) >= 10 ? |
| 71 | $preseleccio_isox : |
| 72 | $preseleccio_isox || map( $convocs, 12, $__isox_aleatori ); |
| 73 | |
| 74 | $nombre_entitats = array_length( $delegades ); |
| 75 | |
| 76 | $__entitat_aleatoria = $x => { |
| 77 | $ord_entitat_aleatoria = |
| 78 | number_from_seed( timestamp, $nombre_entitats ); |
| 79 | $entitat_seleccionada = $delegades[ $ord_entitat_aleatoria ]; |
| 80 | $entitat_seleccionada_habilitada = |
| 81 | $entitats[ $entitat_seleccionada ] AND |
| 82 | $entitats[ $entitat_seleccionada ].estat == 'habilitada'; |
| 83 | $entitat_seleccionada_habilitada ? |
| 84 | $entitat_seleccionada : '' |
| 85 | }; |
| 86 | |
| 87 | $preseleccio_entitats = map( $convocs, 12, $__entitat_aleatoria ); |
| 88 | |
| 89 | $seleccio_entitats = |
| 90 | array_length( $preseleccio_entitats ) >= 10 ? |
| 91 | $preseleccio_entitats : |
| 92 | $preseleccio_entitats || map( $convocs, 12, $__entitat_aleatoria ); |
| 93 | |
| 94 | $__delegada_aleatoria = $x => { |
| 95 | $ord_delegada_aleatoria = |
| 96 | number_from_seed( timestamp, $generics.Nombre_Delegades ); |
| 97 | $seleccio_entitats[ $ord_delegada_aleatoria ] |
| 98 | }; |
| 99 | |
| 100 | $seleccio_delegades = map( $seleccio_entitats, 12, $__delegada_aleatoria ); |
| 101 | |
| 102 | $nova_convocatoria = { |
| 103 | isox: $seleccio_isox, |
| 104 | delegades: $seleccio_delegades, |
| 105 | temps: timestamp |
| 106 | }; |
| 107 | |
| 108 | $convocatories[ $idprop ] = $nova_convocatoria; |
| 109 | } |
| 110 | |
| 111 | if ( $proces == 'decisio_validacio' ) { |
| 112 | |
| 113 | $convocatoria = $convocatories[ $idprop ]; |
| 114 | $validacio = $validacions[ $idprop ]; |
| 115 | $deliberacio = $deliberacions[ $idprop ]; |
| 116 | $refus = $refusos[ $idprop ]; |
| 117 | |
| 118 | |
| 119 | if ( ! $convocatoria ) |
| 120 | { bounce( 'No hi ha cap convocatoria amb aquesta id' ); } |
| 121 | |
| 122 | |
| 123 | if ( $validacio OR $refus ) |
| 124 | { bounce( 'Aquesta proposta ja ha estat tractada' ); } |
| 125 | |
| 126 | $_isox = $convocatoria.isox[ $adr__ ] ? $adr__ : false; |
| 127 | $_delegada = $convocatoria.delegades[ $adr__ ] ? $adr__ : false; |
| 128 | |
| 129 | |
| 130 | if ( ! $_isox AND ! $_delegada ) |
| 131 | { bounce( 'Adreça no convocada' ); } |
| 132 | |
| 133 | |
| 134 | if ( |
| 135 | $deliberacio.isox.aprovacions[ $adr__ ] OR |
| 136 | $deliberacio.delegades.aprovacions[ $adr__ ] ) |
| 137 | { bounce( "Ja hi consta una decisió d'aquesta adreça per a aquesta proposta" ); } |
| 138 | |
| 139 | $grup = $_isox ? 'isox' : $_delegada ? 'delegades' : bounce( 'error' ); |
| 140 | |
| 141 | |
| 142 | if ( $deliberacio[ $grup ].refusada OR $deliberacio[ $grup ].aprovada ) |
| 143 | { bounce( 'Deliberacio de ' || $grup || ' ja enllestida' ); } |
| 144 | } |
| 145 | }", |
| 146 | "messages": [ |
| 147 | { |
| 148 | "app": "data", |
| 149 | "payload": "{ $args }" |
| 150 | }, |
| 151 | { |
| 152 | "if": "{ $proces == 'convocatoria_validadores' }", |
| 153 | "app": "payment", |
| 154 | "payload": { |
| 155 | "asset": "{ $_unitat }", |
| 156 | "outputs": [ |
| 157 | { |
| 158 | "if": "{ $seleccio_isox[0] }", |
| 159 | "address": "{ $seleccio_isox[0] }", |
| 160 | "amount": "{ $qt }" |
| 161 | }, |
| 162 | { |
| 163 | "if": "{ $seleccio_isox[1] }", |
| 164 | "address": "{ $seleccio_isox[0] }", |
| 165 | "amount": "{ $qt }" |
| 166 | } |
| 167 | ] |
| 168 | } |
| 169 | }, |
| 170 | { |
| 171 | "app": "state", |
| 172 | "state": "{ |
| 173 | response[ 'Procés' ] = $proces; |
| 174 | response[ 'Proposta' ] = $idprop; |
| 175 | |
| 176 | |
| 177 | if ( $proces == 'decisio' ) { |
| 178 | if ( $__arg( 'decisio' ) == 'refusada' ) { |
| 179 | $deliberacio[ $grup ].refus = $adr__; |
| 180 | $deliberacio[ $grup ].refusada = timestamp; |
| 181 | $refusos[ $idprop ] = timestamp; |
| 182 | response[ 'Validació' ] = 'refusada'; |
| 183 | } |
| 184 | |
| 185 | if ( $__arg( 'decisio' ) == 'aprovada' ) { |
| 186 | $deliberacio[ $grup ].aprovacions[] = $adr__; |
| 187 | response[ 'Validació de la proposta aprovada per' ] = $adr__; |
| 188 | |
| 189 | $nombre_aprovacions = $deliberacio[ $grup ].aprovacions; |
| 190 | if ( array_length( $nombre_aprovacions == $generics.Nombre_Aprovacions ) ) { |
| 191 | $deliberacio[ $grup ].aprovada = timestamp; |
| 192 | response[ 'Validació de la proposta aprovada per' ] = $grup; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if ( $deliberacio.isox.aprovada AND $deliberacio.delegades.aprovada ) { |
| 197 | $validacions[ $idprop ] = timestamp; |
| 198 | response[ 'Validació' ] = 'aprovada'; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | |
| 203 | if ( $proces == 'validacio_directa_TEST' ) { |
| 204 | $validacions[ $idprop ] = timestamp; |
| 205 | response[ 'Validació' ] = 'aprovada'; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | if ( $args.nou_portal ) { |
| 210 | var[ 'anterior_portal' ] = var[ 'nou_portal' ]; |
| 211 | var[ 'nou_portal' ] = $args.nou_portal; |
| 212 | response[ 'Nou portal de _Validacions ' ] = $args.nou_portal; |
| 213 | } |
| 214 | |
| 215 | |
| 216 | if ( $args.copia_dades ) { |
| 217 | if ( ! $args.totes ) { |
| 218 | $__valvar = $refvar => { |
| 219 | var[ $refvar ] = |
| 220 | $args[ $refvar ] ? |
| 221 | var[ $darrera_versio ][ $refvar ] : |
| 222 | {}; |
| 223 | }; |
| 224 | |
| 225 | $refs = [ |
| 226 | 'validacions', 'convocatories', |
| 227 | 'deliberacions', 'refusos' |
| 228 | ]; |
| 229 | |
| 230 | $valora = map( $refs, 8, $__valvar ); |
| 231 | } |
| 232 | } else { |
| 233 | var[ 'validacions' ] = $validacions; |
| 234 | var[ 'convocatories' ] = $convocatories; |
| 235 | var[ 'deliberacions' ] = $deliberacions; |
| 236 | var[ 'refusos' ] = $refusos; |
| 237 | } |
| 238 | }" |
| 239 | } |
| 240 | ] |
| 241 | } |
| 242 | ] |