tx · 2LmFCPKDWAxPQVWtiko78HQLF3RFmvWbzCSLYKGdTWK9 3N8y4wxX3JC4TdrCJBXX16SjWf6X256hrep: -0.01000000 Waves 2022.11.19 14:54 [2323967] smart account 3N8y4wxX3JC4TdrCJBXX16SjWf6X256hrep > SELF 0.00000000 Waves
{ "type": 13, "id": "2LmFCPKDWAxPQVWtiko78HQLF3RFmvWbzCSLYKGdTWK9", "fee": 1000000, "feeAssetId": null, "timestamp": 1668858874614, "version": 2, "chainId": 84, "sender": "3N8y4wxX3JC4TdrCJBXX16SjWf6X256hrep", "senderPublicKey": "7v5L7QkXxfkirALdyqmox38QCsa9jtfAtgUfHTh34eWq", "proofs": [ "2mSrJ1j4Er5c8XMeSq2xWAUj2tFcjd61Ms6Uiy56qvsKKhhhzMHPvbd3NG6BK1mdWJLvzYjfUh2pKZEag29ax7Ay" ], "script": "base64:BgIJCAISBQoDCAgYCQAFTVVMVDgAgMLXLwALdXNkbkFzc2V0SWQBIPd26vf3g8pl224T7gI7z1gplanB0Y3yS9ps2B1igMjeAAtiYWNrRW5kQWRkcgkBEUBleHRyTmF0aXZlKDEwNjIpAQIjM041U3BYMjFSM1I3NVFvNGViM013RkZ2VzdUVXp5aHZhdnYAEGFsbG93ZWRSZXNvdXJjZXMJAMwIAgIDT2lsCQDMCAICA09yZQkAzAgCAgRXb29kCQDMCAICBFNhbmQJAMwIAgIEQ2xheQkAzAgCAgdPcmdhbmljBQNuaWwACmNvbnRpbmVudHMJAMwIAgIIQW1lcmljYXMJAMwIAgIGRXVyb3BlCQDMCAICBEFzaWEJAMwIAgIGQWZyaWNhCQDMCAICB09jZWFuaWEFA25pbAEda2V5U3RvcmVSZXNCeUNvbnRpbmVudEFuZFR5cGUCCWNvbnRpbmVudAdyZXNUeXBlCQCsAgIJAKwCAgkArAICAiBzdG9yZVJlc291cmNlQnlDb250aW5lbnRBbmRUeXBlXwUJY29udGluZW50AgFfBQdyZXNUeXBlAAdpZHhUeXBlAAAAC2lkeFF1YW50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WwAAAoBBSRmMF8xAgIkYQIkaQMJAGcCBQIkaQUCJHMFAiRhCQEFYWRkZXICBQIkYQkAkQMCBQIkbAUCJGkKAQUkZjBfMgICJGECJGkDCQBnAgUCJGkFAiRzBQIkYQkAAgECFExpc3Qgc2l6ZSBleGNlZWRzIDEwCQEFJGYwXzICCQEFJGYwXzECCQEFJGYwXzECCQEFJGYwXzECCQEFJGYwXzECCQEFJGYwXzECCQEFJGYwXzECCQEFJGYwXzECCQEFJGYwXzECCQEFJGYwXzECCQEFJGYwXzECBQUkYWNjMAAAAAEAAgADAAQABQAGAAcACAAJAAoJAM0IAggFBnJlc3VsdAJfMQkBDlNjcmlwdFRyYW5zZmVyAwULdXNlckFkZHJlc3MIBQZyZXN1bHQCXzIFC3VzZG5Bc3NldElkADmw7Ug=", "height": 2323967, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: H5ME1UH6gzgR9osALhakoc5TRBWvyLcoHBEcVwgQvfQt Next: DL78pGCqVfxGpLR21WQkRs7KhhDFtPVS9oq6a5TtudL Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let MULT8 = 100000000 | |
5 | 5 | ||
6 | 6 | let usdnAssetId = base58'HezsdQuRDtzksAYUy97gfhKy7Z1NW2uXYSHA3bgqenNZ' | |
7 | 7 | ||
36 | 36 | then throw(("Unknown resource: " + resType)) | |
37 | 37 | else { | |
38 | 38 | let resKey = keyStoreResByContinentAndType(continent, resType) | |
39 | - | let storedAmount = valueOrElse(getInteger(resKey), 0) | |
40 | 39 | let q = parseIntValue(parts[idxQuantity]) | |
41 | - | $Tuple2((acc._1 :+ IntegerEntry(resKey, q)), (acc._2 + fraction(q, parseIntValue(parts[idxPrice]), | |
40 | + | $Tuple2((acc._1 :+ IntegerEntry(resKey, (valueOrElse(getInteger(resKey), 0) + q))), (acc._2 + fraction(q, parseIntValue(parts[idxPrice]), MULT8))) | |
42 | 41 | } | |
43 | 42 | } | |
44 | 43 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | - | let | |
4 | + | let MULT8 = 100000000 | |
5 | 5 | ||
6 | 6 | let usdnAssetId = base58'HezsdQuRDtzksAYUy97gfhKy7Z1NW2uXYSHA3bgqenNZ' | |
7 | 7 | ||
8 | 8 | let backEndAddr = addressFromStringValue("3N5SpX21R3R75Qo4eb3MwFFvW7TUzyhvavv") | |
9 | 9 | ||
10 | 10 | let allowedResources = ["Oil", "Ore", "Wood", "Sand", "Clay", "Organic"] | |
11 | 11 | ||
12 | 12 | let continents = ["Americas", "Europe", "Asia", "Africa", "Oceania"] | |
13 | 13 | ||
14 | 14 | func keyStoreResByContinentAndType (continent,resType) = ((("storeResourceByContinentAndType_" + continent) + "_") + resType) | |
15 | 15 | ||
16 | 16 | ||
17 | 17 | let idxType = 0 | |
18 | 18 | ||
19 | 19 | let idxQuantity = 1 | |
20 | 20 | ||
21 | 21 | let idxPrice = 2 | |
22 | 22 | ||
23 | 23 | @Callable(i) | |
24 | 24 | func sellResources (userAddressStr,continent,resources) = if ((i.caller != backEndAddr)) | |
25 | 25 | then throw("permission denied") | |
26 | 26 | else if ((size(i.payments) != 0)) | |
27 | 27 | then throw("sellResources doesn't require any payments") | |
28 | 28 | else if (!(containsElement(continents, continent))) | |
29 | 29 | then throw(("Unknown continent: " + continent)) | |
30 | 30 | else { | |
31 | 31 | let userAddress = addressFromStringValue(userAddressStr) | |
32 | 32 | func adder (acc,elem) = { | |
33 | 33 | let parts = split(elem, "_") | |
34 | 34 | let resType = parts[idxType] | |
35 | 35 | if (!(containsElement(allowedResources, resType))) | |
36 | 36 | then throw(("Unknown resource: " + resType)) | |
37 | 37 | else { | |
38 | 38 | let resKey = keyStoreResByContinentAndType(continent, resType) | |
39 | - | let storedAmount = valueOrElse(getInteger(resKey), 0) | |
40 | 39 | let q = parseIntValue(parts[idxQuantity]) | |
41 | - | $Tuple2((acc._1 :+ IntegerEntry(resKey, q)), (acc._2 + fraction(q, parseIntValue(parts[idxPrice]), | |
40 | + | $Tuple2((acc._1 :+ IntegerEntry(resKey, (valueOrElse(getInteger(resKey), 0) + q))), (acc._2 + fraction(q, parseIntValue(parts[idxPrice]), MULT8))) | |
42 | 41 | } | |
43 | 42 | } | |
44 | 43 | ||
45 | 44 | let result = { | |
46 | 45 | let $l = resources | |
47 | 46 | let $s = size($l) | |
48 | 47 | let $acc0 = $Tuple2(nil, 0) | |
49 | 48 | func $f0_1 ($a,$i) = if (($i >= $s)) | |
50 | 49 | then $a | |
51 | 50 | else adder($a, $l[$i]) | |
52 | 51 | ||
53 | 52 | func $f0_2 ($a,$i) = if (($i >= $s)) | |
54 | 53 | then $a | |
55 | 54 | else throw("List size exceeds 10") | |
56 | 55 | ||
57 | 56 | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) | |
58 | 57 | } | |
59 | 58 | (result._1 :+ ScriptTransfer(userAddress, result._2, usdnAssetId)) | |
60 | 59 | } | |
61 | 60 | ||
62 | 61 |
github/deemru/w8io/026f985 29.59 ms ◑