tx · 5R3UgoPr5yrLBYn9tkS1vbxHtVXno8g8tkVtKs8Y4mKB 3N9nVNxRXkYG1LxBamitnLpZzXcjGDZ2Q6z: -0.01400000 Waves 2019.10.17 01:45 [723173] smart account 3N9nVNxRXkYG1LxBamitnLpZzXcjGDZ2Q6z > SELF 0.00000000 Waves
{ "type": 13, "id": "5R3UgoPr5yrLBYn9tkS1vbxHtVXno8g8tkVtKs8Y4mKB", "fee": 1400000, "feeAssetId": null, "timestamp": 1571265807393, "version": 1, "sender": "3N9nVNxRXkYG1LxBamitnLpZzXcjGDZ2Q6z", "senderPublicKey": "EEGsMXJbL3i6pER7gfBpcw87Km3h2gz6qiqhqPXbdob1", "proofs": [ "3vLW2ZuKjUnwBcXWdgoNsqhL9fCtZMfGARgMr4EHgemfT42aLVqxZzez855CZSxBSLqJu3K1vMChEkYr5eTNPdAu" ], "script": "base64:AAIDAAAAAAAAABIIARIAEgUKAwgBCBIAEgMKAQEAAAANAAAAAAVvd25lcgEAAAAgxI5sOc85F96AyMEOQS+ZrrcXbjWOtavgO5Vy9VGjFCwBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAABm51bWJlcgQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAUAAAAGbnVtYmVyAQAAAA5nZXRTdHJpbmdCeUtleQAAAAEAAAADa2V5BAAAAAZzdHJpbmcEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWECAAAABG5vbmUFAAAABnN0cmluZwEAAAAPZ2V0SXRlbUtleVByaWNlAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9wcmljZQEAAAARZ2V0V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mVzdWx0AAAAAgkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgUAAAAKY3VycmVudEtleQUAAAAJbmV3QW1vdW50BQAAAANuaWwJAQAAAAtUcmFuc2ZlclNldAAAAAEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAAWkAAAAGY2FsbGVyBQAAAAZhbW91bnQFAAAABHVuaXQFAAAAA25pbAAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAEAAAAByRtYXRjaDAFAAAAAnR4AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAABRTZXRTY3JpcHRUcmFuc2FjdGlvbgQAAAABYQUAAAAHJG1hdGNoMAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAFAAAABW93bmVyAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAA9EYXRhVHJhbnNhY3Rpb24EAAAAAWIFAAAAByRtYXRjaDAGB8xVdWQ=", "chainId": 84, "height": 723173, "spentComplexity": 0 } View: original | compacted Prev: 8NCvqyjmtQstQ75WrkrNXTxFduHQxDRAYpJfvVeotNXD Next: 52xKkKdaBEAYbHWbm2QPGu3Pm2SA95jyQ8wUdrigUJcB Diff:
Old | New | Differences | |
---|---|---|---|
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let owner = base58'EEGsMXJbL3i6pER7gfBpcw87Km3h2gz6qiqhqPXbdob1' | |
5 | 5 | ||
6 | - | @Callable(i) | |
7 | - | func purchare () = { | |
8 | - | let pmt = extract(i.payment) | |
9 | - | if (isDefined(pmt.assetId)) | |
10 | - | then throw("you can use WAVES only at the moment") | |
11 | - | else { | |
12 | - | let customerAddres = 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 | - | } | |
19 | - | if ((price > pmt.amount)) | |
20 | - | then throw("purchare amount cannot be less that item price") | |
21 | - | else if ((pmt.amount > price)) | |
22 | - | then throw("purchare amount cannot be higher that item price") | |
23 | - | else WriteSet([DataEntry(("status:purchare_item_A_customer_" + customerAddres), "confirmed"), DataEntry(("price:purchare_item_A_customer" + customerAddres), price)]) | |
24 | - | } | |
6 | + | func getNumberByKey (key) = { | |
7 | + | let number = match getInteger(this, key) { | |
8 | + | case a: Int => | |
9 | + | a | |
10 | + | case _ => | |
11 | + | 0 | |
12 | + | } | |
13 | + | number | |
25 | 14 | } | |
26 | 15 | ||
16 | + | ||
17 | + | func getStringByKey (key) = { | |
18 | + | let string = match getString(this, key) { | |
19 | + | case a: String => | |
20 | + | a | |
21 | + | case _ => | |
22 | + | "none" | |
23 | + | } | |
24 | + | string | |
25 | + | } | |
26 | + | ||
27 | + | ||
28 | + | func getItemKeyPrice (item) = (item + "_price") | |
29 | + | ||
30 | + | ||
31 | + | func getValueItemPrice (item) = getNumberByKey(getItemKeyPrice(item)) | |
32 | + | ||
33 | + | ||
34 | + | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "count") | |
35 | + | ||
36 | + | ||
37 | + | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | + | ||
39 | + | ||
40 | + | func getKeyItem (supplier,title) = ("item_" + toBase58String(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) = getStringByKey(getKeyItemSupplier(item)) | |
50 | + | ||
51 | + | ||
52 | + | func getKeyBalanceSupplier (account) = (account + "_balance") | |
53 | + | ||
54 | + | ||
55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
27 | 56 | ||
28 | 57 | ||
29 | 58 | @Callable(i) | |
47 | 76 | } | |
48 | 77 | let newAmount = (currentAmount + pmt.amount) | |
49 | 78 | WriteSet([DataEntry(currentKey, newAmount)]) | |
79 | + | } | |
80 | + | } | |
81 | + | ||
82 | + | ||
83 | + | ||
84 | + | @Callable(i) | |
85 | + | func addItem (title,price,data) = { | |
86 | + | let supplierAddres = toBase58String(i.caller.bytes) | |
87 | + | let item = getKeyItem(supplierAddres, title) | |
88 | + | if ((0 >= price)) | |
89 | + | then throw("purchase amount cannot be less that item price") | |
90 | + | else if (("none" != getValueItemSupplier(item))) | |
91 | + | then throw("an item is alreadt exist") | |
92 | + | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddres), DataEntry(getItemKeyPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
93 | + | } | |
94 | + | ||
95 | + | ||
96 | + | ||
97 | + | @Callable(i) | |
98 | + | func purchare () = { | |
99 | + | let pmt = extract(i.payment) | |
100 | + | if (isDefined(pmt.assetId)) | |
101 | + | then throw("you can use WAVES only at the moment") | |
102 | + | else { | |
103 | + | let customerAddres = toBase58String(i.caller.bytes) | |
104 | + | let price = match getInteger(this, "item_A_coupon_price") { | |
105 | + | case a: Int => | |
106 | + | a | |
107 | + | case _ => | |
108 | + | 0 | |
109 | + | } | |
110 | + | if ((price > pmt.amount)) | |
111 | + | then throw("purchare amount cannot be less that item price") | |
112 | + | else if ((pmt.amount > price)) | |
113 | + | then throw("purchare amount cannot be higher that item price") | |
114 | + | else WriteSet([DataEntry(("status:purchare_item_A_customer_" + customerAddres), "confirmed"), DataEntry(("price:purchare_item_A_customer" + customerAddres), price)]) | |
50 | 115 | } | |
51 | 116 | } | |
52 | 117 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let owner = base58'EEGsMXJbL3i6pER7gfBpcw87Km3h2gz6qiqhqPXbdob1' | |
5 | 5 | ||
6 | - | @Callable(i) | |
7 | - | func purchare () = { | |
8 | - | let pmt = extract(i.payment) | |
9 | - | if (isDefined(pmt.assetId)) | |
10 | - | then throw("you can use WAVES only at the moment") | |
11 | - | else { | |
12 | - | let customerAddres = 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 | - | } | |
19 | - | if ((price > pmt.amount)) | |
20 | - | then throw("purchare amount cannot be less that item price") | |
21 | - | else if ((pmt.amount > price)) | |
22 | - | then throw("purchare amount cannot be higher that item price") | |
23 | - | else WriteSet([DataEntry(("status:purchare_item_A_customer_" + customerAddres), "confirmed"), DataEntry(("price:purchare_item_A_customer" + customerAddres), price)]) | |
24 | - | } | |
6 | + | func getNumberByKey (key) = { | |
7 | + | let number = match getInteger(this, key) { | |
8 | + | case a: Int => | |
9 | + | a | |
10 | + | case _ => | |
11 | + | 0 | |
12 | + | } | |
13 | + | number | |
25 | 14 | } | |
26 | 15 | ||
16 | + | ||
17 | + | func getStringByKey (key) = { | |
18 | + | let string = match getString(this, key) { | |
19 | + | case a: String => | |
20 | + | a | |
21 | + | case _ => | |
22 | + | "none" | |
23 | + | } | |
24 | + | string | |
25 | + | } | |
26 | + | ||
27 | + | ||
28 | + | func getItemKeyPrice (item) = (item + "_price") | |
29 | + | ||
30 | + | ||
31 | + | func getValueItemPrice (item) = getNumberByKey(getItemKeyPrice(item)) | |
32 | + | ||
33 | + | ||
34 | + | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "count") | |
35 | + | ||
36 | + | ||
37 | + | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
38 | + | ||
39 | + | ||
40 | + | func getKeyItem (supplier,title) = ("item_" + toBase58String(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) = getStringByKey(getKeyItemSupplier(item)) | |
50 | + | ||
51 | + | ||
52 | + | func getKeyBalanceSupplier (account) = (account + "_balance") | |
53 | + | ||
54 | + | ||
55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
27 | 56 | ||
28 | 57 | ||
29 | 58 | @Callable(i) | |
30 | 59 | func deposit () = { | |
31 | 60 | let pmt = extract(i.payment) | |
32 | 61 | if (isDefined(pmt.assetId)) | |
33 | 62 | then throw("you can use WAVES only at the moment") | |
34 | 63 | else { | |
35 | 64 | let currentKey = toBase58String(i.caller.bytes) | |
36 | 65 | let currentAmount = match getInteger(this, ("wl_sts" + currentKey)) { | |
37 | 66 | case a: Int => | |
38 | 67 | a | |
39 | 68 | case _ => | |
40 | 69 | 0 | |
41 | 70 | } | |
42 | 71 | let wlStsCurr = match getString(this, ("wls_sts" + currentKey)) { | |
43 | 72 | case a: String => | |
44 | 73 | a | |
45 | 74 | case _ => | |
46 | 75 | throw("user has not waitlisted") | |
47 | 76 | } | |
48 | 77 | let newAmount = (currentAmount + pmt.amount) | |
49 | 78 | WriteSet([DataEntry(currentKey, newAmount)]) | |
79 | + | } | |
80 | + | } | |
81 | + | ||
82 | + | ||
83 | + | ||
84 | + | @Callable(i) | |
85 | + | func addItem (title,price,data) = { | |
86 | + | let supplierAddres = toBase58String(i.caller.bytes) | |
87 | + | let item = getKeyItem(supplierAddres, title) | |
88 | + | if ((0 >= price)) | |
89 | + | then throw("purchase amount cannot be less that item price") | |
90 | + | else if (("none" != getValueItemSupplier(item))) | |
91 | + | then throw("an item is alreadt exist") | |
92 | + | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddres), DataEntry(getItemKeyPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
93 | + | } | |
94 | + | ||
95 | + | ||
96 | + | ||
97 | + | @Callable(i) | |
98 | + | func purchare () = { | |
99 | + | let pmt = extract(i.payment) | |
100 | + | if (isDefined(pmt.assetId)) | |
101 | + | then throw("you can use WAVES only at the moment") | |
102 | + | else { | |
103 | + | let customerAddres = toBase58String(i.caller.bytes) | |
104 | + | let price = match getInteger(this, "item_A_coupon_price") { | |
105 | + | case a: Int => | |
106 | + | a | |
107 | + | case _ => | |
108 | + | 0 | |
109 | + | } | |
110 | + | if ((price > pmt.amount)) | |
111 | + | then throw("purchare amount cannot be less that item price") | |
112 | + | else if ((pmt.amount > price)) | |
113 | + | then throw("purchare amount cannot be higher that item price") | |
114 | + | else WriteSet([DataEntry(("status:purchare_item_A_customer_" + customerAddres), "confirmed"), DataEntry(("price:purchare_item_A_customer" + customerAddres), price)]) | |
50 | 115 | } | |
51 | 116 | } | |
52 | 117 | ||
53 | 118 | ||
54 | 119 | ||
55 | 120 | @Callable(i) | |
56 | 121 | func withdraw (amount) = { | |
57 | 122 | let currentKey = toBase58String(i.caller.bytes) | |
58 | 123 | let currentAmount = match getInteger(this, currentKey) { | |
59 | 124 | case a: Int => | |
60 | 125 | a | |
61 | 126 | case _ => | |
62 | 127 | 0 | |
63 | 128 | } | |
64 | 129 | let newAmount = (currentAmount - amount) | |
65 | 130 | if ((0 > amount)) | |
66 | 131 | then throw("can't withdraw negative amount") | |
67 | 132 | else if ((0 > newAmount)) | |
68 | 133 | then throw("not enough balance") | |
69 | 134 | else ScriptResult(WriteSet([DataEntry(currentKey, newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, unit)])) | |
70 | 135 | } | |
71 | 136 | ||
72 | 137 | ||
73 | 138 | @Verifier(tx) | |
74 | 139 | func verify () = match tx { | |
75 | 140 | case a: SetScriptTransaction => | |
76 | 141 | sigVerify(tx.bodyBytes, tx.proofs[0], owner) | |
77 | 142 | case b: DataTransaction => | |
78 | 143 | true | |
79 | 144 | case _ => | |
80 | 145 | false | |
81 | 146 | } | |
82 | 147 |
github/deemru/w8io/169f3d6 31.82 ms ◑