1 | | - | {-# STDLIB_VERSION 3 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let WAVES = "WAVES" |
---|
5 | | - | |
---|
6 | | - | let IntType = 0 |
---|
7 | | - | |
---|
8 | | - | let StringType = 1 |
---|
9 | | - | |
---|
10 | | - | let BytesType = 2 |
---|
11 | | - | |
---|
12 | | - | func getNumberByKey (key) = match getInteger(this, key) { |
---|
13 | | - | case v: Int => |
---|
14 | | - | v |
---|
15 | | - | case _ => |
---|
16 | | - | 0 |
---|
17 | | - | } |
---|
18 | | - | |
---|
19 | | - | |
---|
20 | | - | func getBytesByKey (key) = match getBinary(this, key) { |
---|
21 | | - | case v: ByteVector => |
---|
22 | | - | v |
---|
23 | | - | case _ => |
---|
24 | | - | base58'2CsAf' |
---|
25 | | - | } |
---|
26 | | - | |
---|
27 | | - | |
---|
28 | | - | func getStringByKey (key) = match getString(this, key) { |
---|
29 | | - | case v: String => |
---|
30 | | - | v |
---|
31 | | - | case _ => |
---|
32 | | - | "" |
---|
33 | | - | } |
---|
34 | | - | |
---|
35 | | - | |
---|
36 | | - | func getStringByAddressAndKey (address,key) = match getString(address, key) { |
---|
37 | | - | case v: String => |
---|
38 | | - | v |
---|
39 | | - | case _ => |
---|
40 | | - | "" |
---|
41 | | - | } |
---|
42 | | - | |
---|
43 | | - | |
---|
44 | | - | func getNumberByAddressAndKey (address,key) = match getInteger(address, key) { |
---|
45 | | - | case v: Int => |
---|
46 | | - | v |
---|
47 | | - | case _ => |
---|
48 | | - | 0 |
---|
49 | | - | } |
---|
50 | | - | |
---|
51 | | - | |
---|
52 | | - | let OraclesKey = "oracles" |
---|
53 | | - | |
---|
54 | | - | let SubscriberAddressKey = "subscriber_address" |
---|
55 | | - | |
---|
56 | | - | let TypeKey = "type" |
---|
57 | | - | |
---|
58 | | - | let GravityContractKey = "gravity_contract" |
---|
59 | | - | |
---|
60 | | - | let BftCoefficientKey = "bft_coefficient" |
---|
61 | | - | |
---|
62 | | - | let LastHeightKey = "last_height" |
---|
63 | | - | |
---|
64 | | - | let LastRoundKey = "last_round" |
---|
65 | | - | |
---|
66 | | - | let LastPulseIdKey = "last_pulse_id" |
---|
67 | | - | |
---|
68 | | - | func getHashDataKey (pulseId) = ("data_hash_" + toString(pulseId)) |
---|
69 | | - | |
---|
70 | | - | |
---|
71 | | - | func getHeightByPulseKey (pulseId) = ("height_" + toString(pulseId)) |
---|
72 | | - | |
---|
73 | | - | |
---|
74 | | - | func ConsulsKey (round) = ("consuls_" + toString(round)) |
---|
75 | | - | |
---|
76 | | - | |
---|
77 | | - | let oracles = split(getStringByKey(OraclesKey), ",") |
---|
78 | | - | |
---|
79 | | - | let bftCoefficient = getNumberByKey(BftCoefficientKey) |
---|
80 | | - | |
---|
81 | | - | let gracityContract = addressFromStringValue(getStringByKey(GravityContractKey)) |
---|
82 | | - | |
---|
83 | | - | let lastGravityRound = getNumberByAddressAndKey(gracityContract, LastRoundKey) |
---|
84 | | - | |
---|
85 | | - | let consuls = split(getStringByAddressAndKey(gracityContract, ConsulsKey(lastGravityRound)), ",") |
---|
86 | | - | |
---|
87 | | - | let subscriberAddress = getStringByKey(SubscriberAddressKey) |
---|
88 | | - | |
---|
89 | | - | let type = getNumberByKey(TypeKey) |
---|
90 | | - | |
---|
91 | | - | let lastPulseId = getNumberByKey(LastPulseIdKey) |
---|
92 | | - | |
---|
93 | | - | func getHashData (pulseId) = getBytesByKey(getHashDataKey(pulseId)) |
---|
94 | | - | |
---|
95 | | - | |
---|
96 | | - | func getHeightByPulse (pulseId) = getNumberByKey(getHeightByPulseKey(pulseId)) |
---|
97 | | - | |
---|
98 | | - | |
---|
99 | | - | func validateSign (hash,sign,oracle) = if ((sign != "nil")) |
---|
100 | | - | then if (sigVerify(hash, fromBase58String(sign), fromBase58String(oracle))) |
---|
101 | | - | then 1 |
---|
102 | | - | else 0 |
---|
103 | | - | else 0 |
---|
104 | | - | |
---|
105 | | - | |
---|
106 | | - | @Callable(i) |
---|
107 | | - | func sendHashValue (hash,signs) = { |
---|
108 | | - | let signList = split(signs, ",") |
---|
109 | | - | let count = ((((validateSign(hash, signList[0], oracles[0]) + validateSign(hash, signList[1], oracles[1])) + validateSign(hash, signList[2], oracles[2])) + validateSign(hash, signList[3], oracles[3])) + validateSign(hash, signList[4], oracles[4])) |
---|
110 | | - | if ((bftCoefficient > count)) |
---|
111 | | - | then throw("invalid bft count") |
---|
112 | | - | else { |
---|
113 | | - | let currentPulseId = (lastPulseId + 1) |
---|
114 | | - | WriteSet([DataEntry(getHashDataKey(currentPulseId), hash), DataEntry(getHeightByPulseKey(currentPulseId), height), DataEntry(LastHeightKey, height), DataEntry(LastPulseIdKey, currentPulseId)]) |
---|
115 | | - | } |
---|
116 | | - | } |
---|
117 | | - | |
---|
118 | | - | |
---|
119 | | - | |
---|
120 | | - | @Callable(i) |
---|
121 | | - | func updateOracles (newSortedOracles,stringSigns,round) = { |
---|
122 | | - | let signs = split(stringSigns, ",") |
---|
123 | | - | let count = ((((validateSign(toBytes(newSortedOracles), signs[0], consuls[0]) + validateSign(toBytes(newSortedOracles), signs[1], consuls[1])) + validateSign(toBytes(newSortedOracles), signs[2], consuls[2])) + validateSign(toBytes(newSortedOracles), signs[3], consuls[3])) + validateSign(toBytes(newSortedOracles), signs[4], consuls[4])) |
---|
124 | | - | if ((bftCoefficient > count)) |
---|
125 | | - | then throw("invalid bft count") |
---|
126 | | - | else WriteSet([DataEntry(OraclesKey, newSortedOracles), DataEntry(((LastRoundKey + "_") + toString(round)), round)]) |
---|
127 | | - | } |
---|
128 | | - | |
---|
129 | | - | |
---|
130 | | - | @Verifier(i) |
---|
131 | | - | func sendValueToSub () = match i { |
---|
132 | | - | case invokeTx: InvokeScriptTransaction => |
---|
133 | | - | let vBytes = if ((type == IntType)) |
---|
134 | | - | then { |
---|
135 | | - | let v = match invokeTx.args[0] { |
---|
136 | | - | case v: Int => |
---|
137 | | - | v |
---|
138 | | - | case _ => |
---|
139 | | - | throw("invalid value type") |
---|
140 | | - | } |
---|
141 | | - | toBytes(v) |
---|
142 | | - | } |
---|
143 | | - | else if ((type == StringType)) |
---|
144 | | - | then { |
---|
145 | | - | let v = match invokeTx.args[0] { |
---|
146 | | - | case v: String => |
---|
147 | | - | v |
---|
148 | | - | case _ => |
---|
149 | | - | throw("invalid value type") |
---|
150 | | - | } |
---|
151 | | - | toBytes(v) |
---|
152 | | - | } |
---|
153 | | - | else if ((type == BytesType)) |
---|
154 | | - | then { |
---|
155 | | - | let v = match invokeTx.args[0] { |
---|
156 | | - | case v: ByteVector => |
---|
157 | | - | v |
---|
158 | | - | case _ => |
---|
159 | | - | throw("invalid value type") |
---|
160 | | - | } |
---|
161 | | - | v |
---|
162 | | - | } |
---|
163 | | - | else throw("invalid value type") |
---|
164 | | - | let vPulseId = match invokeTx.args[1] { |
---|
165 | | - | case vPulseId: Int => |
---|
166 | | - | vPulseId |
---|
167 | | - | case _ => |
---|
168 | | - | throw("invalid height type") |
---|
169 | | - | } |
---|
170 | | - | if ((invokeTx.function != "attachData")) |
---|
171 | | - | then throw("invalid function name") |
---|
172 | | - | else if ((size(invokeTx.args) != 2)) |
---|
173 | | - | then throw("invalid args size") |
---|
174 | | - | else if ((invokeTx.dApp != addressFromStringValue(subscriberAddress))) |
---|
175 | | - | then throw("invalid dapp address") |
---|
176 | | - | else if ((getHeightByPulse(vPulseId) != height)) |
---|
177 | | - | then throw("invalid height") |
---|
178 | | - | else if ((getHashData(vPulseId) == base58'2CsAf')) |
---|
179 | | - | then throw("invalid pulse id") |
---|
180 | | - | else if ((keccak256(vBytes) != getHashData(vPulseId))) |
---|
181 | | - | then throw("invalid keccak256(value)") |
---|
182 | | - | else true |
---|
183 | | - | case _ => |
---|
184 | | - | sigVerify(i.bodyBytes, i.proofs[0], i.senderPublicKey) |
---|
185 | | - | } |
---|
186 | | - | |
---|
| 1 | + | {-# STDLIB_VERSION 4 #-} |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let publicKeyEth = base58'2sAQGNeFdzACYHGCvSVaxhgYKPes' |
---|
| 4 | + | (ecrecover(keccak256(tx.bodyBytes), tx.proofs[0]) == publicKeyEth) |
---|