Unit ID
SMYYc/rz7y6aIRfz/h8ks4He6ssxuWxFm2BGxELQVp0=
Received
09.12.2021 03:01:44
Confirmation delay (full node)
3 minutes 36 seconds
Confirmation delay (light node)
7 minutes 3 seconds
Messages
Definition
Definition: [ "autonomous agent", { "getters": "{ $getPrice = ()=>{ $priceStr = data_feed[[oracles=params.issuer, feed_name=this_address, ifseveral="last", type="string"]]; $chunks = split($priceStr, " "); $price = $chunks[0]; return $price; }; $getPriceAsset = ()=>{ $priceStr = data_feed[[oracles=params.issuer, feed_name=this_address, ifseveral="last", type="string"]]; $chunks = split($priceStr, " "); $asset = $chunks[0]; return $asset; }; $getSales = ()=>var["sales"]; }", "init": "{ $CT_ADDRESS = "ZIT3YPDTLGAO7MVO2ONNDMSEYS2VELX6"; $OWNER = params.issuer; $LICENSE_ASSET = var["licenseAsset"]; if ($LICENSE_ASSET){ $priceStr = data_feed[[oracles=$OWNER, feed_name=this_address, ifseveral="last", type="string"]]; $chunks = split($priceStr, " "); require(length($chunks) == 2, "Malformed data_feed. It should have only 2 items"); $PRICE = $chunks[0]; require(is_integer($PRICE), "Price must be an integer"); require($PRICE > 0, "Price must be positive"); require(is_valid_amount($PRICE), "Price must be a valid amount"); $PRICE_ASSET = $chunks[1]; require(asset[$PRICE_ASSET].exists, "Price asset does not exist"); } $method = trigger.data["method"]; response["method"] = $method; response["who"] = trigger.data["to"] OTHERWISE trigger.address; $CUT = 0.03; if ($LICENSE_ASSET AND NOT $method) bounce("method field is mandatory"); }", "messages": { "cases": [ { "if": "{NOT $LICENSE_ASSET}", "init": "{ response["method"] = "initialize"; }", "messages": [ { "if": "{params.cap}", "app": "asset", "payload": { "is_private": false, "cap": "{params.cap OTHERWISE 0}", "is_transferrable": "{NOT NOT params.tradeable}", "auto_destroy": false, "fixed_denominations": false, "issued_by_definer_only": true, "cosigned_by_definer": false, "spender_attested": false } }, { "if": "{NOT params.cap}", "app": "asset", "payload": { "is_private": false, "is_transferrable": "{NOT NOT params.tradeable}", "auto_destroy": false, "fixed_denominations": false, "issued_by_definer_only": true, "cosigned_by_definer": false, "spender_attested": false } }, { "app": "state", "state": "{ var["licenseAsset"] = response_unit; }" } ] }, { "if": "{trigger.address == $OWNER AND $method == "payout"}", "messages": { "cases": [ { "if": "{$method == "payout"}", "messages": [ { "app": "payment", "payload": { "asset": "{trigger.data.asset OTHERWISE $PRICE_ASSET}", "outputs": [ { "address": "{$OWNER}" } ] } } ] } ] } }, { "if": "{$method == "buy"}", "init": "{ $copies = floor(trigger.output[[asset=$PRICE_ASSET]]/$PRICE, 0); require($copies > 0, "You cannot buy less than 1 license"); $hasReferral = (trigger.data["r"] AND is_valid_address(trigger.data["r"])); $cut = $hasReferral ? $CUT/2 : $CUT; $cutAmount = round(trigger.output[[asset=$PRICE_ASSET]] * $cut, 0); response["amount"] = $copies; }", "messages": [ { "app": "payment", "payload": { "asset": "{$LICENSE_ASSET}", "outputs": [ { "address": "{trigger.data["to"] OTHERWISE trigger.initial_address}", "amount": "{$copies}" } ] } }, { "app": "payment", "payload": { "asset": "{$PRICE_ASSET}", "outputs": [ { "address": "{$CT_ADDRESS}", "amount": "{$cutAmount}" }, { "if": "{$hasReferral}", "address": "{trigger.data["r"]}", "amount": "{$cutAmount}" } ] } }, { "app": "state", "state": "{ var["sales"]+=1; }" } ] } ] } } ]
Technical information
Fees:
4,152 bytes
(452 headers, 3700 payload)
Level:2503566
Witnessed level:2503559
Main chain index:2483676
Latest included mc index:2483675
Status:stable/confirmed/final