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