1 | | - | {-# STDLIB_VERSION 5 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let SEP = "__" |
---|
5 | | - | |
---|
6 | | - | func keyBeneficiaryAddress () = "%s%s__cfg__beneficiaryAddress" |
---|
7 | | - | |
---|
8 | | - | |
---|
9 | | - | func keyConstructorInterval () = "%s%s__cfg__nodeContructorInterval" |
---|
10 | | - | |
---|
11 | | - | |
---|
12 | | - | func keyLastUpdateHeight () = "%s__lastUpdatedHeight" |
---|
13 | | - | |
---|
14 | | - | |
---|
15 | | - | func keyScriptUpdateHash () = "%s__scriptUpdateHash" |
---|
16 | | - | |
---|
17 | | - | |
---|
18 | | - | let nodeRegistry = addressFromStringValue("3MsU936briqQ2XZMpkhWdrV8EsNwm5iCuRY") |
---|
19 | | - | |
---|
20 | | - | @Callable(i) |
---|
21 | | - | func constructor (beneficiaryAddressStr58) = if ((this != i.caller)) |
---|
22 | | - | then throw("permissions denied") |
---|
23 | | - | else { |
---|
24 | | - | let beneficiaryAddress = addressFromStringValue(beneficiaryAddressStr58) |
---|
25 | | - | if ((beneficiaryAddress == this)) |
---|
26 | | - | then throw("mining node address is not allowed as a beneficiaryAddress") |
---|
27 | | - | else [StringEntry(keyBeneficiaryAddress(), toString(beneficiaryAddress)), IntegerEntry(keyLastUpdateHeight(), height)] |
---|
28 | | - | } |
---|
29 | | - | |
---|
30 | | - | |
---|
31 | | - | @Verifier(tx) |
---|
32 | | - | func verify () = match tx { |
---|
33 | | - | case inv: InvokeScriptTransaction => |
---|
34 | | - | if ((inv.fee > (5 * 100000))) |
---|
35 | | - | then throw(("InvokeScriptTransaction - fee amount is greater than max allowed: " + toString(inv.fee))) |
---|
36 | | - | else if (isDefined(inv.feeAssetId)) |
---|
37 | | - | then throw("InvokeScriptTransaction - only WAVES is allowed as feeAssetId") |
---|
38 | | - | else if ((addressFromRecipient(inv.dApp) == nodeRegistry)) |
---|
39 | | - | then true |
---|
40 | | - | else if ((addressFromRecipient(inv.dApp) == this)) |
---|
41 | | - | then { |
---|
42 | | - | let lastUpdatedHeight = valueOrElse(getInteger(this, keyLastUpdateHeight()), 0) |
---|
43 | | - | let constrInterval = valueOrElse(getInteger(nodeRegistry, keyConstructorInterval()), 43200) |
---|
44 | | - | if ((constrInterval > (height - lastUpdatedHeight))) |
---|
45 | | - | then throw("InvokeScriptTransaction - impossible to call constructor very often") |
---|
46 | | - | else sigVerify_32Kb(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
47 | | - | } |
---|
48 | | - | else throw("InvokeScriptTransaction - invalid dapp address") |
---|
49 | | - | case stx: SetScriptTransaction => |
---|
50 | | - | let scriptBytes = value(stx.script) |
---|
51 | | - | let hash = toBase58String(keccak256_32Kb(blake2b256_32Kb(scriptBytes))) |
---|
52 | | - | let allowedHash = valueOrElse(getString(nodeRegistry, keyScriptUpdateHash()), "") |
---|
53 | | - | let allowByHash = if ((allowedHash != "")) |
---|
54 | | - | then (allowedHash == hash) |
---|
55 | | - | else false |
---|
56 | | - | let allowBySig = sigVerify_32Kb(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
57 | | - | if (allowBySig) |
---|
58 | | - | then true |
---|
59 | | - | else allowByHash |
---|
60 | | - | case _ => |
---|
61 | | - | throw("not allowed") |
---|
62 | | - | } |
---|
63 | | - | |
---|
| 1 | + | # no script |
---|