tx · HiaxjgkBon59CX7NBhKuMdu6wXGxGEenUYX8JGcE3bsA
3MxS2LBsPnEGA6AetWPqWTZjmQu8zUySd2c: -0.01000000 Waves
2021.07.06 17:54 [1601899] smart account 3MxS2LBsPnEGA6AetWPqWTZjmQu8zUySd2c > SELF 0.00000000 Waves
{
"type": 13,
"id": "HiaxjgkBon59CX7NBhKuMdu6wXGxGEenUYX8JGcE3bsA",
"fee": 1000000,
"feeAssetId": null,
"timestamp": 1625583265127,
"version": 2,
"chainId": 84,
"sender": "3MxS2LBsPnEGA6AetWPqWTZjmQu8zUySd2c",
"senderPublicKey": "9dJbLdKrkcPAEacPHvgivaqbGgimy4WN2MRrE6XXWFQu",
"proofs": [
"Esps78FgZwXnLBDqFwFh6jPNp9FzmUYsUSgdx23QbwVMbQYXw1mfShkUGrcyz9p5YntAHHZ9qP1RspXpcdAJ9gU"
],
"script": "base64:AAIFAAAAAAAAAh0IAhIFCgMIAQgSAwoBCBoKCgJhMRIETk9ORRoUCgJhMhIOZ2V0TnVtYmVyQnlLZXkaCQoCYTMSA2tleRoJCgJhNBIDbnVtGg0KAmE1EgckbWF0Y2gwGgcKAmE2EgFhGhEKAmE3EgtnZXRTdHJCeUtleRoJCgJhOBIDc3RyGhUKAmE5Eg9nZXRLZXlJdGVtUHJpY2UaCgoCYjESBGl0ZW0aFwoCYjISEWdldFZhbHVlSXRlbVByaWNlGhsKAmIzEhVnZXRLZXlVc2VySXRlbUNvdW50ZXIaCgoCYjQSBHVzZXIaHQoCYjUSF2dldFZhbHVlVXNlckl0ZW1Db3VudGVyGhAKAmI2EgpnZXRLZXlJdGVtGg4KAmI3EghzdXBwbGllchoLCgJiOBIFdGl0bGUaFAoCYjkSDmdldEtleUl0ZW1EYXRhGhgKAmMxEhJnZXRLZXlJdGVtU3VwcGxpZXIaGgoCYzISFGdldFZhbHVlSXRlbVN1cHBsaWVyGhsKAmMzEhVnZXRLZXlCYWxhbmNlU3VwcGxpZXIaDQoCYzQSB2FjY291bnQ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AAGYAAAACBQAAAAJjNwgFAAAAAmQxAAAABmFtb3VudAkAAAIAAAABAgAAAC5QdXJjaGFzZSBhbW91bnQgY2Fubm90IGJlIGxlc3MgdGhhbiBpdGVtIHByaWNlAwkAAAAAAAACBQAAAAJjOQUAAAACYTEJAAACAAAAAQIAAAAXU3VwcGxpZXIgZG9lcyBub3QgZXhpc3QJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJiMwAAAAIFAAAAAmQyBQAAAAJiMQkAAGQAAAACCQEAAAACYjUAAAACBQAAAAJkMgUAAAACYjEAAAAAAAAAAAEJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJjMwAAAAEFAAAAAmM5CQAAZAAAAAIJAQAAAAJjNQAAAAEFAAAAAmM5CAUAAAACZDEAAAAGYW1vdW50BQAAAANuaWwAAAAARhiIrg==",
"height": 1601899,
"applicationStatus": "succeeded",
"spentComplexity": 0
}
View: original | compacted
Prev: BojZK2d3u858GAovt2E22EQS2hqfc8FtnUBKwgPckYTN
Next: zwakKpemf7yZ1ytwhjtfUxJLTAeL44dNBzYchFU5MHp
Diff:
Old | New | | Differences |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 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 | + | |
---|
5 | 16 | | |
---|
6 | 17 | | func getStrByKey (key) = { |
---|
7 | 18 | | let str = match getString(this, key) { |
---|
|
17 | 28 | | func getKeyItemPrice (item) = (item + "_price") |
---|
18 | 29 | | |
---|
19 | 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 | + | |
---|
20 | 40 | | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) |
---|
21 | 41 | | |
---|
22 | 42 | | |
---|
|
27 | 47 | | |
---|
28 | 48 | | |
---|
29 | 49 | | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) |
---|
| 50 | + | |
---|
| 51 | + | |
---|
| 52 | + | func getKeyBalanceSupplier (account) = (account + "_balance") |
---|
| 53 | + | |
---|
| 54 | + | |
---|
| 55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) |
---|
30 | 56 | | |
---|
31 | 57 | | |
---|
32 | 58 | | @Callable(i) |
---|
|
41 | 67 | | } |
---|
42 | 68 | | |
---|
43 | 69 | | |
---|
| 70 | + | |
---|
| 71 | + | @Callable(i) |
---|
| 72 | + | func purchase (item) = { |
---|
| 73 | + | let pmt = i.payments[0] |
---|
| 74 | + | if (isDefined(pmt.assetId)) |
---|
| 75 | + | then throw("WAVES ONLY HHEUAWHEUAS") |
---|
| 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 ((supplierAddress == NONE)) |
---|
| 83 | + | then throw("Supplier does not exist") |
---|
| 84 | + | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))] |
---|
| 85 | + | } |
---|
| 86 | + | } |
---|
| 87 | + | |
---|
| 88 | + | |
---|
Full:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 5 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 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 | + | |
---|
5 | 16 | | |
---|
6 | 17 | | func getStrByKey (key) = { |
---|
7 | 18 | | let str = match getString(this, key) { |
---|
8 | 19 | | case a: String => |
---|
9 | 20 | | a |
---|
10 | 21 | | case _ => |
---|
11 | 22 | | NONE |
---|
12 | 23 | | } |
---|
13 | 24 | | str |
---|
14 | 25 | | } |
---|
15 | 26 | | |
---|
16 | 27 | | |
---|
17 | 28 | | func getKeyItemPrice (item) = (item + "_price") |
---|
18 | 29 | | |
---|
19 | 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 | + | |
---|
20 | 40 | | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) |
---|
21 | 41 | | |
---|
22 | 42 | | |
---|
23 | 43 | | func getKeyItemData (item) = (item + "_data") |
---|
24 | 44 | | |
---|
25 | 45 | | |
---|
26 | 46 | | func getKeyItemSupplier (item) = (item + "_owner") |
---|
27 | 47 | | |
---|
28 | 48 | | |
---|
29 | 49 | | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) |
---|
| 50 | + | |
---|
| 51 | + | |
---|
| 52 | + | func getKeyBalanceSupplier (account) = (account + "_balance") |
---|
| 53 | + | |
---|
| 54 | + | |
---|
| 55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) |
---|
30 | 56 | | |
---|
31 | 57 | | |
---|
32 | 58 | | @Callable(i) |
---|
33 | 59 | | func addItem (title,price,data) = { |
---|
34 | 60 | | let supplierAddress = toBase58String(i.caller.bytes) |
---|
35 | 61 | | let item = getKeyItem(supplierAddress, title) |
---|
36 | 62 | | if ((0 >= price)) |
---|
37 | 63 | | then throw("Purchase amount cannot be less than item price") |
---|
38 | 64 | | else if ((getValueItemSupplier(item) != NONE)) |
---|
39 | 65 | | then throw("an item already exists") |
---|
40 | 66 | | else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)] |
---|
41 | 67 | | } |
---|
42 | 68 | | |
---|
43 | 69 | | |
---|
| 70 | + | |
---|
| 71 | + | @Callable(i) |
---|
| 72 | + | func purchase (item) = { |
---|
| 73 | + | let pmt = i.payments[0] |
---|
| 74 | + | if (isDefined(pmt.assetId)) |
---|
| 75 | + | then throw("WAVES ONLY HHEUAWHEUAS") |
---|
| 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 ((supplierAddress == NONE)) |
---|
| 83 | + | then throw("Supplier does not exist") |
---|
| 84 | + | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))] |
---|
| 85 | + | } |
---|
| 86 | + | } |
---|
| 87 | + | |
---|
| 88 | + | |
---|