tx · vWcCUP2hmEfqY76RapkjBHy55S5VTDW3F2UzJYY9q2P 3NA37aEhY3CSPtrXjKUsNibx5i45P7FxuA4: -0.01000010 Waves 2021.07.07 13:26 [1603065] smart account 3NA37aEhY3CSPtrXjKUsNibx5i45P7FxuA4 > SELF 0.00000000 Waves
{ "type": 13, "id": "vWcCUP2hmEfqY76RapkjBHy55S5VTDW3F2UzJYY9q2P", "fee": 1000010, "feeAssetId": null, "timestamp": 1625653574453, "version": 2, "chainId": 84, "sender": "3NA37aEhY3CSPtrXjKUsNibx5i45P7FxuA4", "senderPublicKey": "B3Kkg7AgjdZYrAW5kNXeBi1KfWcjdiHpEnu3tsfirQPy", "proofs": [ "Kw1Qq6NKJr9toNRDLLhfUT8yd2BgQMJUVjsxbAGUE9fExdRtW6hEcKmoJ8Y2FgPpQ5CNKCmYQtHzbANq65ojdft" ], "script": "base64:AAIFAAAAAAAAAcQIAhIDCgEIGgoKAmExEgROT05FGhQKAmEyEg5nZXROdW1iZXJCeUtleRoJCgJhMxIDa2V5GgkKAmE0EgNudW0aDQoCYTUSByRtYXRjaDAaBwoCYTYSAWEaEQoCYTcSC2dldFN0ckJ5S2V5GgkKAmE4EgNzdHIaFQoCYTkSD2dldEtleUl0ZW1QcmljZRoKCgJiMRIEaXRlbRoXCgJiMhIRZ2V0VmFsdWVJdGVtUHJpY2UaGwoCYjMSFWdldEtleVVzZXJJdGVtQ291bnRlchoKCgJiNBIEdXNlchodCgJiNRIXZ2V0VmFsdWVVc2VySXRlbUNvdW50ZXIaGAoCYjYSEmdldEtleUl0ZW1TdXBwbGllchoaCgJiNxIUZ2V0VmFsdWVJdGVtU3VwcGxpZXIaGwoCYjgSFWdldEtleUJhbGFuY2VTdXBwbGllchoNCgJiORIHYWNjb3VudBodCgJjMRIXZ2V0VmFsdWVCYWxhbmNlU3VwcGxpZXIaBwoCYzISAWkaCQoCYzMSA3BtdBoRCgJjNBILdXNlckFkZHJlc3MaCwoCYzUSBXByaWNlGhQKAmM2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AAAB5XQVZFUyB0b2tlbiBvbmx5IGF0IHRoZSBtb21lbnQEAAAAAmM0CQACWAAAAAEICAUAAAACYzIAAAAGY2FsbGVyAAAABWJ5dGVzBAAAAAJjNQkBAAAAAmIyAAAAAQUAAAACYjEEAAAAAmM2CQEAAAACYjcAAAABBQAAAAJiMQMJAABmAAAAAgUAAAACYzUIBQAAAAJjMwAAAAZhbW91bnQJAAACAAAAAQIAAAAtcHVyY2hhc2UgYW11bnQgY2Fubm90IGJlIGxlc3MgdGhhbiBpdGVtIHByaWNlAwkAAGYAAAACCAUAAAACYzMAAAAGYW1vdW50BQAAAAJjNQkAAAIAAAABAgAAADBwdXJjaGFzZSBhbW91bnQgY2Fubm90IGJlIGhpZ2hlciB0aGFuIGl0ZW0gcHJpY2UDCQAAAAAAAAIFAAAAAmM2BQAAAAJhMQkAAAIAAAABAgAAAB5TdXBwbGllciBhZGRyZXNzIGRvZXNuJ3QgZXhpc3QJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJiMwAAAAIFAAAAAmM0BQAAAAJiMQkAAGQAAAACCQEAAAACYjUAAAACBQAAAAJjNAUAAAACYjEAAAAAAAAAAAEJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJiOAAAAAEFAAAAAmM2CQAAZAAAAAIJAQAAAAJjMQAAAAEFAAAAAmM2CAUAAAACYzMAAAAGYW1vdW50BQAAAANuaWwAAAAAT0GD2g==", "height": 1603065, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: AzAEvBHtfnCsQHcnd61HGPZGaeGjaWBibsxjtDwak3xb Next: Hzv75npaNZc1rN2vQWxrsm7A3HG7SY6vmMCXnZiWxJxD Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | 5 | ||
6 | 6 | func getNumberByKey (key) = { | |
7 | 7 | let num = match getInteger(this, key) { | |
8 | 8 | case a: Int => | |
9 | 9 | a | |
10 | 10 | case _ => | |
11 | 11 | 0 | |
12 | 12 | } | |
13 | 13 | num | |
14 | 14 | } | |
15 | 15 | ||
16 | 16 | ||
17 | 17 | func getStrByKey (key) = { | |
18 | 18 | let str = match getString(this, key) { | |
19 | 19 | case a: String => | |
20 | 20 | a | |
21 | 21 | case _ => | |
22 | 22 | NONE | |
23 | 23 | } | |
24 | 24 | str | |
25 | 25 | } | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | func getKeyItemPrice (item) = (item + "_price") | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getKeyItemSupplier (item) = (item + "_data") | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | @Callable(i) | |
53 | 53 | func purchase (item) = { | |
54 | 54 | let pmt = i.payments[0] | |
55 | 55 | if (isDefined(pmt.assetId)) | |
56 | 56 | then throw("WAVES token only at the moment") | |
57 | 57 | else { | |
58 | 58 | let userAddress = toBase58String(i.caller.bytes) | |
59 | 59 | let price = getValueItemPrice(item) | |
60 | 60 | let supplierAddres = getValueItemSupplier(item) | |
61 | 61 | if ((price > pmt.amount)) | |
62 | 62 | then throw("purchase amunt cannot be less than item price") | |
63 | 63 | else if ((pmt.amount > price)) | |
64 | 64 | then throw("purchase amount cannot be higher than item price") | |
65 | 65 | else if ((supplierAddres == NONE)) | |
66 | 66 | then throw("Supplier address doesn't exist") | |
67 | 67 | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddres), (getValueBalanceSupplier(supplierAddres) + pmt.amount))] | |
68 | 68 | } | |
69 | 69 | } | |
70 | 70 | ||
71 | 71 |
github/deemru/w8io/026f985 39.13 ms ◑