tx · 8pnJqJbszCSDrwmXrpjRCGJWByxnAnpMeqs3YvgrAP2P 3MtoBpCc3s2T4CxasJ5MXrZZsU339D28mvD: -0.01400000 Waves 2021.05.27 10:41 [1543773] smart account 3MtoBpCc3s2T4CxasJ5MXrZZsU339D28mvD > SELF 0.00000000 Waves
{ "type": 13, "id": "8pnJqJbszCSDrwmXrpjRCGJWByxnAnpMeqs3YvgrAP2P", "fee": 1400000, "feeAssetId": null, "timestamp": 1622101287942, "version": 2, "chainId": 84, "sender": "3MtoBpCc3s2T4CxasJ5MXrZZsU339D28mvD", "senderPublicKey": "8SRjg8K8B7rhV2pih6qRgku886VQE4phwNCDjWZu1fUe", "proofs": [ "2ZMkG5GvrPBSSd5p8C3qPeDnG9rFDKAR3on7r5DU52GwHyGGsg9QXyVABtsYXdXPSGJ13PxoEhgAReoVBoWzXKxb" ], "script": "base64:AAIEAAAAAAAAACwIAhIDCgEIEgMKAQESAwoBARIECgIIARIHCgUICAEBCBIECgIIARIECgIIAQAAAAsBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAABm51bWJlcgQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAUAAAAGbnVtYmVyAAAAAAROT05FAgAAAARub25lAQAAAA5nZXRTdHJpbmdCeUtleQAAAAEAAAADa2V5BAAAAAZzdHJpbmcEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEFAAAABE5PTkUFAAAABnN0cmluZwEAAAAPZ2V0S2V5VXNlckVtYWlsAAAAAQAAAAR1c2VyCQABLAAAAAIJAAEsAAAAAgIAAAAFdXNlcl8FAAAABHVzZXICAAAABl9lbWFpbAE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AAAAGYW1vdW50AwkBAAAAASEAAAABCQEAAAAJaXNEZWZpbmVkAAAAAQkBAAAABXZhbHVlAAAAAQgFAAAAAWkAAAAIcGF5bWVudHMJAAACAAAAAQIAAAAgbmVlZCBhdHRhY2ggcGF5bWVudCB3aXRoIE5ZQU4tMjUEAAAAB3BheW1lbnQJAAGRAAAAAggFAAAAAWkAAAAIcGF5bWVudHMAAAAAAAAAAAAJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwkBAAAAB0FkZHJlc3MAAAABCAgFAAAAAWkAAAAGY2FsbGVyAAAABWJ5dGVzBQAAAAZhbW91bnQJAAJZAAAAAQUAAAAHYXNzZXRJZAkABEwAAAACCQEAAAAEQnVybgAAAAIJAQAAAAV2YWx1ZQAAAAEIBQAAAAdwYXltZW50AAAAB2Fzc2V0SWQIBQAAAAdwYXltZW50AAAABmFtb3VudAUAAAADbmlsAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXmr84sx", "height": 1543773, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: G7ZUnwUL1hJsaW99CjoWZmEMqZzBEgGW196hRDK7dMyZ Next: 9MHM6rYEE4J74pRrDBiYcp4fEN4MEhZ3Wv37UwLTVXH1 Diff:
Old | New | Differences | |
---|---|---|---|
31 | 31 | func getValueUserEmail (user) = getStringByKey(getKeyUserEmail(user)) | |
32 | 32 | ||
33 | 33 | ||
34 | - | func | |
34 | + | func getKeyNyanToken () = "dApp_tokenId" | |
35 | 35 | ||
36 | 36 | ||
37 | - | func getValueUserBalance (user) = getNumberByKey(getKeyUserBalance(user)) | |
38 | - | ||
39 | - | ||
40 | - | func getKeyDAppAssetId () = "dApp_assetId" | |
41 | - | ||
42 | - | ||
43 | - | func getValueDAppAssetId () = getStringByKey(getKeyDAppAssetId()) | |
44 | - | ||
45 | - | ||
46 | - | func getKeyDAppBalance () = "dApp_balance" | |
47 | - | ||
48 | - | ||
49 | - | func getValueDAppBalance () = getNumberByKey(getKeyDAppBalance()) | |
50 | - | ||
51 | - | ||
52 | - | func getKeyAssetAmount (asset) = (("asset_" + asset) + "_amount") | |
53 | - | ||
54 | - | ||
55 | - | func getValueAssetAmount (asset) = getNumberByKey(getKeyAssetAmount(asset)) | |
37 | + | func getValueNyanToken () = getStringByKey(getKeyNyanToken()) | |
56 | 38 | ||
57 | 39 | ||
58 | 40 | func getKeyAssetPrice (asset) = (("asset_" + asset) + "_price") | |
69 | 51 | ||
70 | 52 | @Callable(i) | |
71 | 53 | func signUp (email) = { | |
72 | - | let | |
73 | - | let | |
74 | - | if (( | |
75 | - | then throw(" | |
76 | - | else [StringEntry(getKeyUserEmail( | |
54 | + | let userAddressStr = toBase58String(i.caller.bytes) | |
55 | + | let userEmailStr = getValueUserEmail(userAddressStr) | |
56 | + | if ((userEmailStr != NONE)) | |
57 | + | then throw("User is already registered") | |
58 | + | else [StringEntry(getKeyUserEmail(userEmailStr), email)] | |
77 | 59 | } | |
78 | 60 | ||
79 | 61 | ||
80 | 62 | ||
81 | 63 | @Callable(i) | |
82 | - | func | |
83 | - | let | |
84 | - | if (( | |
85 | - | then throw(" | |
64 | + | func issueNyanToken (quantity) = { | |
65 | + | let nyanTokenStr = getValueNyanToken() | |
66 | + | if ((nyanTokenStr != NONE)) | |
67 | + | then throw("NYAN Token already issued") | |
86 | 68 | else { | |
87 | - | let | |
88 | - | let | |
89 | - | [ | |
69 | + | let nyanTokenIssue = Issue("NYAN Token", "NYAN Token is a cryptocurrency token that operates on the Waves platform", quantity, 0, true) | |
70 | + | let nyanTokenAssetIdStr = toBase58String(calculateAssetId(nyanTokenIssue)) | |
71 | + | [nyanTokenIssue, StringEntry(getKeyNyanToken(), nyanTokenAssetIdStr)] | |
90 | 72 | } | |
91 | 73 | } | |
92 | 74 | ||
93 | 75 | ||
94 | 76 | ||
95 | 77 | @Callable(i) | |
96 | - | func | |
97 | - | let | |
98 | - | if (( | |
99 | - | then throw(" | |
78 | + | func reissueNyanToken (quantity) = { | |
79 | + | let nyanTokenStr = getValueNyanToken() | |
80 | + | if ((nyanTokenStr != NONE)) | |
81 | + | then throw("NYAN Token was not issued") | |
100 | 82 | else { | |
101 | - | let currentDAppBalance = getValueDAppBalance() | |
102 | - | let newBalance = (currentDAppBalance + quantity) | |
103 | - | [Reissue(fromBase58String(dAppAssetId), quantity, true), IntegerEntry(getKeyDAppBalance(), newBalance)] | |
83 | + | let nyanToken = fromBase58String(nyanTokenStr) | |
84 | + | [Reissue(nyanToken, quantity, true)] | |
104 | 85 | } | |
105 | 86 | } | |
106 | 87 | ||
107 | 88 | ||
108 | 89 | ||
109 | 90 | @Callable(i) | |
110 | - | func transferToken (recipient,amount) = { | |
111 | - | let currentDAppBalance = getValueDAppBalance() | |
91 | + | func transferNyanToken (recipient,amount) = { | |
92 | + | let userEmailStr = getValueUserEmail(recipient) | |
93 | + | let nyanTokenStr = getValueNyanToken() | |
94 | + | let nyanToken = fromBase58String(nyanTokenStr) | |
95 | + | let currentDAppBalance = assetBalance(this, nyanToken) | |
112 | 96 | let newDAppBalance = (currentDAppBalance - amount) | |
113 | - | if ((0 > newDAppBalance)) | |
114 | - | then throw("not enoung balance") | |
97 | + | if ((userEmailStr == NONE)) | |
98 | + | then throw("You cannot transfer NYAN Token to a user who is not registered") | |
99 | + | else if ((0 > amount)) | |
100 | + | then throw("It is impossible to transfer a negative amount") | |
101 | + | else if ((0 > newDAppBalance)) | |
102 | + | then throw("Not enough NYAN Tokens to transfer") | |
103 | + | else { | |
104 | + | let recipientAddress = Address(fromBase58String(recipient)) | |
105 | + | [ScriptTransfer(recipientAddress, amount, nyanToken)] | |
106 | + | } | |
107 | + | } | |
108 | + | ||
109 | + | ||
110 | + | ||
111 | + | @Callable(i) | |
112 | + | func issueAssetToken (name,description,quantity,price,data) = { | |
113 | + | let assetTokenIssue = Issue(name, description, quantity, 0, true) | |
114 | + | let assetTokenAssetIdStr = toBase58String(calculateAssetId(assetTokenIssue)) | |
115 | + | if ((quantity == 0)) | |
116 | + | then [assetTokenIssue, IntegerEntry(getKeyAssetPrice(assetTokenAssetIdStr), price), StringEntry(getKeyAssetData(assetTokenAssetIdStr), data)] | |
115 | 117 | else { | |
116 | - | let currentUserAddress = toBase58String(i.caller.bytes) | |
117 | - | let currentUserBalance = getValueUserBalance(currentUserAddress) | |
118 | - | let newUserBalance = (currentUserBalance + amount) | |
119 | - | [IntegerEntry(getKeyDAppBalance(), newDAppBalance), IntegerEntry(getKeyUserBalance(recipient), newUserBalance), ScriptTransfer(Address(fromBase58String(recipient)), amount, fromBase58String(getValueDAppAssetId()))] | |
118 | + | let nyanTokenStr = getValueNyanToken() | |
119 | + | let nyanToken = fromBase58String(nyanTokenStr) | |
120 | + | let currentDAppBalance = assetBalance(this, nyanToken) | |
121 | + | let amount = (quantity * price) | |
122 | + | let newDAppBalance = (currentDAppBalance - amount) | |
123 | + | if ((0 > newDAppBalance)) | |
124 | + | then throw("Not enough NYAN Tokens to issue an asset") | |
125 | + | else [assetTokenIssue, Burn(nyanToken, amount), IntegerEntry(getKeyAssetPrice(assetTokenAssetIdStr), price), StringEntry(getKeyAssetData(assetTokenAssetIdStr), data)] | |
120 | 126 | } | |
121 | 127 | } | |
122 | 128 | ||
123 | 129 | ||
124 | 130 | ||
125 | 131 | @Callable(i) | |
126 | - | func | |
127 | - | let | |
128 | - | let | |
129 | - | ||
130 | - | | |
131 | - | ||
132 | - | ||
133 | - | ||
134 | - | ||
135 | - | ||
136 | - | let | |
137 | - | ||
138 | - | ||
132 | + | func reissueAssetToken (assetId,quantity) = { | |
133 | + | let nyanTokenStr = getValueNyanToken() | |
134 | + | let nyanToken = fromBase58String(nyanTokenStr) | |
135 | + | let currentDAppBalance = assetBalance(this, nyanToken) | |
136 | + | let assetPrice = getValueAssetPrice(assetId) | |
137 | + | let amount = (quantity * assetPrice) | |
138 | + | let newDAppBalance = (currentDAppBalance - amount) | |
139 | + | if ((0 > newDAppBalance)) | |
140 | + | then throw("Not enough NYAN Tokens to reissue an asset") | |
141 | + | else { | |
142 | + | let assetTokenAssetId = fromBase58String(assetId) | |
143 | + | [Reissue(assetTokenAssetId, quantity, true), Burn(nyanToken, amount)] | |
144 | + | } | |
139 | 145 | } | |
140 | 146 | ||
141 | 147 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | func getNumberByKey (key) = { | |
5 | 5 | let number = match getInteger(this, key) { | |
6 | 6 | case a: Int => | |
7 | 7 | a | |
8 | 8 | case _ => | |
9 | 9 | 0 | |
10 | 10 | } | |
11 | 11 | number | |
12 | 12 | } | |
13 | 13 | ||
14 | 14 | ||
15 | 15 | let NONE = "none" | |
16 | 16 | ||
17 | 17 | func getStringByKey (key) = { | |
18 | 18 | let string = match getString(this, key) { | |
19 | 19 | case a: String => | |
20 | 20 | a | |
21 | 21 | case _ => | |
22 | 22 | NONE | |
23 | 23 | } | |
24 | 24 | string | |
25 | 25 | } | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | func getKeyUserEmail (user) = (("user_" + user) + "_email") | |
29 | 29 | ||
30 | 30 | ||
31 | 31 | func getValueUserEmail (user) = getStringByKey(getKeyUserEmail(user)) | |
32 | 32 | ||
33 | 33 | ||
34 | - | func | |
34 | + | func getKeyNyanToken () = "dApp_tokenId" | |
35 | 35 | ||
36 | 36 | ||
37 | - | func getValueUserBalance (user) = getNumberByKey(getKeyUserBalance(user)) | |
38 | - | ||
39 | - | ||
40 | - | func getKeyDAppAssetId () = "dApp_assetId" | |
41 | - | ||
42 | - | ||
43 | - | func getValueDAppAssetId () = getStringByKey(getKeyDAppAssetId()) | |
44 | - | ||
45 | - | ||
46 | - | func getKeyDAppBalance () = "dApp_balance" | |
47 | - | ||
48 | - | ||
49 | - | func getValueDAppBalance () = getNumberByKey(getKeyDAppBalance()) | |
50 | - | ||
51 | - | ||
52 | - | func getKeyAssetAmount (asset) = (("asset_" + asset) + "_amount") | |
53 | - | ||
54 | - | ||
55 | - | func getValueAssetAmount (asset) = getNumberByKey(getKeyAssetAmount(asset)) | |
37 | + | func getValueNyanToken () = getStringByKey(getKeyNyanToken()) | |
56 | 38 | ||
57 | 39 | ||
58 | 40 | func getKeyAssetPrice (asset) = (("asset_" + asset) + "_price") | |
59 | 41 | ||
60 | 42 | ||
61 | 43 | func getValueAssetPrice (asset) = getNumberByKey(getKeyAssetPrice(asset)) | |
62 | 44 | ||
63 | 45 | ||
64 | 46 | func getKeyAssetData (asset) = (("asset_" + asset) + "_data") | |
65 | 47 | ||
66 | 48 | ||
67 | 49 | func getValueAssetData (asset) = getStringByKey(getKeyAssetPrice(asset)) | |
68 | 50 | ||
69 | 51 | ||
70 | 52 | @Callable(i) | |
71 | 53 | func signUp (email) = { | |
72 | - | let | |
73 | - | let | |
74 | - | if (( | |
75 | - | then throw(" | |
76 | - | else [StringEntry(getKeyUserEmail( | |
54 | + | let userAddressStr = toBase58String(i.caller.bytes) | |
55 | + | let userEmailStr = getValueUserEmail(userAddressStr) | |
56 | + | if ((userEmailStr != NONE)) | |
57 | + | then throw("User is already registered") | |
58 | + | else [StringEntry(getKeyUserEmail(userEmailStr), email)] | |
77 | 59 | } | |
78 | 60 | ||
79 | 61 | ||
80 | 62 | ||
81 | 63 | @Callable(i) | |
82 | - | func | |
83 | - | let | |
84 | - | if (( | |
85 | - | then throw(" | |
64 | + | func issueNyanToken (quantity) = { | |
65 | + | let nyanTokenStr = getValueNyanToken() | |
66 | + | if ((nyanTokenStr != NONE)) | |
67 | + | then throw("NYAN Token already issued") | |
86 | 68 | else { | |
87 | - | let | |
88 | - | let | |
89 | - | [ | |
69 | + | let nyanTokenIssue = Issue("NYAN Token", "NYAN Token is a cryptocurrency token that operates on the Waves platform", quantity, 0, true) | |
70 | + | let nyanTokenAssetIdStr = toBase58String(calculateAssetId(nyanTokenIssue)) | |
71 | + | [nyanTokenIssue, StringEntry(getKeyNyanToken(), nyanTokenAssetIdStr)] | |
90 | 72 | } | |
91 | 73 | } | |
92 | 74 | ||
93 | 75 | ||
94 | 76 | ||
95 | 77 | @Callable(i) | |
96 | - | func | |
97 | - | let | |
98 | - | if (( | |
99 | - | then throw(" | |
78 | + | func reissueNyanToken (quantity) = { | |
79 | + | let nyanTokenStr = getValueNyanToken() | |
80 | + | if ((nyanTokenStr != NONE)) | |
81 | + | then throw("NYAN Token was not issued") | |
100 | 82 | else { | |
101 | - | let currentDAppBalance = getValueDAppBalance() | |
102 | - | let newBalance = (currentDAppBalance + quantity) | |
103 | - | [Reissue(fromBase58String(dAppAssetId), quantity, true), IntegerEntry(getKeyDAppBalance(), newBalance)] | |
83 | + | let nyanToken = fromBase58String(nyanTokenStr) | |
84 | + | [Reissue(nyanToken, quantity, true)] | |
104 | 85 | } | |
105 | 86 | } | |
106 | 87 | ||
107 | 88 | ||
108 | 89 | ||
109 | 90 | @Callable(i) | |
110 | - | func transferToken (recipient,amount) = { | |
111 | - | let currentDAppBalance = getValueDAppBalance() | |
91 | + | func transferNyanToken (recipient,amount) = { | |
92 | + | let userEmailStr = getValueUserEmail(recipient) | |
93 | + | let nyanTokenStr = getValueNyanToken() | |
94 | + | let nyanToken = fromBase58String(nyanTokenStr) | |
95 | + | let currentDAppBalance = assetBalance(this, nyanToken) | |
112 | 96 | let newDAppBalance = (currentDAppBalance - amount) | |
113 | - | if ((0 > newDAppBalance)) | |
114 | - | then throw("not enoung balance") | |
97 | + | if ((userEmailStr == NONE)) | |
98 | + | then throw("You cannot transfer NYAN Token to a user who is not registered") | |
99 | + | else if ((0 > amount)) | |
100 | + | then throw("It is impossible to transfer a negative amount") | |
101 | + | else if ((0 > newDAppBalance)) | |
102 | + | then throw("Not enough NYAN Tokens to transfer") | |
103 | + | else { | |
104 | + | let recipientAddress = Address(fromBase58String(recipient)) | |
105 | + | [ScriptTransfer(recipientAddress, amount, nyanToken)] | |
106 | + | } | |
107 | + | } | |
108 | + | ||
109 | + | ||
110 | + | ||
111 | + | @Callable(i) | |
112 | + | func issueAssetToken (name,description,quantity,price,data) = { | |
113 | + | let assetTokenIssue = Issue(name, description, quantity, 0, true) | |
114 | + | let assetTokenAssetIdStr = toBase58String(calculateAssetId(assetTokenIssue)) | |
115 | + | if ((quantity == 0)) | |
116 | + | then [assetTokenIssue, IntegerEntry(getKeyAssetPrice(assetTokenAssetIdStr), price), StringEntry(getKeyAssetData(assetTokenAssetIdStr), data)] | |
115 | 117 | else { | |
116 | - | let currentUserAddress = toBase58String(i.caller.bytes) | |
117 | - | let currentUserBalance = getValueUserBalance(currentUserAddress) | |
118 | - | let newUserBalance = (currentUserBalance + amount) | |
119 | - | [IntegerEntry(getKeyDAppBalance(), newDAppBalance), IntegerEntry(getKeyUserBalance(recipient), newUserBalance), ScriptTransfer(Address(fromBase58String(recipient)), amount, fromBase58String(getValueDAppAssetId()))] | |
118 | + | let nyanTokenStr = getValueNyanToken() | |
119 | + | let nyanToken = fromBase58String(nyanTokenStr) | |
120 | + | let currentDAppBalance = assetBalance(this, nyanToken) | |
121 | + | let amount = (quantity * price) | |
122 | + | let newDAppBalance = (currentDAppBalance - amount) | |
123 | + | if ((0 > newDAppBalance)) | |
124 | + | then throw("Not enough NYAN Tokens to issue an asset") | |
125 | + | else [assetTokenIssue, Burn(nyanToken, amount), IntegerEntry(getKeyAssetPrice(assetTokenAssetIdStr), price), StringEntry(getKeyAssetData(assetTokenAssetIdStr), data)] | |
120 | 126 | } | |
121 | 127 | } | |
122 | 128 | ||
123 | 129 | ||
124 | 130 | ||
125 | 131 | @Callable(i) | |
126 | - | func | |
127 | - | let | |
128 | - | let | |
129 | - | ||
130 | - | | |
131 | - | ||
132 | - | ||
133 | - | ||
134 | - | ||
135 | - | ||
136 | - | let | |
137 | - | ||
138 | - | ||
132 | + | func reissueAssetToken (assetId,quantity) = { | |
133 | + | let nyanTokenStr = getValueNyanToken() | |
134 | + | let nyanToken = fromBase58String(nyanTokenStr) | |
135 | + | let currentDAppBalance = assetBalance(this, nyanToken) | |
136 | + | let assetPrice = getValueAssetPrice(assetId) | |
137 | + | let amount = (quantity * assetPrice) | |
138 | + | let newDAppBalance = (currentDAppBalance - amount) | |
139 | + | if ((0 > newDAppBalance)) | |
140 | + | then throw("Not enough NYAN Tokens to reissue an asset") | |
141 | + | else { | |
142 | + | let assetTokenAssetId = fromBase58String(assetId) | |
143 | + | [Reissue(assetTokenAssetId, quantity, true), Burn(nyanToken, amount)] | |
144 | + | } | |
139 | 145 | } | |
140 | 146 | ||
141 | 147 | ||
142 | 148 | ||
143 | 149 | @Callable(i) | |
144 | 150 | func exchangeAssetToken (assetId,amount) = if (!(isDefined(value(i.payments)))) | |
145 | 151 | then throw("need attach payment with NYAN-25") | |
146 | 152 | else { | |
147 | 153 | let payment = i.payments[0] | |
148 | 154 | [ScriptTransfer(Address(i.caller.bytes), amount, fromBase58String(assetId)), Burn(value(payment.assetId), payment.amount)] | |
149 | 155 | } | |
150 | 156 | ||
151 | 157 | ||
152 | 158 | @Verifier(tx) | |
153 | 159 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
154 | 160 |
github/deemru/w8io/169f3d6 40.90 ms ◑