tx · HA3ycgx84Pc3o6HhH924uAFc8abfC89Vp9PxnF5CD4a2

3MxQPEhyQMQL5C4JN29toSkF9amf8iQSCPc:  -0.05000000 Waves

2020.03.20 12:04 [917455] smart account 3MxQPEhyQMQL5C4JN29toSkF9amf8iQSCPc > SELF 0.00000000 Waves

{ "type": 13, "id": "HA3ycgx84Pc3o6HhH924uAFc8abfC89Vp9PxnF5CD4a2", "fee": 5000000, "feeAssetId": null, "timestamp": 1584695045798, "version": 1, "sender": "3MxQPEhyQMQL5C4JN29toSkF9amf8iQSCPc", "senderPublicKey": "3n7vYRqT664Gwk9F1i5yM11opnuaH4yABXXnsxP6kxUQ", "proofs": [ "3WHX3mWLyJYE2PhCiKfowjg44RvUjZ4vtkR5KzR9uNqpBjLPprscsnaH8EktBTEhywr4WRFK7tF7G6RkmZKK914v" ], "script": "base64:AAIDAAAAAAAAABwIARIECgIIARIAEgQKAgEIEgQKAggBEgQKAggBAAAAHgEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAEAAAAOZ2V0U3RyaW5nQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQIAAAAAAQAAAAxnZXRCb29sQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABBsAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAB0Jvb2xlYW4EAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEHAQAAABhnZXROdW1iZXJCeUFkZHJlc3NBbmRLZXkAAAACAAAAB2FkZHJlc3M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AABBQAAAARoYXNoAgAAAAAJAAACAAAAAQIAAAARcHJvcG9zYWwgaXMgZXhpc3QJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABRnZXRFeHBpcmVQcm9wb3NhbEtleQAAAAEFAAAABGhhc2gFAAAADGV4cGFpckhlaWdodAkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAE2dldE93bmVyUHJvcG9zYWxLZXkAAAABBQAAAARoYXNoCQAEJQAAAAEIBQAAAAFpAAAABmNhbGxlcgkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAF2dldEFyZ3VtZW50c1Byb3Bvc2FsS2V5AAAAAQUAAAAEaGFzaAUAAAAJYXJndW1lbnRzBQAAAANuaWwAAAAAOjMLFw==", "chainId": 84, "height": 917455, "spentComplexity": 0 } View: original | compacted Prev: ADtAH7WeiUBvWZKApwzgc6BvosAMN8AhHqhVA6BuFNzc Next: none Diff:
OldNewDifferences
7474
7575 let neutrinoContract = addressFromStringValue(getStringByKey(NeutrinoContractKey))
7676
77+let controlContract = addressFromStringValue(getStringByAddressAndKey(neutrinoContract, ControlContractKey))
78+
7779 let neutrinoAssetId = fromBase58String(getStringByAddressAndKey(neutrinoContract, NeutrinoAssetIdKey))
7880
7981 func getContractBalance (assetId) = getNumberByKey(getContractBalanceKey(assetId))
9496 func getVote (owner,hash) = getStringByKey(getVoteKey(owner, hash))
9597
9698
99+func getRewardsConfigKey (owner,share,receiver) = ((((("stakingconfig_" + owner) + "_") + toString(share)) + "_") + receiver)
100+
101+
102+func getCurrentRewardsConfigKey (owner) = ("stakingconfig_current_" + owner)
103+
104+
105+func getRewardsConfigStartKey (configKey,isStart) = (configKey + (if (isStart)
106+ then "_start"
107+ else "_end"))
108+
109+
110+func internallockNeutrino (i,receiver,share) = {
111+ let pmt = extract(i.payment)
112+ if (!(isDefined(addressFromString(receiver))))
113+ then throw(("Invalid address format " + receiver))
114+ else if ((pmt.assetId != neutrinoAssetId))
115+ then throw("can use usd only")
116+ else if ((share > 100))
117+ then throw("staking rewards share cannot be higher than 100%")
118+ else if ((1 > share))
119+ then throw("staking rewards share cannot be lower than 1%")
120+ else {
121+ let account = toString(i.caller)
122+ let assetIdString = toBase58String(value(pmt.assetId))
123+ let currentConfig = getStringByKey(getCurrentRewardsConfigKey(account))
124+ let newCurrentConfig = getRewardsConfigKey(account, share, receiver)
125+ let isNewConfig = !((currentConfig == newCurrentConfig))
126+ let end = if (isNewConfig)
127+ then height
128+ else 0
129+ let start = if (isNewConfig)
130+ then height
131+ else getNumberByKey(getRewardsConfigStartKey(newCurrentConfig, true))
132+ WriteSet([DataEntry(getContractBalanceKey(assetIdString), (getContractBalance(assetIdString) + pmt.amount)), DataEntry(getUserBalanceKey(account, assetIdString), (getUserBalance(account, assetIdString) + pmt.amount)), DataEntry(getRewardsConfigStartKey(currentConfig, false), end), DataEntry(getRewardsConfigStartKey(newCurrentConfig, true), start), DataEntry(getCurrentRewardsConfigKey(account), newCurrentConfig)])
133+ }
134+ }
135+
136+
97137 @Callable(i)
98-func lockNeutrino () = {
99- let pmt = extract(i.payment)
100- if ((pmt.assetId != neutrinoAssetId))
101- then throw("can use neutrino")
102- else {
103- let account = toString(i.caller)
104- let assetIdString = toBase58String(valueOrErrorMessage(pmt.assetId, "parse value error"))
105- WriteSet([DataEntry(getContractBalanceKey(assetIdString), (getContractBalance(assetIdString) + pmt.amount)), DataEntry(getUserBalanceKey(account, assetIdString), (getUserBalance(account, assetIdString) + pmt.amount))])
106- }
107- }
138+func lockNeutrinoSP (receiver,share) = internallockNeutrino(i, receiver, share)
139+
140+
141+
142+@Callable(i)
143+func lockNeutrino () = internallockNeutrino(i, toString(i.caller), 100)
108144
109145
110146
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 func getNumberByKey (key) = match getInteger(this, key) {
55 case a: Int =>
66 a
77 case _ =>
88 0
99 }
1010
1111
1212 func getStringByKey (key) = match getString(this, key) {
1313 case a: String =>
1414 a
1515 case _ =>
1616 ""
1717 }
1818
1919
2020 func getBoolByKey (key) = match getBoolean(this, key) {
2121 case a: Boolean =>
2222 a
2323 case _ =>
2424 false
2525 }
2626
2727
2828 func getNumberByAddressAndKey (address,key) = match getInteger(addressFromStringValue(address), key) {
2929 case a: Int =>
3030 a
3131 case _ =>
3232 0
3333 }
3434
3535
3636 func getStringByAddressAndKey (address,key) = match getString(address, key) {
3737 case a: String =>
3838 a
3939 case _ =>
4040 ""
4141 }
4242
4343
4444 let NeutrinoAssetIdKey = "neutrino_asset_id"
4545
4646 let NeutrinoContractKey = "neutrino_contract"
4747
4848 let BalanceKey = "rpd_balance"
4949
5050 let ControlContractKey = "control_contract"
5151
5252 let AdminsKey = "admins"
5353
5454 func getUserBalanceKey (owner,assetId) = ((((BalanceKey + "_") + assetId) + "_") + owner)
5555
5656
5757 func getContractBalanceKey (assetId) = ((BalanceKey + "_") + assetId)
5858
5959
6060 func getExpireProposalKey (hash) = (("proposal_expire" + "_") + hash)
6161
6262
6363 func getOwnerProposalKey (hash) = (("proposal_owner" + "_") + hash)
6464
6565
6666 func getArgumentsProposalKey (hash) = (("proposal_arguments" + "_") + hash)
6767
6868
6969 func getVoteKey (owner,hash) = (((("proposal_vote" + "_") + owner) + "_") + hash)
7070
7171
7272 func convertJsonArrayToList (jsonArray) = split(jsonArray, ",")
7373
7474
7575 let neutrinoContract = addressFromStringValue(getStringByKey(NeutrinoContractKey))
7676
77+let controlContract = addressFromStringValue(getStringByAddressAndKey(neutrinoContract, ControlContractKey))
78+
7779 let neutrinoAssetId = fromBase58String(getStringByAddressAndKey(neutrinoContract, NeutrinoAssetIdKey))
7880
7981 func getContractBalance (assetId) = getNumberByKey(getContractBalanceKey(assetId))
8082
8183
8284 func getUserBalance (owner,assetId) = getNumberByKey(getUserBalanceKey(owner, assetId))
8385
8486
8587 func getExpireProposal (hash) = getNumberByKey(getExpireProposalKey(hash))
8688
8789
8890 func getOwnerProposal (hash) = getStringByKey(getOwnerProposalKey(hash))
8991
9092
9193 func getArgumentsProposal (hash) = getStringByKey(getArgumentsProposalKey(hash))
9294
9395
9496 func getVote (owner,hash) = getStringByKey(getVoteKey(owner, hash))
9597
9698
99+func getRewardsConfigKey (owner,share,receiver) = ((((("stakingconfig_" + owner) + "_") + toString(share)) + "_") + receiver)
100+
101+
102+func getCurrentRewardsConfigKey (owner) = ("stakingconfig_current_" + owner)
103+
104+
105+func getRewardsConfigStartKey (configKey,isStart) = (configKey + (if (isStart)
106+ then "_start"
107+ else "_end"))
108+
109+
110+func internallockNeutrino (i,receiver,share) = {
111+ let pmt = extract(i.payment)
112+ if (!(isDefined(addressFromString(receiver))))
113+ then throw(("Invalid address format " + receiver))
114+ else if ((pmt.assetId != neutrinoAssetId))
115+ then throw("can use usd only")
116+ else if ((share > 100))
117+ then throw("staking rewards share cannot be higher than 100%")
118+ else if ((1 > share))
119+ then throw("staking rewards share cannot be lower than 1%")
120+ else {
121+ let account = toString(i.caller)
122+ let assetIdString = toBase58String(value(pmt.assetId))
123+ let currentConfig = getStringByKey(getCurrentRewardsConfigKey(account))
124+ let newCurrentConfig = getRewardsConfigKey(account, share, receiver)
125+ let isNewConfig = !((currentConfig == newCurrentConfig))
126+ let end = if (isNewConfig)
127+ then height
128+ else 0
129+ let start = if (isNewConfig)
130+ then height
131+ else getNumberByKey(getRewardsConfigStartKey(newCurrentConfig, true))
132+ WriteSet([DataEntry(getContractBalanceKey(assetIdString), (getContractBalance(assetIdString) + pmt.amount)), DataEntry(getUserBalanceKey(account, assetIdString), (getUserBalance(account, assetIdString) + pmt.amount)), DataEntry(getRewardsConfigStartKey(currentConfig, false), end), DataEntry(getRewardsConfigStartKey(newCurrentConfig, true), start), DataEntry(getCurrentRewardsConfigKey(account), newCurrentConfig)])
133+ }
134+ }
135+
136+
97137 @Callable(i)
98-func lockNeutrino () = {
99- let pmt = extract(i.payment)
100- if ((pmt.assetId != neutrinoAssetId))
101- then throw("can use neutrino")
102- else {
103- let account = toString(i.caller)
104- let assetIdString = toBase58String(valueOrErrorMessage(pmt.assetId, "parse value error"))
105- WriteSet([DataEntry(getContractBalanceKey(assetIdString), (getContractBalance(assetIdString) + pmt.amount)), DataEntry(getUserBalanceKey(account, assetIdString), (getUserBalance(account, assetIdString) + pmt.amount))])
106- }
107- }
138+func lockNeutrinoSP (receiver,share) = internallockNeutrino(i, receiver, share)
139+
140+
141+
142+@Callable(i)
143+func lockNeutrino () = internallockNeutrino(i, toString(i.caller), 100)
108144
109145
110146
111147 @Callable(i)
112148 func unlockNeutrino (unlockAmount,assetIdString) = {
113149 let account = toString(i.caller)
114150 let assetId = fromBase58String(assetIdString)
115151 let balance = (getUserBalance(account, assetIdString) - unlockAmount)
116152 if ((0 > balance))
117153 then throw("invalid amount")
118154 else if ((assetId != neutrinoAssetId))
119155 then throw("can use neutrino")
120156 else ScriptResult(WriteSet([DataEntry(getContractBalanceKey(assetIdString), (getContractBalance(assetIdString) - unlockAmount)), DataEntry(getUserBalanceKey(account, assetIdString), balance)]), TransferSet([ScriptTransfer(addressFromStringValue(account), unlockAmount, neutrinoAssetId)]))
121157 }
122158
123159
124160
125161 @Callable(i)
126162 func vote (hash,indexArgument) = {
127163 let arguments = split(getArgumentsProposal(hash), ",")
128164 let argument = arguments[indexArgument]
129165 if ((height > getExpireProposal(hash)))
130166 then throw("proposal is expired")
131167 else WriteSet([DataEntry(getVoteKey(toString(i.caller), hash), argument)])
132168 }
133169
134170
135171
136172 @Callable(i)
137173 func createProposal (arguments,expairHeight) = {
138174 let hash = toBase58String(keccak256(((toBytes(arguments) + toBytes(expairHeight)) + i.callerPublicKey)))
139175 if ((getOwnerProposal(hash) != ""))
140176 then throw("proposal is exist")
141177 else WriteSet([DataEntry(getExpireProposalKey(hash), expairHeight), DataEntry(getOwnerProposalKey(hash), toString(i.caller)), DataEntry(getArgumentsProposalKey(hash), arguments)])
142178 }
143179
144180

github/deemru/w8io/026f985 
31.81 ms