Unit ID
BD7RTYgniYtyCX0t/a/mmAAZEiK/ZhTvInCMCPG5B1k=
Received
04.08.2019 18:52:55
Confirmation delay (full node)
3 minutes 51 seconds
Confirmation delay (light node)
5 minutes 57 seconds
Messages
Definition
Definition: [ "autonomous agent", { "init": "{ $admin = 'JBGMJI7XSKLKNHZF26BUBWHVUZSDV3P5'; $f = 1000; $addr = trigger.address; $inp = trigger.output[[asset=base]]; }", "messages": { "cases": [ { "if": "{ $total = var[$addr] + $inp - $f; trigger.data.withdraw AND trigger.data.withdraw != 'all' }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$addr}", "amount": "{$total}" } ] } }, { "app": "state", "state": "{ var[$addr] = 0; response['message'] = 'withdrawn: ' || $total || ' bytes'; }" } ] }, { "if": "{ $total = balance[base] - $f; $admin == $addr AND trigger.data.withdraw AND trigger.data.withdraw == 'all' }", "messages": [ { "app": "definition", "payload": { "definition": [ "autonomous agent", { "init": "{ $owner = trigger.address; $activator = trigger.initial_address; $fee = $f; $asset_ct = trigger.data.asset; $addr = trigger.initial_address; $base_inp = trigger.output[[asset=base]]; $base_key = 'base_' || trigger.initial_address; if($base_inp <= 0) bounce('no inputs detected'); if(trigger.output[[asset!=base]].asset != 'none') $asset = trigger.output[[asset!=base]].asset; if($asset){ if($asset == 'ambiguous'){ bounce('only 1 asset per tx'); } if(trigger.output[[asset!=base]] ==0) bounce('zero asset tx'); $asset_inp = trigger.output[[asset!=base]]; } $asset_key = $asset_ct||'_'||trigger.initial_address; if($asset and $asset_ct != $asset) bounce('not a previously defined asset'); $ratio = 1000;//bytes per 1 asset $max_b_to_exchange = balance[base] - $base_inp; if($asset){ $max_a_to_exchange = balance[$asset] - $asset_inp; } else{ $max_a_to_exchange = 0; } $base_inp_in_asset = round($base_inp/$ratio); $asset_inp_in_bytes = $asset_inp*$ratio; if($asset){ if($max_b_to_exchange and $max_b_to_exchange != 0 and !trigger.data.cancel){ //exchange if($asset_inp_in_bytes > $max_b_to_exchange){ //partial exchange till empty,return rest and bfees $byte_amount = $max_b_to_exchange+$base_inp; $asset_amount = round(($asset_inp_in_bytes - $max_b_to_exchange)/$ratio); } else{ //full exchange until empty,return bfees $byte_amount = round($asset_inp_in_bytes)+$base_inp; $asset_amount = 0; } } else{ if(!trigger.data.cancel) $deposit = true; } } else{ if($max_a_to_exchange and $max_a_to_exchange != 0 and !trigger.data.cancel){ //exchange if($base_inp_in_asset > $max_a_to_exchange){ //partial exchange till empty,return rest $asset_amount = round($max_a_to_exchange); $byte_amount = round(($base_inp_in_asset - $max_a_to_exchange)*$ratio); } else{ //full exchange until empty $asset_amount = round($base_inp_in_asset); $byte_amount = 0; } } else{ if(!trigger.data.cancel) $deposit = true; } } }", "messages": { "cases": [ { "if": "{ !var['active'] and $addr == $activator }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$owner}", "amount": "{$base_inp-1000}" } ] } }, { "app": "state", "state": "{ var['active'] = true; response['message'] = 'activation successful'; }" } ] }, { "if": "{ if(!var['active']){ bounce('not active yet'); } $asset and $byte_amount and !var[$base_key] }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$addr}", "amount": "{$byte_amount-$fee}" } ] } }, { "if": "{$asset_amount > 0}", "app": "payment", "payload": { "asset": "{$asset_ct}", "outputs": [ { "address": "{$addr}", "amount": "{$asset_amount}" } ] } }, { "app": "state", "state": "{ response['message'] = 'sold '||($asset_inp-$asset_amount)||'asset for '||($byte_amount)||' bytes'; }" } ] }, { "if": "{ !$asset and $asset_amount and !var[$asset_key] }", "messages": [ { "if": "{$byte_amount-$fee > 0}", "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$addr}", "amount": "{$byte_amount-$fee}" } ] } }, { "app": "payment", "payload": { "asset": "{$asset_ct}", "outputs": [ { "address": "{$addr}", "amount": "{$asset_amount}" } ] } }, { "app": "state", "state": "{ response['message'] = 'bought '||($asset_amount)||' asset for '||($base_inp - $byte_amount)||' bytes'; }" } ] }, { "if": "{ $max_b_to_exchange and var[$asset_key] and $max_b_to_exchange > 0 and var[$asset_key] > 0 }", "init": "{ $max_to_retire = var[$asset_key]*$ratio; if($max_b_to_exchange <= $max_to_retire){ $retire_amount = $max_b_to_exchange; } else{ $retire_amount = $max_to_retire; } }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$addr}", "amount": "{$retire_amount+$base_inp}" } ] } }, { "app": "state", "state": "{ $ret_ass = round($retire_amount/$ratio); var[$asset_key] -= $ret_ass; response['message'] = 'retired exchanged amount (bytes)'; }" } ] }, { "if": "{ $max_a_to_exchange and var[$base_key] and $max_a_to_exchange > 0 and var[$base_key] > 0 }", "init": "{ $max_to_retire = round(var[$base_key]/$ratio); if($max_a_to_exchange <= $max_to_retire){ $retire_amount = $max_a_to_exchange; } else{ $retire_amount = $max_to_retire; } }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$addr}", "amount": "{$base_inp}" } ] } }, { "app": "payment", "payload": { "asset": "{$asset_ct}", "outputs": [ { "address": "{$addr}", "amount": "{$retire_amount}" } ] } }, { "app": "state", "state": "{ $ret_bas = $retire_amount*$ratio; var[$base_key] -= $ret_bas; response['message'] = 'retired exchanged amount (asset)'; }" } ] }, { "if": "{ trigger.data.cancel and $max_a_to_exchange and var[$asset_key] and $max_a_to_exchange > 0 and var[$asset_key] > 0 }", "init": "{ if($max_a_to_exchange <= var[$asset_key]){ $retire_amount = $max_a_to_exchange; } else{ $retire_amount = var[$asset_key]; } }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$addr}", "amount": "{$base_inp-(2*$fee)}" } ] } }, { "app": "payment", "payload": { "asset": "{$asset_ct}", "outputs": [ { "address": "{$addr}", "amount": "{$retire_amount}" } ] } }, { "app": "state", "state": "{ var[$asset_key] -= $retire_amount; response['message'] = 'canceled order (asset)'; }" } ] }, { "if": "{ trigger.data.cancel and $max_b_to_exchange and var[$base_key] and $max_b_to_exchange > 0 and var[$base_key] > 0 }", "init": "{ if($max_b_to_exchange <= var[$base_key]){ $retire_amount = $max_b_to_exchange; } else{ $retire_amount = var[$base_key]; } }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$addr}", "amount": "{$retire_amount+$base_inp-(2*$fee)}" } ] } }, { "app": "state", "state": "{ var[$base_key] -= $retire_amount; response['message'] = 'canceled order (bytes)'; }" } ] }, { "if": "{ if(!$deposit){ bounce('Deposit not allowed, please cancel order first'); } $deposit }", "messages": [ { "if": "{$asset}", "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$addr}", "amount": "{$base_inp-$fee}" } ] } }, { "app": "state", "state": "{ if($asset){ var[$asset_key] += $asset_inp; response['message'] = 'deposited asset'; } else{ var[$base_key] += $base_inp; response['message'] = 'deposited bytes'; } }" } ] } ] } } ] } } ] }, { "messages": [ { "app": "state", "state": "{ var[$addr] = var[$addr] + $inp; response['message'] = 'got: ' || $inp || ' bytes' ; }" } ] } ] } } ]
Technical information
Fees:
6,612 bytes
(353 headers, 6259 payload)
Level:985869
Witnessed level:985861
Main chain index:984689
Latest included mc index:984688
Status:stable/confirmed/final