tx · GKUB4z2ctU5hWWnHDoAPSbjLmamAnMPHvLQfRoLb7kVG 3N9GKCsktAL7oPFmaKsgPBoDfu3ijk23Vmm: -0.01400000 Waves 2020.03.20 23:23 [918134] smart account 3N9GKCsktAL7oPFmaKsgPBoDfu3ijk23Vmm > SELF 0.00000000 Waves
{ "type": 13, "id": "GKUB4z2ctU5hWWnHDoAPSbjLmamAnMPHvLQfRoLb7kVG", "fee": 1400000, "feeAssetId": null, "timestamp": 1584735819762, "version": 1, "sender": "3N9GKCsktAL7oPFmaKsgPBoDfu3ijk23Vmm", "senderPublicKey": "BjzUYgMDny7cYArZdjtnVo62UoVZKiCEeCoKYFnevrWU", "proofs": [ "UaevpDgiZ26ehF6z5Q4ibojPxUYQ5xL8ba2ZuuxRwdMtepbNjvyhENUyunwoeSLvcdcxvpzQb2ogViT2F96DTPr" ], "script": "base64:AAIDAAAAAAAAABYIARIDCgEBEgcKBQgICAEBEgQKAggBAAAAGAAAAAAHYUJpdENPMgEAAAAgx/h6AJ03UJ8qMmy7JIhz3VjOE4OL3ofCGi0oG2fBKJYAAAAACHN0YXJ0UXR5AAAAAAAAAknwAAAAAAhub21QcmljZQAAAAAABfXhAAAAAAAETk9ORQIAAAAEbm9uZQAAAAALT3duZXJQdWJLZXkBAAAAIJ+YQBeV0x/8GNlJbr9kR/uTmvTPi2KwfwbDWc0arYRJAAAAAAZpc3N1ZXIJAQAAAAdBZGRyZXNzAAAAAQEAAAAaAVTUPeuO2Y1p2TpK+OH14WsDuVCV2jcMFFQBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAAA251bQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAUAAAADbnVtAQAAAAtnZXRTdHJCeUtleQAAAAEAAAADa2V5BAAAAANzdHIEAAAAByRtYXRjaDAJAAQ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AgkBAAAACURhdGFFbnRyeQAAAAIFAAAABGl0ZW0FAAAACW5ld0Ftb3VudAUAAAADbmlsCQEAAAALVHJhbnNmZXJTZXQAAAABCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMIBQAAAAFpAAAABmNhbGxlcgUAAAAGYW1vdW50BQAAAAdhQml0Q08yBQAAAANuaWwAAAABAAAAAnR4AQAAAAZ2ZXJpZnkAAAAABAAAAAckbWF0Y2gwBQAAAAJ0eAMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAUU2V0U2NyaXB0VHJhbnNhY3Rpb24EAAAAAXQFAAAAByRtYXRjaDAJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAABQAAAAtPd25lclB1YktleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAPRGF0YVRyYW5zYWN0aW9uBAAAAAFkBQAAAAckbWF0Y2gwBgMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAATVHJhbnNmZXJUcmFuc2FjdGlvbgQAAAACdHgFAAAAByRtYXRjaDAEAAAACXJlY2lwaWVudAkAAlgAAAABCAkABCQAAAABCAUAAAACdHgAAAAJcmVjaXBpZW50AAAABWJ5dGVzAwkAAAAAAAACCAUAAAACdHgAAAAGc2VuZGVyBQAAAAZpc3N1ZXIGCQAAAgAAAAECAAAAIFlvdSBjYW4ndCB0cmFuc2ZlcnJlZCB0aGlzIHRva2VuB2pJkJY=", "chainId": 84, "height": 918134, "spentComplexity": 0 } View: original | compacted Prev: z1ee8qEkJGEi92t1LHqzy2qSXDfhkTgS12HtkKZrcqC Next: BbqMRkVoNxEV9oUmRXZ9Ckq3bJeDafhEF46b81ngcdiu Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let aBitCO2 = base58'ETbtNp6MBuSM9EfjmLDwctrYEBBiq8CZ7ti7zbwTktry' | |
5 | 5 | ||
6 | 6 | let startQty = 150000 | |
7 | 7 | ||
8 | 8 | let nomPrice = 100000000 | |
9 | 9 | ||
10 | 10 | let NONE = "none" | |
11 | 11 | ||
12 | 12 | let OwnerPubKey = base58'BjzUYgMDny7cYArZdjtnVo62UoVZKiCEeCoKYFnevrWU' | |
13 | 13 | ||
14 | 14 | let issuer = Address(base58'3N9GKCsktAL7oPFmaKsgPBoDfu3ijk23Vmm') | |
15 | 15 | ||
16 | 16 | func getNumberByKey (key) = { | |
17 | 17 | let num = match getInteger(this, key) { | |
18 | 18 | case a: Int => | |
19 | 19 | a | |
20 | 20 | case _ => | |
21 | 21 | 0 | |
22 | 22 | } | |
23 | 23 | num | |
24 | 24 | } | |
25 | 25 | ||
26 | 26 | ||
27 | 27 | func getStrByKey (key) = { | |
28 | 28 | let str = match getString(this, key) { | |
29 | 29 | case a: String => | |
30 | 30 | a | |
31 | 31 | case _ => | |
32 | 32 | NONE | |
33 | 33 | } | |
34 | 34 | str | |
35 | 35 | } | |
36 | 36 | ||
37 | 37 | ||
38 | 38 | func getKeyItem (supplier,title) = ("Bit-CO2_token: " + toBase58String(sha256(toBytes((supplier + title))))) | |
39 | 39 | ||
40 | 40 | ||
41 | 41 | func getKeyItemSupplier (item) = (item + "_to_Amazonian_Conservation") | |
42 | 42 | ||
43 | 43 | ||
44 | 44 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
45 | 45 | ||
46 | 46 | ||
47 | 47 | func getKeyBalanceQtySupplier (item) = "Offered_Qty, balance:" | |
48 | 48 | ||
49 | 49 | ||
50 | 50 | func getValueBalanceQtySupplier (item) = getNumberByKey(getKeyBalanceQtySupplier(item)) | |
51 | 51 | ||
52 | 52 | ||
53 | 53 | func getKeyBalanceSupplier (supplier) = "Seller_Balance,_waves:" | |
54 | 54 | ||
55 | 55 | ||
56 | 56 | func getValueBalanceSupplier (supplier) = getNumberByKey(getKeyBalanceSupplier(supplier)) | |
57 | 57 | ||
58 | 58 | ||
59 | 59 | func getKeyUserItemCounter (user,item) = "Order_№:" | |
60 | 60 | ||
61 | 61 | ||
62 | 62 | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
63 | 63 | ||
64 | 64 | ||
65 | 65 | func getKeyItemUser (item) = "UserName:" | |
66 | 66 | ||
67 | 67 | ||
68 | 68 | func getValueItemUser (item) = getStrByKey(getKeyItemUser(item)) | |
69 | 69 | ||
70 | 70 | ||
71 | 71 | func getKeyItemUserData (item) = "UserCountry:" | |
72 | 72 | ||
73 | 73 | ||
74 | 74 | func getKeyItemDiscountUser (item) = "UserDiscount,_%:" | |
75 | 75 | ||
76 | 76 | ||
77 | 77 | func getValueItemDiscountUser (item) = getNumberByKey(getKeyItemDiscountUser(item)) | |
78 | 78 | ||
79 | 79 | ||
80 | 80 | func getKeyItemUserOrderQty (item) = "Order_qty,_tokens:" | |
81 | 81 | ||
82 | 82 | ||
83 | 83 | func getValueItemUserOrderQty (item) = getNumberByKey(getKeyItemUserOrderQty(item)) | |
84 | 84 | ||
85 | 85 | ||
86 | 86 | @Callable(i) | |
87 | 87 | func deposit (amount) = { | |
88 | 88 | let pmt = extract(i.payment) | |
89 | 89 | if ((pmt.assetId != aBitCO2)) | |
90 | 90 | then throw("Use cBitCO2 tokens only for the wallet deposit") | |
91 | 91 | else { | |
92 | 92 | let supplier = toBase58String(i.caller.bytes) | |
93 | 93 | let currentAmount = match getInteger(this, supplier) { | |
94 | 94 | case a: Int => | |
95 | 95 | a | |
96 | 96 | case _ => | |
97 | 97 | startQty | |
98 | 98 | } | |
99 | 99 | let newAmount = (currentAmount + pmt.amount) | |
100 | 100 | WriteSet([DataEntry(supplier, newAmount)]) | |
101 | 101 | } | |
102 | 102 | } | |
103 | 103 | ||
104 | 104 | ||
105 | 105 | ||
106 | 106 | @Callable(i) | |
107 | 107 | func purchase (item,userName,userData,userDiscount,orderQty) = { | |
108 | 108 | let pmt = extract(i.payment) | |
109 | 109 | if (isDefined(pmt.assetId)) | |
110 | 110 | then throw("you can adquire cBitCO2 only by Waves tokens") | |
111 | 111 | else { | |
112 | 112 | let supplier = match getString(this, getKeyItemSupplier(item)) { | |
113 | 113 | case a: String => | |
114 | 114 | a | |
115 | 115 | case _ => | |
116 | 116 | NONE | |
117 | 117 | } | |
118 | 118 | let preIcoQty = match getInteger(this, getKeyBalanceQtySupplier(item)) { | |
119 | 119 | case a: Int => | |
120 | 120 | a | |
121 | 121 | case _ => | |
122 | 122 | startQty | |
123 | 123 | } | |
124 | 124 | let balanceSupplier = match getInteger(this, getKeyBalanceSupplier(supplier)) { | |
125 | 125 | case a: Int => | |
126 | 126 | a | |
127 | 127 | case _ => | |
128 | 128 | 0 | |
129 | 129 | } | |
130 | 130 | let userAddress = toBase58String(i.caller.bytes) | |
131 | 131 | let buyerTokenPrice = ((nomPrice * (100 - userDiscount)) / 100) | |
132 | 132 | let totalAmount = (orderQty * buyerTokenPrice) | |
133 | 133 | if ((totalAmount > pmt.amount)) | |
134 | 134 | then throw("Payment Amount cannot be less than item Purchase Order") | |
135 | 135 | else if ((pmt.amount > totalAmount)) | |
136 | 136 | then throw("Payment Amount can't be higher than item Purchase Order") | |
137 | 137 | else ScriptResult(WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceQtySupplier(item), (preIcoQty - orderQty)), DataEntry(getKeyItemUser(item), userName), DataEntry(getKeyItemUserData(item), userData), DataEntry(getKeyItemDiscountUser(item), userDiscount), DataEntry(getKeyItemUserOrderQty(item), orderQty), DataEntry(("UserPrice_1_token,_waves:_" + userAddress), buyerTokenPrice), DataEntry(("Payment_amount,_waves:_" + userAddress), totalAmount), DataEntry(("Order_Status:_" + userAddress), "confirmed"), DataEntry(getKeyBalanceSupplier(supplier), (balanceSupplier + pmt.amount))]), TransferSet([ScriptTransfer(addressFromStringValue(userAddress), orderQty, aBitCO2)])) | |
138 | 138 | } | |
139 | 139 | } | |
140 | 140 | ||
141 | 141 | ||
142 | 142 | ||
143 | 143 | @Callable(i) | |
144 | 144 | func withdraw (item,amount) = { | |
145 | 145 | let userAddress = toBase58String(i.caller.bytes) | |
146 | 146 | let supplier = match getString(this, getKeyItemSupplier(item)) { | |
147 | 147 | case a: String => | |
148 | 148 | a | |
149 | 149 | case _ => | |
150 | 150 | NONE | |
151 | 151 | } | |
152 | 152 | let preIcoQty = match getInteger(this, getKeyBalanceQtySupplier(item)) { | |
153 | 153 | case a: Int => | |
154 | 154 | a | |
155 | 155 | case _ => | |
156 | 156 | startQty | |
157 | 157 | } | |
158 | 158 | let newAmount = (preIcoQty - amount) | |
159 | 159 | if ((0 > amount)) | |
160 | 160 | then throw("Can't withdraw negative amount") | |
161 | 161 | else if ((0 > newAmount)) | |
162 | 162 | then throw("Not enought /suficiente balance") | |
163 | 163 | else ScriptResult(WriteSet([DataEntry(item, newAmount)]), TransferSet([ScriptTransfer(i.caller, amount, aBitCO2)])) | |
164 | 164 | } | |
165 | 165 | ||
166 | 166 | ||
167 | 167 | @Verifier(tx) | |
168 | 168 | func verify () = match tx { | |
169 | 169 | case t: SetScriptTransaction => | |
170 | 170 | sigVerify(tx.bodyBytes, tx.proofs[0], OwnerPubKey) | |
171 | 171 | case d: DataTransaction => | |
172 | 172 | true | |
173 | 173 | case tx: TransferTransaction => | |
174 | 174 | let recipient = toBase58String(addressFromRecipient(tx.recipient).bytes) | |
175 | 175 | if ((tx.sender == issuer)) | |
176 | 176 | then true | |
177 | 177 | else throw("You can't transferred this token") | |
178 | 178 | case _ => | |
179 | 179 | false | |
180 | 180 | } | |
181 | 181 |
github/deemru/w8io/169f3d6 44.50 ms ◑