-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDANAA.Oscript.txt
93 lines (86 loc) · 3.38 KB
/
DANAA.Oscript.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
[
/*
# DANAA
Dynamic Assets Names Autonomous Agent (for Obyte)
## Use cases:
Let you register a nicer name for your assets.
* Add a new entry: set at minimum: 'unit_id', 'shortName', 'ticker' and 'decimals';
* Change one of your exisiting entries: set at minimum: 'unit_id', 'shortName', 'ticker' and 'decimals';
* Get the nice name from another aa: var["<DANAA_address>"][<asset id>_shortName];
## State variables
* <unit_id>_shortName: contains the new_name and can be used by other AA to show this nice name;
* <unit_id>_issuer: address of the user that issued the asset; we have to trust the address that register the asset to be the issuer as we cannot access any field of an units;
* <unit_id>_ticker: ticker choosen to represente the asset;
* <unit_id>_decimals: number of decimal possible with this asset;
optionals:
* <unit_id>_name: full name of the asset, by default concatenation of shortName and Issuer;
* <unit_id>_description: short description, by default "Asset called +$shortName+ issued by +$issuer+, with +$decimals+ decimals available. Its ticker is +$ticker+ and it is defined by the unit '+$unit_id+'."
## TODO
* In the future if it possible to access the fields of an unit, we could allow only the author of the asset unit to be able to choose a name for its asset.
*/
"autonomous agent",{
init: "{
$aa_name = "DANAA"; // Dynamic Asset Names Autonomous Agent;
$owner = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; // could withdraw the dust is calculable.
$unit_id = trigger.data.unit_id;
$short_name = trigger.data.short_name;
$ticker = trigger.data.ticker;
$issuer = trigger.address; // preferrably the address to be able to modify it
$name = trigger.data.name otherwise $short_name||" by "||$issuer;
}",
messages: {
cases: [
{ // 1. adding a new entry
if: "{ $unit_id and $short_name and $ticker}",
init: "{
// check decimal
if (trigger.data.decimals)
{
if (trigger.data.decimals < 0)
bounce ("'decimals' must be > 0 !");
else
$decimals = trigger.data.decimals;
}
else
$decimals = 0;
// if exist must be issuer.
if (var[$unit_id])
if (trigger.address != var[$unit_id||"_issuer"])
bounce ("Already registered and not by you !");
$description = trigger.data.description otherwise "Asset called "||$short_name||" issued by "||$issuer||", with "||$decimals||" decimals available. Its ticker is "||$ticker||" and it is defined by the unit '"||$unit_id||"'.";
}",
messages: [
{ // return fee to user
app: 'payment', payload: {
asset: "{'base'}",
outputs: [{
address: "{$issuer}",
amount: "{trigger.output[[asset=base]] - 1000}"
}]
}
},
{
app: "state", state: "{
var[$unit_id||"_shortName"] = $short_name;
var[$unit_id||"_issuer"] = $issuer;
var[$unit_id||"_name"] = $name;
var[$unit_id||"_ticker"] = $ticker;
var[$unit_id||"_decimals"] = $decimals;
var[$unit_id||"_description"] = $description;
}"
}
]
},
{ // default case
messages: [
{
app: "state", state: "{
bounce ("Specify the following fields: 'unit_id', 'shortname', 'ticker', 'decimal' and optionaly 'name, and description' that can be by default built from the previous fields.");
}"
}
]
}
]
}
}
]