tx · 5WoyqpqANQrx3RvLtdDpwc8BD45ifKxG6ifs368Pribw 3N1kdSFBBitRyEbeQUg3f5DbvXtX2ZKRMiK: -0.01000000 Waves 2022.03.31 02:13 [1987300] smart account 3N1kdSFBBitRyEbeQUg3f5DbvXtX2ZKRMiK > SELF 0.00000000 Waves
{ "type": 13, "id": "5WoyqpqANQrx3RvLtdDpwc8BD45ifKxG6ifs368Pribw", "fee": 1000000, "feeAssetId": null, "timestamp": 1648682014737, "version": 2, "chainId": 84, "sender": "3N1kdSFBBitRyEbeQUg3f5DbvXtX2ZKRMiK", "senderPublicKey": "DdhyEEzQFx6gFJTjhWxhpiSMV2agMDrDGVDi5P1QmsH1", "proofs": [ "3tdtHfpFi1GjUp2RJmtP5JsY3Cc2b1E6Xgx6HV7HhoicPTwboGjeDsWqTZRxgM2k2Vv9JQa4LUZYDg3DFPb6y2CL" ], "script": "base64:AAIFAAAAAAAAAA4IAhIDCgEIEgASAwoBAQAAAAkAAAAAB2tleUluaXQCAAAABGluaXQAAAAACmtleUFzc2V0SWQCAAAAB2Fzc2V0SWQAAAAACGtleVRvdGFsAgAAAAxzdGFrZWRfdG90YWwBAAAACWtleVN0YWtlZAAAAAEAAAAHYWRkcmVzcwUAAAAHYWRkcmVzcwAAAAAGaXNJbml0CQEAAAALdmFsdWVPckVsc2UAAAACCQAEGwAAAAIFAAAABHRoaXMFAAAAB2tleUluaXQHAAAAAAdhc3NldElkCQACWQAAAAEJAQAAABFAZXh0ck5hdGl2ZSgxMDUzKQAAAAIFAAAABHRoaXMFAAAACmtleUFzc2V0SWQAAAAAC3RvdGFsU3Rha2VkCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQaAAAAAgUAAAAEdGhpcwUAAAAIa2V5VG90YWwJAAEsAAAAAgkAASwAAAACAgAAABJDYW4ndCByZWFkIGZpZWxkICcFAAAACGtleVRvdGFsAgAAAAEnAQAAABRleHRyYWN0UGF5bWVudEFtb3VudAAAAAEAAAAIcGF5bW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F2YWlsYWJsZSB0byB3aXRoZHJhdwkABEwAAAACAwkAAAAAAAACBQAAAAZhbW91bnQFAAAADnN0YWtlZEJ5Q2FsbGVyCQEAAAALRGVsZXRlRW50cnkAAAABCQEAAAAJa2V5U3Rha2VkAAAAAQUAAAAJY2FsbGVyU3RyCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkBAAAACWtleVN0YWtlZAAAAAEFAAAACWNhbGxlclN0cgkAAGUAAAACBQAAAA5zdGFrZWRCeUNhbGxlcgUAAAAGYW1vdW50CQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACBQAAAAhrZXlUb3RhbAkAAGUAAAACBQAAAAt0b3RhbFN0YWtlZAUAAAAGYW1vdW50CQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAANpbnYAAAAGY2FsbGVyBQAAAAZhbW91bnQFAAAAB2Fzc2V0SWQFAAAAA25pbAAAAACkrCuW", "height": 1987300, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: none Full:
Old | New | Differences | |
---|---|---|---|
1 | - | # no script | |
1 | + | {-# STDLIB_VERSION 5 #-} | |
2 | + | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | + | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let keyInit = "init" | |
5 | + | ||
6 | + | let keyAssetId = "assetId" | |
7 | + | ||
8 | + | let keyTotal = "staked_total" | |
9 | + | ||
10 | + | func keyStaked (address) = address | |
11 | + | ||
12 | + | ||
13 | + | let isInit = valueOrElse(getBoolean(this, keyInit), false) | |
14 | + | ||
15 | + | let assetId = fromBase58String(getStringValue(this, keyAssetId)) | |
16 | + | ||
17 | + | let totalStaked = valueOrErrorMessage(getInteger(this, keyTotal), (("Can't read field '" + keyTotal) + "'")) | |
18 | + | ||
19 | + | func extractPaymentAmount (payments) = if ((size(payments) != 1)) | |
20 | + | then throw("Single payment required") | |
21 | + | else if ((payments[0].assetId != assetId)) | |
22 | + | then throw("Payment should be in REDS token") | |
23 | + | else if ((0 >= payments[0].amount)) | |
24 | + | then throw("Payment amount must be greater then 0") | |
25 | + | else payments[0].amount | |
26 | + | ||
27 | + | ||
28 | + | func getCurrentStakedAmount (user) = valueOrElse(getInteger(this, keyStaked(user)), 0) | |
29 | + | ||
30 | + | ||
31 | + | @Callable(inv) | |
32 | + | func init (hashrateAssetId) = { | |
33 | + | let newAssetId = valueOrErrorMessage(assetInfo(fromBase58String(hashrateAssetId)), "Can't find asset").id | |
34 | + | if (isInit) | |
35 | + | then throw("DApp is already init") | |
36 | + | else [StringEntry("assetId", toBase58String(newAssetId))] | |
37 | + | } | |
38 | + | ||
39 | + | ||
40 | + | ||
41 | + | @Callable(inv) | |
42 | + | func stake () = { | |
43 | + | let callerStr = toString(inv.caller) | |
44 | + | let pmtAmount = extractPaymentAmount(inv.payments) | |
45 | + | let currentStakeAmount = getCurrentStakedAmount(callerStr) | |
46 | + | [IntegerEntry(keyStaked(callerStr), (currentStakeAmount + pmtAmount)), IntegerEntry(keyTotal, (totalStaked + pmtAmount))] | |
47 | + | } | |
48 | + | ||
49 | + | ||
50 | + | ||
51 | + | @Callable(inv) | |
52 | + | func withdraw (amount) = { | |
53 | + | let callerStr = toString(inv.caller) | |
54 | + | let stakedByCaller = getCurrentStakedAmount(callerStr) | |
55 | + | if ((size(inv.payments) != 0)) | |
56 | + | then throw("There should be no payments for this function") | |
57 | + | else if ((0 >= amount)) | |
58 | + | then throw("Amount must be positive") | |
59 | + | else if ((amount > totalStaked)) | |
60 | + | then throw("You cannot withdraw more funds than total staked on the dApp") | |
61 | + | else if ((amount > stakedByCaller)) | |
62 | + | then throw("You don't have enough staked funds available to withdraw") | |
63 | + | else [if ((amount == stakedByCaller)) | |
64 | + | then DeleteEntry(keyStaked(callerStr)) | |
65 | + | else IntegerEntry(keyStaked(callerStr), (stakedByCaller - amount)), IntegerEntry(keyTotal, (totalStaked - amount)), ScriptTransfer(inv.caller, amount, assetId)] | |
66 | + | } | |
67 | + | ||
68 | + |
github/deemru/w8io/03bedc9 16.27 ms ◑![]()