tx · FfCyS8xwSAAYPb9DTjHEHZhzGvJ2EfbVxbom5qMCQUts 3N91zFrRoofbPpkoDbWKrQsQSdLu2EgLL8c: -0.01000000 Waves 2023.11.27 15:35 [2861819] smart account 3N91zFrRoofbPpkoDbWKrQsQSdLu2EgLL8c > SELF 0.00000000 Waves
{ "type": 13, "id": "FfCyS8xwSAAYPb9DTjHEHZhzGvJ2EfbVxbom5qMCQUts", "fee": 1000000, "feeAssetId": null, "timestamp": 1701088590114, "version": 2, "chainId": 84, "sender": "3N91zFrRoofbPpkoDbWKrQsQSdLu2EgLL8c", "senderPublicKey": "5FyjUYCR5Q8jvG6ri6Ysz574HerUK6r1LJzzQ7DvSkLk", "proofs": [ "HyzZMYCyc7J2gfHkYwQZ3TkEQU8K7GSwk1H6dxigSb62bddk8LKYKDboMKy6hj423faqyL3AxkLptSDtUJ1dQ2J" ], "script": "base64:BgIVCAISBgoEAgICARIECgIICBIDCgECIQAJc2VwYXJhdG9yAgJfXwAHY2hhaW5JZAkAyQECCQDKAQIIBQR0aGlzBWJ5dGVzAAEAAQAIY2hhaW5JZFQBAVQACGNoYWluSWRXAQFXAQttdXN0QWRkcmVzcwIBaQdhZGRyZXNzAwkAAAIIBQFpBmNhbGxlcgUHYWRkcmVzcwYJAAIBAhFwZXJtaXNzaW9uIGRlbmllZAEIbXVzdFRoaXMBAWkJAQttdXN0QWRkcmVzcwIFAWkFBHRoaXMAC3dhdmVzU3RyaW5nAgVXQVZFUwANcXVldWVJdGVtU2l6ZQAgAQxwYXJzZUFzc2V0SWQBBWlucHV0AwkAAAIFBWlucHV0BQt3YXZlc1N0cmluZwUEdW5pdAkA2QQBBQVpbnB1dAEPYXNzZXRJZFRvU3RyaW5nAQVpbnB1dAMJAAACBQVpbnB1dAUEdW5pdAULd2F2ZXNTdHJpbmcJANgEAQkBBXZhbHVlAQUFaW5wdXQAEWtTZXJ2aWNlUHVibGljS2V5AhQlc19fc2VydmljZVB1YmxpY0tleQANa0JvdFB1YmxpY0t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vdW50AAUEdW5pdAUDbmlsCQCUCgIJAM4IAgUHYWN0aW9ucwkAzAgCCQELQmluYXJ5RW50cnkCCQEYa0FjY291bnRDcmVhdG9yUHVibGljS2V5AQUOYWNjb3VudEFkZHJlc3MFEGNyZWF0b3JQdWJsaWNLZXkFA25pbAUEdW5pdAkAAgECJFN0cmljdCB2YWx1ZSBpcyBub3QgZXF1YWwgdG8gaXRzZWxmLgDkfR+U", "height": 2861819, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 7t3hKbDaEDscitJVr4p2E8VYHPpHPdBu2XdTzHaHbpfw Next: 5jp7TUAuSrb2N5aiXScgKDBiKk3ahQJf3GJ8CGxVzjLU Diff:
Old | New | Differences | |
---|---|---|---|
18 | 18 | ||
19 | 19 | ||
20 | 20 | let wavesString = "WAVES" | |
21 | + | ||
22 | + | let queueItemSize = 32 | |
21 | 23 | ||
22 | 24 | func parseAssetId (input) = if ((input == wavesString)) | |
23 | 25 | then unit | |
43 | 45 | func rewardAmount () = valueOrErrorMessage(getInteger(this, kRewardAmount), "reward amount is not set") | |
44 | 46 | ||
45 | 47 | ||
46 | - | let | |
48 | + | let REQUEST_STATUS_EMPTY = 0 | |
47 | 49 | ||
48 | - | let | |
50 | + | let REQUEST_STATUS_READY = 1 | |
49 | 51 | ||
50 | - | func | |
52 | + | func kRequestStatus (requestId) = makeString(["%s%s", toBase58String(requestId), "status"], separator) | |
51 | 53 | ||
52 | 54 | ||
53 | - | func | |
55 | + | func kAccountCreatorPublicKey (accountAddress) = makeString(["%s%s", toString(accountAddress), "creatorPublicKey"], separator) | |
54 | 56 | ||
55 | 57 | ||
56 | - | func | |
58 | + | func kRequestOwnerPublicKey (requestId) = makeString(["%s%s", toBase58String(requestId), "ownerPublicKey"], separator) | |
57 | 59 | ||
58 | 60 | ||
59 | - | func | |
61 | + | func kRequestAmountAssetId (requestId) = makeString(["%s%s", toBase58String(requestId), "amountAssetId"], separator) | |
60 | 62 | ||
61 | 63 | ||
62 | - | func | |
64 | + | func kRequestPriceAssetId (requestId) = makeString(["%s%s", toBase58String(requestId), "priceAssetId"], separator) | |
63 | 65 | ||
64 | 66 | ||
65 | - | func | |
67 | + | func kRequestIdToAccountPublicKey (requestId) = makeString(["%s%s", toBase58String(requestId), "requestIdToAccountPublicKey"], separator) | |
66 | 68 | ||
67 | 69 | ||
68 | - | func | |
70 | + | func kAccountAddressToRequestId (accountAddress) = makeString(["%s%s", toString(accountAddress), "accountAddressToRequestId"], separator) | |
69 | 71 | ||
70 | 72 | ||
71 | - | func kAccountAddressToAccountId (accountAddress) = makeString(["%s%s", toString(accountAddress), "accountAddressToAccountId"], separator) | |
73 | + | func kRequestsQueue () = makeString(["%s", "requestsQueue"], separator) | |
74 | + | ||
75 | + | ||
76 | + | func requestsQueue () = valueOrElse(getBinary(this, kRequestsQueue()), base58'') | |
77 | + | ||
78 | + | ||
79 | + | func kAccountsQueue () = makeString(["%s", "accountsQueue"], separator) | |
80 | + | ||
81 | + | ||
82 | + | func accountsQueue () = valueOrElse(getBinary(this, kAccountsQueue()), base58'') | |
72 | 83 | ||
73 | 84 | ||
74 | 85 | func kPairAllowed (amountAssetId,priceAssetId) = makeString(["%s%s%s", assetIdToString(amountAssetId), assetIdToString(priceAssetId), "pairAllowed"], separator) | |
92 | 103 | ||
93 | 104 | ||
94 | 105 | @Callable(i) | |
95 | - | func | |
96 | - | let | |
106 | + | func requestAccount (amountAssetIdStr,priceAssetIdStr) = { | |
107 | + | let requestId = sha256(((i.caller.bytes + fromBase58String(amountAssetIdStr)) + fromBase58String(priceAssetIdStr))) | |
97 | 108 | let amountAssetId = parseAssetId(amountAssetIdStr) | |
98 | 109 | let priceAssetId = parseAssetId(priceAssetIdStr) | |
99 | 110 | let checks = [if ((size(i.payments) == 1)) | |
104 | 115 | then true | |
105 | 116 | else throw("invalid amount"), if (pairAllowed(amountAssetId, priceAssetId)) | |
106 | 117 | then true | |
107 | - | else throw("pair is not allowed"), if ((getInteger(this, | |
118 | + | else throw("pair is not allowed"), if ((getInteger(this, kRequestStatus(requestId)) == unit)) | |
108 | 119 | then true | |
109 | - | else throw("account already exists")] | |
120 | + | else throw("account is already exists")] | |
110 | 121 | if ((checks == checks)) | |
111 | - | then $Tuple2([IntegerEntry(kAccountStatus(accountId), 0), BinaryEntry(kAccountOwnerPublicKey(accountId), i.callerPublicKey), StringEntry(kAccountAmountAssetId(accountId), amountAssetIdStr), StringEntry(kAccountPriceAssetId(accountId), priceAssetIdStr)], unit) | |
122 | + | then { | |
123 | + | let actions = if ((size(accountsQueue()) == 0)) | |
124 | + | then [IntegerEntry(kRequestStatus(requestId), REQUEST_STATUS_EMPTY), BinaryEntry(kRequestsQueue(), (requestsQueue() + requestId))] | |
125 | + | else { | |
126 | + | let accountPublicKey = take(accountsQueue(), queueItemSize) | |
127 | + | let accountAddress = addressFromPublicKey(accountPublicKey) | |
128 | + | let creatorAddress = addressFromPublicKey(valueOrErrorMessage(getBinary(this, kAccountCreatorPublicKey(accountAddress)), "invalid creator public key")) | |
129 | + | [BinaryEntry(kAccountsQueue(), drop(accountsQueue(), queueItemSize)), IntegerEntry(kRequestStatus(requestId), REQUEST_STATUS_READY), BinaryEntry(kRequestIdToAccountPublicKey(requestId), accountPublicKey), StringEntry(kAccountAddressToRequestId(accountAddress), toBase58String(requestId)), ScriptTransfer(creatorAddress, rewardAmount(), unit)] | |
130 | + | } | |
131 | + | $Tuple2((actions ++ [BinaryEntry(kRequestOwnerPublicKey(requestId), i.callerPublicKey), StringEntry(kRequestAmountAssetId(requestId), amountAssetIdStr), StringEntry(kRequestPriceAssetId(requestId), priceAssetIdStr)]), unit) | |
132 | + | } | |
112 | 133 | else throw("Strict value is not equal to itself.") | |
113 | 134 | } | |
114 | 135 | ||
115 | 136 | ||
116 | 137 | ||
117 | 138 | @Callable(i) | |
118 | - | func | |
139 | + | func addAccount (creatorPublicKey) = { | |
119 | 140 | let accountPublicKey = i.callerPublicKey | |
120 | 141 | let accountAddress = i.caller | |
121 | - | let checks = [if ((accountStatus(accountId) == ACCOUNT_STATUS_EMPTY)) | |
142 | + | let creatorAddress = addressFromPublicKey(creatorPublicKey) | |
143 | + | let checks = [if ((getBinary(this, kAccountCreatorPublicKey(accountAddress)) == unit)) | |
122 | 144 | then true | |
123 | 145 | else throw("account is already exists"), if ( match scriptHash(accountAddress) { | |
124 | 146 | case b: ByteVector => | |
130 | 152 | else throw("invalid script")] | |
131 | 153 | if ((checks == checks)) | |
132 | 154 | then { | |
133 | - | let creatorAddress = addressFromPublicKey(creatorPublicKey) | |
134 | - | $Tuple2([IntegerEntry(kAccountStatus(accountId), ACCOUNT_STATUS_READY), BinaryEntry(kAccountCreatorPublicKey(accountId), creatorPublicKey), BinaryEntry(kAccountIdToAccountPublicKey(accountId), accountPublicKey), StringEntry(kAccountAddressToAccountId(accountAddress), accountId), ScriptTransfer(creatorAddress, rewardAmount(), unit)], unit) | |
155 | + | let actions = if ((size(requestsQueue()) == 0)) | |
156 | + | then [BinaryEntry(kAccountsQueue(), (accountsQueue() + accountPublicKey))] | |
157 | + | else { | |
158 | + | let requestId = take(requestsQueue(), queueItemSize) | |
159 | + | [BinaryEntry(kRequestsQueue(), drop(requestsQueue(), queueItemSize)), IntegerEntry(kRequestStatus(requestId), REQUEST_STATUS_READY), BinaryEntry(kRequestIdToAccountPublicKey(requestId), accountPublicKey), StringEntry(kAccountAddressToRequestId(accountAddress), toBase58String(requestId)), ScriptTransfer(creatorAddress, rewardAmount(), unit)] | |
160 | + | } | |
161 | + | $Tuple2((actions ++ [BinaryEntry(kAccountCreatorPublicKey(accountAddress), creatorPublicKey)]), unit) | |
135 | 162 | } | |
136 | 163 | else throw("Strict value is not equal to itself.") | |
137 | 164 | } |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let separator = "__" | |
5 | 5 | ||
6 | 6 | let chainId = take(drop(this.bytes, 1), 1) | |
7 | 7 | ||
8 | 8 | let chainIdT = base58'2T' | |
9 | 9 | ||
10 | 10 | let chainIdW = base58'2W' | |
11 | 11 | ||
12 | 12 | func mustAddress (i,address) = if ((i.caller == address)) | |
13 | 13 | then true | |
14 | 14 | else throw("permission denied") | |
15 | 15 | ||
16 | 16 | ||
17 | 17 | func mustThis (i) = mustAddress(i, this) | |
18 | 18 | ||
19 | 19 | ||
20 | 20 | let wavesString = "WAVES" | |
21 | + | ||
22 | + | let queueItemSize = 32 | |
21 | 23 | ||
22 | 24 | func parseAssetId (input) = if ((input == wavesString)) | |
23 | 25 | then unit | |
24 | 26 | else fromBase58String(input) | |
25 | 27 | ||
26 | 28 | ||
27 | 29 | func assetIdToString (input) = if ((input == unit)) | |
28 | 30 | then wavesString | |
29 | 31 | else toBase58String(value(input)) | |
30 | 32 | ||
31 | 33 | ||
32 | 34 | let kServicePublicKey = "%s__servicePublicKey" | |
33 | 35 | ||
34 | 36 | let kBotPublicKey = "%s__botPublicKey" | |
35 | 37 | ||
36 | 38 | let kAccountScript = "%s__accountScript" | |
37 | 39 | ||
38 | 40 | func accountScript () = valueOrErrorMessage(getBinary(this, kAccountScript), "account script is not set") | |
39 | 41 | ||
40 | 42 | ||
41 | 43 | let kRewardAmount = "%s__rewardAmount" | |
42 | 44 | ||
43 | 45 | func rewardAmount () = valueOrErrorMessage(getInteger(this, kRewardAmount), "reward amount is not set") | |
44 | 46 | ||
45 | 47 | ||
46 | - | let | |
48 | + | let REQUEST_STATUS_EMPTY = 0 | |
47 | 49 | ||
48 | - | let | |
50 | + | let REQUEST_STATUS_READY = 1 | |
49 | 51 | ||
50 | - | func | |
52 | + | func kRequestStatus (requestId) = makeString(["%s%s", toBase58String(requestId), "status"], separator) | |
51 | 53 | ||
52 | 54 | ||
53 | - | func | |
55 | + | func kAccountCreatorPublicKey (accountAddress) = makeString(["%s%s", toString(accountAddress), "creatorPublicKey"], separator) | |
54 | 56 | ||
55 | 57 | ||
56 | - | func | |
58 | + | func kRequestOwnerPublicKey (requestId) = makeString(["%s%s", toBase58String(requestId), "ownerPublicKey"], separator) | |
57 | 59 | ||
58 | 60 | ||
59 | - | func | |
61 | + | func kRequestAmountAssetId (requestId) = makeString(["%s%s", toBase58String(requestId), "amountAssetId"], separator) | |
60 | 62 | ||
61 | 63 | ||
62 | - | func | |
64 | + | func kRequestPriceAssetId (requestId) = makeString(["%s%s", toBase58String(requestId), "priceAssetId"], separator) | |
63 | 65 | ||
64 | 66 | ||
65 | - | func | |
67 | + | func kRequestIdToAccountPublicKey (requestId) = makeString(["%s%s", toBase58String(requestId), "requestIdToAccountPublicKey"], separator) | |
66 | 68 | ||
67 | 69 | ||
68 | - | func | |
70 | + | func kAccountAddressToRequestId (accountAddress) = makeString(["%s%s", toString(accountAddress), "accountAddressToRequestId"], separator) | |
69 | 71 | ||
70 | 72 | ||
71 | - | func kAccountAddressToAccountId (accountAddress) = makeString(["%s%s", toString(accountAddress), "accountAddressToAccountId"], separator) | |
73 | + | func kRequestsQueue () = makeString(["%s", "requestsQueue"], separator) | |
74 | + | ||
75 | + | ||
76 | + | func requestsQueue () = valueOrElse(getBinary(this, kRequestsQueue()), base58'') | |
77 | + | ||
78 | + | ||
79 | + | func kAccountsQueue () = makeString(["%s", "accountsQueue"], separator) | |
80 | + | ||
81 | + | ||
82 | + | func accountsQueue () = valueOrElse(getBinary(this, kAccountsQueue()), base58'') | |
72 | 83 | ||
73 | 84 | ||
74 | 85 | func kPairAllowed (amountAssetId,priceAssetId) = makeString(["%s%s%s", assetIdToString(amountAssetId), assetIdToString(priceAssetId), "pairAllowed"], separator) | |
75 | 86 | ||
76 | 87 | ||
77 | 88 | func pairAllowed (amountAssetId,priceAssetId) = valueOrElse(getBoolean(this, kPairAllowed(amountAssetId, priceAssetId)), false) | |
78 | 89 | ||
79 | 90 | ||
80 | 91 | let serviceAddress = addressFromPublicKey(getBinaryValue(this, kServicePublicKey)) | |
81 | 92 | ||
82 | 93 | let botPublicKey = getBinaryValue(this, kBotPublicKey) | |
83 | 94 | ||
84 | 95 | @Callable(i) | |
85 | 96 | func init (servicePublicKey,botPublicKey,accountScript,rewardAmount) = { | |
86 | 97 | let checkCaller = mustThis(i) | |
87 | 98 | if ((checkCaller == checkCaller)) | |
88 | 99 | then $Tuple2([BinaryEntry(kServicePublicKey, servicePublicKey), BinaryEntry(kBotPublicKey, botPublicKey), BinaryEntry(kAccountScript, accountScript), IntegerEntry(kRewardAmount, rewardAmount)], unit) | |
89 | 100 | else throw("Strict value is not equal to itself.") | |
90 | 101 | } | |
91 | 102 | ||
92 | 103 | ||
93 | 104 | ||
94 | 105 | @Callable(i) | |
95 | - | func | |
96 | - | let | |
106 | + | func requestAccount (amountAssetIdStr,priceAssetIdStr) = { | |
107 | + | let requestId = sha256(((i.caller.bytes + fromBase58String(amountAssetIdStr)) + fromBase58String(priceAssetIdStr))) | |
97 | 108 | let amountAssetId = parseAssetId(amountAssetIdStr) | |
98 | 109 | let priceAssetId = parseAssetId(priceAssetIdStr) | |
99 | 110 | let checks = [if ((size(i.payments) == 1)) | |
100 | 111 | then true | |
101 | 112 | else throw("1 payment is required"), if ((i.payments[0].assetId == unit)) | |
102 | 113 | then true | |
103 | 114 | else throw("invalid asset"), if ((i.payments[0].amount == rewardAmount())) | |
104 | 115 | then true | |
105 | 116 | else throw("invalid amount"), if (pairAllowed(amountAssetId, priceAssetId)) | |
106 | 117 | then true | |
107 | - | else throw("pair is not allowed"), if ((getInteger(this, | |
118 | + | else throw("pair is not allowed"), if ((getInteger(this, kRequestStatus(requestId)) == unit)) | |
108 | 119 | then true | |
109 | - | else throw("account already exists")] | |
120 | + | else throw("account is already exists")] | |
110 | 121 | if ((checks == checks)) | |
111 | - | then $Tuple2([IntegerEntry(kAccountStatus(accountId), 0), BinaryEntry(kAccountOwnerPublicKey(accountId), i.callerPublicKey), StringEntry(kAccountAmountAssetId(accountId), amountAssetIdStr), StringEntry(kAccountPriceAssetId(accountId), priceAssetIdStr)], unit) | |
122 | + | then { | |
123 | + | let actions = if ((size(accountsQueue()) == 0)) | |
124 | + | then [IntegerEntry(kRequestStatus(requestId), REQUEST_STATUS_EMPTY), BinaryEntry(kRequestsQueue(), (requestsQueue() + requestId))] | |
125 | + | else { | |
126 | + | let accountPublicKey = take(accountsQueue(), queueItemSize) | |
127 | + | let accountAddress = addressFromPublicKey(accountPublicKey) | |
128 | + | let creatorAddress = addressFromPublicKey(valueOrErrorMessage(getBinary(this, kAccountCreatorPublicKey(accountAddress)), "invalid creator public key")) | |
129 | + | [BinaryEntry(kAccountsQueue(), drop(accountsQueue(), queueItemSize)), IntegerEntry(kRequestStatus(requestId), REQUEST_STATUS_READY), BinaryEntry(kRequestIdToAccountPublicKey(requestId), accountPublicKey), StringEntry(kAccountAddressToRequestId(accountAddress), toBase58String(requestId)), ScriptTransfer(creatorAddress, rewardAmount(), unit)] | |
130 | + | } | |
131 | + | $Tuple2((actions ++ [BinaryEntry(kRequestOwnerPublicKey(requestId), i.callerPublicKey), StringEntry(kRequestAmountAssetId(requestId), amountAssetIdStr), StringEntry(kRequestPriceAssetId(requestId), priceAssetIdStr)]), unit) | |
132 | + | } | |
112 | 133 | else throw("Strict value is not equal to itself.") | |
113 | 134 | } | |
114 | 135 | ||
115 | 136 | ||
116 | 137 | ||
117 | 138 | @Callable(i) | |
118 | - | func | |
139 | + | func addAccount (creatorPublicKey) = { | |
119 | 140 | let accountPublicKey = i.callerPublicKey | |
120 | 141 | let accountAddress = i.caller | |
121 | - | let checks = [if ((accountStatus(accountId) == ACCOUNT_STATUS_EMPTY)) | |
142 | + | let creatorAddress = addressFromPublicKey(creatorPublicKey) | |
143 | + | let checks = [if ((getBinary(this, kAccountCreatorPublicKey(accountAddress)) == unit)) | |
122 | 144 | then true | |
123 | 145 | else throw("account is already exists"), if ( match scriptHash(accountAddress) { | |
124 | 146 | case b: ByteVector => | |
125 | 147 | (b == blake2b256_32Kb(accountScript())) | |
126 | 148 | case _ => | |
127 | 149 | false | |
128 | 150 | }) | |
129 | 151 | then true | |
130 | 152 | else throw("invalid script")] | |
131 | 153 | if ((checks == checks)) | |
132 | 154 | then { | |
133 | - | let creatorAddress = addressFromPublicKey(creatorPublicKey) | |
134 | - | $Tuple2([IntegerEntry(kAccountStatus(accountId), ACCOUNT_STATUS_READY), BinaryEntry(kAccountCreatorPublicKey(accountId), creatorPublicKey), BinaryEntry(kAccountIdToAccountPublicKey(accountId), accountPublicKey), StringEntry(kAccountAddressToAccountId(accountAddress), accountId), ScriptTransfer(creatorAddress, rewardAmount(), unit)], unit) | |
155 | + | let actions = if ((size(requestsQueue()) == 0)) | |
156 | + | then [BinaryEntry(kAccountsQueue(), (accountsQueue() + accountPublicKey))] | |
157 | + | else { | |
158 | + | let requestId = take(requestsQueue(), queueItemSize) | |
159 | + | [BinaryEntry(kRequestsQueue(), drop(requestsQueue(), queueItemSize)), IntegerEntry(kRequestStatus(requestId), REQUEST_STATUS_READY), BinaryEntry(kRequestIdToAccountPublicKey(requestId), accountPublicKey), StringEntry(kAccountAddressToRequestId(accountAddress), toBase58String(requestId)), ScriptTransfer(creatorAddress, rewardAmount(), unit)] | |
160 | + | } | |
161 | + | $Tuple2((actions ++ [BinaryEntry(kAccountCreatorPublicKey(accountAddress), creatorPublicKey)]), unit) | |
135 | 162 | } | |
136 | 163 | else throw("Strict value is not equal to itself.") | |
137 | 164 | } | |
138 | 165 | ||
139 | 166 |
github/deemru/w8io/169f3d6 55.36 ms ◑