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 + "_data") |
---|
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 | | - | |
---|
| 11 | + | let BLACKLISTED = "blacklist" |
---|
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 [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)] |
---|
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("WAVES token only at the moment") |
---|
76 | | - | else { |
---|
77 | | - | let userAddress = toBase58String(i.caller.bytes) |
---|
78 | | - | let price = getValueItemPrice(item) |
---|
79 | | - | let supplierAddres = getValueItemSupplier(item) |
---|
80 | | - | if ((price > pmt.amount)) |
---|
81 | | - | then throw("purchase amunt 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 ((supplierAddres == NONE)) |
---|
85 | | - | then throw("Supplier address doesn't exist") |
---|
86 | | - | else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddres), (getValueBalanceSupplier(supplierAddres) + pmt.amount))] |
---|
87 | | - | } |
---|
88 | | - | } |
---|
89 | | - | |
---|
90 | | - | |
---|
91 | | - | |
---|
92 | | - | @Callable(i) |
---|
93 | | - | func withdraw () = { |
---|
94 | | - | let supplierAddress = toBase58String(i.caller.bytes) |
---|
95 | | - | let balance = getValueBalanceSupplier(supplierAddress) |
---|
96 | | - | if ((0 >= balance)) |
---|
97 | | - | then throw("za mało środków") |
---|
98 | | - | else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)] |
---|
| 14 | + | func setstatus (supplier,status) = { |
---|
| 15 | + | let account = toBase58String(i.caller.bytes) |
---|
| 16 | + | if ((account != verifier)) |
---|
| 17 | + | then throw("only oracle veryfier are able to manage whilelist") |
---|
| 18 | + | else if (if ((status != VERIFIED)) |
---|
| 19 | + | then (status != BLACKLISTED) |
---|
| 20 | + | else false) |
---|
| 21 | + | then throw("waiting status") |
---|
| 22 | + | else [StringEntry(getExtValueItemWhiteListStatus(supplier), status)] |
---|