| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $nom_AA = 'Getons'; |
| 6 | $versio = '0.1'; |
| 7 | |
| 8 | $_AUT_000 = 'C4KIJSUWVM7BGWTLXKX3K4PNRXV7OY4W'; |
| 9 | |
| 10 | $adr__ = trigger.address; |
| 11 | $args = trigger.data; |
| 12 | |
| 13 | $__bota = $txt => bounce ( $nom_AA || ' >>> ' || $txt ); |
| 14 | |
| 15 | |
| 16 | $__autoritzada = ( $x ) => { |
| 17 | $aut = var[ $args._Portal ][ '_AUT_' || $x ]; |
| 18 | $aut AND $aut == $adr__ |
| 19 | }; |
| 20 | |
| 21 | |
| 22 | if ( $adr__ != $_AUT_000 |
| 23 | AND ! $__autoritzada( '0' ) |
| 24 | AND ! $__autoritzada( 'A' ) |
| 25 | AND ! $__autoritzada( 'B' ) |
| 26 | AND ! $__autoritzada( 'C' ) |
| 27 | ) { $__bota( 'No autoritzada' ); } |
| 28 | |
| 29 | |
| 30 | $es_AUT_000 = $adr__ == $_AUT_000; |
| 31 | if ( ! $es_AUT_000 OR ( !! $es_AUT_000 AND !! var[ '_AUT_0' ] ) ) { |
| 32 | |
| 33 | |
| 34 | if ( $args.acc == 'confirmacio' ) { |
| 35 | $proposta = var[ $args.id ]; |
| 36 | |
| 37 | |
| 38 | if ( ! $proposta ) |
| 39 | { $__bota( "No hi ha cap proposta de nou getó amb aquesta ref" ); } |
| 40 | |
| 41 | |
| 42 | if ( $proposta.proposant == $adr__ ) |
| 43 | { $__bota( "El procés de confirmació l'ha d'endegar una altra AUT" ); } |
| 44 | |
| 45 | |
| 46 | if ( var[ 'Lapse' ] > timestamp - $proposta.temps ) |
| 47 | { $__bota( "Encara no es pot confirmar la proposta" ); } |
| 48 | |
| 49 | |
| 50 | if ( ! var[ $args._Validacions ][ $args.id ] ) |
| 51 | { $__bota( "La proposta encara no ha estat validada" ); } |
| 52 | |
| 53 | $acc = 'confirmacio'; |
| 54 | } else { $acc = 'proposta'; } |
| 55 | } else { $acc = 'drecera'; } |
| 56 | |
| 57 | $ref_geto = 'geto_' || $args.id; |
| 58 | $estat = 'actiu'; |
| 59 | }", |
| 60 | "messages": [ |
| 61 | { |
| 62 | "app": "data_feed", |
| 63 | "payload": { |
| 64 | "{ $ref_geto }": "{ $args.estat }" |
| 65 | } |
| 66 | }, |
| 67 | { |
| 68 | "app": "state", |
| 69 | "state": "{ |
| 70 | if ( $acc == 'drecera' ) { |
| 71 | var[ $ref_geto ] = |
| 72 | { |
| 73 | id: $args.id, |
| 74 | proposant: $adr__, |
| 75 | confirmant: $adr__, |
| 76 | temps: timestamp, |
| 77 | estat: $args.estat |
| 78 | }; |
| 79 | response[ 'Getó operatiu' ] = $args.id; |
| 80 | } |
| 81 | if ( $acc == 'confirmacio' ) { |
| 82 | $prop = var[ 'nou_geto_' || $args.id ]; |
| 83 | var[ $ref_geto ] = |
| 84 | { |
| 85 | id: $prop.id, |
| 86 | proposant: $prop.proposant, |
| 87 | confirmant: $adr__, |
| 88 | temps: timestamp, |
| 89 | estat: $prop.estat |
| 90 | }; |
| 91 | response[ 'Getó operatiu' ] = $args.id; |
| 92 | } |
| 93 | if ( $acc == 'proposta' ) { |
| 94 | $ordinal = var[ 'ordinal' ]; |
| 95 | var[ 'ordinal' ] = ! $ordinal ? 1 : $ordinal + 1; |
| 96 | |
| 97 | $ref_proposta = 'nou_geto_' || $ordinal; |
| 98 | var[ $ref_proposta ] = |
| 99 | { |
| 100 | id: $args.id, |
| 101 | estat: $args.estat, |
| 102 | ordinal: $ordinal, |
| 103 | proposant: $adr__, |
| 104 | temps: timestamp, |
| 105 | }; |
| 106 | response[ 'ref proposta' ] = $ref_proposta; |
| 107 | response[ 'data mínima per a la confirmació'] = |
| 108 | timestamp_to_string( timestamp + $args.lapse ); |
| 109 | } |
| 110 | response[ 'acc' ] = $acc; |
| 111 | }" |
| 112 | } |
| 113 | ] |
| 114 | } |
| 115 | ] |