| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{\r |
| 5 | $nom_AA = 'Accions';\r |
| 6 | |
| 7 | $_Portal_original = trigger.address; |
| 8 | \r |
| 9 | $_Portal_actual = var[ 'portal_actual' ] otherwise $_Portal_original;\r |
| 10 | \r |
| 11 | if ( $_Portal_actual != trigger.address )\r |
| 12 | {\r |
| 13 | $versions_Portal = var[ $_Portal_actual ][ 'versions' ];\r |
| 14 | $_Portal = substring( $versions_Portal.Portal, 0, 32 );\r |
| 15 | if ( $_Portal != trigger.address ) bounce ( 'Portal no reconegut' );\r |
| 16 | } else\r |
| 17 | $_Portal = $_Portal_actual;\r |
| 18 | \r |
| 19 | |
| 20 | $args = trigger.data;\r |
| 21 | $adr__ = trigger.initial_address;\r |
| 22 | $idgeto = trigger.output[[ asset != base ]].asset;\r |
| 23 | \r |
| 24 | $definidors = var[ $_Portal ][ 'definidors' ];\r |
| 25 | $versions = var[ $_Portal ][ 'versions' ] otherwise {};\r |
| 26 | $versions.Portal = $versions.Portal otherwise $_Portal;\r |
| 27 | $versions.Accions = $versions.Accions otherwise this_address;\r |
| 28 | $versions.Getons = $versions.Getons otherwise $definidors._Getons;\r |
| 29 | $refs_getons = var[ $_Portal ][ 'refs_getons' ];\r |
| 30 | $refgeto = $args.refgeto;\r |
| 31 | \r |
| 32 | \r |
| 33 | |
| 34 | \r |
| 35 | |
| 36 | $__arg = $arg =>\r |
| 37 | $args[ $arg ] otherwise bounce( "Cal proporcionar el valor de: " || $arg );\r |
| 38 | \r |
| 39 | $__dada = $refval => {\r |
| 40 | data_feed[[ oracles = $versions.Accions, feed_name = $refval, ifnone = false ]]\r |
| 41 | };\r |
| 42 | \r |
| 43 | $__dada_geto = $refval => {\r |
| 44 | data_feed[[ oracles = $versions.Getons, feed_name = $refval, ifnone = false ]]\r |
| 45 | };\r |
| 46 | \r |
| 47 | $__dada_portal = $refval => {\r |
| 48 | data_feed[[ oracles = $versions.Portal, feed_name = $refval, ifnone = false ]]\r |
| 49 | };\r |
| 50 | \r |
| 51 | $__param = $refparam => {\r |
| 52 | $refgeto == 'estels'?\r |
| 53 | $definidors[ $refparam ] :\r |
| 54 | $__dada_geto( $refgeto || '_' || $refparam )\r |
| 55 | };\r |
| 56 | \r |
| 57 | |
| 58 | $__qtSuficient = $ref, $q =>\r |
| 59 | $__param( $ref ) > $q ?\r |
| 60 | bounce( "L'" || $ref || " és de " || $__param( $ref ) )\r |
| 61 | : true;\r |
| 62 | \r |
| 63 | |
| 64 | $__subscrita = $adr =>\r |
| 65 | !! $__dada( 'subscripcio_' || $adr || '_en_' || $refgeto ) ?\r |
| 66 | true :\r |
| 67 | bounce( "Adreça no subscrita per a " || $refgeto );\r |
| 68 | \r |
| 69 | |
| 70 | $__renovada = $adr => {\r |
| 71 | $cicle_renovat = $__dada( 'renovacio_' || $adr || '_en_' || $refgeto || '_cicle' );\r |
| 72 | $cicle_renovat >= $__dada( 'cicle_actual' ) ?\r |
| 73 | true :\r |
| 74 | bounce( "Subscripció de l'adreça " || $adr || " no renovada en " || $refgeto\r |
| 75 | || " per al cicle actual: " || $__dada( 'cicle_actual' ) )\r |
| 76 | };\r |
| 77 | \r |
| 78 | \r |
| 79 | |
| 80 | $ACC = $__arg( 'accio' );\r |
| 81 | $qt = $__arg( 'qt_accio' );\r |
| 82 | $cicle_actual = $__dada( 'cicle_actual' ) otherwise 1;\r |
| 83 | $escala_actual = $__dada( 'escala_actual' ) otherwise 1;\r |
| 84 | \r |
| 85 | \r |
| 86 | |
| 87 | |
| 88 | $ref_avis = $refgeto || '_avis_' || $adr__;\r |
| 89 | $rebot = $__dada_geto( $ref_avis || '_rebot' );\r |
| 90 | $temps_avis = $__dada_geto( $ref_avis );\r |
| 91 | $avis_es_actual =\r |
| 92 | !! $temps_avis AND\r |
| 93 | $temps_avis + ( $definidors.Lapse * 2 ) < timestamp;\r |
| 94 | \r |
| 95 | if ( $avis_es_actual AND $rebot ) \r |
| 96 | bounce ( $__dada_geto( $ref_avis || '_text' ) );\r |
| 97 | \r |
| 98 | \r |
| 99 | |
| 100 | $secc_ref = $ACC == 'Diposit' ? 'diposits' : to_lower( $ACC ) || 'ns';\r |
| 101 | $ref_total = 'total_' || $secc_ref || '_en_' || $refgeto;\r |
| 102 | $total_acc = $__dada( $ref_total ) otherwise 0;\r |
| 103 | \r |
| 104 | \r |
| 105 | |
| 106 | if ( $ACC == 'Activacio' ) {\r |
| 107 | $ref_Activacio = 'activacio_' || $adr__ || '_en_' || $refgeto;\r |
| 108 | \r |
| 109 | if ( !! $__dada( $ref_Activacio ) ) bounce( 'Adreça ja activada' );\r |
| 110 | \r |
| 111 | $condicions =\r |
| 112 | $__qtSuficient( 'Import_Activacio', $qt )\r |
| 113 | AND $__arg( 'nom' );\r |
| 114 | }\r |
| 115 | \r |
| 116 | \r |
| 117 | |
| 118 | if ( $ACC == 'Subscripcio' ) {\r |
| 119 | $ref_subscripcio = 'subscripcio_' || $adr__ || '_en_' || $refgeto;\r |
| 120 | $ref_renovacio = 'renovacio_' || $adr__ || '_en_' || $refgeto;\r |
| 121 | \r |
| 122 | if ( !! $__dada( $ref_subscripcio ) ) bounce( 'Adreça ja subscrita' );\r |
| 123 | \r |
| 124 | $condicions =\r |
| 125 | $__qtSuficient( 'Import_Subscripcio', $qt )\r |
| 126 | AND $__arg( 'nom' )\r |
| 127 | AND $__arg( 'derivacio' );\r |
| 128 | }\r |
| 129 | \r |
| 130 | \r |
| 131 | |
| 132 | if ( $ACC == 'Renovacio' ) {\r |
| 133 | $ref_renovacio = 'renovacio_' || $adr__ || '_en_' || $refgeto;\r |
| 134 | $cicle_renovat = $__dada( $ref_renovacio || '_cicle' ) otherwise 1;\r |
| 135 | \r |
| 136 | if ( $cicle_actual == $cicle_renovat )\r |
| 137 | bounce( 'Cicle actual ( ' || $cicle_actual || ' ) ja renovat' );\r |
| 138 | \r |
| 139 | $condicions =\r |
| 140 | $__subscrita( $adr__ )\r |
| 141 | AND $__qtSuficient( 'Import_Renovacio', $qt );\r |
| 142 | }\r |
| 143 | \r |
| 144 | \r |
| 145 | |
| 146 | if ( $ACC == 'Diposit' ) {\r |
| 147 | $ref_diposit = 'diposit_' || $args.ordinal;\r |
| 148 | \r |
| 149 | if ( $qt < $__param( 'Diposit_Minim' ) )\r |
| 150 | bounce( 'El dipòsit mínim és de ' || $__param( 'Diposit_Minim' ) );\r |
| 151 | \r |
| 152 | $condicions =\r |
| 153 | $__subscrita( $adr__ )\r |
| 154 | AND $__renovada( $adr__ );\r |
| 155 | \r |
| 156 | $taxa_conversio = $__param( 'Taxa_Conversio' );\r |
| 157 | $cicles_diposit = $__param( 'Cicles_Diposit' );\r |
| 158 | $cicle_conversio = $cicle_actual + $cicles_diposit;\r |
| 159 | $taxa = round( $qt * $taxa_conversio / 100, 0 );\r |
| 160 | $qt_conversio = $qt - $taxa;\r |
| 161 | }\r |
| 162 | \r |
| 163 | \r |
| 164 | |
| 165 | if ( $ACC == 'Contribucio' )\r |
| 166 | {\r |
| 167 | $ref_contribucio = 'contribucio_' || $args.ordinal;\r |
| 168 | \r |
| 169 | $escala_act = $__dada( 'escala_actual' );\r |
| 170 | $interval = timestamp - $__dada( 'data_escala_' || $escala_act );\r |
| 171 | }\r |
| 172 | \r |
| 173 | \r |
| 174 | |
| 175 | if ( $ACC == 'Transfer' )\r |
| 176 | {\r |
| 177 | $data_cicle_actual = $__dada( 'data_cicle_' || $cicle_actual );\r |
| 178 | $salt_cicle = timestamp - $data_cicle_actual > $definidors.Interval;\r |
| 179 | $nou_cicle = $salt_cicle ? $cicle_actual + 1 : $cicle_actual;\r |
| 180 | \r |
| 181 | $total_FOP = $__dada_portal( 'total_FOP_en_estels' ) otherwise 0;\r |
| 182 | $nova_escala = length( $total_FOP );\r |
| 183 | $salt_escala = $nova_escala > $escala_actual;\r |
| 184 | }\r |
| 185 | \r |
| 186 | \r |
| 187 | |
| 188 | $retorn_minim = 10000;\r |
| 189 | $qt_retorn =\r |
| 190 | balance[ base ] > 20000 ?\r |
| 191 | balance[ base ] - $retorn_minim :\r |
| 192 | 0;\r |
| 193 | }", |
| 194 | "messages": [ |
| 195 | { |
| 196 | "if": "{ $qt_retorn > $retorn_minim }", |
| 197 | "app": "payment", |
| 198 | "payload": { |
| 199 | "asset": "base", |
| 200 | "outputs": [ |
| 201 | { |
| 202 | "address": "{ $_Portal_actual }", |
| 203 | "amount": "{ $qt_retorn }" |
| 204 | } |
| 205 | ] |
| 206 | } |
| 207 | }, |
| 208 | { |
| 209 | "if": "{ $ACC == 'inicialitzacio' }", |
| 210 | "app": "data_feed", |
| 211 | "payload": { |
| 212 | "{ 'cicle_actual' }": 1, |
| 213 | "{ 'data_cicle_1' }": "{ timestamp }", |
| 214 | "{ 'escala_cicle_1' }": 1, |
| 215 | "{ 'escala_actual' }": 1, |
| 216 | "{ 'data_escala_1' }": "{ timestamp }", |
| 217 | "{ 'cicle_escala_1' }": 1 |
| 218 | } |
| 219 | }, |
| 220 | { |
| 221 | "if": "{ $ACC == 'Transfer' AND $salt_escala AND ! $salt_cicle }", |
| 222 | "app": "data_feed", |
| 223 | "payload": { |
| 224 | "{ 'escala_actual' }": "{ $nova_escala }", |
| 225 | "{ 'data_escala_' || $nova_escala }": "{ timestamp }", |
| 226 | "{ 'cicle_escala_' || $nova_escala }": "{ $cicle_actual }" |
| 227 | } |
| 228 | }, |
| 229 | { |
| 230 | "if": "{ $ACC == 'Transfer' AND $salt_cicle }", |
| 231 | "app": "data_feed", |
| 232 | "payload": { |
| 233 | "{ 'cicle_actual' }": "{ $nou_cicle }", |
| 234 | "{ 'data_cicle_' || $nou_cicle }": "{ timestamp }", |
| 235 | "{ 'escala_cicle_' || $nou_cicle }": "{ $escala_actual }" |
| 236 | } |
| 237 | }, |
| 238 | { |
| 239 | "if": "{ $ACC == 'Activacio' }", |
| 240 | "app": "data_feed", |
| 241 | "payload": { |
| 242 | "{ $ref_total }": "{ $total_acc + $qt }", |
| 243 | "{ $ref_Activacio }": "{ timestamp }", |
| 244 | "{ $ref_Activacio || '_nom' }": "{ $args.nom }", |
| 245 | "{ $ref_Activacio || '_qt' }": "{ $qt }", |
| 246 | "{ $ref_Activacio || '_cicle' }": "{ $cicle_actual }", |
| 247 | "{ $ref_Activacio || '_escala' }": "{ $refgeto == 'estels' ? $escala_actual : 100 }" |
| 248 | } |
| 249 | }, |
| 250 | { |
| 251 | "if": "{ $ACC == 'Subscripcio' }", |
| 252 | "app": "data_feed", |
| 253 | "payload": { |
| 254 | "{ $ref_total }": "{ $total_acc + $qt }", |
| 255 | "{ $ref_subscripcio }": "{ timestamp }", |
| 256 | "{ $ref_subscripcio || '_nom' }": "{ $args.nom }", |
| 257 | "{ $ref_subscripcio || '_cicle' }": "{ $cicle_actual }", |
| 258 | "{ $ref_subscripcio || '_derivacio' }": "{ $args.derivacio }", |
| 259 | "{ $ref_renovacio }": "{ timestamp }", |
| 260 | "{ $ref_renovacio || '_cicle' }": "{ $cicle_actual }" |
| 261 | } |
| 262 | }, |
| 263 | { |
| 264 | "if": "{ $ACC == 'Renovacio' }", |
| 265 | "app": "data_feed", |
| 266 | "payload": { |
| 267 | "{ $ref_total }": "{ $total_acc + $qt }", |
| 268 | "{ $ref_renovacio }": "{ timestamp }", |
| 269 | "{ $ref_renovacio || '_cicle' }": "{ $cicle_actual }" |
| 270 | } |
| 271 | }, |
| 272 | { |
| 273 | "if": "{ $ACC == 'Diposit' }", |
| 274 | "app": "data_feed", |
| 275 | "payload": { |
| 276 | "{ $ref_total }": "{ $total_acc + $qt }", |
| 277 | "{ $ref_diposit }": "{ $qt }", |
| 278 | "{ $ref_diposit || '_dipositant' }": "{ $adr__ }", |
| 279 | "{ $ref_diposit || '_cicle' }": "{ $cicle_actual }", |
| 280 | "{ $ref_diposit || '_geto_diposit' }": "{ $refgeto }", |
| 281 | "{ $ref_diposit || '_data' }": "{ timestamp }", |
| 282 | "{ $ref_diposit || '_taxa' }": "{ $taxa_conversio }", |
| 283 | "{ $ref_diposit || '_qt_conversio' }": "{ $qt_conversio }", |
| 284 | "{ $ref_diposit || '_cicle_conversio' }": "{ $taxa_conversio }" |
| 285 | } |
| 286 | }, |
| 287 | { |
| 288 | "if": "{ $ACC == 'Contribucio' }", |
| 289 | "app": "data_feed", |
| 290 | "payload": { |
| 291 | "{ $ref_total }": "{ $total_acc + $qt }", |
| 292 | "{ $ref_contribucio }": "{ $qt }", |
| 293 | "{ $ref_contribucio || '_contribuidora' }": "{ $adr__ }", |
| 294 | "{ $ref_contribucio || '_cicle' }": "{ $cicle_actual }", |
| 295 | "{ $ref_contribucio || '_escala' }": "{ $escala_actual }", |
| 296 | "{ $ref_contribucio || '_interval' }": "{ $interval }", |
| 297 | "{ $ref_contribucio || '_data' }": "{ timestamp }" |
| 298 | } |
| 299 | }, |
| 300 | { |
| 301 | "app": "state", |
| 302 | "state": "{\r |
| 303 | |
| 304 | |
| 305 | if ( $avis_es_actual )\r |
| 306 | response[ 'AVÍS !' ] = $__dada_geto( $ref_avis || '_text' );\r |
| 307 | \r |
| 308 | |
| 309 | if ( $ACC == 'Activacio' )\r |
| 310 | response[ 'Activació' ] =\r |
| 311 | "Amb nom: " || $args.nom || " de l'adr " || $adr__ || " per operar amb " || $refgeto;\r |
| 312 | \r |
| 313 | |
| 314 | if ( $ACC == 'Subscripcio' )\r |
| 315 | response[ 'Subscripció' ] =\r |
| 316 | "Amb nom: " || $args.nom || " de l'adr " || $adr__ ||\r |
| 317 | " per al cicle " || $cicle_actual || " per operar amb " || $refgeto;\r |
| 318 | \r |
| 319 | |
| 320 | if ( $ACC == 'Renovacio' )\r |
| 321 | response[ 'Renovació' ] =\r |
| 322 | "De la subscripció per al cicle " || $cicle_actual\r |
| 323 | || " de l'adr " || $adr__ || " en " || $refgeto;\r |
| 324 | \r |
| 325 | |
| 326 | if ( $ACC == 'Diposit' ) {\r |
| 327 | response[ 'Dipòsit' ] = $ref_diposit;\r |
| 328 | response[ 'Dipositant' ] = $adr__;\r |
| 329 | response[ 'Qt dipòsit' ] = $qt;\r |
| 330 | response[ 'Qt conversió' ] = $qt_conversio;\r |
| 331 | response[ 'Taxa' ] = $taxa_conversio;\r |
| 332 | response[ 'Data dipòsit' ] = timestamp_to_string( timestamp, 'date' );\r |
| 333 | response[ 'Hora dipòsit' ] = timestamp_to_string( timestamp, 'time' );\r |
| 334 | response[ 'Cicle dipòsit' ] = $cicle_actual;\r |
| 335 | response[ 'Cicle conversió' ] = $cicle_actual + $cicle_conversio;\r |
| 336 | }\r |
| 337 | \r |
| 338 | |
| 339 | if ( $ACC == 'Contribucio' ) {\r |
| 340 | response[ 'Contribució' ] = $ref_contribucio;\r |
| 341 | response[ 'Contribuïdora' ] = $adr__;\r |
| 342 | response[ 'Quantitat' ] = $qt;\r |
| 343 | response[ 'Escala actual' ] = $nova_escala;\r |
| 344 | }\r |
| 345 | \r |
| 346 | |
| 347 | response[ 'Cicle actual' ] =\r |
| 348 | $salt_cicle ? 'Nou cicle: ' || $nou_cicle : $cicle_actual;\r |
| 349 | response[ 'Escala actual' ] =\r |
| 350 | $salt_escala AND ! $salt_cicle ? 'Nova Escala: ' || $nova_escala : $escala_actual;\r |
| 351 | response[ 'Acció realitzada' ] = $ACC;\r |
| 352 | response[ 'Romanent Registre' ] = balance[ base ] || ' bytes';\r |
| 353 | if ( $qt_retorn > $retorn_minim )\r |
| 354 | response[ 'Transferits a Portal' ] = $qt_retorn || ' bytes';\r |
| 355 | \r |
| 356 | |
| 357 | if ( $_Portal != $_Portal_actual ) {\r |
| 358 | var[ 'anterior_portal' ] = var[ 'portal_actual' ];\r |
| 359 | var[ 'portal_actual' ] = $_Portal;\r |
| 360 | response[ 'Nou portal actual' ] = $_Portal;\r |
| 361 | }\r |
| 362 | }" |
| 363 | } |
| 364 | ] |
| 365 | } |
| 366 | ] |