2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let NONE = "NONE" |
---|
5 | | - | |
---|
6 | | - | let customer = "CUSTOMER" |
---|
7 | | - | |
---|
8 | | - | let supplier = "SUPPLIER" |
---|
9 | | - | |
---|
10 | | - | let ericPubKey = base58'8haEN2a7ZmkzawLmnr5rFX14X1oHi5kjt8NQUDNjSDLG' |
---|
11 | | - | |
---|
12 | | - | func getStringByKey (key) = match getString(key) { |
---|
13 | | - | case a: String => |
---|
14 | | - | a |
---|
15 | | - | case _ => |
---|
16 | | - | NONE |
---|
17 | | - | } |
---|
18 | | - | |
---|
19 | | - | |
---|
20 | | - | func getItemHash (supplier,title) = { |
---|
21 | | - | let comboTitle = (supplier + title) |
---|
22 | | - | ("item_" + toBase58String(sha256(toBytes(comboTitle)))) |
---|
23 | | - | } |
---|
24 | | - | |
---|
25 | | - | |
---|
26 | | - | func getNameKey (type,addr) = (((type + "_") + addr) + "_name") |
---|
27 | | - | |
---|
28 | | - | |
---|
29 | | - | func getItemSupplierKey (item) = (item + "_owner") |
---|
30 | | - | |
---|
31 | | - | |
---|
32 | | - | func getItemPriceKey (item) = (item + "_price") |
---|
33 | | - | |
---|
34 | | - | |
---|
35 | | - | func getItemDataKey (item) = (item + "_data") |
---|
36 | | - | |
---|
37 | | - | |
---|
38 | | - | func getValueItemSupplier (item) = { |
---|
39 | | - | let itemKey = getItemSupplierKey(item) |
---|
40 | | - | getStringByKey(itemKey) |
---|
41 | | - | } |
---|
42 | | - | |
---|
43 | | - | |
---|
44 | | - | @Callable(i) |
---|
45 | | - | func register (type) = { |
---|
46 | | - | let addr = toBase58String(i.caller.bytes) |
---|
47 | | - | if (if (isDefined(type)) |
---|
48 | | - | then if ((type == customer)) |
---|
49 | | - | then true |
---|
50 | | - | else (type == supplier) |
---|
51 | | - | else false) |
---|
52 | | - | then [StringEntry(getNameKey(type, addr), addr)] |
---|
53 | | - | else throw("Invalid func parameters") |
---|
54 | | - | } |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | |
---|
58 | | - | @Callable(i) |
---|
59 | | - | func createItem (title,price,count,data,owner) = { |
---|
60 | | - | let supplierAddress = toBase58String(i.caller.bytes) |
---|
61 | | - | let item = getItemHash(supplierAddress, title) |
---|
62 | | - | if ((0 >= price)) |
---|
63 | | - | then throw("Price can not be negative value or zero") |
---|
64 | | - | else if ((getValueItemSupplier(item) != NONE)) |
---|
65 | | - | then throw("Item already exists") |
---|
66 | | - | else [StringEntry(getItemSupplierKey(item), supplierAddress), IntegerEntry(getItemPriceKey(item), price), IntegerEntry(getItemPriceKey(item), count), StringEntry(getItemDataKey(item), data)] |
---|
67 | | - | } |
---|
68 | | - | |
---|
69 | | - | |
---|
70 | | - | |
---|
71 | | - | @Callable(i) |
---|
72 | | - | func deleteItem (title) = { |
---|
73 | | - | let supplierAddress = toBase58String(i.caller.bytes) |
---|
74 | | - | let item = getItemHash(supplierAddress, title) |
---|
75 | | - | if ((getValueItemSupplier(item) != NONE)) |
---|
76 | | - | then [DeleteEntry(getItemSupplierKey(item)), DeleteEntry(getItemPriceKey(item)), DeleteEntry(getItemDataKey(item))] |
---|
77 | | - | else throw("No such item present") |
---|
78 | | - | } |
---|
79 | | - | |
---|
80 | | - | |
---|
81 | | - | |
---|
82 | | - | @Callable(i) |
---|
83 | | - | func deleteEntry (key) = if ((i.callerPublicKey == ericPubKey)) |
---|
84 | | - | then [DeleteEntry(key)] |
---|
85 | | - | else throw("Only Eric can delete entries") |
---|
86 | | - | |
---|
87 | | - | |
---|
88 | | - | |
---|
89 | | - | @Callable(i) |
---|
90 | | - | func unregister (type) = if (if ((type == supplier)) |
---|
91 | | - | then true |
---|
92 | | - | else (type == customer)) |
---|
93 | | - | then { |
---|
94 | | - | let addr = toBase58String(i.caller.bytes) |
---|
95 | | - | [DeleteEntry(getNameKey(type, addr))] |
---|
96 | | - | } |
---|
97 | | - | else throw("Illegal argument") |
---|
98 | | - | |
---|
99 | | - | |
---|
100 | | - | @Verifier(tx) |
---|
101 | | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|
102 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|