tx · BkfyGK3pZkEeWk3LYDiZeTbQtcZqCtekwit6mzWuE4WK 3MyBtJnMg6n7m1sDczbrijVyosLnRh4FFbc: -0.01000000 Waves 2022.05.25 13:47 [2067116] smart account 3MyBtJnMg6n7m1sDczbrijVyosLnRh4FFbc > SELF 0.00000000 Waves
{ "type": 13, "id": "BkfyGK3pZkEeWk3LYDiZeTbQtcZqCtekwit6mzWuE4WK", "fee": 1000000, "feeAssetId": null, "timestamp": 1653475679383, "version": 2, "chainId": 84, "sender": "3MyBtJnMg6n7m1sDczbrijVyosLnRh4FFbc", "senderPublicKey": "H3EzJ6fSm7jHKo92xYdNTXaaQYKj9z5q2DJFovRDLJpf", "proofs": [ "ubEjJCsJRCU93V5E8U6bn2ofXr1GphjB2cBucX9UjveaveJ4ZB3fGCCvn1kzr4P92tCGXSSZJUmhpVf42AQzjDo" ], "script": "base64:AAIFAAAAAAAAABMIAhIECgIICBIECgIIARIDCgEIAAAACQAAAAADU0VQAgAAAAJfXwEAAAARa2V5Q29udHJvbEFkZHJlc3MAAAAAAgAAABwlcyVzX19jb25maWdfX2NvbnRyb2xBZGRyZXNzAQAAAA5rZXlSZXN0QWRkcmVzcwAAAAACAAAAGSVzJXNfX2NvbmZpZ19fcmVzdEFkZHJlc3MBAAAADGdldFN0ck9yRmFpbAAAAAEAAAADa2V5CQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5CQABLAAAAAIJAAEsAAAAAgIAAAAPTWFuZGF0b3J5IHRoaXMuBQAAAANrZXkCAAAADyBpcyBub3QgZGVmaW5lZAEAAAAQZ2V0QWRkcmVzc09yRmFpbAAAAAEAAAADa2V5CQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQmAAAAAQkBAAAADGdldFN0ck9yRmFpbAAAAAEFAAAAA2tleQkAASwAAAACAgAAAB9mYWlsIHRvIHBhcnNlIGFkZHJlc3MgZm9yIHRoaXMuBQAAAANrZ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0c1JFQURPTkxZCQAETAAAAAIFAAAADW5ldXRyaW5vU3RhdHMFAAAAA25pbAAAAABbV/qF", "height": 2067116, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6RABzX8ZBZnt2GEAkhKeJyjr5xuoutocqmmVhA3a5VSz Next: D1sBqEz4jSZqNar2sbrEN6Q5orehz8TFVYsYP9nHYJjt Diff:
Old | New | Differences | |
---|---|---|---|
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | - | let MULT6 = 1000000 | |
7 | - | ||
8 | - | let MULT8 = 100000000 | |
9 | - | ||
10 | - | let WAVESIDSTR = "WAVES" | |
11 | - | ||
12 | - | let WAVESID = fromBase58String(WAVESIDSTR) | |
13 | - | ||
14 | - | func getIntOrFail (key) = valueOrErrorMessage(getInteger(this, key), (("Mandatory this." + key) + " is not defined")) | |
6 | + | func keyControlAddress () = "%s%s__config__controlAddress" | |
15 | 7 | ||
16 | 8 | ||
17 | - | func | |
9 | + | func keyRestAddress () = "%s%s__config__restAddress" | |
18 | 10 | ||
19 | 11 | ||
20 | - | func | |
12 | + | func getStrOrFail (key) = valueOrErrorMessage(getString(this, key), (("Mandatory this." + key) + " is not defined")) | |
21 | 13 | ||
22 | 14 | ||
23 | - | func getAddressOrFail (key) = valueOrErrorMessage(addressFromString( | |
15 | + | func getAddressOrFail (key) = valueOrErrorMessage(addressFromString(getStrOrFail(key)), ("fail to parse address for this." + key)) | |
24 | 16 | ||
25 | 17 | ||
26 | - | func validateAddressOrFail (addressStr) = { | |
27 | - | let address = valueOrErrorMessage(addressFromString(addressStr), ("fail to convert into address " + addressStr)) | |
28 | - | if ((0 > wavesBalance(address).available)) | |
29 | - | then throw() | |
30 | - | else addressStr | |
18 | + | func asString (val) = match val { | |
19 | + | case valStr: String => | |
20 | + | valStr | |
21 | + | case _ => | |
22 | + | throw("fail to cast into String") | |
23 | + | } | |
24 | + | ||
25 | + | ||
26 | + | func produceJson (strMap) = { | |
27 | + | let indexes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] | |
28 | + | let length = size(strMap) | |
29 | + | if (((length % 2) != 0)) | |
30 | + | then throw("only even args size is accepeted") | |
31 | + | else if ((length > size(indexes))) | |
32 | + | then throw(("strMap length is greater then " + toString(size(indexes)))) | |
33 | + | else { | |
34 | + | func produceJson (jsonAccum,nextIdx) = if (if (((nextIdx % 2) == 0)) | |
35 | + | then (length >= (nextIdx + 1)) | |
36 | + | else false) | |
37 | + | then (((((jsonAccum + " | |
38 | + | \"") + strMap[nextIdx]) + "\": \"") + strMap[(nextIdx + 1)]) + "\",") | |
39 | + | else jsonAccum | |
40 | + | ||
41 | + | let preJsonResult = { | |
42 | + | let $l = indexes | |
43 | + | let $s = size($l) | |
44 | + | let $acc0 = "" | |
45 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
46 | + | then $a | |
47 | + | else produceJson($a, $l[$i]) | |
48 | + | ||
49 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
50 | + | then $a | |
51 | + | else throw("List size exceeds 20") | |
52 | + | ||
53 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) | |
54 | + | } | |
55 | + | (("{" + dropRight(preJsonResult, 1)) + "}") | |
56 | + | } | |
31 | 57 | } | |
32 | 58 | ||
33 | 59 | ||
34 | - | ||
60 | + | let controlAcc = getAddressOrFail(keyControlAddress()) | |
35 | 61 | ||
36 | - | ||
37 | - | func keyNodeRewardsTotals (address) = ("%s%s__totals__" + address) | |
38 | - | ||
39 | - | ||
40 | - | func keyDepositAmount () = "%s%s__cfg__depositAmount" | |
41 | - | ||
42 | - | ||
43 | - | func keyNeutrinoAddressStr () = "%s%s__cfg__neutrinoAddress" | |
44 | - | ||
45 | - | ||
46 | - | func keyMasterNodeAddressStr () = "%s%s__cfg__mainNeutrinoNodeAddress" | |
47 | - | ||
48 | - | ||
49 | - | func keyProtocolPartX6 () = "%s%s__cfg__protocolPartX6" | |
50 | - | ||
51 | - | ||
52 | - | func keyBenificaryPartX6 () = "%s%s__cfg__benificaryPartX6" | |
53 | - | ||
54 | - | ||
55 | - | func formatDepositRecord (txIdStr,depositAmount,remainingDepositAmount) = makeString(["%s%d%d%d%d", txIdStr, toString(lastBlock.height), toString(lastBlock.timestamp), toString(depositAmount), toString(remainingDepositAmount)], SEP) | |
56 | - | ||
57 | - | ||
58 | - | func keyRewardHistory (nodeAddress,txId) = makeString(["%s%s%s", "history", toString(nodeAddress), toBase58String(txId)], SEP) | |
59 | - | ||
60 | - | ||
61 | - | func dataRewardHistory (wavesAmountTotal,beneficiaryAmt,protocolAmt,protocolAmtPart1,protocolAmtPart2) = makeString(["%d%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(wavesAmountTotal), toString(beneficiaryAmt), toString(protocolAmt), toString(protocolAmtPart1), toString(protocolAmtPart2)], SEP) | |
62 | - | ||
63 | - | ||
64 | - | func RewardHistoryEntry (nodeAddress,txId,minedAmt,beneficiaryAmt,protocolAmt,protocolAmt1,protocolAmt2) = StringEntry(keyRewardHistory(nodeAddress, txId), dataRewardHistory(minedAmt, beneficiaryAmt, protocolAmt, protocolAmt1, protocolAmt2)) | |
65 | - | ||
66 | - | ||
67 | - | func dataRewardTotals (minedAmt,beneficiaryAmt,protocolAmt,protocolAmtPart1,protocolAmtPart2) = makeString(["%d%d%d%d%d", toString(minedAmt), toString(beneficiaryAmt), toString(protocolAmt), toString(protocolAmtPart1), toString(protocolAmtPart2)], SEP) | |
68 | - | ||
69 | - | ||
70 | - | func RewardTotalsEntry (miner,minedAmt,beneficiaryAmt,protocolAmt,protocolAmtPart1,protocolAmtPart2) = { | |
71 | - | let nodeRewardsTotalsKEY = keyNodeRewardsTotals(toString(miner)) | |
72 | - | let nodeRewardsArray = split(getStrOrElse(nodeRewardsTotalsKEY, dataRewardTotals(0, 0, 0, 0, 0)), SEP) | |
73 | - | let newMinedAmt = (parseIntValue(nodeRewardsArray[1]) + minedAmt) | |
74 | - | let newBeneficiaryAmt = (parseIntValue(nodeRewardsArray[2]) + beneficiaryAmt) | |
75 | - | let newProtocolAmt = (parseIntValue(nodeRewardsArray[3]) + protocolAmt) | |
76 | - | let newProtocolAmtPart1 = (parseIntValue(nodeRewardsArray[4]) + protocolAmtPart1) | |
77 | - | let newProtocolAmtPart2 = (parseIntValue(nodeRewardsArray[5]) + protocolAmtPart2) | |
78 | - | StringEntry(nodeRewardsTotalsKEY, dataRewardTotals(newMinedAmt, newBeneficiaryAmt, newProtocolAmt, newProtocolAmtPart1, newProtocolAmtPart2)) | |
79 | - | } | |
80 | - | ||
62 | + | let restAcc = getAddressOrFail(keyRestAddress()) | |
81 | 63 | ||
82 | 64 | @Callable(i) | |
83 | - | func constructor (depositAmount,neutrinoAddressStr,masterNodeAddressStr,protocolPartX6,benificaryPartX6) = if ((i.caller != this)) | |
84 | - | then throw("permissions denied") | |
85 | - | else if ((0 > depositAmount)) | |
86 | - | then throw("depositAmount less then zero") | |
87 | - | else if ((0 > protocolPartX6)) | |
88 | - | then throw("protocolPartX6 less then zero") | |
89 | - | else if ((0 > benificaryPartX6)) | |
90 | - | then throw("benificaryPartX6 less then zero") | |
91 | - | else if (((protocolPartX6 + benificaryPartX6) != MULT6)) | |
92 | - | then throw("parts sum must be 1") | |
93 | - | else [IntegerEntry(keyDepositAmount(), depositAmount), StringEntry(keyNeutrinoAddressStr(), validateAddressOrFail(neutrinoAddressStr)), StringEntry(keyMasterNodeAddressStr(), validateAddressOrFail(masterNodeAddressStr)), IntegerEntry(keyProtocolPartX6(), protocolPartX6), IntegerEntry(keyBenificaryPartX6(), benificaryPartX6)] | |
65 | + | func constructor (controlAddress58,restAddress58) = if ((i.caller != this)) | |
66 | + | then throw("not authorized") | |
67 | + | else [StringEntry(keyControlAddress(), controlAddress58), StringEntry(keyRestAddress(), restAddress58)] | |
94 | 68 | ||
95 | 69 | ||
96 | 70 | ||
97 | 71 | @Callable(i) | |
98 | - | func wouldLikeToBeNeutrinoNode () = if ((size(i.payments) != 1)) | |
99 | - | then throw("exact 1 payment must be attached") | |
100 | - | else if ((i.caller != i.originCaller)) | |
101 | - | then throw("dapp to dapp calls are not allowed") | |
102 | - | else { | |
103 | - | let pmt = i.payments[0] | |
104 | - | let deposit = pmt.amount | |
105 | - | let pmtAssetId = valueOrElse(pmt.assetId, WAVESID) | |
106 | - | let expectedDepositAmount = getIntOrFail(keyDepositAmount()) | |
107 | - | let txId = toBase58String(i.transactionId) | |
108 | - | let nodeAddress = toString(i.caller) | |
109 | - | let nodeRegistryKEY = keyNodeRegistry(nodeAddress) | |
110 | - | if ((pmtAssetId != WAVESID)) | |
111 | - | then throw("only Waves can be used for deposit") | |
112 | - | else if ((deposit != expectedDepositAmount)) | |
113 | - | then throw((("exactly " + toString(expectedDepositAmount)) + " Wavelets are expected")) | |
114 | - | else if ((getStrOrElse(nodeRegistryKEY, "") != "")) | |
115 | - | then throw("your node already registered") | |
116 | - | else [StringEntry(nodeRegistryKEY, formatDepositRecord(txId, deposit, deposit))] | |
117 | - | } | |
72 | + | func stakeNsbtPageREADONLY (userAddressStrOpt,nsbtAmtDiff) = { | |
73 | + | let gnsbtInfo = asString(invoke(restAcc, "gnsbtInfoREADONLY", [userAddressStrOpt, nsbtAmtDiff], nil)) | |
74 | + | let swapInfo = asString(invoke(restAcc, "swapInfoREADONLY", [userAddressStrOpt], nil)) | |
75 | + | $Tuple2(nil, produceJson(["gnsbtInfoREADONLY", gnsbtInfo, "swapInfoREADONLY", swapInfo])) | |
76 | + | } | |
118 | 77 | ||
119 | 78 | ||
120 | 79 | ||
121 | 80 | @Callable(i) | |
122 | - | func distibuteMinerReward (benificaryAddressStr) = if ((size(i.payments) != 1)) | |
123 | - | then throw("exact 1 payment must be attached") | |
124 | - | else if ((i.caller != i.originCaller)) | |
125 | - | then throw("dapp to dapp calls are not allowed") | |
126 | - | else { | |
127 | - | let pmt = i.payments[0] | |
128 | - | let minedAmt = pmt.amount | |
129 | - | let pmtAssetId = valueOrElse(pmt.assetId, WAVESID) | |
130 | - | if ((pmtAssetId != WAVESID)) | |
131 | - | then throw("only Waves can be used") | |
132 | - | else { | |
133 | - | let neutrinoAddress = getAddressOrFail(keyNeutrinoAddressStr()) | |
134 | - | let masterNodeAddress = getAddressOrFail(keyMasterNodeAddressStr()) | |
135 | - | let minerAddress = i.caller | |
136 | - | let benificaryAddress = addressFromStringValue(benificaryAddressStr) | |
137 | - | let protocolPart = getIntOrFail(keyProtocolPartX6()) | |
138 | - | let benificaryPart = getIntOrFail(keyBenificaryPartX6()) | |
139 | - | if ((wavesBalance(minerAddress).available != 0)) | |
140 | - | then throw("all Waves must be sent from Node") | |
141 | - | else { | |
142 | - | let benificaryAmt = fraction(minedAmt, benificaryPart, MULT6) | |
143 | - | let protocolAmt = (minedAmt - benificaryAmt) | |
144 | - | let protocolAmt1 = (protocolAmt / 2) | |
145 | - | let protocolAmt2 = (protocolAmt - protocolAmt1) | |
146 | - | [ScriptTransfer(benificaryAddress, benificaryAmt, unit), ScriptTransfer(neutrinoAddress, protocolAmt1, unit), ScriptTransfer(masterNodeAddress, protocolAmt2, unit), RewardHistoryEntry(minerAddress, i.transactionId, minedAmt, benificaryAmt, protocolAmt, protocolAmt1, protocolAmt2), RewardTotalsEntry(minerAddress, minedAmt, benificaryAmt, protocolAmt, protocolAmt1, protocolAmt2)] | |
147 | - | } | |
148 | - | } | |
149 | - | } | |
81 | + | func buyNsbtPageREADONLY (userAddressStrOpt) = { | |
82 | + | let gnsbtInfo = asString(invoke(restAcc, "gnsbtInfoREADONLY", [userAddressStrOpt, 0], nil)) | |
83 | + | let neutrinoStats = asString(invoke(restAcc, "neutrinoStatsREADONLY", nil, nil)) | |
84 | + | $Tuple2(nil, produceJson(["gnsbtInfoREADONLY", gnsbtInfo, "neutrinoStatsREADONLY", neutrinoStats])) | |
85 | + | } | |
150 | 86 | ||
151 | 87 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let SEP = "__" | |
5 | 5 | ||
6 | - | let MULT6 = 1000000 | |
7 | - | ||
8 | - | let MULT8 = 100000000 | |
9 | - | ||
10 | - | let WAVESIDSTR = "WAVES" | |
11 | - | ||
12 | - | let WAVESID = fromBase58String(WAVESIDSTR) | |
13 | - | ||
14 | - | func getIntOrFail (key) = valueOrErrorMessage(getInteger(this, key), (("Mandatory this." + key) + " is not defined")) | |
6 | + | func keyControlAddress () = "%s%s__config__controlAddress" | |
15 | 7 | ||
16 | 8 | ||
17 | - | func | |
9 | + | func keyRestAddress () = "%s%s__config__restAddress" | |
18 | 10 | ||
19 | 11 | ||
20 | - | func | |
12 | + | func getStrOrFail (key) = valueOrErrorMessage(getString(this, key), (("Mandatory this." + key) + " is not defined")) | |
21 | 13 | ||
22 | 14 | ||
23 | - | func getAddressOrFail (key) = valueOrErrorMessage(addressFromString( | |
15 | + | func getAddressOrFail (key) = valueOrErrorMessage(addressFromString(getStrOrFail(key)), ("fail to parse address for this." + key)) | |
24 | 16 | ||
25 | 17 | ||
26 | - | func validateAddressOrFail (addressStr) = { | |
27 | - | let address = valueOrErrorMessage(addressFromString(addressStr), ("fail to convert into address " + addressStr)) | |
28 | - | if ((0 > wavesBalance(address).available)) | |
29 | - | then throw() | |
30 | - | else addressStr | |
18 | + | func asString (val) = match val { | |
19 | + | case valStr: String => | |
20 | + | valStr | |
21 | + | case _ => | |
22 | + | throw("fail to cast into String") | |
23 | + | } | |
24 | + | ||
25 | + | ||
26 | + | func produceJson (strMap) = { | |
27 | + | let indexes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] | |
28 | + | let length = size(strMap) | |
29 | + | if (((length % 2) != 0)) | |
30 | + | then throw("only even args size is accepeted") | |
31 | + | else if ((length > size(indexes))) | |
32 | + | then throw(("strMap length is greater then " + toString(size(indexes)))) | |
33 | + | else { | |
34 | + | func produceJson (jsonAccum,nextIdx) = if (if (((nextIdx % 2) == 0)) | |
35 | + | then (length >= (nextIdx + 1)) | |
36 | + | else false) | |
37 | + | then (((((jsonAccum + " | |
38 | + | \"") + strMap[nextIdx]) + "\": \"") + strMap[(nextIdx + 1)]) + "\",") | |
39 | + | else jsonAccum | |
40 | + | ||
41 | + | let preJsonResult = { | |
42 | + | let $l = indexes | |
43 | + | let $s = size($l) | |
44 | + | let $acc0 = "" | |
45 | + | func $f0_1 ($a,$i) = if (($i >= $s)) | |
46 | + | then $a | |
47 | + | else produceJson($a, $l[$i]) | |
48 | + | ||
49 | + | func $f0_2 ($a,$i) = if (($i >= $s)) | |
50 | + | then $a | |
51 | + | else throw("List size exceeds 20") | |
52 | + | ||
53 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) | |
54 | + | } | |
55 | + | (("{" + dropRight(preJsonResult, 1)) + "}") | |
56 | + | } | |
31 | 57 | } | |
32 | 58 | ||
33 | 59 | ||
34 | - | ||
60 | + | let controlAcc = getAddressOrFail(keyControlAddress()) | |
35 | 61 | ||
36 | - | ||
37 | - | func keyNodeRewardsTotals (address) = ("%s%s__totals__" + address) | |
38 | - | ||
39 | - | ||
40 | - | func keyDepositAmount () = "%s%s__cfg__depositAmount" | |
41 | - | ||
42 | - | ||
43 | - | func keyNeutrinoAddressStr () = "%s%s__cfg__neutrinoAddress" | |
44 | - | ||
45 | - | ||
46 | - | func keyMasterNodeAddressStr () = "%s%s__cfg__mainNeutrinoNodeAddress" | |
47 | - | ||
48 | - | ||
49 | - | func keyProtocolPartX6 () = "%s%s__cfg__protocolPartX6" | |
50 | - | ||
51 | - | ||
52 | - | func keyBenificaryPartX6 () = "%s%s__cfg__benificaryPartX6" | |
53 | - | ||
54 | - | ||
55 | - | func formatDepositRecord (txIdStr,depositAmount,remainingDepositAmount) = makeString(["%s%d%d%d%d", txIdStr, toString(lastBlock.height), toString(lastBlock.timestamp), toString(depositAmount), toString(remainingDepositAmount)], SEP) | |
56 | - | ||
57 | - | ||
58 | - | func keyRewardHistory (nodeAddress,txId) = makeString(["%s%s%s", "history", toString(nodeAddress), toBase58String(txId)], SEP) | |
59 | - | ||
60 | - | ||
61 | - | func dataRewardHistory (wavesAmountTotal,beneficiaryAmt,protocolAmt,protocolAmtPart1,protocolAmtPart2) = makeString(["%d%d%d%d%d%d%d", toString(lastBlock.height), toString(lastBlock.timestamp), toString(wavesAmountTotal), toString(beneficiaryAmt), toString(protocolAmt), toString(protocolAmtPart1), toString(protocolAmtPart2)], SEP) | |
62 | - | ||
63 | - | ||
64 | - | func RewardHistoryEntry (nodeAddress,txId,minedAmt,beneficiaryAmt,protocolAmt,protocolAmt1,protocolAmt2) = StringEntry(keyRewardHistory(nodeAddress, txId), dataRewardHistory(minedAmt, beneficiaryAmt, protocolAmt, protocolAmt1, protocolAmt2)) | |
65 | - | ||
66 | - | ||
67 | - | func dataRewardTotals (minedAmt,beneficiaryAmt,protocolAmt,protocolAmtPart1,protocolAmtPart2) = makeString(["%d%d%d%d%d", toString(minedAmt), toString(beneficiaryAmt), toString(protocolAmt), toString(protocolAmtPart1), toString(protocolAmtPart2)], SEP) | |
68 | - | ||
69 | - | ||
70 | - | func RewardTotalsEntry (miner,minedAmt,beneficiaryAmt,protocolAmt,protocolAmtPart1,protocolAmtPart2) = { | |
71 | - | let nodeRewardsTotalsKEY = keyNodeRewardsTotals(toString(miner)) | |
72 | - | let nodeRewardsArray = split(getStrOrElse(nodeRewardsTotalsKEY, dataRewardTotals(0, 0, 0, 0, 0)), SEP) | |
73 | - | let newMinedAmt = (parseIntValue(nodeRewardsArray[1]) + minedAmt) | |
74 | - | let newBeneficiaryAmt = (parseIntValue(nodeRewardsArray[2]) + beneficiaryAmt) | |
75 | - | let newProtocolAmt = (parseIntValue(nodeRewardsArray[3]) + protocolAmt) | |
76 | - | let newProtocolAmtPart1 = (parseIntValue(nodeRewardsArray[4]) + protocolAmtPart1) | |
77 | - | let newProtocolAmtPart2 = (parseIntValue(nodeRewardsArray[5]) + protocolAmtPart2) | |
78 | - | StringEntry(nodeRewardsTotalsKEY, dataRewardTotals(newMinedAmt, newBeneficiaryAmt, newProtocolAmt, newProtocolAmtPart1, newProtocolAmtPart2)) | |
79 | - | } | |
80 | - | ||
62 | + | let restAcc = getAddressOrFail(keyRestAddress()) | |
81 | 63 | ||
82 | 64 | @Callable(i) | |
83 | - | func constructor (depositAmount,neutrinoAddressStr,masterNodeAddressStr,protocolPartX6,benificaryPartX6) = if ((i.caller != this)) | |
84 | - | then throw("permissions denied") | |
85 | - | else if ((0 > depositAmount)) | |
86 | - | then throw("depositAmount less then zero") | |
87 | - | else if ((0 > protocolPartX6)) | |
88 | - | then throw("protocolPartX6 less then zero") | |
89 | - | else if ((0 > benificaryPartX6)) | |
90 | - | then throw("benificaryPartX6 less then zero") | |
91 | - | else if (((protocolPartX6 + benificaryPartX6) != MULT6)) | |
92 | - | then throw("parts sum must be 1") | |
93 | - | else [IntegerEntry(keyDepositAmount(), depositAmount), StringEntry(keyNeutrinoAddressStr(), validateAddressOrFail(neutrinoAddressStr)), StringEntry(keyMasterNodeAddressStr(), validateAddressOrFail(masterNodeAddressStr)), IntegerEntry(keyProtocolPartX6(), protocolPartX6), IntegerEntry(keyBenificaryPartX6(), benificaryPartX6)] | |
65 | + | func constructor (controlAddress58,restAddress58) = if ((i.caller != this)) | |
66 | + | then throw("not authorized") | |
67 | + | else [StringEntry(keyControlAddress(), controlAddress58), StringEntry(keyRestAddress(), restAddress58)] | |
94 | 68 | ||
95 | 69 | ||
96 | 70 | ||
97 | 71 | @Callable(i) | |
98 | - | func wouldLikeToBeNeutrinoNode () = if ((size(i.payments) != 1)) | |
99 | - | then throw("exact 1 payment must be attached") | |
100 | - | else if ((i.caller != i.originCaller)) | |
101 | - | then throw("dapp to dapp calls are not allowed") | |
102 | - | else { | |
103 | - | let pmt = i.payments[0] | |
104 | - | let deposit = pmt.amount | |
105 | - | let pmtAssetId = valueOrElse(pmt.assetId, WAVESID) | |
106 | - | let expectedDepositAmount = getIntOrFail(keyDepositAmount()) | |
107 | - | let txId = toBase58String(i.transactionId) | |
108 | - | let nodeAddress = toString(i.caller) | |
109 | - | let nodeRegistryKEY = keyNodeRegistry(nodeAddress) | |
110 | - | if ((pmtAssetId != WAVESID)) | |
111 | - | then throw("only Waves can be used for deposit") | |
112 | - | else if ((deposit != expectedDepositAmount)) | |
113 | - | then throw((("exactly " + toString(expectedDepositAmount)) + " Wavelets are expected")) | |
114 | - | else if ((getStrOrElse(nodeRegistryKEY, "") != "")) | |
115 | - | then throw("your node already registered") | |
116 | - | else [StringEntry(nodeRegistryKEY, formatDepositRecord(txId, deposit, deposit))] | |
117 | - | } | |
72 | + | func stakeNsbtPageREADONLY (userAddressStrOpt,nsbtAmtDiff) = { | |
73 | + | let gnsbtInfo = asString(invoke(restAcc, "gnsbtInfoREADONLY", [userAddressStrOpt, nsbtAmtDiff], nil)) | |
74 | + | let swapInfo = asString(invoke(restAcc, "swapInfoREADONLY", [userAddressStrOpt], nil)) | |
75 | + | $Tuple2(nil, produceJson(["gnsbtInfoREADONLY", gnsbtInfo, "swapInfoREADONLY", swapInfo])) | |
76 | + | } | |
118 | 77 | ||
119 | 78 | ||
120 | 79 | ||
121 | 80 | @Callable(i) | |
122 | - | func distibuteMinerReward (benificaryAddressStr) = if ((size(i.payments) != 1)) | |
123 | - | then throw("exact 1 payment must be attached") | |
124 | - | else if ((i.caller != i.originCaller)) | |
125 | - | then throw("dapp to dapp calls are not allowed") | |
126 | - | else { | |
127 | - | let pmt = i.payments[0] | |
128 | - | let minedAmt = pmt.amount | |
129 | - | let pmtAssetId = valueOrElse(pmt.assetId, WAVESID) | |
130 | - | if ((pmtAssetId != WAVESID)) | |
131 | - | then throw("only Waves can be used") | |
132 | - | else { | |
133 | - | let neutrinoAddress = getAddressOrFail(keyNeutrinoAddressStr()) | |
134 | - | let masterNodeAddress = getAddressOrFail(keyMasterNodeAddressStr()) | |
135 | - | let minerAddress = i.caller | |
136 | - | let benificaryAddress = addressFromStringValue(benificaryAddressStr) | |
137 | - | let protocolPart = getIntOrFail(keyProtocolPartX6()) | |
138 | - | let benificaryPart = getIntOrFail(keyBenificaryPartX6()) | |
139 | - | if ((wavesBalance(minerAddress).available != 0)) | |
140 | - | then throw("all Waves must be sent from Node") | |
141 | - | else { | |
142 | - | let benificaryAmt = fraction(minedAmt, benificaryPart, MULT6) | |
143 | - | let protocolAmt = (minedAmt - benificaryAmt) | |
144 | - | let protocolAmt1 = (protocolAmt / 2) | |
145 | - | let protocolAmt2 = (protocolAmt - protocolAmt1) | |
146 | - | [ScriptTransfer(benificaryAddress, benificaryAmt, unit), ScriptTransfer(neutrinoAddress, protocolAmt1, unit), ScriptTransfer(masterNodeAddress, protocolAmt2, unit), RewardHistoryEntry(minerAddress, i.transactionId, minedAmt, benificaryAmt, protocolAmt, protocolAmt1, protocolAmt2), RewardTotalsEntry(minerAddress, minedAmt, benificaryAmt, protocolAmt, protocolAmt1, protocolAmt2)] | |
147 | - | } | |
148 | - | } | |
149 | - | } | |
81 | + | func buyNsbtPageREADONLY (userAddressStrOpt) = { | |
82 | + | let gnsbtInfo = asString(invoke(restAcc, "gnsbtInfoREADONLY", [userAddressStrOpt, 0], nil)) | |
83 | + | let neutrinoStats = asString(invoke(restAcc, "neutrinoStatsREADONLY", nil, nil)) | |
84 | + | $Tuple2(nil, produceJson(["gnsbtInfoREADONLY", gnsbtInfo, "neutrinoStatsREADONLY", neutrinoStats])) | |
85 | + | } | |
150 | 86 | ||
151 | 87 |
github/deemru/w8io/026f985 32.43 ms ◑