-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsV3.ride
97 lines (69 loc) · 4.11 KB
/
settingsV3.ride
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
94
95
96
97
{-# STDLIB_VERSION 6 #-}
{-# SCRIPT_TYPE ACCOUNT #-}
{-# CONTENT_TYPE DAPP #-}
let WavesId = "WAVES"
let Arr10 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
let ConfigAddressKey = "configAddress"
let InputsQuantityKey = "inputsQuantity"
let ConfigAddress = addressFromStringValue(this.getStringValue(ConfigAddressKey))
let InputsQuantity = ConfigAddress.getIntegerValue(InputsQuantityKey)
func makeAssetOperationKey(chain: String, asset: String, operation: String) = makeString(["assetOperation", chain, asset, operation], "_")
func makeChainIdKey(chain: String) = "chainId_" + chain
func makeBlacklistedDelegateKey(delegate: String) = "blacklistedDelegate_" + delegate
func makeInputAssetIndexKey(chain: String, asset: String) = makeString([ "inputAssetIndex", chain, asset], "_")
func getChainId(chain: String) = ConfigAddress.getInteger(makeChainIdKey(chain))
func getBlacklistedDelegate(delegate: String) = ConfigAddress.getBoolean(makeBlacklistedDelegateKey(delegate))
func getInputAssetIndex(chain: String, asset: String) = ConfigAddress.getIntegerValue(makeInputAssetIndexKey(chain, asset))
func getAssetOperation(chain: String, asset: String, operation: String) = ConfigAddress.getInteger(makeAssetOperationKey(chain, asset, operation))
@Callable(i)
func setup(configAddress: String) = {
if (i.caller != this) then throw("Access denied") else
if (i.payments.size() != 0) then throw("Payments are prohibited") else
if (addressFromString(configAddress) == unit) then throw("Invalid configAddress: " + configAddress) else
[StringEntry(ConfigAddressKey, configAddress)]
}
@Callable(i)
func applySettings(
inputChains: List[String],
inputAssets: List[String],
outputChains: List[String],
outputAssets: List[String],
assetOperations: List[String],
delegates: List[String]) = {
if (i.payments.size() != 0) then throw("Payments are prohibited") else
if (i.caller == this) then throw("Self call is prohibited") else
let callerAddressStr = i.caller.toString()
let inputChainsSize = inputChains.size()
let inputAssetsSize = inputAssets.size()
let outputChainsSize = outputChains.size()
let outputAssetsSize = outputAssets.size()
let assetOperationsSize = assetOperations.size()
let delegatesSize = delegates.size()
if (InputsQuantity != inputChainsSize || inputChainsSize != inputAssetsSize ||
inputAssetsSize != outputChainsSize || outputChainsSize != outputAssetsSize ||
outputAssetsSize != assetOperationsSize || assetOperationsSize != delegatesSize)
then throw("Mismatch argument sizes") else
func settingsFold(accum: List[StringEntry|IntegerEntry|BinaryEntry], index: Int) = {
if (index >= InputsQuantity) then accum else
let inputChain = inputChains[index]
if (getChainId(inputChain) == unit) then throw("Invalid chain: " + inputChain) else
let inputAsset = inputAssets[index]
if (getInputAssetIndex(inputChain, inputAsset) != index) then throw("Invalid inputAsset: " + inputChain + "," + inputAsset) else
let outputChain = outputChains[index]
if (getChainId(outputChain) == unit) then throw("Invalid chain: " + outputChain) else
let outputAsset = outputAssets[index]
let operation = assetOperations[index]
if (getAssetOperation(outputChain, outputAsset, operation) == unit) then throw("Invalid arguments: " + outputChain + "," + outputAsset + "," + operation) else
let delegate = delegates[index]
if (getBlacklistedDelegate(delegate) != unit) then throw("Prohibited delegate: " + delegate) else
let isValidWavesAddress = addressFromString(delegate) != unit
let isValidEthAddress = delegate.take(2) == "0x" && fromBase16String(delegate.drop(2)).size() == 20
if (!(outputChain == WavesId && isValidWavesAddress || outputChain != WavesId && isValidEthAddress)) then throw("Invalid delegate: " + delegate) else
let settingsKey = makeString(["settings", callerAddressStr, inputChain, inputAsset], "_")
let settingsValue = makeString([outputChain, outputAsset, operation, delegate], "_")
accum :+ StringEntry(settingsKey, settingsValue)
}
FOLD<10>(Arr10, [], settingsFold)
}
@Verifier(tx)
func verify() = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)