| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $nom_AA = 'Portal'; |
| 6 | $versio = '0.1.2'; |
| 7 | |
| 8 | $_AUT_000 = 'C4KIJSUWVM7BGWTLXKX3K4PNRXV7OY4W'; |
| 9 | |
| 10 | $adr__ = trigger.address; |
| 11 | $args = trigger.data; |
| 12 | |
| 13 | $generics = var['Generics']; |
| 14 | |
| 15 | $__bota = $txt => bounce ( $nom_AA || ' >>> ' || $txt ); |
| 16 | |
| 17 | if ( $args.proces == 'definicio_geto' OR $args.proces == 'esmena_generics' ) { |
| 18 | |
| 19 | $__arg = $arg => |
| 20 | $args[ $arg ] ? |
| 21 | $args[ $arg ] : |
| 22 | $__bota( "Cal proporcionar el valor de: " || $arg ); |
| 23 | |
| 24 | |
| 25 | $__autoritzada = ( $x ) => { |
| 26 | $aut = $generics[ '_AUT_' || $x ]; |
| 27 | $aut AND $aut == $adr__ |
| 28 | }; |
| 29 | |
| 30 | |
| 31 | if ( $adr__ != $_AUT_000 |
| 32 | AND ! $__autoritzada( '0' ) |
| 33 | AND ! $__autoritzada( 'A' ) |
| 34 | AND ! $__autoritzada( 'B' ) |
| 35 | AND ! $__autoritzada( 'C' ) |
| 36 | ) { $__bota( 'No autoritzada' ); } |
| 37 | |
| 38 | |
| 39 | $es_AUT_000 = $adr__ == $_AUT_000; |
| 40 | if ( ! $es_AUT_000 OR ( $es_AUT_000 AND $__autoritzada( '0' ) ) ) { |
| 41 | |
| 42 | if ( $args.tasca == 'confirmacio' ) { |
| 43 | $proposta = var[ $args.idprop ]; |
| 44 | |
| 45 | |
| 46 | if ( ! $proposta ) |
| 47 | { $__bota( "No hi ha cap proposta de nou getó amb aquesta ref" ); } |
| 48 | |
| 49 | |
| 50 | if ( $proposta.proposant == $adr__ ) |
| 51 | { $__bota( "El procés de confirmació l'ha d'endegar una altra AUT" ); } |
| 52 | |
| 53 | |
| 54 | if ( var[ 'Lapse' ] > timestamp - $proposta.temps ) |
| 55 | { $__bota( "Encara no es pot confirmar la proposta" ); } |
| 56 | |
| 57 | |
| 58 | if ( ! var[ $args._Validacions ][ $args.idprop ] ) |
| 59 | { $__bota( "La proposta encara no ha estat validada" ); } |
| 60 | |
| 61 | $tasca = 'confirmacio'; |
| 62 | |
| 63 | } else { |
| 64 | |
| 65 | $ref = $__arg( 'ref' ); |
| 66 | $val = $__arg( 'val' ); |
| 67 | |
| 68 | |
| 69 | if ( var[ $__arg( 'ref' ) ] AND var[ $ref ] == $val ) |
| 70 | { $__bota( "El valor proposat coincideix amb l'actual" ); } |
| 71 | |
| 72 | |
| 73 | $ord_darrera_prop = var[ 'ordinal_proposta_' || $ref ]; |
| 74 | $darrera_prop = var[ 'proposta_' || $ref || '_' || $ord_darrera_prop ]; |
| 75 | |
| 76 | if ( !! $darrera_prop AND $darrera_prop.val == $val ) |
| 77 | { $__bota( "El valor proposat coincideix amb el de la darrera proposta" ); } |
| 78 | |
| 79 | $ref_ordinal = 'ordinal_proposta_' || $ref; |
| 80 | $ordinal = var[ $ref_ordinal ]; |
| 81 | |
| 82 | $nou_ordinal = ! $ordinal ? 1 : $ordinal + 1; |
| 83 | |
| 84 | $tasca = 'proposta'; |
| 85 | } |
| 86 | } else { |
| 87 | $ref = $__arg( 'ref' ); |
| 88 | $val = $__arg( 'val' ); |
| 89 | $tasca = 'drecera'; } |
| 90 | } |
| 91 | }", |
| 92 | "messages": { |
| 93 | "cases": [ |
| 94 | { |
| 95 | "if": "{ $args.proces == 'acces' }", |
| 96 | "init": "{ |
| 97 | $args._Portal = this_address; |
| 98 | $args._FOP = $generics._FOP; |
| 99 | $args._Estels = $generics._Estels; |
| 100 | |
| 101 | $args.geto = trigger.output[[ asset != base ]].asset; |
| 102 | $args.qt = trigger.output[[ asset = $args.geto ]]; |
| 103 | }", |
| 104 | "messages": [ |
| 105 | { |
| 106 | "app": "data", |
| 107 | "payload": "{ $args }" |
| 108 | }, |
| 109 | { |
| 110 | "app": "payment", |
| 111 | "payload": { |
| 112 | "asset": "{ $args.geto }", |
| 113 | "outputs": [ |
| 114 | { |
| 115 | "address": "{ var[ '_Acces' ] }", |
| 116 | "amount": "{ $args.qt }" |
| 117 | } |
| 118 | ] |
| 119 | } |
| 120 | } |
| 121 | ] |
| 122 | }, |
| 123 | { |
| 124 | "if": "{ $args.proces == 'esmena_generics' }", |
| 125 | "messages": [ |
| 126 | { |
| 127 | "app": "state", |
| 128 | "state": "{ |
| 129 | |
| 130 | if ( $tasca == 'drecera' ) { |
| 131 | if ( $ref == 'multiple' ) { |
| 132 | |
| 133 | $__valvar = $refvar => |
| 134 | $args[ $refvar ] ? |
| 135 | $args[ $refvar ] : |
| 136 | $generics[ $refvar ]; |
| 137 | |
| 138 | var[ 'Generics' ] = { |
| 139 | _Acces: $__valvar( '_Acces' ), |
| 140 | _Getons: $__valvar( '_Getons' ), |
| 141 | _Validacions: $__valvar( '_Validacions' ), |
| 142 | _FRO: $__valvar( '_FRO' ), |
| 143 | _FOP: $__valvar( '_FOP' ), |
| 144 | _FDIP: $__valvar( '_FDIP' ), |
| 145 | _Estels: $__valvar( '_Estels' ), |
| 146 | Interval: $__valvar( 'Interval' ), |
| 147 | Lapse: $__valvar( 'Lapse' ), |
| 148 | _Transfer: $__valvar( '_Transfer' ), |
| 149 | _Capacitacio: $__valvar( '_Capacitacio' ), |
| 150 | _Avis: $__valvar( '_Avis' ), |
| 151 | Import_Activacio: $__valvar( 'Import_Activacio' ), |
| 152 | Import_Subscripcio: $__valvar( 'Import_Subscripcio' ), |
| 153 | Import_Renovacio: $__valvar( 'Import_Renovacio' ), |
| 154 | Taxa_Conversio: $__valvar( 'Taxa_Conversio' ), |
| 155 | Factor_Conversio: $__valvar( 'Factor_Conversio' ), |
| 156 | Cicles_Latencia: $__valvar( 'Cicles_Latencia' ), |
| 157 | _AUT_0: $__valvar( '_AUT_0' ), |
| 158 | _AUT_A: $__valvar( '_AUT_A' ), |
| 159 | _AUT_B: $__valvar( '_AUT_B' ), |
| 160 | _AUT_C: $__valvar( '_AUT_C' ), |
| 161 | }; |
| 162 | |
| 163 | response[ '_Acces' ] = $__valvar( '_Acces' ); |
| 164 | response[ '_Getons' ] = $__valvar( '_Getons' ); |
| 165 | response[ '_Validacions' ] = $__valvar( '_Validacions' ); |
| 166 | response[ '_FRO' ] = $__valvar( '_FRO' ); |
| 167 | response[ '_FOP' ] = $__valvar( '_FOP' ); |
| 168 | response[ '_FDIP' ] = $__valvar( '_FDIP' ); |
| 169 | response[ '_Estels' ] = $__valvar( 'id_Estels' ); |
| 170 | response[ 'Interval' ] = $__valvar( 'Interval' ); |
| 171 | response[ 'Lapse' ] = $__valvar( 'Lapse' ); |
| 172 | response[ '_Transfer' ] = $__valvar( '_Transfer' ); |
| 173 | response[ '_Capacitacio' ] = $__valvar( '_Capacitacio' ); |
| 174 | response[ '_Avis' ] = $__valvar( '_Avis' ); |
| 175 | response[ 'Import_Activacio' ] = $__valvar( 'Import_Activacio' ); |
| 176 | response[ 'Import_Subscripcio' ] = $__valvar( 'Import_Subscripcio' ); |
| 177 | response[ 'Import_Renovacio' ] = $__valvar( 'Import_Activacio' ); |
| 178 | response[ 'Taxa_Conversio' ] = $__valvar( 'Taxa_Conversio' ); |
| 179 | response[ 'Factor_Conversio' ] = $__valvar( 'Factor_Conversio' ); |
| 180 | response[ 'Cicles_Latencia' ] = $__valvar( 'Cicles_Latencia' ); |
| 181 | response[ '_AUT_0' ] = $__valvar( '_AUT_0' ); |
| 182 | response[ '_AUT_A' ] = $__valvar( '_AUT_A' ); |
| 183 | response[ '_AUT_B' ] = $__valvar( '_AUT_B' ); |
| 184 | response[ '_AUT_C' ] = $__valvar( '_AUT_C' ); |
| 185 | |
| 186 | } else { |
| 187 | var[ $ref ] = $val; |
| 188 | response[ 'nova ref' ] = $ref; |
| 189 | response[ 'nou val' ] = $val; |
| 190 | } |
| 191 | } else if ( $tasca == 'confirmacio' ) { |
| 192 | var[ $proposta.ref ] = $proposta.val; |
| 193 | response[ 'proposta' ] = $args.idprop; |
| 194 | response[ 'nova ref' ] = $proposta.ref; |
| 195 | response[ 'nou val' ] = $proposta.val; |
| 196 | } else { |
| 197 | var[ $ref_ordinal ] = $nou_ordinal; |
| 198 | |
| 199 | $id_proposta = 'proposta_' || $ref || '_' || $nou_ordinal; |
| 200 | var[ $id_proposta ] = |
| 201 | { |
| 202 | ref: $ref, |
| 203 | val: $val, |
| 204 | ordinal: $nou_ordinal, |
| 205 | proposant: $adr__, |
| 206 | temps: timestamp, |
| 207 | }; |
| 208 | |
| 209 | response[ 'proposta' ] = $id_proposta; |
| 210 | response[ 'nova ref' ] = $ref; |
| 211 | response[ 'nou val' ] = $val; |
| 212 | response[ 'data proposta' ] = timestamp_to_string( timestamp ); |
| 213 | response[ 'data inici confirmació'] = |
| 214 | timestamp_to_string( timestamp + var[ 'Lapse' ] ); |
| 215 | } |
| 216 | }" |
| 217 | } |
| 218 | ] |
| 219 | }, |
| 220 | { |
| 221 | "if": "{ $args.proces == 'definicio_geto' }", |
| 222 | "messages": [ |
| 223 | { |
| 224 | "if": "{ $tasca != 'proposta' }", |
| 225 | "app": "asset", |
| 226 | "payload": { |
| 227 | "cap": "{ $args.cap otherwise 1e9 }", |
| 228 | "is_private": false, |
| 229 | "is_transferrable": true, |
| 230 | "auto_destroy": "{ !! $args.auto_destroy }", |
| 231 | "fixed_denominations": false, |
| 232 | "issued_by_definer_only": true, |
| 233 | "cosigned_by_definer": false, |
| 234 | "spender_attested": false |
| 235 | } |
| 236 | }, |
| 237 | { |
| 238 | "app": "state", |
| 239 | "state": "{ |
| 240 | if ( $tasca != 'confirmacio' ) { |
| 241 | $perfil = { |
| 242 | id : response_unit, |
| 243 | _FOG : $__arg( '_FOG' ), |
| 244 | _AUT_A : $__arg( '_AUT_A' ), |
| 245 | factor_conversio : $__arg( 'factor_conversio' ), |
| 246 | import_activacio : $__arg( 'import_activacio' ), |
| 247 | import_subscripcio : $__arg( 'import_subscripcio' ), |
| 248 | import_renovacio : $__arg( 'import_renovacio' ), |
| 249 | taxa_conversio : $__arg( 'taxa_conversio' ), |
| 250 | derivacio_aFOG : $__arg( 'derivacio_aFOG' ), |
| 251 | activacions_restringides : $__arg( 'activacions_restringides' ), |
| 252 | subscripcions_restringides : $__arg( 'subscripcions_restringides' ), |
| 253 | recepcions_restringides : $__arg( 'recepcions_restringides' ), |
| 254 | conversions_restringides : $__arg( 'conversions_restringides' ), |
| 255 | valors_esmenables : $__arg( 'valors_esmenables' ), |
| 256 | llistats_editables : $__arg( 'llistats_editables' ), |
| 257 | bloqueig_possible : $__arg( 'bloqueig_possible' ), |
| 258 | }; |
| 259 | } |
| 260 | if ( $tasca == 'drecera' ) { |
| 261 | $getons = var[ 'Getons' ]; |
| 262 | |
| 263 | $getons[ response_unit ] = |
| 264 | { |
| 265 | proposant: $adr__, |
| 266 | confirmant: $adr__, |
| 267 | temps: timestamp, |
| 268 | perfil: $perfil |
| 269 | }; |
| 270 | response[ 'Getó operatiu' ] = response_unit; |
| 271 | } |
| 272 | if ( $tasca == 'confirmacio' ) { |
| 273 | $prop = var[ $args.ref_proposta ]; |
| 274 | $getons = var[ 'Getons' ]; |
| 275 | |
| 276 | $getons[ response_unit ] = |
| 277 | { |
| 278 | proposant: $prop.proposant, |
| 279 | confirmant: $adr__, |
| 280 | temps: timestamp, |
| 281 | perfil: $prop.perfil |
| 282 | }; |
| 283 | response[ 'Getó operatiu' ] = $args.id; |
| 284 | } |
| 285 | if ( $tasca == 'proposta' ) { |
| 286 | $id_proposta = 'nou_geto_' || $ordinal; |
| 287 | var[ $id_proposta ] = |
| 288 | { |
| 289 | proposant: $adr__, |
| 290 | temps: timestamp, |
| 291 | perfil: $perfil |
| 292 | }; |
| 293 | response[ 'proposta' ] = $id_proposta; |
| 294 | response[ 'data inici confirmació'] = |
| 295 | timestamp_to_string( timestamp + $args.lapse ); |
| 296 | } |
| 297 | response[ 'tasca' ] = $tasca; |
| 298 | }" |
| 299 | } |
| 300 | ] |
| 301 | }, |
| 302 | { |
| 303 | "if": "{ $args.proces == 'emissio_getons' }", |
| 304 | "messages": [ |
| 305 | { |
| 306 | "app": "payment", |
| 307 | "payload": { |
| 308 | "asset": "{trigger.data.asset}", |
| 309 | "outputs": [ |
| 310 | { |
| 311 | "address": "{trigger.address}", |
| 312 | "amount": "{trigger.data.amount}" |
| 313 | } |
| 314 | ] |
| 315 | } |
| 316 | } |
| 317 | ] |
| 318 | } |
| 319 | ] |
| 320 | } |
| 321 | } |
| 322 | ] |