Unit ID
Tgoy75Yiw2OS1rLDZCdKI6NT7tTFG18KnaVSSkVMv8g=
Received
22.09.2019 21:16:57
Confirmation delay (full node)
4 minutes 53 seconds
Confirmation delay (light node)
7 minutes 27 seconds
Messages
Definition
Definition: [ "autonomous agent", { "init": "{ $ASSET = 'hd936lRtPN11pkgNv8qVnqN2OHMyAp8P/NsLp6KsuqA='; $FEE_LIMIT = 3000;//byte limit where AA starts paying trigger unit commissions //account;permission;byte; $A = 'a';$P = 'p';$B='b';$T='total_bytes';$S='last_storage_size';$L='last_address'; $trigger_cost = unit[trigger.unit].headers_commission + unit[trigger.unit].payload_commission; $addr = trigger.address; $last_addr = var[$L]; $balance = balance[base] - trigger.output[[asset=base]]; $free_mode = ($balance - var[$T]) > $FEE_LIMIT; $addr_key = $A||$addr; $byte_key = $B ||$addr; $last_key = $B ||$last_addr; $base_inp = trigger.output[[asset=base]]+($free_mode?$trigger_cost:0); $value = trigger.data.value; if(!trigger.data.approve AND $value AND (typeof($value) != 'number' OR $value <= 0)) bounce('Value param invalid'); $last_storage_size = var[$S] otherwise 0;//last execution storage size $storage_size = storage_size;//actual storage size $update_st = $last_storage_size != $storage_size; $diff_st = $last_storage_size - $storage_size; }", "messages": { "cases": [ { "if": "{ trigger.data.approve }", "init": "{ $approve = trigger.data.approve; $perm_key = $P || $addr || $approve; if(!var[$addr_key]) bounce('You have no funds'); if(!is_valid_address($approve) OR $approve == $addr) bounce('approve param invalid, specify address to approve instead of any other value'); if(!$value) bounce('Value param missing'); if(typeof($value) != 'number' OR $value < 0) bounce('Value param invalid'); }", "messages": [ { "app": "state", "state": "{ var[$perm_key] = $value; if(var[$perm_key] == 0) var[$perm_key] = false; var[$byte_key] += $base_inp; var[$T] += $base_inp; if($update_st){ var[$last_key] -= $diff_st; var[$S] = $sto;} var[$L] = trigger.address; response['message'] = 'Approved '||$approve||' to spend '||$value ||' from your account'; }" } ] }, { "if": "{ trigger.data.withdraw_bytes }", "init": "{ if(!var[$byte_key]) bounce('No bytes to withdraw'); if($update_st){ if($last_addr == $addr) $diff = $diff_st > 0?$diff_st:0; } $w_amount = var[$byte_key]-$diff; $w_par = is_integer(trigger.data.withdraw_bytes)?trigger.data.withdraw_bytes:0; }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$addr}", "amount": "{$w_amount+$base_inp-$w_par}" } ] } }, { "app": "state", "state": "{ $w_fee = unit[response_unit].headers_commission + unit[response_unit].payload_commission; if($w_fee != $w_par) bounce('Your withdraw costs '||$w_fee||' bytes, please use withdraw_bytes param to set exact fee'); var[$byte_key] -= $w_amount; var[$T] -= $w_amount; if(var[$byte_key] == 0) var[$byte_key] = false; if(var[$T] == 0) var[$T] = false; if($update_st AND $last_addr != $addr){ var[$last_key] -= $diff_st; var[$S] = $sto;} var[$L] = trigger.address; response['message'] = 'Withdrawn '||$w_amount||' bytes from your account'; }" } ] }, { "if": "{ trigger.data.deposit }", "init": "{ if(trigger.output[[asset!=base]].asset != 'none') $asset = trigger.output[[asset!=base]].asset; else bounce('You must deposit '||$ASSET); if($asset == 'ambiguous') bounce('Only 1 asset per tx'); if($asset != $ASSET) bounce('You must deposit '||$ASSET); $asset_inp = trigger.output[[asset!=base]]; }", "messages": [ { "app": "state", "state": "{ var[$addr_key] += $asset_inp; var[$byte_key] += $base_inp; var[$T] += $base_inp; if($update_st){ var[$last_key] -= $diff_st; var[$S] = $sto;} var[$L] = trigger.address; response['message'] = 'Added '||$asset_inp||' to your account'; }" } ] }, { "if": "{ trigger.data.withdraw }", "init": "{ if(!var[$addr_key]) bounce('Nothing to withdraw'); $max_w = var[$addr_key]-(var[$addr_key] % 1); if(!$value) bounce('Value param missing, max to withdraw '||$max_w) ; $w_amount = $value - ($value % 1); if($w_amount <= 0) bounce('Max to withdraw '||$max_w); if($w_amount > $max_w) bounce('Not enough funds, max to withdraw '||$max_w); }", "messages": [ { "app": "payment", "payload": { "asset": "{$ASSET}", "outputs": [ { "address": "{$addr}", "amount": "{$w_amount}" } ] } }, { "app": "state", "state": "{ $w_fee = unit[response_unit].headers_commission + unit[response_unit].payload_commission; var[$addr_key] -= $w_amount; if(var[$addr_key] == 0) var[$addr_key]=false; var[$byte_key] += $base_inp-$w_fee; var[$T] += $base_inp-$w_fee; if($update_st){ var[$last_key]-=$diff_st; var[$S]=$sto;} var[$L] = trigger.address; response['message'] = 'Withdrawn '||$w_amount||' from your account'; }" } ] }, { "if": "{ trigger.data.transfer }", "init": "{ $to = trigger.data.transfer; if(!is_valid_address($to) OR $to == $addr) bounce('transfer param invalid, specify address to instead of any other value'); if(!var[$addr_key]) bounce('No funds found'); if(!$value) bounce('Value param missing'); if($value > var[$addr_key]) bounce('You have max '||var[$addr_key]); }", "messages": [ { "app": "state", "state": "{ var[$A || $to] += $value; var[$addr_key] -= $value; if(var[$addr_key] == 0) var[$addr_key] = false; var[$byte_key] += $base_inp; var[$T] += $base_inp; if($update_st){ var[$last_key] -= $diff_st; var[$S] = $sto;} var[$L] = trigger.address; response['message'] = 'Transferred '||$value||' to '||$to; }" } ] }, { "if": "{ trigger.data.transfer_from }", "init": "{ $from = trigger.data.transfer_from; $to = trigger.data.to; $from_key = $A || $from; $perm_key = $P || $from || $addr; if(!is_valid_address($from)) bounce('transfer_from param invalid, specify from address instead of any other value'); if(!$to) bounce('To param missing'); if(!is_valid_address($to)) bounce('To param invalid'); if(!var[$from_key]) bounce('Account have no funds'); if(!$value) bounce('Value param missing'); if(!var[$perm_key]) bounce('Not allowed to spend'); if(var[$perm_key] < $value) bounce('You can spend max '||var[$perm_key]); if(var[$from_key] < $value) bounce('Account have '||var[$from_key]); }", "messages": [ { "app": "state", "state": "{ var[$A || $to] += $value; var[$from_key] -= $value; if(var[$from_key] == 0) var[$from_key] = false; var[$perm_key] -= $value; if(var[$perm_key] == 0) var[$perm_key] = false; var[$byte_key] += $base_inp; var[$T] += $base_inp; if($update_st){ var[$last_key] -= $diff_st; var[$S] = $sto;} var[$L] = trigger.address; response['message'] = 'Transferred '||$value||' to '||$to; }" } ] }, { "messages": [ { "app": "state", "state": "{ if(trigger.output[[asset!=base]].asset != 'none') bounce('To deposit an asset, use deposit param'); if($update_st){ var[$last_key] -= $diff_st; var[$S] = $sto;} var[$L] = trigger.address; response['usage'] = 'Send param = 1 for continue.'; response['accepted_params'] = 'deposit, withdraw, transfer, transfer_from, approve, withdraw_bytes'; response['message'] = 'Received bytes for funding AA operation, thaanks!'; }" } ] } ] } } ]
Technical information
Fees:
7,421 bytes
(353 headers, 7068 payload)
Level:1071881
Witnessed level:1071873
Main chain index:1070646
Latest included mc index:1070645
Status:stable/confirmed/final