tx · 55hNEsKebyqGS8vCw8oeiuQCqf4PRUB5yBvh7WwQxZQG 3MtTheYx7F8GojnQXdBq5njwKSWwWDR8Yx3: -0.01400000 Waves 2020.11.20 18:23 [1273880] smart account 3MtTheYx7F8GojnQXdBq5njwKSWwWDR8Yx3 > SELF 0.00000000 Waves
{ "type": 13, "id": "55hNEsKebyqGS8vCw8oeiuQCqf4PRUB5yBvh7WwQxZQG", "fee": 1400000, "feeAssetId": null, "timestamp": 1605885849843, "version": 2, "chainId": 84, "sender": "3MtTheYx7F8GojnQXdBq5njwKSWwWDR8Yx3", "senderPublicKey": "24o2mnMP6y64dijDFoZKhDpV73e1gCFKxQcZ6X9q3z1B", "proofs": [ "52S2y4Ah2Cca94URVJGzvuHvqhovhvXARUkvVtNGKdUNwSWdE4rfDSQ9hV2NrsNgJ8DfUqnGSEEKt3634veMdKHg" ], "script": "base64:AAIEAAAAAAAAABAIAhIDCgEIEgUKAwgBCBIAAAAAEAAAAAARYWNjb3VudDFQdWJsaWNLZXkBAAAAIPeNeDDs4TWVhR1bzOk94lFsHOraL9B/FRj0XfVMj0hOAAAAABFhY2NvdW50MlB1YmxpY0tleQEAAAAgG1e/aEwKrtMkcq9WyiLLAHtKPJgLd/oAoUXcKuUDIhUAAAAADm90aGVyUHVibGljS2V5AQAAACDnblGJprjxGAm9jEz8V5M0TOEG6bhNvbMQquBNrx0dWgAAAAAETk9ORQIAAAAEbm9uZQEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFA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VudHJ5AAAAAgkBAAAAD2dldEtleUl0ZW1QcmljZQAAAAEFAAAABGl0ZW0FAAAABXByaWNlCQAETAAAAAIJAQAAAAtTdHJpbmdFbnRyeQAAAAIJAQAAAA5nZXRLZXlJdGVtRGF0YQAAAAEFAAAABGl0ZW0FAAAABGRhdGEFAAAAA25pbAAAAAFpAQAAAAh3aXRoZHJhdwAAAAAEAAAAD3N1cHBsaWVyQWRkcmVzcwkAAlgAAAABCAgFAAAAAWkAAAAGY2FsbGVyAAAABWJ5dGVzBAAAAAdiYWxhbmNlCQEAAAAXZ2V0VmFsdWVCYWxhbmNlU3VwcGxpZXIAAAABBQAAAA9zdXBwbGllckFkZHJlc3MDCQAAZwAAAAIAAAAAAAAAAAAFAAAAB2JhbGFuY2UJAAACAAAAAQIAAAAUaW5zdWZmaWNpZW50IGJhbGFuY2UJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAABVnZXRLZXlCYWxhbmNlU3VwcGxpZXIAAAABBQAAAA9zdXBwbGllckFkZHJlc3MAAAAAAAAAAAAJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwkBAAAAEUBleHRyTmF0aXZlKDEwNjIpAAAAAQUAAAAPc3VwcGxpZXJBZGRyZXNzBQAAAAdiYWxhbmNlBQAAAAR1bml0BQAAAANuaWwAAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAABq7Ojcw=", "height": 1273880, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 5RyV7rb3i2oC27HBC9Zwh8vCFeLLQb85bpyJ2UgXuJvr Next: 8jmkyYve2ey2uqgxv62N2sSstm4jUoBKbW8Pthdjgeqd Diff:
Old | New | Differences | |
---|---|---|---|
96 | 96 | } | |
97 | 97 | ||
98 | 98 | ||
99 | + | ||
100 | + | @Callable(i) | |
101 | + | func withdraw () = { | |
102 | + | let supplierAddress = toBase58String(i.caller.bytes) | |
103 | + | let balance = getValueBalanceSupplier(supplierAddress) | |
104 | + | if ((0 >= balance)) | |
105 | + | then throw("insufficient balance") | |
106 | + | else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)] | |
107 | + | } | |
108 | + | ||
109 | + | ||
99 | 110 | @Verifier(tx) | |
100 | 111 | func verify () = true | |
101 | 112 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let account1PublicKey = base58'HfLpRhXtnuCabRyNT6z7soaXcbUpwLUhjyBCVQ4szwzd' | |
5 | 5 | ||
6 | 6 | let account2PublicKey = base58'2qjcWuL7QitmuhkSTM7CnNxurCYXuqJ9ubswLBGmXfDv' | |
7 | 7 | ||
8 | 8 | let otherPublicKey = base58'GaQkBG6yLLAarb8wvPrEKnQhFqWomD2ZGT1T4vVx24qw' | |
9 | 9 | ||
10 | 10 | let NONE = "none" | |
11 | 11 | ||
12 | 12 | func getNumberByKey (key) = { | |
13 | 13 | let num = match getInteger(this, key) { | |
14 | 14 | case a: Int => | |
15 | 15 | a | |
16 | 16 | case _ => | |
17 | 17 | 0 | |
18 | 18 | } | |
19 | 19 | num | |
20 | 20 | } | |
21 | 21 | ||
22 | 22 | ||
23 | 23 | func getStrByKey (key) = { | |
24 | 24 | let str = match getString(this, key) { | |
25 | 25 | case a: String => | |
26 | 26 | a | |
27 | 27 | case _ => | |
28 | 28 | NONE | |
29 | 29 | } | |
30 | 30 | str | |
31 | 31 | } | |
32 | 32 | ||
33 | 33 | ||
34 | 34 | func getKeyItemPrice (item) = (item + "_price") | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
38 | 38 | ||
39 | 39 | ||
40 | 40 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func getKeyItemData (item) = (item + "_data") | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func getKeyItemSupplier (item) = (item + "_owner") | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
56 | 56 | ||
57 | 57 | ||
58 | 58 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
59 | 59 | ||
60 | 60 | ||
61 | 61 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
62 | 62 | ||
63 | 63 | ||
64 | 64 | @Callable(i) | |
65 | 65 | func purchase (item) = { | |
66 | 66 | let pmt = value(i.payments) | |
67 | 67 | if (isDefined(pmt[0].assetId)) | |
68 | 68 | then throw("WAVES tokens only") | |
69 | 69 | else { | |
70 | 70 | let userAddress = toBase58String(i.caller.bytes) | |
71 | 71 | let price = getValueItemPrice(item) | |
72 | 72 | let supplierAddress = getValueItemSupplier(item) | |
73 | 73 | if ((price > pmt[0].amount)) | |
74 | 74 | then throw("purchase less than item price") | |
75 | 75 | else if ((pmt[0].amount > price)) | |
76 | 76 | then throw("purchase amount higher than item price") | |
77 | 77 | else if ((size(pmt) > 1)) | |
78 | 78 | then throw("single item only") | |
79 | 79 | else if ((supplierAddress == NONE)) | |
80 | 80 | then throw("supplier doesn't exist") | |
81 | 81 | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt[0].amount))] | |
82 | 82 | } | |
83 | 83 | } | |
84 | 84 | ||
85 | 85 | ||
86 | 86 | ||
87 | 87 | @Callable(i) | |
88 | 88 | func addItem (title,price,data) = { | |
89 | 89 | let supplierAddress = toBase58String(i.caller.bytes) | |
90 | 90 | let item = getKeyItem(supplierAddress, title) | |
91 | 91 | if ((0 >= price)) | |
92 | 92 | then throw("purchase amount cannot be less than item price") | |
93 | 93 | else if ((getValueItemSupplier(item) != NONE)) | |
94 | 94 | then throw("an item already exist") | |
95 | 95 | else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)] | |
96 | 96 | } | |
97 | 97 | ||
98 | 98 | ||
99 | + | ||
100 | + | @Callable(i) | |
101 | + | func withdraw () = { | |
102 | + | let supplierAddress = toBase58String(i.caller.bytes) | |
103 | + | let balance = getValueBalanceSupplier(supplierAddress) | |
104 | + | if ((0 >= balance)) | |
105 | + | then throw("insufficient balance") | |
106 | + | else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)] | |
107 | + | } | |
108 | + | ||
109 | + | ||
99 | 110 | @Verifier(tx) | |
100 | 111 | func verify () = true | |
101 | 112 |
github/deemru/w8io/169f3d6 24.74 ms ◑