Unit ID
fBAZfpqGEmekIXJJaAJCnbphz9NlPkrBVoZwsYjXGPM=
Received
05.10.2019 17:46:44
Confirmation delay (full node)
4 minutes 58 seconds
Confirmation delay (light node)
7 minutes 56 seconds
Messages
Definition
Definition: [ "autonomous agent", { "bounce_fees": { "base": 10000 }, "init": "{ $howto = "To store asset, choose a secret phrase (max length of 1024 char), pass it through a sha256 hasher. Send the funds with 'store = true' + 'hash_of_my_secret = <hash of secret phrase>. To withdraw use the hash and 'withdraw = true' then follow messages (the withdraw will be available for you only during 1 hours, you will have to provide your secret phrase during this period"; }", "messages": { "cases": [ { "if": "{ !!trigger.data.store and !!trigger.data.hash_of_my_secret }", "init": "{ if (!!var[trigger.data.hash_of_my_secret]) // already existing in state bounce ("This hash already exist, choose another secret phrase to hash"); }", "messages": [ { "app": "state", "state": "{ $non_byte = trigger.output[[asset!=base]].asset; // return the asset if different than bytes $asset = ($non_byte != "none") ? $non_byte : "base"; // the asset is the non-byte if existing $amount = trigger.output[[asset=$asset]].amount; // get the amount of the asset. var[trigger.data.hash_of_my_secret] = $amount || " " || $asset; response['message'] = "Safely stored, to withdraw later, use 'withdraw = true' + 'hash_of_my_secret = <hash of secret phrase> and wait for messages in payment"; }" } ] }, { "if": "{ !!trigger.data.withdraw and !!trigger.data.hash_of_my_secret }", "init": "{ if (!var[trigger.data.hash_of_my_secret]) // not existing in state bounce ("This hash do not exist"); if (!!var[trigger.data.hash_of_my_secret||"_withdrawer"]) if (timestamp < var[trigger.data.hash_of_my_secret||"_Dead_line_timestamp"]) bounce ("There is a withdraw request in progress"); // determine a period in which this address can provide the secret phrase $dead_line = timestamp + 60*60 ; // add 1 hour }", "messages": [ { "app": "data", "payload": { "message": "{ "You have until "|| timestamp_to_string($dead_line, 'datetime') ||" to provide the secret key" }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ trigger.initial_address }", "amount": "{ 5 }" } ] } }, { "app": "state", "state": "{ if (!!var[trigger.data.hash_of_my_secret||"_withdrawer"]) // if outdated request exist var[var[trigger.data.hash_of_my_secret||"_withdrawer"]] = false; // remove it var[trigger.data.hash_of_my_secret||"_withdrawer"] = trigger.initial_address; var[trigger.data.hash_of_my_secret||"_Dead_line_timestamp"] = $dead_line; var[trigger.initial_address] = trigger.data.hash_of_my_secret; // initial to be able to work through other AA as well response['message'] = "You have until "|| timestamp_to_string($dead_line, 'datetime') ||" to provide the secret key"; }" } ] }, { "if": "{ !!trigger.data.secret_phrase }", "init": "{ // waiting secret key from this address? if (!var[trigger.initial_address]) bounce ("Attention!, I'm not ready to receive your secret phrase, don't send it or it can compromised"); $hash = var[trigger.initial_address]; // check if it is not to late if (timestamp > var[$hash||"_Dead_line_timestamp"]) bounce ("Too late! don't send you secret phrase!, use 'withdraw' + 'hash_of_my_secret' again"); // check that the secret phrase is valid: if (sha256(trigger.data.secret_phrase) != $hash) bounce ("The secret phrase hash does not match with the one previously given"||$hash||" "||sha256(trigger.data.secret_phrase)); // prepare asset and amount to withdraw $separator_position = index_of(var[$hash], " "); $withdraw_amount = substring(var[$hash], 0, $separator_position); $withdraw_asset = substring(var[$hash], $separator_position); }", "messages": [ { "app": "payment", "payload": { "asset": "{ 'base' }", "outputs": [ { "address": "{ trigger.initial_address }", "amount": "{ $withdraw_amount }" } ] } }, { "app": "state", "state": "{ response['message'] = $withdraw_amount || " Funds sent "|| $withdraw_asset; // delete all states var[trigger.initial_address] = false; var[trigger.initial_address||"_Dead_line_timestamp"] = false; var[$hash||"_withdrawer"]=false; var[$hash||"_Dead_line_timestamp"]=false; response['message'] = "Funds sent"; }" } ] }, { "messages": [ { "app": "state", "state": "{ bounce ($howto); }" } ] } ] } } ]
Technical information
Fees:
5,381 bytes
(353 headers, 5028 payload)
Level:1093244
Witnessed level:1093237
Main chain index:1092005
Latest included mc index:1092004
Status:stable/confirmed/final