tx · 6MSZ5K7oA84jrWRR1rU2wmxWrR1JtvP6KFB5PofzVfFK

3MstgGUbpZXoVkvJwJC3cxrnTeyVdNzF7VW:  -0.01400000 Waves

2019.10.24 01:42 [733355] smart account 3MstgGUbpZXoVkvJwJC3cxrnTeyVdNzF7VW > SELF 0.00000000 Waves

{ "type": 13, "id": "6MSZ5K7oA84jrWRR1rU2wmxWrR1JtvP6KFB5PofzVfFK", "fee": 1400000, "feeAssetId": null, "timestamp": 1571870618598, "version": 1, "sender": "3MstgGUbpZXoVkvJwJC3cxrnTeyVdNzF7VW", "senderPublicKey": "13YevTfaVEoXJ5hu2kSjqnp2j2E8RV3NHHFM6giCFssY", "proofs": [ "2ftHzGCos3Jn4Rsb4zvLwmH685pSeMJE6oTV5T54jNhypVD6Q32FNSe64mp7rHKxAnDkGVk2RVumXa8QhuJaYYtR" ], "script": "base64:AAIDAAAAAAAAABUIARIAEgUKAwgBCBIDCgEIEgMKAQEAAAAOAAAAAAVPV05FUgEAAAAgAKbz5MdxP05qBtYSxXJqn4C6YVMLl9rDunp3cgoCCTsBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAABm51bWJlcgQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAUAAAAGbnVtYmVyAAAAAAROT05FAgAAAARub25lAQAAAA5nZXRTdHJpbmdCeUtleQAAAAEAAAADa2V5BAAAAAZzdHJpbmcEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEFAAAABE5PTkUFAAAABnN0cmluZwEAAAAKZ2V0SXRlbUtleQAAAAIAAAAIc3VwcGxpZXIAAAAFdGl0bGUEAAAABml0ZW1J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AGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAUAAAAFT1dORVIDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAD0RhdGFUcmFuc2FjdGlvbgQAAAABYgUAAAAHJG1hdGNoMAYHmZFXNQ==", "chainId": 84, "height": 733355, "spentComplexity": 0 } View: original | compacted Prev: E6RWCirKWgu6RT8uCR2TSjrbNmHQHd52gRQ3EpCftdcA Next: none Diff:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let owner = base58'13YevTfaVEoXJ5hu2kSjqnp2j2E8RV3NHHFM6giCFssY'
4+let OWNER = base58'13YevTfaVEoXJ5hu2kSjqnp2j2E8RV3NHHFM6giCFssY'
55
66 func getNumberByKey (key) = {
77 let number = match getInteger(this, key) {
1414 }
1515
1616
17+let NONE = "none"
18+
1719 func getStringByKey (key) = {
1820 let string = match getString(this, key) {
1921 case a: String =>
2022 a
2123 case _ =>
22- "none"
24+ NONE
2325 }
2426 string
2527 }
2628
2729
28-func getItemKeyPrice (item) = (item + "_price")
30+func getItemKey (supplier,title) = {
31+ let itemId = (supplier + title)
32+ ("item_" + toBase58String(toBytes(itemId)))
33+ }
2934
3035
31-func getValueItemPrice (item) = getNumberByKey(getItemKeyPrice(item))
36+func getItemOwnerKey (item) = (item + "_owner")
3237
3338
34-func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "count")
39+func getItemOwnerValue (item) = getStringByKey(getItemOwnerKey(item))
3540
3641
37-func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
42+func getItemPriceKey (item) = (item + "_price")
3843
3944
40-func getKeyItem (supplier,title) = ("item_" + toBase58String(toBytes((supplier + title))))
45+func getItemPriceValue (item) = getNumberByKey(getItemPriceKey(item))
4146
4247
43-func getKeyItemData (item) = (item + "_data")
48+func getItemDataKey (item) = (item + "_data")
4449
4550
46-func getKeyItemSupplier (item) = (item + "_owner")
51+func getItemDataValue (item) = getStringByKey(getItemDataKey(item))
4752
4853
49-func getValueItemSupplier (item) = getStringByKey(getKeyItemSupplier(item))
54+func getAccountBalanceKey (account) = (("account_" + account) + "_balance")
5055
5156
52-func getKeyBalanceSupplier (account) = (account + "_balance")
57+func getAccountBalanceValue (account) = getNumberByKey(getAccountBalanceKey(account))
5358
5459
55-func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
60+func getPurchasePriceKey (item,customer) = (((("purchase_" + item) + "_customer_") + customer) + "_price")
5661
5762
58-@Callable(i)
63+@Callable(inv)
5964 func deposit () = {
60- let pmt = extract(i.payment)
61- if (isDefined(pmt.assetId))
62- then throw("you can use WAVES only at the moment")
65+ let payment = extract(inv.payment)
66+ if (isDefined(payment.assetId))
67+ then throw("you can only use WAVES at the moment")
6368 else {
64- let currentKey = toBase58String(i.caller.bytes)
65- let currentAmount = match getInteger(this, ("wl_sts" + currentKey)) {
66- case a: Int =>
67- a
68- case _ =>
69- 0
70- }
71- let wlStsCurr = match getString(this, ("wls_sts" + currentKey)) {
72- case a: String =>
73- a
74- case _ =>
75- throw("user has not waitlisted")
76- }
77- let newAmount = (currentAmount + pmt.amount)
78- WriteSet([DataEntry(currentKey, newAmount)])
69+ let accountAddress = toBase58String(inv.caller.bytes)
70+ let currentAmount = getAccountBalanceValue(accountAddress)
71+ let newAmount = (currentAmount + payment.amount)
72+ WriteSet([DataEntry(accountAddress, newAmount)])
7973 }
8074 }
8175
8276
8377
84-@Callable(i)
78+@Callable(inv)
8579 func addItem (title,price,data) = {
86- let supplierAddres = toBase58String(i.caller.bytes)
87- let item = getKeyItem(supplierAddres, title)
80+ let supplierAddress = toBase58String(inv.caller.bytes)
81+ let item = getItemKey(supplierAddress, title)
8882 if ((0 >= price))
8983 then throw("purchase amount cannot be less that item price")
90- else if (("none" != getValueItemSupplier(item)))
84+ else if ((NONE != getItemOwnerValue(item)))
9185 then throw("an item is alreadt exist")
92- else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddres), DataEntry(getItemKeyPrice(item), price), DataEntry(getKeyItemData(item), data)])
86+ else WriteSet([DataEntry(getItemOwnerKey(item), supplierAddress), DataEntry(getItemPriceKey(item), price), DataEntry(getItemDataKey(item), data)])
9387 }
9488
9589
9690
97-@Callable(i)
98-func purchase () = {
99- let pmt = extract(i.payment)
100- if (isDefined(pmt.assetId))
101- then throw("you can use WAVES only at the moment")
91+@Callable(inv)
92+func purchase (item) = {
93+ let payment = extract(inv.payment)
94+ if (isDefined(payment.assetId))
95+ then throw("you can only use WAVES at the moment")
10296 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))
97+ let customerAddress = toBase58String(inv.caller.bytes)
98+ let price = getItemPriceValue(item)
99+ if ((price > payment.amount))
111100 then throw("purchase amount cannot be less that item price")
112- else if ((pmt.amount > price))
101+ else if ((payment.amount > price))
113102 then throw("purchase amount cannot be higher that item price")
114- else WriteSet([DataEntry(("status:purchase_item_A_customer_" + customerAddres), "confirmed"), DataEntry(("price:purchase_item_A_customer" + customerAddres), price)])
103+ else WriteSet([DataEntry(getPurchasePriceKey(item, customerAddress), price)])
115104 }
116105 }
117106
119108
120109 @Callable(inv)
121110 func withdraw (amount) = {
122- let currentKey = toBase58String(inv.caller.bytes)
123- let currentAmount = getNumberByKey(currentKey)
111+ let accountAddress = toBase58String(inv.caller.bytes)
112+ let currentAmount = getAccountBalanceValue(accountAddress)
124113 let newAmount = (currentAmount - amount)
125114 if ((0 > amount))
126- then throw("can't withdraw negative amount")
115+ then throw("cannot withdraw negative amount")
127116 else if ((0 > newAmount))
128117 then throw("not enough balance")
129- else ScriptResult(WriteSet([DataEntry(currentKey, newAmount)]), TransferSet([ScriptTransfer(inv.caller, amount, unit)]))
118+ else ScriptResult(WriteSet([DataEntry(getAccountBalanceKey(accountAddress), newAmount)]), TransferSet([ScriptTransfer(inv.caller, amount, unit)]))
130119 }
131120
132121
133122 @Verifier(tx)
134123 func verify () = match tx {
135124 case a: SetScriptTransaction =>
136- sigVerify(tx.bodyBytes, tx.proofs[0], owner)
125+ sigVerify(tx.bodyBytes, tx.proofs[0], OWNER)
137126 case b: DataTransaction =>
138127 true
139128 case _ =>
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let owner = base58'13YevTfaVEoXJ5hu2kSjqnp2j2E8RV3NHHFM6giCFssY'
4+let OWNER = base58'13YevTfaVEoXJ5hu2kSjqnp2j2E8RV3NHHFM6giCFssY'
55
66 func getNumberByKey (key) = {
77 let number = match getInteger(this, key) {
88 case a: Int =>
99 a
1010 case _ =>
1111 0
1212 }
1313 number
1414 }
1515
1616
17+let NONE = "none"
18+
1719 func getStringByKey (key) = {
1820 let string = match getString(this, key) {
1921 case a: String =>
2022 a
2123 case _ =>
22- "none"
24+ NONE
2325 }
2426 string
2527 }
2628
2729
28-func getItemKeyPrice (item) = (item + "_price")
30+func getItemKey (supplier,title) = {
31+ let itemId = (supplier + title)
32+ ("item_" + toBase58String(toBytes(itemId)))
33+ }
2934
3035
31-func getValueItemPrice (item) = getNumberByKey(getItemKeyPrice(item))
36+func getItemOwnerKey (item) = (item + "_owner")
3237
3338
34-func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "count")
39+func getItemOwnerValue (item) = getStringByKey(getItemOwnerKey(item))
3540
3641
37-func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
42+func getItemPriceKey (item) = (item + "_price")
3843
3944
40-func getKeyItem (supplier,title) = ("item_" + toBase58String(toBytes((supplier + title))))
45+func getItemPriceValue (item) = getNumberByKey(getItemPriceKey(item))
4146
4247
43-func getKeyItemData (item) = (item + "_data")
48+func getItemDataKey (item) = (item + "_data")
4449
4550
46-func getKeyItemSupplier (item) = (item + "_owner")
51+func getItemDataValue (item) = getStringByKey(getItemDataKey(item))
4752
4853
49-func getValueItemSupplier (item) = getStringByKey(getKeyItemSupplier(item))
54+func getAccountBalanceKey (account) = (("account_" + account) + "_balance")
5055
5156
52-func getKeyBalanceSupplier (account) = (account + "_balance")
57+func getAccountBalanceValue (account) = getNumberByKey(getAccountBalanceKey(account))
5358
5459
55-func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
60+func getPurchasePriceKey (item,customer) = (((("purchase_" + item) + "_customer_") + customer) + "_price")
5661
5762
58-@Callable(i)
63+@Callable(inv)
5964 func deposit () = {
60- let pmt = extract(i.payment)
61- if (isDefined(pmt.assetId))
62- then throw("you can use WAVES only at the moment")
65+ let payment = extract(inv.payment)
66+ if (isDefined(payment.assetId))
67+ then throw("you can only use WAVES at the moment")
6368 else {
64- let currentKey = toBase58String(i.caller.bytes)
65- let currentAmount = match getInteger(this, ("wl_sts" + currentKey)) {
66- case a: Int =>
67- a
68- case _ =>
69- 0
70- }
71- let wlStsCurr = match getString(this, ("wls_sts" + currentKey)) {
72- case a: String =>
73- a
74- case _ =>
75- throw("user has not waitlisted")
76- }
77- let newAmount = (currentAmount + pmt.amount)
78- WriteSet([DataEntry(currentKey, newAmount)])
69+ let accountAddress = toBase58String(inv.caller.bytes)
70+ let currentAmount = getAccountBalanceValue(accountAddress)
71+ let newAmount = (currentAmount + payment.amount)
72+ WriteSet([DataEntry(accountAddress, newAmount)])
7973 }
8074 }
8175
8276
8377
84-@Callable(i)
78+@Callable(inv)
8579 func addItem (title,price,data) = {
86- let supplierAddres = toBase58String(i.caller.bytes)
87- let item = getKeyItem(supplierAddres, title)
80+ let supplierAddress = toBase58String(inv.caller.bytes)
81+ let item = getItemKey(supplierAddress, title)
8882 if ((0 >= price))
8983 then throw("purchase amount cannot be less that item price")
90- else if (("none" != getValueItemSupplier(item)))
84+ else if ((NONE != getItemOwnerValue(item)))
9185 then throw("an item is alreadt exist")
92- else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddres), DataEntry(getItemKeyPrice(item), price), DataEntry(getKeyItemData(item), data)])
86+ else WriteSet([DataEntry(getItemOwnerKey(item), supplierAddress), DataEntry(getItemPriceKey(item), price), DataEntry(getItemDataKey(item), data)])
9387 }
9488
9589
9690
97-@Callable(i)
98-func purchase () = {
99- let pmt = extract(i.payment)
100- if (isDefined(pmt.assetId))
101- then throw("you can use WAVES only at the moment")
91+@Callable(inv)
92+func purchase (item) = {
93+ let payment = extract(inv.payment)
94+ if (isDefined(payment.assetId))
95+ then throw("you can only use WAVES at the moment")
10296 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))
97+ let customerAddress = toBase58String(inv.caller.bytes)
98+ let price = getItemPriceValue(item)
99+ if ((price > payment.amount))
111100 then throw("purchase amount cannot be less that item price")
112- else if ((pmt.amount > price))
101+ else if ((payment.amount > price))
113102 then throw("purchase amount cannot be higher that item price")
114- else WriteSet([DataEntry(("status:purchase_item_A_customer_" + customerAddres), "confirmed"), DataEntry(("price:purchase_item_A_customer" + customerAddres), price)])
103+ else WriteSet([DataEntry(getPurchasePriceKey(item, customerAddress), price)])
115104 }
116105 }
117106
118107
119108
120109 @Callable(inv)
121110 func withdraw (amount) = {
122- let currentKey = toBase58String(inv.caller.bytes)
123- let currentAmount = getNumberByKey(currentKey)
111+ let accountAddress = toBase58String(inv.caller.bytes)
112+ let currentAmount = getAccountBalanceValue(accountAddress)
124113 let newAmount = (currentAmount - amount)
125114 if ((0 > amount))
126- then throw("can't withdraw negative amount")
115+ then throw("cannot withdraw negative amount")
127116 else if ((0 > newAmount))
128117 then throw("not enough balance")
129- else ScriptResult(WriteSet([DataEntry(currentKey, newAmount)]), TransferSet([ScriptTransfer(inv.caller, amount, unit)]))
118+ else ScriptResult(WriteSet([DataEntry(getAccountBalanceKey(accountAddress), newAmount)]), TransferSet([ScriptTransfer(inv.caller, amount, unit)]))
130119 }
131120
132121
133122 @Verifier(tx)
134123 func verify () = match tx {
135124 case a: SetScriptTransaction =>
136- sigVerify(tx.bodyBytes, tx.proofs[0], owner)
125+ sigVerify(tx.bodyBytes, tx.proofs[0], OWNER)
137126 case b: DataTransaction =>
138127 true
139128 case _ =>
140129 false
141130 }
142131

github/deemru/w8io/873ac7e 
63.15 ms