Definition: [
"autonomous agent",
{
"messages": [
{
"app": "state",
"state": "{
$checkaddress = trigger.data.address;
if ( !$checkaddress ) // not sure how to check if data.address is an invalid address??? It especially cannot be a logicaladdress
bounce( 'input: { address : address , [ newaddress : newaddress ] , [ checkonly : false ] }');
$logicaladdress = var[ $checkaddress ];
if ( $logicaladdress ){ // EXISTS
$currentaddress = var[ $logicaladdress ];
// TRANSFER
$newaddress = trigger.data.newaddress;
if( $newaddress ){ // again need to check is an valid address??? again cannot be a logicaladdress
if( !trigger.data.notauthorized ){ // for now just allow anyone who paid OR maybe set this to some admin address
//if( var[ $currentaddress ][ 'author' ] == trigger.address ){ // how to get author of an external address???
// transfer to new address only if author of current address ONLY
var[ $logicaladdress ] = $newaddress;
var[ $newaddress ] = $logicaladdress;
if( trigger.data.checkonly ){
response[ "message" ] = "Address transferred from " || $currentaddress || " to " || $newaddress;
}
}
}else{
if( trigger.data.checkonly ) bounce( "You need to be author of " || $currentaddress || " in order to transfer to newaddress" );
}
// CHECK IF LATEST ADDRESS
if( trigger.data.checkonly ){
if( $checkaddress != $currentaddress ) bounce( "Please use latest address at " || $currentaddress );
else bounce( "This address is current" ); // let's bounce even thou computation is Success since we are checking only
}
$route = var[ $logicaladdress ];
}else{ // NEW
var[ "L" || $checkaddress ] = $checkaddress; // create logical address
var[ $checkaddress ] = "L" || $checkaddress; // set checkaddress to logical address
$route = var[ "L" || $checkaddress ];
}
response[ "message" ] = "Routing to " || $route;
}"
}
]
}
]