[
"autonomous agent",
{
"init": "{
$nom_AA = 'Portal';
$versio = '0.1.2';
$_AUT_000 = 'C4KIJSUWVM7BGWTLXKX3K4PNRXV7OY4W';
$adr__ = trigger.address;
$args = trigger.data;
$generics = var['Generics'];
$__bota = $txt => bounce ( $nom_AA || ' >>> ' || $txt );
if ( $args.proces == 'definicio_geto' OR $args.proces == 'esmena_generics' ) {
// Si no s'ha lliurat l'argument especificat, s'atura
$__arg = $arg =>
$args[ $arg ] ?
$args[ $arg ] :
$__bota( "Cal proporcionar el valor de: " || $arg );
$ref = $__arg( 'ref' );
$val = $__arg( 'val' );
// Comprova si una adr consta com a autoritzada
$__autoritzada = ( $x ) => {
$aut = $generics[ '_AUT_' || $x ];
$aut AND $aut == $adr__
};
// Comprova si la adr__ actuant consta com a autoritzada
if ( $adr__ != $_AUT_000
AND ! $__autoritzada( '0' )
AND ! $__autoritzada( 'A' )
AND ! $__autoritzada( 'B' )
AND ! $__autoritzada( 'C' )
) { $__bota( 'No autoritzada' ); }
// _AUT_000 pot saltar-se la validació mentre no existeixi _AUT_0
$es_AUT_000 = $adr__ == $_AUT_000;
if ( ! $es_AUT_000 OR ( $es_AUT_000 AND $__autoritzada( '0' ) ) ) {
if ( $args.tasca == 'confirmacio' ) {
$proposta = var[ $args.id ];
// La proposta ha d'existir
if ( ! $proposta )
{ $__bota( "No hi ha cap proposta de nou getó amb aquesta ref" ); }
// La confirmació l'ha de fer una AUT diferent a la proposant
if ( $proposta.proposant == $adr__ )
{ $__bota( "El procés de confirmació l'ha d'endegar una altra AUT" ); }
// La confirmació només es pot fer quan ha transcorregut el lapse especificat
if ( var[ 'Lapse' ] > timestamp - $proposta.temps )
{ $__bota( "Encara no es pot confirmar la proposta" ); }
// La proposta ha de constar com a validada a _Validacions
if ( ! var[ $args._Validacions ][ $args.id ] )
{ $__bota( "La proposta encara no ha estat validada" ); }
$tasca = 'confirmacio';
} else {
// El valor actual i el proporcionat no han de coincidir
if ( var[ $ref ] AND var[ $ref ] == $val )
{ $__bota( "El valor proposat coincideix amb l'actual" ); }
// El valor proporcionat no ha de coincidir amb el de la darrera proposta
$ord_darrera_prop = var[ 'ordinal_proposta_' || $ref ];
$darrera_prop = var[ 'proposta_' || $ref || '_' || $ord_darrera_prop ];
if ( !! $darrera_prop AND $darrera_prop.val == $val )
{ $__bota( "El valor proposat coincideix amb el de la darrera proposta" ); }
$ref_ordinal = 'ordinal_proposta_' || $ref;
$ordinal = var[ $ref_ordinal ];
$nou_ordinal = ! $ordinal ? 1 : $ordinal + 1;
$tasca = 'proposta';
}
} else { $tasca = 'drecera'; }
}
}",
"messages": {
"cases": [
{
"if": "{ $args.proces == 'acces' }",
"init": "{
$args._Portal = this_address;
$args._FOP = $generics._FOP;
$args._Estels = $generics._Estels;
$args.geto = trigger.output[[ asset != base ]].asset;
$args.qt = trigger.output[[ asset = $args.geto ]];
}",
"messages": [
{
"app": "data",
"payload": "{ $args }"
},
{
"app": "payment",
"payload": {
"asset": "{ $args.geto }",
"outputs": [
{
"address": "{ var[ '_Acces' ] }",
"amount": "{ $args.qt }"
}
]
}
}
]
},
{
"if": "{ $args.proces == 'esmena_generics' }",
"messages": [
{
"app": "state",
"state": "{
if ( $es_AUT_000 AND ! var[ '_AUT_0' ] ) {
if ( $ref == 'multiple' ) {
$__valvar = $refvar =>
$args[ $refvar ] ?
$args[ $refvar ] :
$generics[ $refvar ];
var[ 'Generics' ] = {
_Acces: $__valvar( '_Acces' ),
_Getons: $__valvar( '_Getons' ),
_Validacions: $__valvar( '_Validacions' ),
_FRO: $__valvar( '_FRO' ),
_FOP: $__valvar( '_FOP' ),
_FDIP: $__valvar( '_FDIP' ),
_Estels: $__valvar( '_Estels' ),
Interval: $__valvar( 'Interval' ),
Lapse: $__valvar( 'Lapse' ),
_Transfer: $__valvar( '_Transfer' ),
_Capacitacio: $__valvar( '_Capacitacio' ),
_Avis: $__valvar( '_Avis' ),
Import_Activacio: $__valvar( 'Import_Activacio' ),
Import_Subscripcio: $__valvar( 'Import_Subscripcio' ),
Import_Renovacio: $__valvar( 'Import_Renovacio' ),
Taxa_Conversio: $__valvar( 'Taxa_Conversio' ),
Factor_Conversio: $__valvar( 'Factor_Conversio' ),
Cicles_Latencia: $__valvar( 'Cicles_Latencia' ),
_AUT_0: $__valvar( '_AUT_0' ),
_AUT_A: $__valvar( '_AUT_A' ),
_AUT_B: $__valvar( '_AUT_B' ),
_AUT_C: $__valvar( '_AUT_C' ),
};
response[ '_Acces' ] = $__valvar( '_Acces' );
response[ '_Getons' ] = $__valvar( '_Getons' );
response[ '_Validacions' ] = $__valvar( '_Validacions' );
response[ '_FRO' ] = $__valvar( '_FRO' );
response[ '_FOP' ] = $__valvar( '_FOP' );
response[ '_FDIP' ] = $__valvar( '_FDIP' );
response[ '_Estels' ] = $__valvar( 'id_Estels' );
response[ 'Interval' ] = $__valvar( 'Interval' );
response[ 'Lapse' ] = $__valvar( 'Lapse' );
response[ '_Transfer' ] = $__valvar( '_Transfer' );
response[ '_Capacitacio' ] = $__valvar( '_Capacitacio' );
response[ '_Avis' ] = $__valvar( '_Avis' );
response[ 'Import_Activacio' ] = $__valvar( 'Import_Activacio' );
response[ 'Import_Subscripcio' ] = $__valvar( 'Import_Subscripcio' );
response[ 'Import_Renovacio' ] = $__valvar( 'Import_Activacio' );
response[ 'Taxa_Conversio' ] = $__valvar( 'Taxa_Conversio' );
response[ 'Factor_Conversio' ] = $__valvar( 'Factor_Conversio' );
response[ 'Cicles_Latencia' ] = $__valvar( 'Cicles_Latencia' );
response[ '_AUT_0' ] = $__valvar( '_AUT_0' );
response[ '_AUT_A' ] = $__valvar( '_AUT_A' );
response[ '_AUT_B' ] = $__valvar( '_AUT_B' );
response[ '_AUT_C' ] = $__valvar( '_AUT_C' );
} else {
var[ $ref ] = $val;
response[ 'nova ref' ] = $ref;
response[ 'nou val' ] = $val;
}
} else if ( $args.tasca == 'confirmacio' ) {
var[ $proposta.ref ] = $proposta.val;
response[ 'proposta' ] = $ref;
response[ 'nova ref' ] = $proposta.ref;
response[ 'nou val' ] = $proposta.val;
} else {
var[ $ref_ordinal ] = $nou_ordinal;
$id_proposta = 'proposta_' || $ref || '_' || $nou_ordinal;
var[ $id_proposta ] =
{
ref: $ref,
val: $val,
ordinal: $nou_ordinal,
proposant: $adr__,
temps: timestamp,
};
response[ 'proposta' ] = $id_proposta;
response[ 'nova ref' ] = $ref;
response[ 'nou val' ] = $val;
response[ 'data proposta' ] = timestamp_to_string( timestamp );
response[ 'data inici periode confirmació'] =
timestamp_to_string( timestamp + var[ 'Lapse' ] );
}
}"
}
]
},
{
"if": "{ $args.proces == 'definicio_geto' }",
"messages": [
{
"if": "{ $tasca != 'proposta' }",
"app": "asset",
"payload": {
"cap": "{ $args.cap otherwise 1e9 }",
"is_private": false,
"is_transferrable": true,
"auto_destroy": "{ !! $args.auto_destroy }",
"fixed_denominations": false,
"issued_by_definer_only": true,
"cosigned_by_definer": false,
"spender_attested": false
}
},
{
"app": "state",
"state": "{
if ( $tasca != 'confirmacio' ) {
$perfil = {
id : response_unit,
_FOG : $__arg( '_FOG' ),
_AUT_A : $__arg( '_AUT_A' ),
factor_conversio : $__arg( 'factor_conversio' ),
import_activacio : $__arg( 'import_activacio' ),
import_subscripcio : $__arg( 'import_subscripcio' ),
import_renovacio : $__arg( 'import_renovacio' ),
taxa_conversio : $__arg( 'taxa_conversio' ),
derivacio_aFOG : $__arg( 'derivacio_aFOG' ),
activacions_restringides : $__arg( 'activacions_restringides' ),
subscripcions_restringides : $__arg( 'subscripcions_restringides' ),
recepcions_restringides : $__arg( 'recepcions_restringides' ),
conversions_restringides : $__arg( 'conversions_restringides' ),
valors_esmenables : $__arg( 'valors_esmenables' ),
llistats_editables : $__arg( 'llistats_editables' ),
bloqueig_possible : $__arg( 'bloqueig_possible' ),
};
}
if ( $tasca == 'drecera' ) {
$getons = var[ 'Getons' ];
$getons[ response_unit ] =
{
proposant: $adr__,
confirmant: $adr__,
temps: timestamp,
perfil: $perfil
};
response[ 'Getó operatiu' ] = response_unit;
}
if ( $tasca == 'confirmacio' ) {
$prop = var[ $args.ref_proposta ];
$getons = var[ 'Getons' ];
$getons[ response_unit ] =
{
proposant: $prop.proposant,
confirmant: $adr__,
temps: timestamp,
perfil: $prop.perfil
};
response[ 'Getó operatiu' ] = $args.id;
}
if ( $tasca == 'proposta' ) {
$ref_proposta = 'nou_geto_' || $ordinal;
var[ $ref_proposta ] =
{
proposant: $adr__,
temps: timestamp,
perfil: $perfil
};
response[ 'ref proposta' ] = $ref_proposta;
response[ 'data mínima per a la confirmació'] =
timestamp_to_string( timestamp + $args.lapse );
}
response[ 'tasca' ] = $tasca;
}"
}
]
},
{
"if": "{ $args.proces == 'emissio_getons' }",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{trigger.data.asset}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{trigger.data.amount}"
}
]
}
}
]
}
]
}
}
]