17 | | - | func getStrByKey (key) = { |
---|
18 | | - | let str = match getString(this, key) { |
---|
19 | | - | case a: String => |
---|
20 | | - | a |
---|
| 11 | + | @Verifier(tx) |
---|
| 12 | + | func verify () = { |
---|
| 13 | + | let A1 = sigVerify(tx.bodyBytes, tx.proofs[0], APublicKey) |
---|
| 14 | + | let A2 = sigVerify(tx.bodyBytes, tx.proofs[1], APublicKey) |
---|
| 15 | + | let A3 = sigVerify(tx.bodyBytes, tx.proofs[2], APublicKey) |
---|
| 16 | + | let B1 = sigVerify(tx.bodyBytes, tx.proofs[0], BPublicKey) |
---|
| 17 | + | let B2 = sigVerify(tx.bodyBytes, tx.proofs[1], BPublicKey) |
---|
| 18 | + | let B3 = sigVerify(tx.bodyBytes, tx.proofs[2], BPublicKey) |
---|
| 19 | + | let C1 = sigVerify(tx.bodyBytes, tx.proofs[0], CPublicKey) |
---|
| 20 | + | let C2 = sigVerify(tx.bodyBytes, tx.proofs[1], CPublicKey) |
---|
| 21 | + | let C3 = sigVerify(tx.bodyBytes, tx.proofs[2], CPublicKey) |
---|
| 22 | + | let AB = if (if (if (if (if (if (A1) |
---|
| 23 | + | then B2 |
---|
| 24 | + | else false) |
---|
| 25 | + | then true |
---|
| 26 | + | else if (A1) |
---|
| 27 | + | then B3 |
---|
| 28 | + | else false) |
---|
| 29 | + | then true |
---|
| 30 | + | else if (A2) |
---|
| 31 | + | then B1 |
---|
| 32 | + | else false) |
---|
| 33 | + | then true |
---|
| 34 | + | else if (A2) |
---|
| 35 | + | then B3 |
---|
| 36 | + | else false) |
---|
| 37 | + | then true |
---|
| 38 | + | else if (A3) |
---|
| 39 | + | then B1 |
---|
| 40 | + | else false) |
---|
| 41 | + | then true |
---|
| 42 | + | else if (A3) |
---|
| 43 | + | then B2 |
---|
| 44 | + | else false |
---|
| 45 | + | let AC = if (if (if (if (if (if (A1) |
---|
| 46 | + | then C2 |
---|
| 47 | + | else false) |
---|
| 48 | + | then true |
---|
| 49 | + | else if (A1) |
---|
| 50 | + | then C3 |
---|
| 51 | + | else false) |
---|
| 52 | + | then true |
---|
| 53 | + | else if (A2) |
---|
| 54 | + | then C1 |
---|
| 55 | + | else false) |
---|
| 56 | + | then true |
---|
| 57 | + | else if (A2) |
---|
| 58 | + | then C3 |
---|
| 59 | + | else false) |
---|
| 60 | + | then true |
---|
| 61 | + | else if (A3) |
---|
| 62 | + | then C1 |
---|
| 63 | + | else false) |
---|
| 64 | + | then true |
---|
| 65 | + | else if (A3) |
---|
| 66 | + | then C2 |
---|
| 67 | + | else false |
---|
| 68 | + | let BC = if (if (if (if (if (if (C1) |
---|
| 69 | + | then B2 |
---|
| 70 | + | else false) |
---|
| 71 | + | then true |
---|
| 72 | + | else if (C1) |
---|
| 73 | + | then B3 |
---|
| 74 | + | else false) |
---|
| 75 | + | then true |
---|
| 76 | + | else if (C2) |
---|
| 77 | + | then B1 |
---|
| 78 | + | else false) |
---|
| 79 | + | then true |
---|
| 80 | + | else if (C2) |
---|
| 81 | + | then B3 |
---|
| 82 | + | else false) |
---|
| 83 | + | then true |
---|
| 84 | + | else if (C3) |
---|
| 85 | + | then B1 |
---|
| 86 | + | else false) |
---|
| 87 | + | then true |
---|
| 88 | + | else if (C3) |
---|
| 89 | + | then B2 |
---|
| 90 | + | else false |
---|
| 91 | + | match tx { |
---|
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)) |
---|
56 | | - | |
---|
57 | | - | |
---|
58 | | - | @Callable(i) |
---|
59 | | - | func addItem (title,price,data) = { |
---|
60 | | - | let supplierAddress = toBase58String(i.caller.bytes) |
---|
61 | | - | let item = getKeyItem(supplierAddress, title) |
---|
62 | | - | if ((0 >= price)) |
---|
63 | | - | then throw("purchase amount cannot be less than item price") |
---|
64 | | - | else if ((getValueItemSupplier(item) != NONE)) |
---|
65 | | - | then throw("an item is already exist") |
---|
66 | | - | else $Tuple2([StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)], unit) |
---|
67 | | - | } |
---|
68 | | - | |
---|
69 | | - | |
---|
70 | | - | |
---|
71 | | - | @Callable(i) |
---|
72 | | - | func purchase (item) = { |
---|
73 | | - | let pmt = i.payments[0] |
---|
74 | | - | if (isDefined(pmt.assetId)) |
---|
75 | | - | then throw("can use WAVES only at the moment") |
---|
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 ((pmt.amount > price)) |
---|
83 | | - | then throw("purchase amount cannot be higher than item price") |
---|
84 | | - | else if ((supplierAddress == NONE)) |
---|
85 | | - | then throw("supplier does not exist") |
---|
86 | | - | else $Tuple2([IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))], unit) |
---|
87 | | - | } |
---|
88 | | - | } |
---|
89 | | - | |
---|