tx · 98aJXBwkB6LwXbGfASM3CZZVzreBYBFA1Eghu4HVYD85 3Mv3BEQ8WS2wzrEXuSfxDm7U9UKb5qLSnUc: -0.01400000 Waves 2019.08.10 17:04 [625025] smart account 3Mv3BEQ8WS2wzrEXuSfxDm7U9UKb5qLSnUc > SELF 0.00000000 Waves
{ "type": 13, "id": "98aJXBwkB6LwXbGfASM3CZZVzreBYBFA1Eghu4HVYD85", "fee": 1400000, "feeAssetId": null, "timestamp": 1565445816635, "version": 1, "sender": "3Mv3BEQ8WS2wzrEXuSfxDm7U9UKb5qLSnUc", "senderPublicKey": "BoKgJQhf9RWMmneqYEhyMKeUXMCYRJRhaBTDd2w1Rtx", "proofs": [ "58cpm3fRmztJxGM4T9gLJLG4Lt8KA5BuzZyxigNAEntBvN1Eskkr3w5Pod5aXTMYbq93mVbbneo9eRekCTfTwqTM" ], "script": "base64:AAIDAAAAAAAAAAAAAAACAAAAAApWU1RBc3NldElEAQAAACCucYFuBYSotpFz1qoINfKJVo0JlR9XCghLbxw/TM2XswAAAAANZWlnaHREZWNpbWFscwAAAAAABfXhAAAAAAYAAAABaQEAAAALbWFrZVNlbGxWU1QAAAABAAAABXByaWNlAwkAAGcAAAACAAAAAAAAAAAABQAAAAVwcmljZQkAAAIAAAABAgAAABZwcmljZSBtdXN0IGJlIHBvc2l0aXZlBAAAAAdwYXltZW50CQEAAAAHZXh0cmFjdAAAAAEIBQAAAAFpAAAAB3BheW1lbnQDCQEAAAACIT0AAAACCAUAAAAHcGF5bWVudAAAAAdhc3NldElkBQAAAApWU1RBc3NldElECQAAAgAAAAEJAAEsAAAAAgIAAAARYXNzZXQgaWQgbXVzdCBiZSAJAAJYAAAAAQUAAAAKVlNUQXNzZXRJRAQAAAAHb3JkZXJJZAkAASwAAAACAgAAAAVzZWxsXwkAAlgAAAABCAUAAAABaQAAAA10cmFuc2FjdGlvbklkCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQAB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QAAAAIFAAAABHRoaXMJAAEsAAAAAgUAAAAHb3JkZXJJZAIAAAAGX293bmVyAwkBAAAAAiE9AAAAAgUAAAAFb3duZXIJAAJYAAAAAQgIBQAAAAFpAAAABmNhbGxlcgAAAAVieXRlcwkAAAIAAAABAgAAACZyZXR1cm4gc2hvdWxkIGJlIGNhbGxlZCBieSBvcmRlciBvd25lcgQAAAAGYW1vdW50CQEAAAARQGV4dHJOYXRpdmUoMTA1MCkAAAACBQAAAAR0aGlzCQABLAAAAAIFAAAAB29yZGVySWQCAAAAB19hbW91bnQEAAAABXNwZW50CQEAAAARQGV4dHJOYXRpdmUoMTA1MCkAAAACBQAAAAR0aGlzCQABLAAAAAIFAAAAB29yZGVySWQCAAAABl9zcGVudAQAAAAMcmV0dXJuQW1vdW50CQAAZQAAAAIFAAAABmFtb3VudAUAAAAFc3BlbnQDCQAAZwAAAAIAAAAAAAAAAAAFAAAADHJldHVybkFtb3VudAkAAAIAAAABAgAAABFub3RoaW5nIHRvIHJldHVybgkBAAAADFNjcmlwdFJlc3VsdAAAAAIJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAAEsAAAAAgUAAAAHb3JkZXJJZAIAAAAGX3NwZW50BQAAAAZhbW91bnQFAAAAA25pbAkBAAAAC1RyYW5zZmVyU2V0AAAAAQkABEwAAAACCQEAAAAOU2NyaXB0VHJhbnNmZXIAAAADCAUAAAABaQAAAAZjYWxsZXIFAAAADHJldHVybkFtb3VudAUAAAAKVlNUQXNzZXRJRAUAAAADbmlsAAAAAAIg1N8=", "chainId": 84, "height": 625025, "spentComplexity": 0 } View: original | compacted Prev: ECMx6uzT9saTaxjDdHWmqWSdMQW8EPTvK3RCuD75K7mu Next: 684Jd7wUnqqTo5wKTkMtaRD7MH8ywJuPvpkJrMW9RGVL Diff:
Old | New | Differences | |
---|---|---|---|
42 | 42 | if ((e.assetId != unit)) | |
43 | 43 | then throw("asset must be WAVES") | |
44 | 44 | else { | |
45 | + | let h = getStringValue(this, (f + "_owner")) | |
45 | 46 | let d = getIntegerValue(this, (f + "_price")) | |
46 | - | let | |
47 | - | let | |
48 | - | let | |
49 | - | let | |
50 | - | let | |
51 | - | if (( | |
47 | + | let i = e.amount | |
48 | + | let j = ((i * d) / b) | |
49 | + | let k = getIntegerValue(this, (f + "_amount")) | |
50 | + | let l = getIntegerValue(this, (f + "_spent")) | |
51 | + | let m = (l + j) | |
52 | + | if ((m > k)) | |
52 | 53 | then throw("not enougth asset in order") | |
53 | - | else ScriptResult(WriteSet([DataEntry((f + "_spent"), | |
54 | + | else ScriptResult(WriteSet([DataEntry((f + "_spent"), m)]), TransferSet([ScriptTransfer(c.caller, j, a), ScriptTransfer(extract(addressFromString(h)), i, unit)])) | |
54 | 55 | } | |
55 | 56 | } | |
56 | 57 | ||
63 | 64 | if ((e.assetId != a)) | |
64 | 65 | then throw(("asset must be " + toBase58String(a))) | |
65 | 66 | else { | |
67 | + | let h = getStringValue(this, (f + "_owner")) | |
66 | 68 | let d = getIntegerValue(this, (f + "_price")) | |
67 | - | let | |
68 | - | let | |
69 | - | let | |
70 | - | let | |
71 | - | let | |
72 | - | if (( | |
69 | + | let j = e.amount | |
70 | + | let i = ((j * b) / d) | |
71 | + | let k = getIntegerValue(this, (f + "_amount")) | |
72 | + | let l = getIntegerValue(this, (f + "_spent")) | |
73 | + | let m = (l + j) | |
74 | + | if ((m > k)) | |
73 | 75 | then throw("not enougth asset in order") | |
74 | - | else ScriptResult(WriteSet([DataEntry((f + "_spent"), | |
76 | + | else ScriptResult(WriteSet([DataEntry((f + "_spent"), m)]), TransferSet([ScriptTransfer(c.caller, i, unit), ScriptTransfer(extract(addressFromString(h)), j, a)])) | |
75 | 77 | } | |
76 | 78 | } | |
77 | 79 | ||
80 | 82 | @Callable(c) | |
81 | 83 | func returnBuyVST (g) = { | |
82 | 84 | let f = ("buy_" + g) | |
83 | - | let | |
84 | - | if (( | |
85 | + | let h = getStringValue(this, (f + "_owner")) | |
86 | + | if ((h != toBase58String(c.caller.bytes))) | |
85 | 87 | then throw("return should be called by order owner") | |
86 | 88 | else { | |
87 | - | let | |
88 | - | let | |
89 | + | let k = getIntegerValue(this, (f + "_amount")) | |
90 | + | let l = getIntegerValue(this, (f + "_spent")) | |
89 | 91 | let d = getIntegerValue(this, (f + "_price")) | |
90 | - | let n = ((( | |
92 | + | let n = (((k - l) * b) / d) | |
91 | 93 | if ((0 >= n)) | |
92 | 94 | then throw("nothing to return") | |
93 | - | else ScriptResult(WriteSet([DataEntry((f + "_spent"), | |
95 | + | else ScriptResult(WriteSet([DataEntry((f + "_spent"), k)]), TransferSet([ScriptTransfer(c.caller, n, unit)])) | |
94 | 96 | } | |
95 | 97 | } | |
96 | 98 | ||
99 | 101 | @Callable(c) | |
100 | 102 | func returnSellVST (g) = { | |
101 | 103 | let f = ("sell_" + g) | |
102 | - | let | |
103 | - | if (( | |
104 | + | let h = getStringValue(this, (f + "_owner")) | |
105 | + | if ((h != toBase58String(c.caller.bytes))) | |
104 | 106 | then throw("return should be called by order owner") | |
105 | 107 | else { | |
106 | - | let | |
107 | - | let | |
108 | - | let n = ( | |
108 | + | let k = getIntegerValue(this, (f + "_amount")) | |
109 | + | let l = getIntegerValue(this, (f + "_spent")) | |
110 | + | let n = (k - l) | |
109 | 111 | if ((0 >= n)) | |
110 | 112 | then throw("nothing to return") | |
111 | - | else ScriptResult(WriteSet([DataEntry((f + "_spent"), | |
113 | + | else ScriptResult(WriteSet([DataEntry((f + "_spent"), k)]), TransferSet([ScriptTransfer(c.caller, n, a)])) | |
112 | 114 | } | |
113 | 115 | } | |
114 | 116 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let a = base58'CjxKp2kfytghpfforkYLSoXHzJyJ5QYKLYQYgN7pQV4E' | |
5 | 5 | ||
6 | 6 | let b = 100000000 | |
7 | 7 | ||
8 | 8 | @Callable(c) | |
9 | 9 | func makeSellVST (d) = if ((0 >= d)) | |
10 | 10 | then throw("price must be positive") | |
11 | 11 | else { | |
12 | 12 | let e = extract(c.payment) | |
13 | 13 | if ((e.assetId != a)) | |
14 | 14 | then throw(("asset id must be " + toBase58String(a))) | |
15 | 15 | else { | |
16 | 16 | let f = ("sell_" + toBase58String(c.transactionId)) | |
17 | 17 | WriteSet([DataEntry((f + "_amount"), e.amount), DataEntry((f + "_price"), d), DataEntry((f + "_owner"), toBase58String(c.caller.bytes)), DataEntry((f + "_spent"), 0)]) | |
18 | 18 | } | |
19 | 19 | } | |
20 | 20 | ||
21 | 21 | ||
22 | 22 | ||
23 | 23 | @Callable(c) | |
24 | 24 | func makeBuyVST (d) = if ((0 >= d)) | |
25 | 25 | then throw("price must be positive") | |
26 | 26 | else { | |
27 | 27 | let e = extract(c.payment) | |
28 | 28 | if ((e.assetId != unit)) | |
29 | 29 | then throw("asset id must be WAVES") | |
30 | 30 | else { | |
31 | 31 | let f = ("buy_" + toBase58String(c.transactionId)) | |
32 | 32 | WriteSet([DataEntry((f + "_amount"), ((e.amount * d) / b)), DataEntry((f + "_price"), d), DataEntry((f + "_owner"), toBase58String(c.caller.bytes)), DataEntry((f + "_spent"), 0)]) | |
33 | 33 | } | |
34 | 34 | } | |
35 | 35 | ||
36 | 36 | ||
37 | 37 | ||
38 | 38 | @Callable(c) | |
39 | 39 | func takeSellVST (g) = { | |
40 | 40 | let f = ("sell_" + g) | |
41 | 41 | let e = extract(c.payment) | |
42 | 42 | if ((e.assetId != unit)) | |
43 | 43 | then throw("asset must be WAVES") | |
44 | 44 | else { | |
45 | + | let h = getStringValue(this, (f + "_owner")) | |
45 | 46 | let d = getIntegerValue(this, (f + "_price")) | |
46 | - | let | |
47 | - | let | |
48 | - | let | |
49 | - | let | |
50 | - | let | |
51 | - | if (( | |
47 | + | let i = e.amount | |
48 | + | let j = ((i * d) / b) | |
49 | + | let k = getIntegerValue(this, (f + "_amount")) | |
50 | + | let l = getIntegerValue(this, (f + "_spent")) | |
51 | + | let m = (l + j) | |
52 | + | if ((m > k)) | |
52 | 53 | then throw("not enougth asset in order") | |
53 | - | else ScriptResult(WriteSet([DataEntry((f + "_spent"), | |
54 | + | else ScriptResult(WriteSet([DataEntry((f + "_spent"), m)]), TransferSet([ScriptTransfer(c.caller, j, a), ScriptTransfer(extract(addressFromString(h)), i, unit)])) | |
54 | 55 | } | |
55 | 56 | } | |
56 | 57 | ||
57 | 58 | ||
58 | 59 | ||
59 | 60 | @Callable(c) | |
60 | 61 | func takeBuyVST (g) = { | |
61 | 62 | let f = ("buy_" + g) | |
62 | 63 | let e = extract(c.payment) | |
63 | 64 | if ((e.assetId != a)) | |
64 | 65 | then throw(("asset must be " + toBase58String(a))) | |
65 | 66 | else { | |
67 | + | let h = getStringValue(this, (f + "_owner")) | |
66 | 68 | let d = getIntegerValue(this, (f + "_price")) | |
67 | - | let | |
68 | - | let | |
69 | - | let | |
70 | - | let | |
71 | - | let | |
72 | - | if (( | |
69 | + | let j = e.amount | |
70 | + | let i = ((j * b) / d) | |
71 | + | let k = getIntegerValue(this, (f + "_amount")) | |
72 | + | let l = getIntegerValue(this, (f + "_spent")) | |
73 | + | let m = (l + j) | |
74 | + | if ((m > k)) | |
73 | 75 | then throw("not enougth asset in order") | |
74 | - | else ScriptResult(WriteSet([DataEntry((f + "_spent"), | |
76 | + | else ScriptResult(WriteSet([DataEntry((f + "_spent"), m)]), TransferSet([ScriptTransfer(c.caller, i, unit), ScriptTransfer(extract(addressFromString(h)), j, a)])) | |
75 | 77 | } | |
76 | 78 | } | |
77 | 79 | ||
78 | 80 | ||
79 | 81 | ||
80 | 82 | @Callable(c) | |
81 | 83 | func returnBuyVST (g) = { | |
82 | 84 | let f = ("buy_" + g) | |
83 | - | let | |
84 | - | if (( | |
85 | + | let h = getStringValue(this, (f + "_owner")) | |
86 | + | if ((h != toBase58String(c.caller.bytes))) | |
85 | 87 | then throw("return should be called by order owner") | |
86 | 88 | else { | |
87 | - | let | |
88 | - | let | |
89 | + | let k = getIntegerValue(this, (f + "_amount")) | |
90 | + | let l = getIntegerValue(this, (f + "_spent")) | |
89 | 91 | let d = getIntegerValue(this, (f + "_price")) | |
90 | - | let n = ((( | |
92 | + | let n = (((k - l) * b) / d) | |
91 | 93 | if ((0 >= n)) | |
92 | 94 | then throw("nothing to return") | |
93 | - | else ScriptResult(WriteSet([DataEntry((f + "_spent"), | |
95 | + | else ScriptResult(WriteSet([DataEntry((f + "_spent"), k)]), TransferSet([ScriptTransfer(c.caller, n, unit)])) | |
94 | 96 | } | |
95 | 97 | } | |
96 | 98 | ||
97 | 99 | ||
98 | 100 | ||
99 | 101 | @Callable(c) | |
100 | 102 | func returnSellVST (g) = { | |
101 | 103 | let f = ("sell_" + g) | |
102 | - | let | |
103 | - | if (( | |
104 | + | let h = getStringValue(this, (f + "_owner")) | |
105 | + | if ((h != toBase58String(c.caller.bytes))) | |
104 | 106 | then throw("return should be called by order owner") | |
105 | 107 | else { | |
106 | - | let | |
107 | - | let | |
108 | - | let n = ( | |
108 | + | let k = getIntegerValue(this, (f + "_amount")) | |
109 | + | let l = getIntegerValue(this, (f + "_spent")) | |
110 | + | let n = (k - l) | |
109 | 111 | if ((0 >= n)) | |
110 | 112 | then throw("nothing to return") | |
111 | - | else ScriptResult(WriteSet([DataEntry((f + "_spent"), | |
113 | + | else ScriptResult(WriteSet([DataEntry((f + "_spent"), k)]), TransferSet([ScriptTransfer(c.caller, n, a)])) | |
112 | 114 | } | |
113 | 115 | } | |
114 | 116 | ||
115 | 117 |
github/deemru/w8io/026f985 64.47 ms ◑