| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{\r |
| 5 | $nom_AA = 'Getons';\r |
| 6 | |
| 7 | |
| 8 | $_Portal = trigger.address; |
| 9 | if ( $_Portal != trigger.address ) bounce ( 'Portal no reconegut' );\r |
| 10 | \r |
| 11 | |
| 12 | $args = trigger.data;\r |
| 13 | $adr__ = trigger.initial_address;\r |
| 14 | $idgeto = trigger.output[[ asset != base ]].asset;\r |
| 15 | $dades = $args.dades otherwise {};\r |
| 16 | \r |
| 17 | $__dada = $refval => {\r |
| 18 | data_feed[[ oracles = $args._Registre, feed_name = $refval, ifnone = false ]]\r |
| 19 | };\r |
| 20 | \r |
| 21 | |
| 22 | $proces = $args.proces;\r |
| 23 | $operacio = $args.operacio;\r |
| 24 | $idprop = $args.idprop;\r |
| 25 | $ref = $args.ref;\r |
| 26 | $val = $args.val;\r |
| 27 | \r |
| 28 | |
| 29 | $__arg = $arg =>\r |
| 30 | $args[ $arg ] otherwise\r |
| 31 | bounce( "Cal proporcionar el valor de: " || $arg );\r |
| 32 | \r |
| 33 | $refgeto = 'geto_' || $__arg( 'nomgeto' );\r |
| 34 | \r |
| 35 | |
| 36 | $estat = $__dada( $refgeto || '_estat' ) otherwise '';\r |
| 37 | if ( $estat != 'operatiu' )\r |
| 38 | bounce( 'Getó inexistent o no operatiu' );\r |
| 39 | \r |
| 40 | |
| 41 | $_AUT_A = $__dada( $refgeto || '_AUT_A' ) otherwise '';\r |
| 42 | $_AUT_B = $__dada( $refgeto || '_AUT_B' ) otherwise '';\r |
| 43 | $_AUT_C = $__dada( $refgeto || '_AUT_C' ) otherwise '';\r |
| 44 | \r |
| 45 | $aut_provisional = ! $__dada( $refgeto || '_AUT_0' );\r |
| 46 | \r |
| 47 | if ( ! $aut_provisional AND \r |
| 48 | $_AUT_A != $adr__ AND $_AUT_B != $adr__ AND $_AUT_C != $adr__ )\r |
| 49 | bounce ( 'No autoritzada per administrar el getó' );\r |
| 50 | \r |
| 51 | if ( $proces == 'esmena_geto' ) {\r |
| 52 | $definidors_esmenables = \r |
| 53 | 'taxa_conversio, derivacio, import_activacio, ' ||\r |
| 54 | 'import_subscripcio, import_renovacio, ' ||\r |
| 55 | 'cicles_diposit, _AUT_A, _AUT_B, _AUT_C';\r |
| 56 | \r |
| 57 | if ( $operacio == 'proposta' ) {\r |
| 58 | $refdef = $ref otherwise 'cap';\r |
| 59 | if ( ! contains( $definidors_esmenables, $refdef ) )\r |
| 60 | bounce( 'Definidor inexistent o no esmenable' );\r |
| 61 | \r |
| 62 | if ( $__dada( $refgeto || '_valors_esmenables') < 1 )\r |
| 63 | bounce( "Els valors definidors d'aquest getó no són esmenables" );\r |
| 64 | \r |
| 65 | $dades[ $idprop ] = timestamp;\r |
| 66 | $dades[ $idprop || '_proposant' ] = $adr__;\r |
| 67 | $dades[ $idprop || '_refgeto' ] = $refgeto;\r |
| 68 | $dades[ $idprop || '_ref' ] = $__arg( 'ref' );\r |
| 69 | $dades[ $idprop || '_val' ] = $__arg( 'val' );\r |
| 70 | }\r |
| 71 | if ( $operacio == 'confirmacio' ) {\r |
| 72 | $refg = $__dada( $idprop || '_refgeto' );\r |
| 73 | $refval = $__dada( $idprop || '_ref' );\r |
| 74 | $dades[ $refg || '_' || $refval ] = $__dada( $idprop || '_val' );\r |
| 75 | }\r |
| 76 | if ( $operacio == 'drecera' AND $aut_provisional ) {\r |
| 77 | $dades[ $refgeto || '_' || $__arg( 'ref' ) ] = $__arg( 'val' );\r |
| 78 | }\r |
| 79 | }\r |
| 80 | \r |
| 81 | if ( $proces == 'capacitacio' ) {\r |
| 82 | if ( $__dada( $refgeto || '_' || $__arg( 'accio' ) || 'ns_restringides') < 1 )\r |
| 83 | bounce( 'Acció no restringible per a aquest getó' );\r |
| 84 | \r |
| 85 | if ( $operacio == 'proposta' ) {\r |
| 86 | $dades[ $idprop ] = timestamp;\r |
| 87 | $dades[ $idprop || '_capacitadora' ] = $adr__;\r |
| 88 | $dades[ $idprop || '_geto' ] = $refgeto;\r |
| 89 | $dades[ $idprop || '_accio' ] = $__arg( 'accio' );\r |
| 90 | $dades[ $idprop || '_capacitada' ] = $__arg( 'adr' );\r |
| 91 | $dades[ $idprop || '_estat' ] = $__arg( 'estat' );\r |
| 92 | }\r |
| 93 | if ( $operacio == 'confirmacio' ) {\r |
| 94 | $get = $__dada( $idprop || '_refgeto' );\r |
| 95 | $acc = $__dada( $idprop || '_accio' );\r |
| 96 | $adr = $__dada( $idprop || '_capacitada' );\r |
| 97 | $ref_capacitacio = 'CPC_' || $get || '_' || $acc || '_' || $adr;\r |
| 98 | $dades[ $ref_capacitacio ] = $__dada( $idprop || '_estat' );\r |
| 99 | }\r |
| 100 | if ( $operacio == 'drecera' AND $aut_provisional ) {\r |
| 101 | $ref_capacitacio =\r |
| 102 | 'CPC_' || $refgeto || '_' || $__arg( 'accio' ) || '_' || $__arg( 'adr' );\r |
| 103 | $dades[ $ref_capacitacio ] = $__arg( 'estat' );\r |
| 104 | }\r |
| 105 | }\r |
| 106 | \r |
| 107 | if ( $proces == 'avis' ) {\r |
| 108 | $rebot =\r |
| 109 | $__dada( $refgeto || '_bloqueig_possible' ) ?\r |
| 110 | $__arg( 'rebot' ) :\r |
| 111 | false;\r |
| 112 | \r |
| 113 | if ( $operacio == 'proposta' ) {\r |
| 114 | $dades[ $idprop ] = timestamp;\r |
| 115 | $dades[ $idprop || '_redactora' ] = $adr__;\r |
| 116 | $dades[ $idprop || '_geto' ] = $refgeto;\r |
| 117 | $dades[ $idprop || '_destinataria' ] = $__arg( 'adr' );\r |
| 118 | $dades[ $idprop || '_rebot' ] = $rebot;\r |
| 119 | $dades[ $idprop || '_text' ] = $__arg( 'text' );\r |
| 120 | }\r |
| 121 | if ( $operacio == 'confirmacio' ) {\r |
| 122 | $get = $__dada( $idprop || '_refgeto' );\r |
| 123 | $adr = $__dada( $idprop || '_destinataria' );\r |
| 124 | $refavis = 'avis_' || $get || '_' || $adr;\r |
| 125 | $dades[ $refavis ] = timestamp;\r |
| 126 | $dades[ $refavis || '_rebot' ] = $__dada( $idprop || '_rebot' );\r |
| 127 | $dades[ $refavis || '_text' ] = $__dada( $idprop || '_text' );\r |
| 128 | }\r |
| 129 | if ( $operacio == 'drecera' AND $aut_provisional ) {\r |
| 130 | $refavis = 'avis_' || $refgeto || '_' || $__arg( 'adr' );\r |
| 131 | $dades[ $refavis ] = timestamp;\r |
| 132 | $dades[ $refavis || '_rebot' ] = $rebot;\r |
| 133 | $dades[ $refavis || '_text' ] = $__arg( 'text' );\r |
| 134 | }\r |
| 135 | }\r |
| 136 | \r |
| 137 | $registre = {};\r |
| 138 | $registre.dades = $dades;\r |
| 139 | }", |
| 140 | "messages": [ |
| 141 | { |
| 142 | "app": "data", |
| 143 | "payload": "{ $registre }" |
| 144 | }, |
| 145 | { |
| 146 | "app": "payment", |
| 147 | "payload": { |
| 148 | "asset": "base", |
| 149 | "outputs": [ |
| 150 | { |
| 151 | "address": "{ $args._Registre }", |
| 152 | "amount": "{ $__dada( 'Provisio' ) }" |
| 153 | } |
| 154 | ] |
| 155 | } |
| 156 | }, |
| 157 | { |
| 158 | "app": "state", |
| 159 | "state": "{\r |
| 160 | response[ 'valors_esmenables' ] = $__dada( $refgeto || '_valors_esmenables');\r |
| 161 | response[ 'Romanent Getons' ] = balance[ base ] || ' bytes';\r |
| 162 | response[ 'proces' ] = $proces;\r |
| 163 | response[ 'operacio' ] = $operacio;\r |
| 164 | }" |
| 165 | } |
| 166 | ] |
| 167 | } |
| 168 | ] |