tx · Hx2b7Bapg92KEj9zdFwqs2Kfh61drkyoBaL6ZDfr9W1B 3NBXRmoaNi1RVTa9JvuXhCeU1kTPGXdbCP7: -0.01400000 Waves 2019.07.04 16:57 [570777] smart account 3NBXRmoaNi1RVTa9JvuXhCeU1kTPGXdbCP7 > SELF 0.00000000 Waves
{ "type": 13, "id": "Hx2b7Bapg92KEj9zdFwqs2Kfh61drkyoBaL6ZDfr9W1B", "fee": 1400000, "feeAssetId": null, "timestamp": 1562248707567, "version": 1, "sender": "3NBXRmoaNi1RVTa9JvuXhCeU1kTPGXdbCP7", "senderPublicKey": "97dwMYPb6V2WyfYZoeFDjc6tbk4b5XRPKkEBgPLC9v4K", "proofs": [ "Sy2zaKcUfQgp9w9ucTjdvWHvgUVXPBtp3Lq9UjdpVw5BkaAx29X67GrQukKeZAUBfqnGeTpQ9x4UAun6bU7ZuzC" ], "script": "base64:AAIDAAAAAAAAAAAAAAANAAAAAAROT05FAgAAAARub25lAQAAAA5nZXROdW1iZXJCeUtleQAAAAEAAAADa2V5BAAAAANudW0EAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEAAAAAAAAAAAAFAAAAA251bQEAAAALZ2V0U3RyQnlLZXkAAAABAAAAA2tleQQAAAADc3RyBAAAAAckbWF0Y2gwCQAEHQAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAGU3RyaW5nBAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhBQAAAAROT05FBQAAAANzdHIBAAAAD2dldEtleUl0ZW1QcmljZQAAAAEAAAAEaXRlbQkAASwAAAACBQAAAARpdGVtAgAAAAZfcHJpY2UBAAAAEWdldFZhbHVlSXRlbVByaWNlAAAAAQAAAARpdGVtCQEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABCQEAAAAPZ2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RkcmVzcwkAAlgAAAABCAgFAAAAAWkAAAAGY2FsbGVyAAAABWJ5dGVzBAAAAAdiYWxhbmNlCQEAAAAXZ2V0VmFsdWVCYWxhbmNlU3VwcGxpZXIAAAABBQAAAA9zdXBwbGllckFkZHJlc3MDCQAAZwAAAAIAAAAAAAAAAAAFAAAAB2JhbGFuY2UJAAACAAAAAQIAAAAUaW5zdWZmaWNpZW50IGJhbGFuY2UJAQAAAAxTY3JpcHRSZXN1bHQAAAACCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAVZ2V0S2V5QmFsYW5jZVN1cHBsaWVyAAAAAQUAAAAPc3VwcGxpZXJBZGRyZXNzAAAAAAAAAAAABQAAAANuaWwJAQAAAAtUcmFuc2ZlclNldAAAAAEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwkBAAAAHEBleHRyVXNlcihhZGRyZXNzRnJvbVN0cmluZykAAAABBQAAAA9zdXBwbGllckFkZHJlc3MFAAAAB2JhbGFuY2UFAAAABHVuaXQFAAAAA25pbAAAAADZHhVF", "chainId": 84, "height": 570777, "spentComplexity": 0 } View: original | compacted Prev: t7RFnzkZdm1ncPm71hZ2Rdd3gBfqCSW5q7RKZjpofZu Next: 7TZqgJzJLpyJ1K8BoNf1DFVLP9iXHPqwV8j9Myxk8xU5 Diff:
Old | New | Differences | |
---|---|---|---|
56 | 56 | ||
57 | 57 | ||
58 | 58 | @Callable(i) | |
59 | - | func | |
59 | + | func withdraw () = { | |
60 | 60 | let supplierAddress = toBase58String(i.caller.bytes) | |
61 | - | let item = getKeyItem(supplierAddress, title) | |
62 | - | if ((0 >= price)) | |
63 | - | then throw("purchase amount cannot be less then item price") | |
64 | - | else if ((getValueItemSupplier(item) != NONE)) | |
65 | - | then throw("an item is already exist") | |
66 | - | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
67 | - | } | |
68 | - | ||
69 | - | ||
70 | - | ||
71 | - | @Callable(i) | |
72 | - | func purchase (item) = { | |
73 | - | let pmt = extract(i.payment) | |
74 | - | if (isDefined(pmt.assetId)) | |
75 | - | then throw("WAVES tokens only at the moment") | |
76 | - | else { | |
77 | - | let userAddress = toBase58String(i.caller.bytes) | |
78 | - | let price = getValueItemPrice(item) | |
79 | - | let supplierAddress = getValueItemSupplier(item) | |
80 | - | if ((price > pmt.amount)) | |
81 | - | then throw("purchase amount cannot be less than item price") | |
82 | - | else if ((pmt.amount > price)) | |
83 | - | then throw("purchase amount cannot be higher than item price") | |
84 | - | else if ((supplierAddress == NONE)) | |
85 | - | then throw("supplier does not exist") | |
86 | - | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
87 | - | } | |
61 | + | let balance = getValueBalanceSupplier(supplierAddress) | |
62 | + | if ((0 >= balance)) | |
63 | + | then throw("insufficient balance") | |
64 | + | else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)])) | |
88 | 65 | } | |
89 | 66 | ||
90 | 67 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
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 getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func getKeyItemData (item) = (item + "_data") | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getKeyItemSupplier (item) = (item + "_owner") | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func getKeyBalanceSupplier (account) = (account + "_balance") | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
56 | 56 | ||
57 | 57 | ||
58 | 58 | @Callable(i) | |
59 | - | func | |
59 | + | func withdraw () = { | |
60 | 60 | let supplierAddress = toBase58String(i.caller.bytes) | |
61 | - | let item = getKeyItem(supplierAddress, title) | |
62 | - | if ((0 >= price)) | |
63 | - | then throw("purchase amount cannot be less then item price") | |
64 | - | else if ((getValueItemSupplier(item) != NONE)) | |
65 | - | then throw("an item is already exist") | |
66 | - | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
67 | - | } | |
68 | - | ||
69 | - | ||
70 | - | ||
71 | - | @Callable(i) | |
72 | - | func purchase (item) = { | |
73 | - | let pmt = extract(i.payment) | |
74 | - | if (isDefined(pmt.assetId)) | |
75 | - | then throw("WAVES tokens only at the moment") | |
76 | - | else { | |
77 | - | let userAddress = toBase58String(i.caller.bytes) | |
78 | - | let price = getValueItemPrice(item) | |
79 | - | let supplierAddress = getValueItemSupplier(item) | |
80 | - | if ((price > pmt.amount)) | |
81 | - | then throw("purchase amount cannot be less than item price") | |
82 | - | else if ((pmt.amount > price)) | |
83 | - | then throw("purchase amount cannot be higher than item price") | |
84 | - | else if ((supplierAddress == NONE)) | |
85 | - | then throw("supplier does not exist") | |
86 | - | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
87 | - | } | |
61 | + | let balance = getValueBalanceSupplier(supplierAddress) | |
62 | + | if ((0 >= balance)) | |
63 | + | then throw("insufficient balance") | |
64 | + | else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)])) | |
88 | 65 | } | |
89 | 66 | ||
90 | 67 |
github/deemru/w8io/026f985 38.38 ms ◑