tx · 7PYJKuwTGQpr32HYDLGVDtLdfdvQjSkwLDEaxye6hG9U 3MpDjmA6c1mGrUUsBtQiSUkpNepyyq2U2bi: -0.01400000 Waves 2019.08.29 18:48 [652706] smart account 3MpDjmA6c1mGrUUsBtQiSUkpNepyyq2U2bi > SELF 0.00000000 Waves
{ "type": 13, "id": "7PYJKuwTGQpr32HYDLGVDtLdfdvQjSkwLDEaxye6hG9U", "fee": 1400000, "feeAssetId": null, "timestamp": 1567093586520, "version": 1, "sender": "3MpDjmA6c1mGrUUsBtQiSUkpNepyyq2U2bi", "senderPublicKey": "GNuHLNfdrBQFcKg3AwDj1fwFdrtuxDna2T8EZCxJA2Z6", "proofs": [ "8Xd2vG6TAeadScepBQCHAmbXwFigjEAwZKRhjkr6yCd5tESrdJYVfhsB7BkMgPPix3yqm8vYhWcEgFBT3yXqeTJ" ], "script": "base64:AAIDAAAAAAAAAAAAAAANAAAAAAROT05FAgAAAARub25lAQAAAA5nZXROdW1iZXJCeUtleQAAAAEAAAADa2V5BAAAAANudW0EAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEAAAAAAAAAAAAFAAAAA251bQEAAAALZ2V0U3RyQnlLZXkAAAABAAAAA2tleQQAAAADc3RyBAAAAAckbWF0Y2gwCQAEHQAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAGU3RyaW5nBAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhBQAAAAROT05FBQAAAANzdHIBAAAAD2dldEtleUl0ZW1QcmljZQAAAAEAAAAEaXRlbQkAASwAAAACBQAAAARpdGVtAgAAAAZfcHJpY2UBAAAAEWdldFZhbHVlSXRlbVByaWNlAAAAAQAAAARpdGVtCQEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABCQEAAAAPZ2V0S2V5SXRl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0VmFsdWVCYWxhbmNlU3VwcGxpZXIAAAABBQAAAA9zdXBwbGllckFkZHJlc3MIBQAAAANwbXQAAAAGYW1vdW50BQAAAANuaWwAAAABaQEAAAAHYWRkSXRlbQAAAAMAAAAFdGl0bGUAAAAFcHJpY2UAAAAEZGF0YQQAAAAPc3VwcGxpZXJBZGRyZXNzCQACWAAAAAEICAUAAAABaQAAAAZjYWxsZXIAAAAFYnl0ZXMEAAAABGl0ZW0JAQAAAApnZXRLZXlJdGVtAAAAAgUAAAAPc3VwcGxpZXJBZGRyZXNzBQAAAAV0aXRsZQMJAABnAAAAAgAAAAAAAAAAAAUAAAAFcHJpY2UJAAACAAAAAQIAAAAucHVyY2hhc2UgYW1vdW50IGNhbm5vdCBiZSBsZXNzIHRoYW4gaXRlbSBwcmljZQMJAQAAAAIhPQAAAAIJAQAAABRnZXRWYWx1ZUl0ZW1TdXBwbGllcgAAAAEFAAAABGl0ZW0FAAAABE5PTkUJAAACAAAAAQIAAAAYYW4gaXRlbSBpcyBhbHJlYWR5IGV4aXN0CQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAASZ2V0S2V5SXRlbVN1cHBsaWVyAAAAAQUAAAAEaXRlbQUAAAAPc3VwcGxpZXJBZGRyZXNzCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQUAAAAEaXRlbQUAAAAFcHJpY2UJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAAA5nZXRLZXlJdGVtRGF0YQAAAAEFAAAABGl0ZW0FAAAABGRhdGEFAAAAA25pbAAAAADsKGkm", "chainId": 84, "height": 652706, "spentComplexity": 0 } View: original | compacted Prev: Cc3yV9QQpQgridXCrfjces97bwfpjVCpbFmxRjBVdLT2 Next: 8bKc43RrtX9AiS43a1SqTMVw6XBDunxoL5JUCjo4zFLd Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let NONE = "none" | |
5 | + | ||
6 | + | func getNumberByKey (key) = { | |
7 | + | let num = match getInteger(this, key) { | |
8 | + | case a: Int => | |
9 | + | a | |
10 | + | case _ => | |
11 | + | 0 | |
12 | + | } | |
13 | + | num | |
14 | + | } | |
15 | + | ||
16 | + | ||
17 | + | func getStrByKey (key) = { | |
18 | + | let str = match getString(this, key) { | |
19 | + | case a: String => | |
20 | + | a | |
21 | + | case _ => | |
22 | + | NONE | |
23 | + | } | |
24 | + | str | |
25 | + | } | |
26 | + | ||
27 | + | ||
28 | + | func getKeyItemPrice (item) = (item + "_price") | |
29 | + | ||
30 | + | ||
31 | + | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
32 | + | ||
33 | + | ||
34 | + | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
35 | + | ||
36 | + | ||
37 | + | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | + | ||
39 | + | ||
40 | + | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
41 | + | ||
42 | + | ||
43 | + | func getKeyItemData (item) = (item + "_data") | |
44 | + | ||
45 | + | ||
46 | + | func getKeyItemSupplier (item) = (item + "_owner") | |
47 | + | ||
48 | + | ||
49 | + | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
50 | + | ||
51 | + | ||
52 | + | func getKeyBalanceSupplier (account) = (account + "_balance") | |
53 | + | ||
54 | + | ||
55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
4 | 56 | ||
5 | 57 | ||
6 | 58 | @Callable(i) | |
7 | - | func purchase () = { | |
59 | + | func purchase (item) = { | |
8 | 60 | let pmt = extract(i.payment) | |
9 | 61 | if (isDefined(pmt.assetId)) | |
10 | - | then throw(" | |
62 | + | then throw("WAVES tokens only at the moment") | |
11 | 63 | else { | |
12 | - | let customerAddress = toBase58String(i.caller.bytes) | |
13 | - | let price = match getInteger(this, "item_A_coupon_price") { | |
14 | - | case a: Int => | |
15 | - | a | |
16 | - | case _ => | |
17 | - | 0 | |
18 | - | } | |
64 | + | let userAddress = toBase58String(i.caller.bytes) | |
65 | + | let price = getValueItemPrice(item) | |
66 | + | let supplierAddress = getValueItemSupplier(item) | |
19 | 67 | if ((price > pmt.amount)) | |
20 | - | then throw("purchase amount | |
68 | + | then throw("purchase amount cannot be less than item price") | |
21 | 69 | else if ((pmt.amount > price)) | |
22 | 70 | then throw("purchase amount cannot be higher than item price") | |
23 | - | else WriteSet([DataEntry(("status:purchase_item_A_customer_" + customerAddress), "confirmed"), DataEntry(("price:purchase_item_A_customer_" + customerAddress), price)]) | |
71 | + | else if ((supplierAddress == NONE)) | |
72 | + | then throw("supplier does not exist") | |
73 | + | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
24 | 74 | } | |
75 | + | } | |
76 | + | ||
77 | + | ||
78 | + | ||
79 | + | @Callable(i) | |
80 | + | func addItem (title,price,data) = { | |
81 | + | let supplierAddress = toBase58String(i.caller.bytes) | |
82 | + | let item = getKeyItem(supplierAddress, title) | |
83 | + | if ((0 >= price)) | |
84 | + | then throw("purchase amount cannot be less than item price") | |
85 | + | else if ((getValueItemSupplier(item) != NONE)) | |
86 | + | then throw("an item is already exist") | |
87 | + | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
25 | 88 | } | |
26 | 89 | ||
27 | 90 |
github/deemru/w8io/026f985 38.82 ms ◑