tx · 8dqeKCXVWCjrjYZfQNKSZ1tBkSmEKGnWcf2gtwrX5iWu 3N6s7QBCvgnCNbR7r4rajA9DsejGtshaLLa: -0.01500000 Waves 2019.12.20 17:51 [817424] smart account 3N6s7QBCvgnCNbR7r4rajA9DsejGtshaLLa > SELF 0.00000000 Waves
{ "type": 13, "id": "8dqeKCXVWCjrjYZfQNKSZ1tBkSmEKGnWcf2gtwrX5iWu", "fee": 1500000, "feeAssetId": null, "timestamp": 1576848709811, "version": 1, "sender": "3N6s7QBCvgnCNbR7r4rajA9DsejGtshaLLa", "senderPublicKey": "5wpzgifs7AQAB2xctYK9m7gDenQv4yCCiLcTgKQTcz9Z", "proofs": [ "xqga8kga8iLb9nbarZj3zucCCq8qT42qRvn9jvvMrHxd2Rfk13UfdJmgJphSYZ1zc1ZMFPWc8eDixQcsA2WGhJ6" ], "script": "base64:AAIDAAAAAAAAABcIARIECgIBARIDCgEIEgMKAQgSAwoBCAAAAAEAAAAAD2F1Y3Rpb25EdXJhdGlvbgkAAGgAAAACAAAAAAAAAAWgAAAAAAAAAAABAAAABAAAAAFpAQAAAAxiZWdpbkF1Y3Rpb24AAAACAAAACG1pblByaWNlAAAACGR1cmF0aW9uAwkAAGYAAAACBQAAAAhkdXJhdGlvbgUAAAAPYXVjdGlvbkR1cmF0aW9uCQAAAgAAAAEJAAEsAAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgIAAAATU3BlY2lmaWVkIGR1cmF0aW9uKAkAAaQAAAABBQAAAAhkdXJhdGlvbgIAAAAfKSBleGNlZWRzIHRoZSBtYXhpbXVtIGR1cmF0aW9uKAkAAaQAAAABBQAAAA9hdWN0aW9uRHVyYXRpb24CAAAAASkEAAAACWF1Y3Rpb25JZAkAAlgAAAABCAUAAAABaQAAAA10cmFuc2FjdGlvbklkBAAAAAdlbmRUaW1lCQAAZAAAAAIIBQAAAAlsYXN0QmxvY2sAAAAGaGVpZ2h0BQAAAAhkdXJhdGlvbgQAAAADcG10CQEAA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JAQAAABxAZXh0clVzZXIoYWRkcmVzc0Zyb21TdHJpbmcpAAAAAQkBAAAABXZhbHVlAAAAAQUAAAAFb3duZXIEAAAACGl0ZW1BZGRyCQACWQAAAAEJAQAAAAV2YWx1ZQAAAAEFAAAABml0ZW1JZAMJAQAAAAIhPQAAAAIFAAAADWNhbGxlckFkZHJlc3MJAQAAAAV2YWx1ZQAAAAEFAAAADWhpZ2hlc3RCaWRkZXIJAAACAAAAAQIAAAANQWNjZXNzIERlbmllZAMJAABmAAAAAgUAAAAHZW5kVGltZQgFAAAACWxhc3RCbG9jawAAAAZoZWlnaHQJAAACAAAAAQIAAAAbQXVjdGlvbiBpcyBub3QgZmluaXNoZWQgeWV0AwkBAAAACWlzRGVmaW5lZAAAAAEJAAQbAAAAAgUAAAAEdGhpcwkAASwAAAACBQAAAAlhdWN0aW9uSWQCAAAAFV93aW5uZXJXaXRoZHJhd1N0YXR1cwkAAAIAAAABAgAAACRUaGUgYmlkIGFtb3VudCBpcyBhbHJlYWR5IHRyYW5zZmVyZWQJAQAAAAxTY3JpcHRSZXN1bHQAAAACCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQABLAAAAAIFAAAACWF1Y3Rpb25JZAIAAAAVX3dpbm5lcldpdGhkcmF3U3RhdHVzBgUAAAADbmlsCQEAAAALVHJhbnNmZXJTZXQAAAABCQAETAAAAAIJAQAAAA5TY3JpcHRUcmFuc2ZlcgAAAAMFAAAAEWhpZ2hlc3RCaWRkZXJBZGRyAAAAAAAAAAABBQAAAAhpdGVtQWRkcgUAAAADbmlsAAAAAN9QPWg=", "chainId": 84, "height": 817424, "spentComplexity": 0 } View: original | compacted Prev: EPxrdjZ98ZSBPQiit62Gx86HLdKjQ7e23JS9vV5uVuQ8 Next: CYC1jUkkJXRZyi1N66THGv2gZCB7wv63itW3qdHykK81 Diff:
Old | New | Differences | |
---|---|---|---|
58 | 58 | ||
59 | 59 | ||
60 | 60 | @Callable(i) | |
61 | - | func withdraw (auctionId) = { | |
62 | - | let pmt = extract(i.payment) | |
61 | + | func ownerWithdraw (auctionId) = { | |
63 | 62 | let callerAddress = toBase58String(i.caller.bytes) | |
64 | 63 | let endTime = getIntegerValue(this, (auctionId + "_endTime")) | |
65 | 64 | let owner = getStringValue(this, (auctionId + "_owner")) | |
69 | 68 | let highestBidderAddr = addressFromStringValue(value(highestBidder)) | |
70 | 69 | let ownerAddr = addressFromStringValue(value(owner)) | |
71 | 70 | let itemAddr = fromBase58String(value(itemId)) | |
72 | - | if ((endTime > lastBlock.height)) | |
73 | - | then throw("Auction is not finished yet") | |
74 | - | else if (!(isDefined(highestBidder))) | |
75 | - | then if (isDefined(getBoolean(this, (auctionId + "_status")))) | |
76 | - | then throw("Owner already withdrawn the item") | |
77 | - | else ScriptResult(WriteSet([DataEntry((auctionId + "_status"), true)]), TransferSet([ScriptTransfer(ownerAddr, 1, itemAddr)])) | |
78 | - | else if (isDefined(getBoolean(this, (auctionId + "_status")))) | |
79 | - | then throw("The item is transfered to the highest bidder and the bid amount is transfered to the owner") | |
80 | - | else ScriptResult(WriteSet([DataEntry((auctionId + "_status"), true)]), TransferSet([ScriptTransfer(highestBidderAddr, 1, itemAddr), ScriptTransfer(ownerAddr, ((highestBidAmt / 100) * 95), unit)])) | |
71 | + | if ((callerAddress != value(owner))) | |
72 | + | then throw("Access Denied") | |
73 | + | else if ((endTime > lastBlock.height)) | |
74 | + | then throw("Auction is not finished yet") | |
75 | + | else if (!(isDefined(highestBidder))) | |
76 | + | then if (isDefined(getBoolean(this, (auctionId + "_ownerWithdrawStatus")))) | |
77 | + | then throw("Item already withdrawn") | |
78 | + | else ScriptResult(WriteSet([DataEntry((auctionId + "_ownerWithdrawStatus"), true)]), TransferSet([ScriptTransfer(ownerAddr, 1, itemAddr)])) | |
79 | + | else if (isDefined(getBoolean(this, (auctionId + "_ownerWithdrawStatus")))) | |
80 | + | then throw("The bid amount is already transfered") | |
81 | + | else ScriptResult(WriteSet([DataEntry((auctionId + "_ownerWithdrawStatus"), true)]), TransferSet([ScriptTransfer(ownerAddr, ((highestBidAmt / 100) * 95), unit)])) | |
82 | + | } | |
83 | + | ||
84 | + | ||
85 | + | ||
86 | + | @Callable(i) | |
87 | + | func winnerWithdraw (auctionId) = { | |
88 | + | let callerAddress = toBase58String(i.caller.bytes) | |
89 | + | let endTime = getIntegerValue(this, (auctionId + "_endTime")) | |
90 | + | let owner = getStringValue(this, (auctionId + "_owner")) | |
91 | + | let highestBidder = getString(this, (auctionId + "_highestBidder")) | |
92 | + | let itemId = getStringValue(this, (auctionId + "_itemId")) | |
93 | + | let highestBidAmt = getIntegerValue(this, (auctionId + "_highestBidAmt")) | |
94 | + | let highestBidderAddr = addressFromStringValue(value(highestBidder)) | |
95 | + | let ownerAddr = addressFromStringValue(value(owner)) | |
96 | + | let itemAddr = fromBase58String(value(itemId)) | |
97 | + | if ((callerAddress != value(highestBidder))) | |
98 | + | then throw("Access Denied") | |
99 | + | else if ((endTime > lastBlock.height)) | |
100 | + | then throw("Auction is not finished yet") | |
101 | + | else if (isDefined(getBoolean(this, (auctionId + "_winnerWithdrawStatus")))) | |
102 | + | then throw("The bid amount is already transfered") | |
103 | + | else ScriptResult(WriteSet([DataEntry((auctionId + "_winnerWithdrawStatus"), true)]), TransferSet([ScriptTransfer(highestBidderAddr, 1, itemAddr)])) | |
81 | 104 | } | |
82 | 105 | ||
83 | 106 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let auctionDuration = (1440 * 1) | |
5 | 5 | ||
6 | 6 | @Callable(i) | |
7 | 7 | func beginAuction (minPrice,duration) = if ((duration > auctionDuration)) | |
8 | 8 | then throw((((("Specified duration(" + toString(duration)) + ") exceeds the maximum duration(") + toString(auctionDuration)) + ")")) | |
9 | 9 | else { | |
10 | 10 | let auctionId = toBase58String(i.transactionId) | |
11 | 11 | let endTime = (lastBlock.height + duration) | |
12 | 12 | let pmt = extract(i.payment) | |
13 | 13 | WriteSet([DataEntry(auctionId, auctionId), DataEntry((auctionId + "_endTime"), endTime), DataEntry((auctionId + "_owner"), toBase58String(i.caller.bytes)), DataEntry((auctionId + "_itemId"), if (isDefined(pmt.assetId)) | |
14 | 14 | then toBase58String(value(pmt.assetId)) | |
15 | 15 | else throw("Item not atached")), DataEntry((auctionId + "_minPrice"), minPrice)]) | |
16 | 16 | } | |
17 | 17 | ||
18 | 18 | ||
19 | 19 | ||
20 | 20 | @Callable(i) | |
21 | 21 | func bid (auctionId) = { | |
22 | 22 | let pmt = extract(i.payment) | |
23 | 23 | let callerAddress = toBase58String(i.caller.bytes) | |
24 | 24 | let endTime = getIntegerValue(this, (auctionId + "_endTime")) | |
25 | 25 | let minPrice = getIntegerValue(this, (auctionId + "_minPrice")) | |
26 | 26 | let highestBidAmt = getInteger(this, (auctionId + "_highestBidAmt")) | |
27 | 27 | let highestBidder = getString(this, (auctionId + "_highestBidder")) | |
28 | 28 | let bidFromTheSameUser = if (isDefined(highestBidder)) | |
29 | 29 | then (value(highestBidder) == callerAddress) | |
30 | 30 | else false | |
31 | 31 | let totalBidAmount = (pmt.amount + (if (bidFromTheSameUser) | |
32 | 32 | then value(highestBidAmt) | |
33 | 33 | else 0)) | |
34 | 34 | if (!(isDefined(getString(this, auctionId)))) | |
35 | 35 | then throw("Auction Id not found") | |
36 | 36 | else if ((lastBlock.height >= endTime)) | |
37 | 37 | then throw("Auction Completed") | |
38 | 38 | else if (if (if (!(isDefined(highestBidAmt))) | |
39 | 39 | then (minPrice >= totalBidAmount) | |
40 | 40 | else false) | |
41 | 41 | then true | |
42 | 42 | else if (isDefined(highestBidAmt)) | |
43 | 43 | then (value(highestBidAmt) >= totalBidAmount) | |
44 | 44 | else false) | |
45 | 45 | then throw(("Bid must be more then " + (if (!(isDefined(highestBidAmt))) | |
46 | 46 | then toString(minPrice) | |
47 | 47 | else toString(value(highestBidAmt))))) | |
48 | 48 | else if (!(isDefined(highestBidder))) | |
49 | 49 | then WriteSet([DataEntry((auctionId + "_highestBidder"), callerAddress), DataEntry((auctionId + "_highestBidAmt"), totalBidAmount)]) | |
50 | 50 | else if (bidFromTheSameUser) | |
51 | 51 | then WriteSet([DataEntry((auctionId + "_highestBidAmt"), totalBidAmount)]) | |
52 | 52 | else { | |
53 | 53 | let previousBidder = addressFromStringValue(value(highestBidder)) | |
54 | 54 | ScriptResult(WriteSet([DataEntry((auctionId + "_highestBidder"), callerAddress), DataEntry((auctionId + "_highestBidAmt"), totalBidAmount)]), TransferSet([ScriptTransfer(previousBidder, value(highestBidAmt), unit)])) | |
55 | 55 | } | |
56 | 56 | } | |
57 | 57 | ||
58 | 58 | ||
59 | 59 | ||
60 | 60 | @Callable(i) | |
61 | - | func withdraw (auctionId) = { | |
62 | - | let pmt = extract(i.payment) | |
61 | + | func ownerWithdraw (auctionId) = { | |
63 | 62 | let callerAddress = toBase58String(i.caller.bytes) | |
64 | 63 | let endTime = getIntegerValue(this, (auctionId + "_endTime")) | |
65 | 64 | let owner = getStringValue(this, (auctionId + "_owner")) | |
66 | 65 | let highestBidder = getString(this, (auctionId + "_highestBidder")) | |
67 | 66 | let itemId = getStringValue(this, (auctionId + "_itemId")) | |
68 | 67 | let highestBidAmt = getIntegerValue(this, (auctionId + "_highestBidAmt")) | |
69 | 68 | let highestBidderAddr = addressFromStringValue(value(highestBidder)) | |
70 | 69 | let ownerAddr = addressFromStringValue(value(owner)) | |
71 | 70 | let itemAddr = fromBase58String(value(itemId)) | |
72 | - | if ((endTime > lastBlock.height)) | |
73 | - | then throw("Auction is not finished yet") | |
74 | - | else if (!(isDefined(highestBidder))) | |
75 | - | then if (isDefined(getBoolean(this, (auctionId + "_status")))) | |
76 | - | then throw("Owner already withdrawn the item") | |
77 | - | else ScriptResult(WriteSet([DataEntry((auctionId + "_status"), true)]), TransferSet([ScriptTransfer(ownerAddr, 1, itemAddr)])) | |
78 | - | else if (isDefined(getBoolean(this, (auctionId + "_status")))) | |
79 | - | then throw("The item is transfered to the highest bidder and the bid amount is transfered to the owner") | |
80 | - | else ScriptResult(WriteSet([DataEntry((auctionId + "_status"), true)]), TransferSet([ScriptTransfer(highestBidderAddr, 1, itemAddr), ScriptTransfer(ownerAddr, ((highestBidAmt / 100) * 95), unit)])) | |
71 | + | if ((callerAddress != value(owner))) | |
72 | + | then throw("Access Denied") | |
73 | + | else if ((endTime > lastBlock.height)) | |
74 | + | then throw("Auction is not finished yet") | |
75 | + | else if (!(isDefined(highestBidder))) | |
76 | + | then if (isDefined(getBoolean(this, (auctionId + "_ownerWithdrawStatus")))) | |
77 | + | then throw("Item already withdrawn") | |
78 | + | else ScriptResult(WriteSet([DataEntry((auctionId + "_ownerWithdrawStatus"), true)]), TransferSet([ScriptTransfer(ownerAddr, 1, itemAddr)])) | |
79 | + | else if (isDefined(getBoolean(this, (auctionId + "_ownerWithdrawStatus")))) | |
80 | + | then throw("The bid amount is already transfered") | |
81 | + | else ScriptResult(WriteSet([DataEntry((auctionId + "_ownerWithdrawStatus"), true)]), TransferSet([ScriptTransfer(ownerAddr, ((highestBidAmt / 100) * 95), unit)])) | |
82 | + | } | |
83 | + | ||
84 | + | ||
85 | + | ||
86 | + | @Callable(i) | |
87 | + | func winnerWithdraw (auctionId) = { | |
88 | + | let callerAddress = toBase58String(i.caller.bytes) | |
89 | + | let endTime = getIntegerValue(this, (auctionId + "_endTime")) | |
90 | + | let owner = getStringValue(this, (auctionId + "_owner")) | |
91 | + | let highestBidder = getString(this, (auctionId + "_highestBidder")) | |
92 | + | let itemId = getStringValue(this, (auctionId + "_itemId")) | |
93 | + | let highestBidAmt = getIntegerValue(this, (auctionId + "_highestBidAmt")) | |
94 | + | let highestBidderAddr = addressFromStringValue(value(highestBidder)) | |
95 | + | let ownerAddr = addressFromStringValue(value(owner)) | |
96 | + | let itemAddr = fromBase58String(value(itemId)) | |
97 | + | if ((callerAddress != value(highestBidder))) | |
98 | + | then throw("Access Denied") | |
99 | + | else if ((endTime > lastBlock.height)) | |
100 | + | then throw("Auction is not finished yet") | |
101 | + | else if (isDefined(getBoolean(this, (auctionId + "_winnerWithdrawStatus")))) | |
102 | + | then throw("The bid amount is already transfered") | |
103 | + | else ScriptResult(WriteSet([DataEntry((auctionId + "_winnerWithdrawStatus"), true)]), TransferSet([ScriptTransfer(highestBidderAddr, 1, itemAddr)])) | |
81 | 104 | } | |
82 | 105 | ||
83 | 106 |
github/deemru/w8io/169f3d6 32.61 ms ◑