| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $nom_AA = 'Emissions'; |
| 6 | |
| 7 | |
| 8 | $_Registre = trigger.data._Registre; |
| 9 | |
| 10 | |
| 11 | $__dada = $refdada => |
| 12 | data_feed[[ oracles = $_Registre, feed_name = $refdada, ifnone = '' ]]; |
| 13 | |
| 14 | |
| 15 | $_Portal = trigger.address; |
| 16 | if ( $_Portal != trigger.address ) bounce ( 'Portal no reconegut' ); |
| 17 | |
| 18 | |
| 19 | $args = trigger.data; |
| 20 | $adr__ = trigger.initial_address; |
| 21 | $unitat = trigger.output[[ asset != base ]].asset; |
| 22 | $qt = trigger.output[[ asset = $unitat ]]; |
| 23 | $proces = $args.proces; |
| 24 | $dades = $args.dades otherwise {}; |
| 25 | $refgeto = 'geto_' || $args.nomgeto; |
| 26 | |
| 27 | |
| 28 | $dada_geto = $refval => $__dada( $refgeto || '_' || $refval ); |
| 29 | |
| 30 | $topall = $dada_geto( 'topall' ); |
| 31 | |
| 32 | if ( $proces == 'emissio' ) { |
| 33 | |
| 34 | |
| 35 | if ( $unitat != $args.id_estels ) |
| 36 | bounce ( 'Cal aportar-hi estels' ); |
| 37 | |
| 38 | |
| 39 | $_AUT_A = $dada_geto( '_AUT_A' ) otherwise ''; |
| 40 | $_AUT_B = $dada_geto( '_AUT_B' ) otherwise ''; |
| 41 | $_AUT_C = $dada_geto( '_AUT_C' ) otherwise ''; |
| 42 | $autoritzacio = $_AUT_A == $adr__ OR $_AUT_B == $adr__ OR $_AUT_C == $adr__; |
| 43 | |
| 44 | if ( ! $autoritzacio ) |
| 45 | bounce ( 'No autoritzada per administrar el getó' ); |
| 46 | |
| 47 | |
| 48 | $minim = $__dada( 'Generacio_Minima' ); |
| 49 | if ( $qt < $minim ) |
| 50 | bounce ( 'Cal aportar-hi si més no ' || $minim || ' estels' ); |
| 51 | |
| 52 | |
| 53 | $total_emissions = $__dada( 'total_emissions_' || $refgeto ) otherwise 0; |
| 54 | if ( $topall < $total_emissions + $qt ) |
| 55 | bounce ( 'Topall de ' || $topall || ' excedit. Total emissions: ' || $total_emissions ); |
| 56 | |
| 57 | |
| 58 | $idgeto = $dada_geto( 'id' ); |
| 59 | $_FOP = $dada_geto( '_FOP' ); |
| 60 | $factor_conversio = $dada_geto( 'factor_conversio' ); |
| 61 | $total_emissio = $qt * $factor_conversio; |
| 62 | $dades[ 'Total_emissions_' || $refgeto ] = $total_emissions + $total_emissio; |
| 63 | $ref_emissio = 'emissio_' || $args.ordinal; |
| 64 | $dades[ $ref_emissio || '_data' ] = timestamp; |
| 65 | $dades[ $ref_emissio || '_geto' ] = $refgeto; |
| 66 | $dades[ $ref_emissio || '_emissora' ] = $adr__; |
| 67 | } |
| 68 | |
| 69 | $registre = {}; |
| 70 | $registre.dades = $dades; |
| 71 | }", |
| 72 | "messages": [ |
| 73 | { |
| 74 | "if": "{ $proces == 'emissio' }", |
| 75 | "app": "payment", |
| 76 | "payload": { |
| 77 | "asset": "{ $idgeto }", |
| 78 | "outputs": [ |
| 79 | { |
| 80 | "address": "{ $_FOP }", |
| 81 | "amount": "{ $total_emissio }" |
| 82 | } |
| 83 | ] |
| 84 | } |
| 85 | }, |
| 86 | { |
| 87 | "app": "state", |
| 88 | "state": "{ |
| 89 | response[ 'Getó' ] = $refgeto; |
| 90 | |
| 91 | if ( $proces == 'emissio' ) { |
| 92 | response[ 'Emissió' ] = $args.ordinal; |
| 93 | response[ 'Adreça emissora' ] = $adr__; |
| 94 | response[ 'FOP destinatari' ] = $_FOP; |
| 95 | response[ 'Estels aportats' ] = $qt; |
| 96 | response[ 'Factor de conversió' ] = $factor_conversio; |
| 97 | response[ 'Unitats emeses' ] = $total_emissio; |
| 98 | response[ 'Total emissions getó' ] = $total_emissions; |
| 99 | } |
| 100 | |
| 101 | if ( $proces == 'dotacio' ) { |
| 102 | response[ 'Procés' ] = $proces; |
| 103 | } |
| 104 | |
| 105 | response[ 'Topall' ] = $topall; |
| 106 | }" |
| 107 | } |
| 108 | ] |
| 109 | } |
| 110 | ] |