| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $_Registre = 'MGIC6DY2L6I4F5MEB3LSBGUCSTNLIJTV'; |
| 6 | |
| 7 | |
| 8 | $__dada = $refdada => |
| 9 | data_feed [[ |
| 10 | oracles = $_Registre, |
| 11 | feed_name = $refdada, |
| 12 | ifnone = 0 |
| 13 | ]]; |
| 14 | |
| 15 | if ( $__dada( '_Portal' ) != trigger.address ) |
| 16 | bounce( 'Portal no reconegut' ); |
| 17 | |
| 18 | |
| 19 | $args = trigger.data; |
| 20 | $adr__ = trigger.initial_address; |
| 21 | $idgeto = trigger.output[[ asset != base ]].asset; |
| 22 | $dades = $args.dades otherwise {}; |
| 23 | |
| 24 | |
| 25 | $proces = $args.proces; |
| 26 | $operacio = $args.operacio; |
| 27 | $idprop = $args.idprop; |
| 28 | $nova_idprop = $args.nova_idprop; |
| 29 | $ref = $args.ref; |
| 30 | $val = $args.val; |
| 31 | $adr = $args.adr; |
| 32 | |
| 33 | |
| 34 | $__arg = $arg => |
| 35 | $args[ $arg ] otherwise |
| 36 | bounce( "Cal proporcionar el valor de: " || $arg ); |
| 37 | |
| 38 | |
| 39 | if ( $proces == 'nova_isox' ) { |
| 40 | $ord_isox = $__dada( 'ordinal_isox' ) + 1; |
| 41 | $_actuant_es_isox_000 = $__dada( 'isox_000' ) == $adr__ ; |
| 42 | $_estat_isox_actuant = $__dada( 'isox_' || $adr__ || '_estat' ) otherwise ''; |
| 43 | $autoritzacio = $_actuant_es_isox_000 OR $_estat_isox_actuant == 'habilitat'; |
| 44 | |
| 45 | if ( ! $autoritzacio ) bounce( $adr__ || ' No autoritzada per a no ísox ' || $_estat_isox_actuant ); |
| 46 | |
| 47 | $index_baules_isox_actuant = |
| 48 | $__dada( 'isox_' || $adr__ || '_index_baules' ) otherwise 1; |
| 49 | $mitjana_index_baules = |
| 50 | $__dada( 'mitjana_index_baules' ) otherwise 1; |
| 51 | $factor_topall_index_baules = |
| 52 | $__dada( 'Factor_Topall_Index_Baules' ) otherwise 1.5; |
| 53 | if ( $index_baules_isox_actuant > |
| 54 | ( $mitjana_index_baules * $factor_topall_index_baules ) ) |
| 55 | bounce( 'No autoritzada per massa baules' ); |
| 56 | |
| 57 | $estat_isox = $__dada( 'isox_' || $adr || '_estat') otherwise ''; |
| 58 | if ( $estat_isox == 'habilitat' ) |
| 59 | bounce( 'Ja hi consta una ísox habilitada amb aquesta adreça' ); |
| 60 | |
| 61 | $_aspirant = $__dada( 'aspirant_' || $adr ); |
| 62 | |
| 63 | if ( $_actuant_es_isox_000 ) { |
| 64 | $index_baules_nova_isox = |
| 65 | $args.index_baules otherwise $mitjana_index_baules; |
| 66 | $dades_alta = |
| 67 | [ 'isox_000', 'isox_000', 1, $index_baules_nova_isox ]; |
| 68 | } else { |
| 69 | $nombre_avals = |
| 70 | $__dada( 'isox_' || $adr__ || '_aval_2' ) ? 2 : |
| 71 | $__dada( 'isox_' || $adr__ || '_aval_1' ) ? 1 : |
| 72 | 0; |
| 73 | |
| 74 | if ( $nombre_avals == 2 ) bounce( "Ja n'has avalat 2" ); |
| 75 | |
| 76 | if ( !! $_aspirant ) { |
| 77 | $_proposant = $__dada( 'aspirant_' || $adr || '_proposant' ); |
| 78 | |
| 79 | if ( $_proposant == $adr__ ) |
| 80 | bounce( "Els dos avals han de provenir d'adreces diferents" ); |
| 81 | |
| 82 | $index_baules_proposant = |
| 83 | $__dada( 'isox_' || $_proposant || '_index_baules' ); |
| 84 | |
| 85 | $index_baules_nova_isox = |
| 86 | 1 + round( ( $index_baules_proposant + $index_baules_isox_actuant ) / 2 ); |
| 87 | |
| 88 | $index_absolut = |
| 89 | $index_baules_nova_isox + ( $mitjana_index_baules * ( $ord_isox - 1 ) ); |
| 90 | |
| 91 | $nova_mitjana_index_baules = |
| 92 | round( $index_absolut / $ord_isox ); |
| 93 | |
| 94 | $dades[ 'isox_' || $adr__ || '_aval_' || ( $nombre_avals + 1 ) ] = $adr; |
| 95 | $dades_alta = |
| 96 | [ |
| 97 | $_proposant, |
| 98 | $adr__, |
| 99 | $index_baules_nova_isox, |
| 100 | $nova_mitjana_index_baules |
| 101 | ]; |
| 102 | } else { |
| 103 | $dades[ 'aspirant_' || $adr ] = timestamp; |
| 104 | $dades[ 'aspirant_' || $adr || '_proposant' ] = $adr__; |
| 105 | $dades[ 'isox_' || $adr__ || '_aval_' || ( $nombre_avals + 1 ) ] = $adr; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if ( !! $dades_alta[0] ) { |
| 110 | $dades[ 'ordinal_isox' ] = $ord_isox; |
| 111 | $dades[ 'isox_' || $ord_isox ] = $adr; |
| 112 | $dades[ 'isox_' || $adr || '_ordinal' ] = 'isox_' || $ord_isox; |
| 113 | $dades[ 'isox_' || $adr || '_proposant' ] = $dades_alta[0]; |
| 114 | $dades[ 'isox_' || $adr || '_confirmant' ] = $dades_alta[1]; |
| 115 | $dades[ 'isox_' || $adr || '_data' ] = timestamp; |
| 116 | $dades[ 'isox_' || $adr || '_estat' ] = 'habilitat'; |
| 117 | $dades[ 'isox_' || $adr || '_index_baules' ] = $dades_alta[2]; |
| 118 | $dades[ 'mitjana_index_baules' ] = $dades_alta[3]; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | if ( $proces == 'nou_estat_isox' ) { |
| 123 | $_isox = $__dada( $idprop || '_adr' ) otherwise $adr; |
| 124 | $nou_estat = $__dada( $idprop || '_estat' ) otherwise $args.estat; |
| 125 | $estat_actual = $__dada( 'isox_' || $_isox || '_estat' ) otherwise ''; |
| 126 | |
| 127 | if ( ! $estat_actual ) |
| 128 | bounce( 'No hi consta cap ísox amb aquesta adreça' ); |
| 129 | |
| 130 | if ( $estat_actual == $nou_estat ) |
| 131 | bounce( "L'estat actual és el mateix que el proposat" ); |
| 132 | |
| 133 | if ( $operacio == 'proposta' ) { |
| 134 | $dades[ $nova_idprop || '_adr' ] = $adr; |
| 135 | $dades[ $nova_idprop || '_estat' ] = $args.estat; |
| 136 | } |
| 137 | |
| 138 | if ( $operacio == 'confirmacio' OR $operacio == 'drecera' ) |
| 139 | $dades[ 'isox_' || $adr || '_estat' ] = $nou_estat; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | if ( $proces == 'nova_delegacio' OR $proces == 'final_delegacio' ) { |
| 144 | $ref_entitat = 'entitat_' || $__arg( 'nom' ); |
| 145 | $estat_entitat = $__dada( $ref_entitat || '_estat' ) otherwise ''; |
| 146 | $adr_entitat = $__dada( $ref_entitat || '_adr' ) otherwise ''; |
| 147 | |
| 148 | if ( $estat_entitat != 'operatiu' ) |
| 149 | bounce( 'Entitat inexistent o no operativa' ); |
| 150 | |
| 151 | if ( $adr_entitat != $adr__ ) |
| 152 | bounce( "L'adreça de l'entitat no és l'actuant" ); |
| 153 | |
| 154 | |
| 155 | $ords = [ "1", "2", "3" ]; |
| 156 | |
| 157 | $ord_delegada_trobada = []; |
| 158 | $semiref_delegada = $ref_entitat || '_delegada_'; |
| 159 | $__troba_delegada = $o => { |
| 160 | $adr_delegada = $__dada( $semiref_delegada || $o ) otherwise ''; |
| 161 | if ( |
| 162 | ! $ord_delegada_trobada[0] |
| 163 | AND $adr_delegada == $adr |
| 164 | ) |
| 165 | $ord_delegada_trobada[0] = $o; |
| 166 | }; |
| 167 | |
| 168 | |
| 169 | foreach( $ords, 3, $__troba_delegada ); |
| 170 | |
| 171 | if ( $proces == 'nova_delegacio' ) { |
| 172 | if ( !! $ord_delegada_trobada[0] ) |
| 173 | bounce( 'Ja hi consta una delegada amb aquesta adreça' ); |
| 174 | |
| 175 | $lloc_trobat = []; |
| 176 | $__troba_lloc_lliure = $o => { |
| 177 | if ( |
| 178 | ! $__dada( $semiref_delegada || $o ) AND |
| 179 | ! $lloc_trobat[0] |
| 180 | ) { |
| 181 | $dades[ $semiref_delegada || $o ] = $adr; |
| 182 | $lloc_trobat[0] = $o; |
| 183 | } |
| 184 | }; |
| 185 | |
| 186 | |
| 187 | $troba_lloc_lliure = map( $ords, 3, $__troba_lloc_lliure ); |
| 188 | |
| 189 | if ( ! $lloc_trobat[0] ) |
| 190 | bounce( 'Ja consten com a habilitades totes les delegacions possibles' ); |
| 191 | } |
| 192 | |
| 193 | if ( $proces == 'final_delegacio' ) { |
| 194 | if ( ! $ord_delegada_trobada[0] ) |
| 195 | bounce( 'No hi consta cap delegada amb aquesta adreça' ); |
| 196 | |
| 197 | $dades[ $semiref_delegada || $ord_delegada_trobada[0] ] = ''; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | |
| 202 | if ( $args.admin_vincles ) { |
| 203 | $tipus_vincle = $__dada( $idprop || '_tipus' ) otherwise $__arg( 'tipus' ); |
| 204 | $nom_vincle = $__dada( $idprop || '_nom' ) otherwise $__arg( 'nom' ); |
| 205 | $ref_vincle = $tipus_vincle || '_' || $nom_vincle; |
| 206 | $ord_vincle = $__dada( $ref_vincle ) otherwise '---'; |
| 207 | $nou_ord_vincle = $__dada( 'ordinal_' || $tipus_vincle ) + 1; |
| 208 | |
| 209 | if ( $proces == 'nou_vincle' ) { |
| 210 | $_vincle = $__dada( $idprop || '_adr' ) otherwise $__arg( 'adr' ); |
| 211 | |
| 212 | |
| 213 | if ( $ord_vincle != '---' ) |
| 214 | bounce( "Ja n'hi ha un amb aquest nom" ); |
| 215 | |
| 216 | |
| 217 | $adr_registrada = $__dada( $ref_vincle || '_adr' ); |
| 218 | if ( !! $adr_registrada ) |
| 219 | bounce( "Ja n'hi ha un amb aquesta adreça" ); |
| 220 | |
| 221 | |
| 222 | if ( $operacio == 'proposta' ) { |
| 223 | $dades[ $nova_idprop || '_adr' ] = $adr; |
| 224 | $dades[ $nova_idprop || '_nom' ] = $args.nom; |
| 225 | } |
| 226 | |
| 227 | if ( $operacio == 'confirmacio' OR $operacio == 'drecera' ) { |
| 228 | $dades[ $ref_vincle ] = $tipus_vincle || '_' || $nou_ord_vincle; |
| 229 | $dades[ $ref_vincle || '_adr' ] = $_vincle; |
| 230 | $dades[ $ref_vincle || '_estat' ] = 'operatiu'; |
| 231 | $dades[ $tipus_vincle || '_' || $nou_ord_vincle ] = $ref_vincle; |
| 232 | $dades[ 'ordinal_' || $tipus_vincle ] = $nou_ord_vincle; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | if ( $proces == 'nou_estat_vincle' ) { |
| 237 | |
| 238 | |
| 239 | $estat_actual = $__dada( $ref_vincle || '_estat' ); |
| 240 | if ( ! $estat_actual ) |
| 241 | bounce( "Vincle desconegut" ); |
| 242 | |
| 243 | |
| 244 | if ( $operacio == 'proposta' ) { |
| 245 | $dades[ $nova_idprop || '_adr' ] = $adr; |
| 246 | $dades[ $nova_idprop || '_estat' ] = $args.estat; |
| 247 | } |
| 248 | |
| 249 | if ( $operacio == 'confirmacio' OR $operacio == 'drecera' ) { |
| 250 | $nou_estat = $__dada( $idprop || '_estat' ) otherwise $args.estat; |
| 251 | $dades[ $ref_vincle || '_estat' ] = $nou_estat; |
| 252 | if ( $nou_estat == 'operatiu' ) { |
| 253 | $dades[ $ref_vincle ] = $nou_ord_vincle; |
| 254 | $dades[ $tipus_vincle || '_' || $nou_ord_vincle ] = $ref_vincle; |
| 255 | } else { |
| 256 | $dades[ $ref_vincle ] = '---'; |
| 257 | $dades[ $tipus_vincle || '_' || $ord_vincle ] = '---'; |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | $registre = {}; |
| 264 | $registre.dades = $dades; |
| 265 | }", |
| 266 | "messages": [ |
| 267 | { |
| 268 | "app": "data", |
| 269 | "payload": "{ $registre }" |
| 270 | }, |
| 271 | { |
| 272 | "app": "payment", |
| 273 | "payload": { |
| 274 | "asset": "base", |
| 275 | "outputs": [ |
| 276 | { |
| 277 | "address": "{ $args._Registre }", |
| 278 | "amount": "{ $__dada( 'Provisio' ) }" |
| 279 | } |
| 280 | ] |
| 281 | } |
| 282 | }, |
| 283 | { |
| 284 | "app": "state", |
| 285 | "state": "{ |
| 286 | if ( !! $nou_estat ) |
| 287 | response[ 'Nou estat ' || $ref_vincle ] = $nou_estat; |
| 288 | |
| 289 | if ( $args.admin_vincles ) { |
| 290 | response[ 'Proposta' ] = $nova_idprop otherwise $ref otherwise 'drecera'; |
| 291 | response[ 'operacio' ] = $operacio; |
| 292 | } |
| 293 | response[ 'proces' ] = $proces; |
| 294 | }" |
| 295 | } |
| 296 | ] |
| 297 | } |
| 298 | ] |