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