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:AAIDAAAAAAAAABUIARIAEgUKAwgBCBIDCgEIEgMKAQEAAAAOAAAAAAVPV05FUgEAAAAgAKbz5MdxP05qBtYSxXJqn4C6YVMLl9rDunp3cgoCCTsBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAABm51bWJlcgQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAUAAAAGbnVtYmVyAAAAAAROT05FAgAAAARub25lAQAAAA5nZXRTdHJpbmdCeUtleQAAAAEAAAADa2V5BAAAAAZzdHJpbmcEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEFAAAABE5PTkUFAAAABnN0cmluZwEAAAAKZ2V0SXRlbUtleQAAAAIAAAAIc3VwcGxpZXIAAAAFdGl0bGUEAAA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l0ZXMJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAUAAAAFT1dORVIDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAD0RhdGFUcmFuc2FjdGlvbgQAAAABYgUAAAAHJG1hdGNoMAYHmZFXNQ==",
"chainId": 84,
"height": 733355,
"spentComplexity": 0
}
View: original | compacted
Prev: E6RWCirKWgu6RT8uCR2TSjrbNmHQHd52gRQ3EpCftdcA
Next: none
Diff:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 3 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let owner = base58'13YevTfaVEoXJ5hu2kSjqnp2j2E8RV3NHHFM6giCFssY' |
---|
| 4 | + | let OWNER = base58'13YevTfaVEoXJ5hu2kSjqnp2j2E8RV3NHHFM6giCFssY' |
---|
5 | 5 | | |
---|
6 | 6 | | func getNumberByKey (key) = { |
---|
7 | 7 | | let number = match getInteger(this, key) { |
---|
|
14 | 14 | | } |
---|
15 | 15 | | |
---|
16 | 16 | | |
---|
| 17 | + | let NONE = "none" |
---|
| 18 | + | |
---|
17 | 19 | | func getStringByKey (key) = { |
---|
18 | 20 | | let string = match getString(this, key) { |
---|
19 | 21 | | case a: String => |
---|
20 | 22 | | a |
---|
21 | 23 | | case _ => |
---|
22 | | - | "none" |
---|
| 24 | + | NONE |
---|
23 | 25 | | } |
---|
24 | 26 | | string |
---|
25 | 27 | | } |
---|
26 | 28 | | |
---|
27 | 29 | | |
---|
28 | | - | func getItemKeyPrice (item) = (item + "_price") |
---|
| 30 | + | func getItemKey (supplier,title) = { |
---|
| 31 | + | let itemId = (supplier + title) |
---|
| 32 | + | ("item_" + toBase58String(toBytes(itemId))) |
---|
| 33 | + | } |
---|
29 | 34 | | |
---|
30 | 35 | | |
---|
31 | | - | func getValueItemPrice (item) = getNumberByKey(getItemKeyPrice(item)) |
---|
| 36 | + | func getItemOwnerKey (item) = (item + "_owner") |
---|
32 | 37 | | |
---|
33 | 38 | | |
---|
34 | | - | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "count") |
---|
| 39 | + | func getItemOwnerValue (item) = getStringByKey(getItemOwnerKey(item)) |
---|
35 | 40 | | |
---|
36 | 41 | | |
---|
37 | | - | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) |
---|
| 42 | + | func getItemPriceKey (item) = (item + "_price") |
---|
38 | 43 | | |
---|
39 | 44 | | |
---|
40 | | - | func getKeyItem (supplier,title) = ("item_" + toBase58String(toBytes((supplier + title)))) |
---|
| 45 | + | func getItemPriceValue (item) = getNumberByKey(getItemPriceKey(item)) |
---|
41 | 46 | | |
---|
42 | 47 | | |
---|
43 | | - | func getKeyItemData (item) = (item + "_data") |
---|
| 48 | + | func getItemDataKey (item) = (item + "_data") |
---|
44 | 49 | | |
---|
45 | 50 | | |
---|
46 | | - | func getKeyItemSupplier (item) = (item + "_owner") |
---|
| 51 | + | func getItemDataValue (item) = getStringByKey(getItemDataKey(item)) |
---|
47 | 52 | | |
---|
48 | 53 | | |
---|
49 | | - | func getValueItemSupplier (item) = getStringByKey(getKeyItemSupplier(item)) |
---|
| 54 | + | func getAccountBalanceKey (account) = (("account_" + account) + "_balance") |
---|
50 | 55 | | |
---|
51 | 56 | | |
---|
52 | | - | func getKeyBalanceSupplier (account) = (account + "_balance") |
---|
| 57 | + | func getAccountBalanceValue (account) = getNumberByKey(getAccountBalanceKey(account)) |
---|
53 | 58 | | |
---|
54 | 59 | | |
---|
55 | | - | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) |
---|
| 60 | + | func getPurchasePriceKey (item,customer) = (((("purchase_" + item) + "_customer_") + customer) + "_price") |
---|
56 | 61 | | |
---|
57 | 62 | | |
---|
58 | | - | @Callable(i) |
---|
| 63 | + | @Callable(inv) |
---|
59 | 64 | | 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") |
---|
63 | 68 | | 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)]) |
---|
79 | 73 | | } |
---|
80 | 74 | | } |
---|
81 | 75 | | |
---|
82 | 76 | | |
---|
83 | 77 | | |
---|
84 | | - | @Callable(i) |
---|
| 78 | + | @Callable(inv) |
---|
85 | 79 | | 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) |
---|
88 | 82 | | if ((0 >= price)) |
---|
89 | 83 | | then throw("purchase amount cannot be less that item price") |
---|
90 | | - | else if (("none" != getValueItemSupplier(item))) |
---|
| 84 | + | else if ((NONE != getItemOwnerValue(item))) |
---|
91 | 85 | | 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)]) |
---|
93 | 87 | | } |
---|
94 | 88 | | |
---|
95 | 89 | | |
---|
96 | 90 | | |
---|
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") |
---|
102 | 96 | | 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)) |
---|
111 | 100 | | then throw("purchase amount cannot be less that item price") |
---|
112 | | - | else if ((pmt.amount > price)) |
---|
| 101 | + | else if ((payment.amount > price)) |
---|
113 | 102 | | 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)]) |
---|
115 | 104 | | } |
---|
116 | 105 | | } |
---|
117 | 106 | | |
---|
|
119 | 108 | | |
---|
120 | 109 | | @Callable(inv) |
---|
121 | 110 | | 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) |
---|
124 | 113 | | let newAmount = (currentAmount - amount) |
---|
125 | 114 | | if ((0 > amount)) |
---|
126 | | - | then throw("can't withdraw negative amount") |
---|
| 115 | + | then throw("cannot withdraw negative amount") |
---|
127 | 116 | | else if ((0 > newAmount)) |
---|
128 | 117 | | 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)])) |
---|
130 | 119 | | } |
---|
131 | 120 | | |
---|
132 | 121 | | |
---|
133 | 122 | | @Verifier(tx) |
---|
134 | 123 | | func verify () = match tx { |
---|
135 | 124 | | case a: SetScriptTransaction => |
---|
136 | | - | sigVerify(tx.bodyBytes, tx.proofs[0], owner) |
---|
| 125 | + | sigVerify(tx.bodyBytes, tx.proofs[0], OWNER) |
---|
137 | 126 | | case b: DataTransaction => |
---|
138 | 127 | | true |
---|
139 | 128 | | case _ => |
---|
Full:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 3 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let owner = base58'13YevTfaVEoXJ5hu2kSjqnp2j2E8RV3NHHFM6giCFssY' |
---|
| 4 | + | let OWNER = base58'13YevTfaVEoXJ5hu2kSjqnp2j2E8RV3NHHFM6giCFssY' |
---|
5 | 5 | | |
---|
6 | 6 | | func getNumberByKey (key) = { |
---|
7 | 7 | | let number = match getInteger(this, key) { |
---|
8 | 8 | | case a: Int => |
---|
9 | 9 | | a |
---|
10 | 10 | | case _ => |
---|
11 | 11 | | 0 |
---|
12 | 12 | | } |
---|
13 | 13 | | number |
---|
14 | 14 | | } |
---|
15 | 15 | | |
---|
16 | 16 | | |
---|
| 17 | + | let NONE = "none" |
---|
| 18 | + | |
---|
17 | 19 | | func getStringByKey (key) = { |
---|
18 | 20 | | let string = match getString(this, key) { |
---|
19 | 21 | | case a: String => |
---|
20 | 22 | | a |
---|
21 | 23 | | case _ => |
---|
22 | | - | "none" |
---|
| 24 | + | NONE |
---|
23 | 25 | | } |
---|
24 | 26 | | string |
---|
25 | 27 | | } |
---|
26 | 28 | | |
---|
27 | 29 | | |
---|
28 | | - | func getItemKeyPrice (item) = (item + "_price") |
---|
| 30 | + | func getItemKey (supplier,title) = { |
---|
| 31 | + | let itemId = (supplier + title) |
---|
| 32 | + | ("item_" + toBase58String(toBytes(itemId))) |
---|
| 33 | + | } |
---|
29 | 34 | | |
---|
30 | 35 | | |
---|
31 | | - | func getValueItemPrice (item) = getNumberByKey(getItemKeyPrice(item)) |
---|
| 36 | + | func getItemOwnerKey (item) = (item + "_owner") |
---|
32 | 37 | | |
---|
33 | 38 | | |
---|
34 | | - | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "count") |
---|
| 39 | + | func getItemOwnerValue (item) = getStringByKey(getItemOwnerKey(item)) |
---|
35 | 40 | | |
---|
36 | 41 | | |
---|
37 | | - | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) |
---|
| 42 | + | func getItemPriceKey (item) = (item + "_price") |
---|
38 | 43 | | |
---|
39 | 44 | | |
---|
40 | | - | func getKeyItem (supplier,title) = ("item_" + toBase58String(toBytes((supplier + title)))) |
---|
| 45 | + | func getItemPriceValue (item) = getNumberByKey(getItemPriceKey(item)) |
---|
41 | 46 | | |
---|
42 | 47 | | |
---|
43 | | - | func getKeyItemData (item) = (item + "_data") |
---|
| 48 | + | func getItemDataKey (item) = (item + "_data") |
---|
44 | 49 | | |
---|
45 | 50 | | |
---|
46 | | - | func getKeyItemSupplier (item) = (item + "_owner") |
---|
| 51 | + | func getItemDataValue (item) = getStringByKey(getItemDataKey(item)) |
---|
47 | 52 | | |
---|
48 | 53 | | |
---|
49 | | - | func getValueItemSupplier (item) = getStringByKey(getKeyItemSupplier(item)) |
---|
| 54 | + | func getAccountBalanceKey (account) = (("account_" + account) + "_balance") |
---|
50 | 55 | | |
---|
51 | 56 | | |
---|
52 | | - | func getKeyBalanceSupplier (account) = (account + "_balance") |
---|
| 57 | + | func getAccountBalanceValue (account) = getNumberByKey(getAccountBalanceKey(account)) |
---|
53 | 58 | | |
---|
54 | 59 | | |
---|
55 | | - | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) |
---|
| 60 | + | func getPurchasePriceKey (item,customer) = (((("purchase_" + item) + "_customer_") + customer) + "_price") |
---|
56 | 61 | | |
---|
57 | 62 | | |
---|
58 | | - | @Callable(i) |
---|
| 63 | + | @Callable(inv) |
---|
59 | 64 | | 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") |
---|
63 | 68 | | 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)]) |
---|
79 | 73 | | } |
---|
80 | 74 | | } |
---|
81 | 75 | | |
---|
82 | 76 | | |
---|
83 | 77 | | |
---|
84 | | - | @Callable(i) |
---|
| 78 | + | @Callable(inv) |
---|
85 | 79 | | 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) |
---|
88 | 82 | | if ((0 >= price)) |
---|
89 | 83 | | then throw("purchase amount cannot be less that item price") |
---|
90 | | - | else if (("none" != getValueItemSupplier(item))) |
---|
| 84 | + | else if ((NONE != getItemOwnerValue(item))) |
---|
91 | 85 | | 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)]) |
---|
93 | 87 | | } |
---|
94 | 88 | | |
---|
95 | 89 | | |
---|
96 | 90 | | |
---|
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") |
---|
102 | 96 | | 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)) |
---|
111 | 100 | | then throw("purchase amount cannot be less that item price") |
---|
112 | | - | else if ((pmt.amount > price)) |
---|
| 101 | + | else if ((payment.amount > price)) |
---|
113 | 102 | | 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)]) |
---|
115 | 104 | | } |
---|
116 | 105 | | } |
---|
117 | 106 | | |
---|
118 | 107 | | |
---|
119 | 108 | | |
---|
120 | 109 | | @Callable(inv) |
---|
121 | 110 | | 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) |
---|
124 | 113 | | let newAmount = (currentAmount - amount) |
---|
125 | 114 | | if ((0 > amount)) |
---|
126 | | - | then throw("can't withdraw negative amount") |
---|
| 115 | + | then throw("cannot withdraw negative amount") |
---|
127 | 116 | | else if ((0 > newAmount)) |
---|
128 | 117 | | 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)])) |
---|
130 | 119 | | } |
---|
131 | 120 | | |
---|
132 | 121 | | |
---|
133 | 122 | | @Verifier(tx) |
---|
134 | 123 | | func verify () = match tx { |
---|
135 | 124 | | case a: SetScriptTransaction => |
---|
136 | | - | sigVerify(tx.bodyBytes, tx.proofs[0], owner) |
---|
| 125 | + | sigVerify(tx.bodyBytes, tx.proofs[0], OWNER) |
---|
137 | 126 | | case b: DataTransaction => |
---|
138 | 127 | | true |
---|
139 | 128 | | case _ => |
---|
140 | 129 | | false |
---|
141 | 130 | | } |
---|
142 | 131 | | |
---|