| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $_Registre = 'MGIC6DY2L6I4F5MEB3LSBGUCSTNLIJTV'; |
| 6 | |
| 7 | $geto = 'Testets'; |
| 8 | $id_geto = 'mXJmtZtH+svDfDdm4lYw5FqSD8elgLJg2DtqCq7GWm8='; |
| 9 | |
| 10 | $adr__ = trigger.initial_address; |
| 11 | $args = trigger.data; |
| 12 | $unitat = trigger.output[[ asset != base ]].asset; |
| 13 | |
| 14 | |
| 15 | $__dada = $refdada => |
| 16 | data_feed [[ |
| 17 | oracles = $_Registre, |
| 18 | feed_name = $refdada, |
| 19 | ifnone = 0 |
| 20 | ]]; |
| 21 | |
| 22 | |
| 23 | $_Portal = trigger.address; |
| 24 | if ( $_Portal != trigger.address |
| 25 | AND $__dada( '_Accions' ) != trigger.address |
| 26 | AND $__dada( '_Getons' ) != trigger.address ) |
| 27 | bounce( 'Accés interdit' ); |
| 28 | |
| 29 | $sentit = $args.sentit; |
| 30 | $total_entrades = $__dada( 'total_entrades_' || $geto ) otherwise 0; |
| 31 | $total_sortides = $__dada( 'total_sortides_' || $geto ) otherwise 0; |
| 32 | $provisio = $unitat == 'none'; |
| 33 | $idgeto_registrada = $__dada( $geto || '_id' ) otherwise ''; |
| 34 | $id_estels = $__dada( 'Estels' ); |
| 35 | |
| 36 | if( $idgeto_registrada != $id_geto ) |
| 37 | bounce( 'La id registrada no coincideix' ); |
| 38 | |
| 39 | if ( ! $provisio ) { |
| 40 | |
| 41 | if( $unitat != $idgeto_registrada AND $unitat != $id_estels ) |
| 42 | bounce( 'Unitat desconeguda' ); |
| 43 | |
| 44 | $estat_geto = $__dada( $geto || '_estat' ) otherwise ''; |
| 45 | |
| 46 | if( $estat_geto != 'operatiu' ) |
| 47 | bounce( 'Getó no operatiu' ); |
| 48 | |
| 49 | $registre = {}; |
| 50 | $dades = {}; |
| 51 | |
| 52 | if ( $sentit == 'entrada' ) { |
| 53 | $qt_entrada = $provisio ? 0 : trigger.output[[ asset = $unitat ]]; |
| 54 | $nou_total_entrades = $total_entrades + $qt_entrada; |
| 55 | $ord_entrada_actual = $__dada( 'ordinal_entrada_' || $geto ) otherwise 0; |
| 56 | $ord_entrada = $ord_entrada_actual + 1; |
| 57 | $ref_entrada = 'entrada_' || $geto || '_' || $ord_entrada; |
| 58 | $dades[ $ref_entrada || '_data' ] = timestamp; |
| 59 | $dades[ $ref_entrada || '_qt' ] = $qt_entrada; |
| 60 | $dades[ $ref_entrada || '_emissora' ] = $args.emissora otherwise $adr__; |
| 61 | $dades[ 'total_entrades_' || $geto ] = $nou_total_entrades; |
| 62 | $dades[ 'ordinal_entrada_' || $geto ] = $ord_entrada; |
| 63 | } |
| 64 | |
| 65 | if ( $sentit == 'sortida' ) { |
| 66 | $qt_sortida = $args.qt; |
| 67 | $rebedora = $args.rebedora; |
| 68 | $ord_sortida_actual = $__dada( 'ordinal_sortida_' || $geto ) otherwise 0; |
| 69 | $ord_sortida = $ord_sortida_actual + 1; |
| 70 | $ref_sortida = 'sortida_' || $ord_sortida; |
| 71 | $nou_total_sortides = $total_sortides - $qt_sortida; |
| 72 | $dades[ $ref_sortida || '_data' ] = timestamp; |
| 73 | $dades[ $ref_sortida || '_qt' ] = $qt_sortida; |
| 74 | $dades[ $ref_sortida || '_actuant' ] = $adr__; |
| 75 | $dades[ $ref_sortida || '_rebedora' ] = $rebedora; |
| 76 | $dades[ 'total_sortides_' || $geto ] = $nou_total_sortides; |
| 77 | $dades[ 'ordinal_sortida_' || $geto ] = $ord_sortida; |
| 78 | } |
| 79 | |
| 80 | $registre.dades = $dades; |
| 81 | $registre.geto = $geto; |
| 82 | } |
| 83 | }", |
| 84 | "messages": [ |
| 85 | { |
| 86 | "if": "{ ! $provisio }", |
| 87 | "app": "data", |
| 88 | "payload": "{ $registre }" |
| 89 | }, |
| 90 | { |
| 91 | "if": "{ ! $provisio }", |
| 92 | "app": "payment", |
| 93 | "payload": { |
| 94 | "asset": "base", |
| 95 | "outputs": [ |
| 96 | { |
| 97 | "address": "{ $_Registre }", |
| 98 | "amount": "{ $__dada( 'Provisio' ) }" |
| 99 | } |
| 100 | ] |
| 101 | } |
| 102 | }, |
| 103 | { |
| 104 | "if": "{ ! $provisio AND $sentit == 'sortida' }", |
| 105 | "app": "payment", |
| 106 | "payload": { |
| 107 | "asset": "{ $id_geto }", |
| 108 | "outputs": [ |
| 109 | { |
| 110 | "address": "{ $rebedora }", |
| 111 | "amount": "{ $qt_sortida }" |
| 112 | } |
| 113 | ] |
| 114 | } |
| 115 | }, |
| 116 | { |
| 117 | "app": "state", |
| 118 | "state": "{ |
| 119 | if ( ! $provisio ) { |
| 120 | if ( $sentit == 'entrada' ) { |
| 121 | response[ $ref_entrada ] = |
| 122 | $qt_entrada || ' ' || $geto || ' de ' || $adr__; |
| 123 | response[ 'Total entrades en ' || $geto ] = $nou_total_entrades; |
| 124 | } |
| 125 | |
| 126 | if ( $sentit == 'sortida') { |
| 127 | response[ $ref_sortida ] = |
| 128 | $qt_sortida || ' ' || $geto || ' a ' || $rebedora; |
| 129 | response[ 'Total sortides en ' || $geto ] = $nou_total_sortides; |
| 130 | } |
| 131 | } |
| 132 | }" |
| 133 | } |
| 134 | ] |
| 135 | } |
| 136 | ] |