1 | | - | {-# STDLIB_VERSION 3 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | func getNumberByKey (key) = match getInteger(this, key) { |
---|
5 | | - | case a: Int => |
---|
6 | | - | a |
---|
7 | | - | case _ => |
---|
8 | | - | 0 |
---|
9 | | - | } |
---|
10 | | - | |
---|
11 | | - | |
---|
12 | | - | func getStringByKey (key) = match getString(this, key) { |
---|
13 | | - | case a: String => |
---|
14 | | - | a |
---|
15 | | - | case _ => |
---|
16 | | - | "" |
---|
17 | | - | } |
---|
18 | | - | |
---|
19 | | - | |
---|
20 | | - | func getBoolByKey (key) = match getBoolean(this, key) { |
---|
21 | | - | case a: Boolean => |
---|
22 | | - | a |
---|
23 | | - | case _ => |
---|
24 | | - | false |
---|
25 | | - | } |
---|
26 | | - | |
---|
27 | | - | |
---|
28 | | - | func getNumberByAddressAndKey (address,key) = match getInteger(addressFromStringValue(address), key) { |
---|
29 | | - | case a: Int => |
---|
30 | | - | a |
---|
31 | | - | case _ => |
---|
32 | | - | 0 |
---|
33 | | - | } |
---|
34 | | - | |
---|
35 | | - | |
---|
36 | | - | func getStringByAddressAndKey (address,key) = match getString(address, key) { |
---|
37 | | - | case a: String => |
---|
38 | | - | a |
---|
39 | | - | case _ => |
---|
40 | | - | "" |
---|
41 | | - | } |
---|
42 | | - | |
---|
43 | | - | |
---|
44 | | - | let NeutrinoAssetIdKey = "3KFXBGGLCjA5Z2DuW4Dq9fDDrHjJJP1ZEkaoajSzuKsC" |
---|
45 | | - | |
---|
46 | | - | let NeutrinoContractKey = "3n7vYRqT664Gwk9F1i5yM11opnuaH4yABXXnsxP6kxUQ" |
---|
47 | | - | |
---|
48 | | - | let BalanceKey = "rpd_balance" |
---|
49 | | - | |
---|
50 | | - | let ControlContractKey = "control_contract" |
---|
51 | | - | |
---|
52 | | - | let AdminsKey = "admins" |
---|
53 | | - | |
---|
54 | | - | func getUserBalanceKey (owner,assetId) = ((((BalanceKey + "_") + assetId) + "_") + owner) |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | func getContractBalanceKey (assetId) = ((BalanceKey + "_") + assetId) |
---|
58 | | - | |
---|
59 | | - | |
---|
60 | | - | func getExpireProposalKey (hash) = (("proposal_expire" + "_") + hash) |
---|
61 | | - | |
---|
62 | | - | |
---|
63 | | - | func getOwnerProposalKey (hash) = (("proposal_owner" + "_") + hash) |
---|
64 | | - | |
---|
65 | | - | |
---|
66 | | - | func getArgumentsProposalKey (hash) = (("proposal_arguments" + "_") + hash) |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | func getVoteKey (owner,hash) = (((("proposal_vote" + "_") + owner) + "_") + hash) |
---|
70 | | - | |
---|
71 | | - | |
---|
72 | | - | func convertJsonArrayToList (jsonArray) = split(jsonArray, ",") |
---|
73 | | - | |
---|
74 | | - | |
---|
75 | | - | let neutrinoContract = addressFromStringValue(getStringByKey(NeutrinoContractKey)) |
---|
76 | | - | |
---|
77 | | - | let controlContract = addressFromStringValue(getStringByAddressAndKey(neutrinoContract, ControlContractKey)) |
---|
78 | | - | |
---|
79 | | - | let neutrinoAssetId = fromBase58String(getStringByAddressAndKey(neutrinoContract, NeutrinoAssetIdKey)) |
---|
80 | | - | |
---|
81 | | - | func getContractBalance (assetId) = getNumberByKey(getContractBalanceKey(assetId)) |
---|
82 | | - | |
---|
83 | | - | |
---|
84 | | - | func getUserBalance (owner,assetId) = getNumberByKey(getUserBalanceKey(owner, assetId)) |
---|
85 | | - | |
---|
86 | | - | |
---|
87 | | - | func getExpireProposal (hash) = getNumberByKey(getExpireProposalKey(hash)) |
---|
88 | | - | |
---|
89 | | - | |
---|
90 | | - | func getOwnerProposal (hash) = getStringByKey(getOwnerProposalKey(hash)) |
---|
91 | | - | |
---|
92 | | - | |
---|
93 | | - | func getArgumentsProposal (hash) = getStringByKey(getArgumentsProposalKey(hash)) |
---|
94 | | - | |
---|
95 | | - | |
---|
96 | | - | func getVote (owner,hash) = getStringByKey(getVoteKey(owner, hash)) |
---|
97 | | - | |
---|
98 | | - | |
---|
99 | | - | @Callable(i) |
---|
100 | | - | func lockNeutrino () = { |
---|
101 | | - | let pmt = extract(i.payment) |
---|
102 | | - | if ((pmt.assetId != neutrinoAssetId)) |
---|
103 | | - | then throw("can use neutrino") |
---|
104 | | - | else { |
---|
105 | | - | let account = toString(i.caller) |
---|
106 | | - | let assetIdString = toBase58String(value(pmt.assetId)) |
---|
107 | | - | WriteSet([DataEntry(getContractBalanceKey(assetIdString), (getContractBalance(assetIdString) + pmt.amount)), DataEntry(getUserBalanceKey(account, assetIdString), (getUserBalance(account, assetIdString) + pmt.amount))]) |
---|
108 | | - | } |
---|
109 | | - | } |
---|
110 | | - | |
---|
111 | | - | |
---|
112 | | - | |
---|
113 | | - | @Callable(i) |
---|
114 | | - | func unlockNeutrino (unlockAmount,assetIdString) = { |
---|
115 | | - | let account = toString(i.caller) |
---|
116 | | - | let assetId = fromBase58String(assetIdString) |
---|
117 | | - | let balance = (getUserBalance(account, assetIdString) - unlockAmount) |
---|
118 | | - | if ((0 > balance)) |
---|
119 | | - | then throw("invalid amount") |
---|
120 | | - | else if ((assetId != neutrinoAssetId)) |
---|
121 | | - | then throw("can use neutrino") |
---|
122 | | - | else ScriptResult(WriteSet([DataEntry(getContractBalanceKey(assetIdString), (getContractBalance(assetIdString) - unlockAmount)), DataEntry(getUserBalanceKey(account, assetIdString), balance)]), TransferSet([ScriptTransfer(addressFromStringValue(account), unlockAmount, neutrinoAssetId)])) |
---|
123 | | - | } |
---|
124 | | - | |
---|
125 | | - | |
---|
126 | | - | |
---|
127 | | - | @Callable(i) |
---|
128 | | - | func vote (hash,indexArgument) = { |
---|
129 | | - | let arguments = split(getArgumentsProposal(hash), ",") |
---|
130 | | - | let argument = arguments[indexArgument] |
---|
131 | | - | if ((height > getExpireProposal(hash))) |
---|
132 | | - | then throw("proposal is expired") |
---|
133 | | - | else WriteSet([DataEntry(getVoteKey(toString(i.caller), hash), argument)]) |
---|
134 | | - | } |
---|
135 | | - | |
---|
136 | | - | |
---|
137 | | - | |
---|
138 | | - | @Callable(i) |
---|
139 | | - | func createProposal (arguments,expairHeight) = { |
---|
140 | | - | let hash = toBase58String(keccak256(((toBytes(arguments) + toBytes(expairHeight)) + i.callerPublicKey))) |
---|
141 | | - | if ((getOwnerProposal(hash) != "")) |
---|
142 | | - | then throw("proposal is exist") |
---|
143 | | - | else WriteSet([DataEntry(getExpireProposalKey(hash), expairHeight), DataEntry(getOwnerProposalKey(hash), toString(i.caller)), DataEntry(getArgumentsProposalKey(hash), arguments)]) |
---|
144 | | - | } |
---|
145 | | - | |
---|
146 | | - | |
---|
| 1 | + | # no script |
---|