tx · 8H87rDQzUsSNTodPrT7ncKhVdCAo1oPipf2QqqTny7k2 3Mz9ndf12uVKYMqYmwUr81wcNLYEgr82ei6: -0.01400000 Waves 2019.11.16 18:15 [767841] smart account 3Mz9ndf12uVKYMqYmwUr81wcNLYEgr82ei6 > SELF 0.00000000 Waves
{ "type": 13, "id": "8H87rDQzUsSNTodPrT7ncKhVdCAo1oPipf2QqqTny7k2", "fee": 1400000, "feeAssetId": null, "timestamp": 1573917407153, "version": 1, "sender": "3Mz9ndf12uVKYMqYmwUr81wcNLYEgr82ei6", "senderPublicKey": "8bmUdC19peGBa1TGeRZaZfpuDG6yKaGYBd8FQvcBLAXR", "proofs": [ "3dDMoLLwR8dnc6GLsfYyfpmEeNBJxheiGVC7G743fe3ziBoE3v2XMuCcTqw66ZumttGe5YS8g6C6Vdgmb8mr8aLi" ], "script": "base64:AAIDAAAAAAAAAAQIARIAAAAADQAAAAAETk9ORQIAAAAEbm9uZQEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9wcmljZQEAAAAOZ2V0S2V5SXRlbURhdGEAAAABAAAABGl0ZW0JAAEsAAAAAgUAAAAEaXRlbQIAAAAFX2RhdGEBAAAADmdldEtleUl0ZW1TdXBwAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9vd25lcgEAAAALZ2V0U3RyQnlLZXkAAAABAAAAA2tleQQAAAADc3RyBAAAAAckbWF0Y2gwCQAEHQAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAGU3RyaW5nBAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhBQAAAAROT05FBQAAAANzdHIBAAAACmdldEtleUl0ZW0AAAACAAAABHN1cHAAAAAFdGl0bGUJAAEsAAAAAgIAAAAFaXRlbV8JAAJYAAAAAQkAAfcAAAABCQABmwAAAAEJAAEsAAAAAgUAAAAEc3VwcAUAAA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ATZ2V0VmFsdWVTdXBwQmFsYW5jZQAAAAEFAAAAB3N1cHBBZHIDCQAAZwAAAAIAAAAAAAAAAAAFAAAAB2JhbGFuY2UJAAACAAAAAQIAAAAUaW5zdWZmaWNpZW50IGJhbGFuY2UJAQAAAAxTY3JpcHRSZXN1bHQAAAACCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAARZ2V0S2V5U3VwcEJhbGFuY2UAAAABBQAAAAdzdXBwQWRyAAAAAAAAAAAABQAAAANuaWwJAQAAAAtUcmFuc2ZlclNldAAAAAEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwkBAAAAHEBleHRyVXNlcihhZGRyZXNzRnJvbVN0cmluZykAAAABBQAAAAdzdXBwQWRyBQAAAAdiYWxhbmNlBQAAAAR1bml0BQAAAANuaWwAAAAAe1nEKg==", "chainId": 84, "height": 767841, "spentComplexity": 0 } View: original | compacted Prev: BH8pWegCNZza68T5ffZRFCFWBFNyYy27VvA5VqfE6L6B Next: CbG2SFGC41RXzayu92DDGmMNxZmZYAeBVZp6xLcc1k4z Diff:
Old | New | Differences | |
---|---|---|---|
56 | 56 | ||
57 | 57 | ||
58 | 58 | @Callable(i) | |
59 | - | func purchase (item) = { | |
60 | - | let pmt = extract(i.payment) | |
61 | - | if (isDefined(pmt.assetId)) | |
62 | - | then throw("Wawes only") | |
63 | - | else { | |
64 | - | let userAdr = toBase58String(i.caller.bytes) | |
65 | - | let price = getValueItemPrice(item) | |
66 | - | let suppAdr = getValueItemSupp(item) | |
67 | - | if ((price > pmt.amount)) | |
68 | - | then throw("purchase amount < price") | |
69 | - | else if ((pmt.amount > price)) | |
70 | - | then throw("purchase amount > price") | |
71 | - | else if ((suppAdr == NONE)) | |
72 | - | then throw("supp not exist") | |
73 | - | else WriteSet([DataEntry(getKeyUserItemCounter(userAdr, item), (getValueUserItemCounter(userAdr, item) + 1)), DataEntry(getKeySuppBalance(suppAdr), (getValueSuppBalance(suppAdr) + pmt.amount))]) | |
74 | - | } | |
59 | + | func withdraw () = { | |
60 | + | let suppAdr = toBase58String(i.caller.bytes) | |
61 | + | let balance = getValueSuppBalance(suppAdr) | |
62 | + | if ((0 >= balance)) | |
63 | + | then throw("insufficient balance") | |
64 | + | else ScriptResult(WriteSet([DataEntry(getKeySuppBalance(suppAdr), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(suppAdr), balance, unit)])) | |
75 | 65 | } | |
76 | 66 | ||
77 | 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 getKeyItemPrice (item) = (item + "_price") | |
7 | 7 | ||
8 | 8 | ||
9 | 9 | func getKeyItemData (item) = (item + "_data") | |
10 | 10 | ||
11 | 11 | ||
12 | 12 | func getKeyItemSupp (item) = (item + "_owner") | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | func getStrByKey (key) = { | |
16 | 16 | let str = match getString(this, key) { | |
17 | 17 | case a: String => | |
18 | 18 | a | |
19 | 19 | case _ => | |
20 | 20 | NONE | |
21 | 21 | } | |
22 | 22 | str | |
23 | 23 | } | |
24 | 24 | ||
25 | 25 | ||
26 | 26 | func getKeyItem (supp,title) = ("item_" + toBase58String(sha256(toBytes((supp + title))))) | |
27 | 27 | ||
28 | 28 | ||
29 | 29 | func getValueItemSupp (item) = getStrByKey(getKeyItemSupp(item)) | |
30 | 30 | ||
31 | 31 | ||
32 | 32 | func getNumberByKey (key) = { | |
33 | 33 | let num = match getInteger(this, key) { | |
34 | 34 | case a: Int => | |
35 | 35 | a | |
36 | 36 | case _ => | |
37 | 37 | 0 | |
38 | 38 | } | |
39 | 39 | num | |
40 | 40 | } | |
41 | 41 | ||
42 | 42 | ||
43 | 43 | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
44 | 44 | ||
45 | 45 | ||
46 | 46 | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
47 | 47 | ||
48 | 48 | ||
49 | 49 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func getKeySuppBalance (supp) = (supp + "_balance") | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | func getValueSuppBalance (supp) = getNumberByKey(getKeySuppBalance(supp)) | |
56 | 56 | ||
57 | 57 | ||
58 | 58 | @Callable(i) | |
59 | - | func purchase (item) = { | |
60 | - | let pmt = extract(i.payment) | |
61 | - | if (isDefined(pmt.assetId)) | |
62 | - | then throw("Wawes only") | |
63 | - | else { | |
64 | - | let userAdr = toBase58String(i.caller.bytes) | |
65 | - | let price = getValueItemPrice(item) | |
66 | - | let suppAdr = getValueItemSupp(item) | |
67 | - | if ((price > pmt.amount)) | |
68 | - | then throw("purchase amount < price") | |
69 | - | else if ((pmt.amount > price)) | |
70 | - | then throw("purchase amount > price") | |
71 | - | else if ((suppAdr == NONE)) | |
72 | - | then throw("supp not exist") | |
73 | - | else WriteSet([DataEntry(getKeyUserItemCounter(userAdr, item), (getValueUserItemCounter(userAdr, item) + 1)), DataEntry(getKeySuppBalance(suppAdr), (getValueSuppBalance(suppAdr) + pmt.amount))]) | |
74 | - | } | |
59 | + | func withdraw () = { | |
60 | + | let suppAdr = toBase58String(i.caller.bytes) | |
61 | + | let balance = getValueSuppBalance(suppAdr) | |
62 | + | if ((0 >= balance)) | |
63 | + | then throw("insufficient balance") | |
64 | + | else ScriptResult(WriteSet([DataEntry(getKeySuppBalance(suppAdr), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(suppAdr), balance, unit)])) | |
75 | 65 | } | |
76 | 66 | ||
77 | 67 |
github/deemru/w8io/169f3d6 41.57 ms ◑