tx · BtjiSioBKbapZmQ6YQ7Qo9PkFG2XkcuXTPQ2RuRmEY63 3N4PzCkHU7VTJeNCPpT8w9XZLnjTsi2YMHN: -0.01000000 Waves 2022.03.31 02:22 [1987311] smart account 3N4PzCkHU7VTJeNCPpT8w9XZLnjTsi2YMHN > SELF 0.00000000 Waves
{ "type": 13, "id": "BtjiSioBKbapZmQ6YQ7Qo9PkFG2XkcuXTPQ2RuRmEY63", "fee": 1000000, "feeAssetId": null, "timestamp": 1648682621931, "version": 2, "chainId": 84, "sender": "3N4PzCkHU7VTJeNCPpT8w9XZLnjTsi2YMHN", "senderPublicKey": "2DVVUYkJNWCMHSCPWEXRjF3THHEdc5bVinyp2c4z8nV8", "proofs": [ "2rdD3qLWzqPrzH3mz1cyRAT3qkTbJtTuXKQknvufUzRjbq9KycrRjB2iNrftDoASTpLwAC5jdaG9BfQkWuZ5hSVf" ], "script": "base64:AAIFAAAAAAAAAA4IAhIDCgEIEgASAwoBAQAAAAkAAAAAB2tleUluaXQCAAAABGluaXQAAAAACmtleUFzc2V0SWQCAAAAB2Fzc2V0SWQAAAAACGtleVRvdGFsAgAAAAxzdGFrZWRfdG90YWwBAAAACWtleVN0YWtlZAAAAAEAAAAHYWRkcmVzcwUAAAAHYWRkcmVzcwAAAAAGaXNJbml0CQEAAAALdmFsdWVPckVsc2UAAAACCQAEGwAAAAIFAAAABHRoaXMFAAAAB2tleUluaXQHAAAAAAdhc3NldElkCQACWQAAAAEJAQAAABFAZXh0ck5hdGl2ZSgxMDUzKQAAAAIFAAAABHRoaXMFAAAACmtleUFzc2V0SWQAAAAAC3RvdGFsU3Rha2VkCQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQaAAAAAgUAAAAEdGhpcwUAAAAIa2V5VG90YWwJAAEsAAAAAgkAASwAAAACAgAAABJDYW4ndCByZWFkIGZpZWxkICcFAAAACGtleVRvdGFsAgAAAAEnAQAAABRleHRyYWN0UGF5bWVudEFtb3VudAAAAAEAAAAIc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oZSBkQXBwAwkAAGYAAAACBQAAAAZhbW91bnQFAAAADnN0YWtlZEJ5Q2FsbGVyCQAAAgAAAAECAAAAOFlvdSBkb24ndCBoYXZlIGVub3VnaCBzdGFrZWQgZnVuZHMgYXZhaWxhYmxlIHRvIHdpdGhkcmF3CQAETAAAAAIDCQAAAAAAAAIFAAAABmFtb3VudAUAAAAOc3Rha2VkQnlDYWxsZXIJAQAAAAtEZWxldGVFbnRyeQAAAAEJAQAAAAlrZXlTdGFrZWQAAAABBQAAAAljYWxsZXJTdHIJAQAAAAxJbnRlZ2VyRW50cnkAAAACCQEAAAAJa2V5U3Rha2VkAAAAAQUAAAAJY2FsbGVyU3RyCQAAZQAAAAIFAAAADnN0YWtlZEJ5Q2FsbGVyBQAAAAZhbW91bnQJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIFAAAACGtleVRvdGFsCQAAZQAAAAIFAAAAC3RvdGFsU3Rha2VkBQAAAAZhbW91bnQJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAA2ludgAAAAZjYWxsZXIFAAAABmFtb3VudAUAAAAHYXNzZXRJZAUAAAADbmlsAAAAAKJIE1Q=", "height": 1987311, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: none Next: GdrRXWwTCaUfpvWwP2nJCwiycPCuXDsJYhrpntDzSEo5 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 [BooleanEntry(keyInit, true), StringEntry("assetId", toBase58String(newAssetId)), IntegerEntry(keyTotal, 0)] | |
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/169f3d6 67.27 ms ◑