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:AAIEAAAAAAAAACwIAhIDCgEIEgMKAQESAwoBARIECgIIARIHCgUICAEBCBIECgIIARIECgIIAQAAAAsBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAABm51bWJlcgQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAUAAAAGbnVtYmVyAAAAAAROT05FAgAAAARub25lAQAAAA5nZXRTdHJpbmdCeUtleQAAAAEAAAADa2V5BAAAAAZzdHJpbmcEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEFAAAABE5PTkUFAAAABnN0cmluZwEAAAAPZ2V0S2V5VXNlckVtYWlsAAAAAQAAAAR1c2VyCQABLAAAAAIJAAEsAAAAAgIAAAAFdXNlcl8FAAAABHVzZXICAAAABl9lbWFpbA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QAAAAGYW1vdW50AwkBAAAAASEAAAABCQEAAAAJaXNEZWZpbmVkAAAAAQkBAAAABXZhbHVlAAAAAQgFAAAAAWkAAAAIcGF5bWVudHMJAAACAAAAAQIAAAAgbmVlZCBhdHRhY2ggcGF5bWVudCB3aXRoIE5ZQU4tMjUEAAAAB3BheW1lbnQJAAGRAAAAAggFAAAAAWkAAAAIcGF5bWVudHMAAAAAAAAAAAAJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwkBAAAAB0FkZHJlc3MAAAABCAgFAAAAAWkAAAAGY2FsbGVyAAAABWJ5dGVzBQAAAAZhbW91bnQJAAJZAAAAAQUAAAAHYXNzZXRJZAkABEwAAAACCQEAAAAEQnVybgAAAAIJAQAAAAV2YWx1ZQAAAAEIBQAAAAdwYXltZW50AAAAB2Fzc2V0SWQIBQAAAAdwYXltZW50AAAABmFtb3VudAUAAAADbmlsAAAAAQAAAAJ0eAEAAAAGdmVyaWZ5AAAAAAkAAfQAAAADCAUAAAACdHgAAAAJYm9keUJ5dGVzCQABkQAAAAIIBQAAAAJ0eAAAAAZwcm9vZnMAAAAAAAAAAAAIBQAAAAJ0eAAAAA9zZW5kZXJQdWJsaWNLZXmr84sx", "height": 1543773, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: G7ZUnwUL1hJsaW99CjoWZmEMqZzBEgGW196hRDK7dMyZ Next: 9MHM6rYEE4J74pRrDBiYcp4fEN4MEhZ3Wv37UwLTVXH1 Diff:
OldNewDifferences
3131 func getValueUserEmail (user) = getStringByKey(getKeyUserEmail(user))
3232
3333
34-func getKeyUserBalance (user) = (("user_" + user) + "_balance")
34+func getKeyNyanToken () = "dApp_tokenId"
3535
3636
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())
5638
5739
5840 func getKeyAssetPrice (asset) = (("asset_" + asset) + "_price")
6951
7052 @Callable(i)
7153 func signUp (email) = {
72- let currentUserAddress = toBase58String(i.caller.bytes)
73- let currentUserEmail = getValueUserEmail(currentUserAddress)
74- if ((currentUserEmail != NONE))
75- then throw("user is already registered")
76- else [StringEntry(getKeyUserEmail(currentUserAddress), email), IntegerEntry(getKeyUserBalance(currentUserAddress), 0)]
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)]
7759 }
7860
7961
8062
8163 @Callable(i)
82-func issueToken (quantity) = {
83- let dAppAssetId = getValueDAppAssetId()
84- if ((dAppAssetId != NONE))
85- then throw("token has already been issued")
64+func issueNyanToken (quantity) = {
65+ let nyanTokenStr = getValueNyanToken()
66+ if ((nyanTokenStr != NONE))
67+ then throw("NYAN Token already issued")
8668 else {
87- let asset = Issue("NYAN-25", "NYAN-25 token", quantity, 0, true)
88- let assetId = calculateAssetId(asset)
89-[asset, StringEntry(getKeyDAppAssetId(), toBase58String(assetId)), IntegerEntry(getKeyDAppBalance(), quantity)]
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)]
9072 }
9173 }
9274
9375
9476
9577 @Callable(i)
96-func reissueToken (quantity) = {
97- let dAppAssetId = getValueDAppAssetId()
98- if ((dAppAssetId == NONE))
99- then throw("token has not been issued")
78+func reissueNyanToken (quantity) = {
79+ let nyanTokenStr = getValueNyanToken()
80+ if ((nyanTokenStr != NONE))
81+ then throw("NYAN Token was not issued")
10082 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)]
10485 }
10586 }
10687
10788
10889
10990 @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)
11296 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)]
115117 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)]
120126 }
121127 }
122128
123129
124130
125131 @Callable(i)
126-func issueAssetToken (name,description,quantity,price,data) = {
127- let asset = Issue(name, description, quantity, 0, true)
128- let assetId = calculateAssetId(asset)
129-[asset, IntegerEntry(getKeyAssetAmount(toBase58String(assetId)), quantity), IntegerEntry(getKeyAssetPrice(toBase58String(assetId)), price), StringEntry(getKeyAssetData(toBase58String(assetId)), data)]
130- }
131-
132-
133-
134-@Callable(i)
135-func reissueAssetToken (assetId,amount) = {
136- let currentAssetTokenAmount = getValueAssetAmount(assetId)
137- let newAssetTokenAmount = (currentAssetTokenAmount + amount)
138-[Reissue(fromBase58String(assetId), amount, true), IntegerEntry(getKeyAssetAmount(assetId), newAssetTokenAmount)]
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+ }
139145 }
140146
141147
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 4 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 func getNumberByKey (key) = {
55 let number = match getInteger(this, key) {
66 case a: Int =>
77 a
88 case _ =>
99 0
1010 }
1111 number
1212 }
1313
1414
1515 let NONE = "none"
1616
1717 func getStringByKey (key) = {
1818 let string = match getString(this, key) {
1919 case a: String =>
2020 a
2121 case _ =>
2222 NONE
2323 }
2424 string
2525 }
2626
2727
2828 func getKeyUserEmail (user) = (("user_" + user) + "_email")
2929
3030
3131 func getValueUserEmail (user) = getStringByKey(getKeyUserEmail(user))
3232
3333
34-func getKeyUserBalance (user) = (("user_" + user) + "_balance")
34+func getKeyNyanToken () = "dApp_tokenId"
3535
3636
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())
5638
5739
5840 func getKeyAssetPrice (asset) = (("asset_" + asset) + "_price")
5941
6042
6143 func getValueAssetPrice (asset) = getNumberByKey(getKeyAssetPrice(asset))
6244
6345
6446 func getKeyAssetData (asset) = (("asset_" + asset) + "_data")
6547
6648
6749 func getValueAssetData (asset) = getStringByKey(getKeyAssetPrice(asset))
6850
6951
7052 @Callable(i)
7153 func signUp (email) = {
72- let currentUserAddress = toBase58String(i.caller.bytes)
73- let currentUserEmail = getValueUserEmail(currentUserAddress)
74- if ((currentUserEmail != NONE))
75- then throw("user is already registered")
76- else [StringEntry(getKeyUserEmail(currentUserAddress), email), IntegerEntry(getKeyUserBalance(currentUserAddress), 0)]
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)]
7759 }
7860
7961
8062
8163 @Callable(i)
82-func issueToken (quantity) = {
83- let dAppAssetId = getValueDAppAssetId()
84- if ((dAppAssetId != NONE))
85- then throw("token has already been issued")
64+func issueNyanToken (quantity) = {
65+ let nyanTokenStr = getValueNyanToken()
66+ if ((nyanTokenStr != NONE))
67+ then throw("NYAN Token already issued")
8668 else {
87- let asset = Issue("NYAN-25", "NYAN-25 token", quantity, 0, true)
88- let assetId = calculateAssetId(asset)
89-[asset, StringEntry(getKeyDAppAssetId(), toBase58String(assetId)), IntegerEntry(getKeyDAppBalance(), quantity)]
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)]
9072 }
9173 }
9274
9375
9476
9577 @Callable(i)
96-func reissueToken (quantity) = {
97- let dAppAssetId = getValueDAppAssetId()
98- if ((dAppAssetId == NONE))
99- then throw("token has not been issued")
78+func reissueNyanToken (quantity) = {
79+ let nyanTokenStr = getValueNyanToken()
80+ if ((nyanTokenStr != NONE))
81+ then throw("NYAN Token was not issued")
10082 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)]
10485 }
10586 }
10687
10788
10889
10990 @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)
11296 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)]
115117 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)]
120126 }
121127 }
122128
123129
124130
125131 @Callable(i)
126-func issueAssetToken (name,description,quantity,price,data) = {
127- let asset = Issue(name, description, quantity, 0, true)
128- let assetId = calculateAssetId(asset)
129-[asset, IntegerEntry(getKeyAssetAmount(toBase58String(assetId)), quantity), IntegerEntry(getKeyAssetPrice(toBase58String(assetId)), price), StringEntry(getKeyAssetData(toBase58String(assetId)), data)]
130- }
131-
132-
133-
134-@Callable(i)
135-func reissueAssetToken (assetId,amount) = {
136- let currentAssetTokenAmount = getValueAssetAmount(assetId)
137- let newAssetTokenAmount = (currentAssetTokenAmount + amount)
138-[Reissue(fromBase58String(assetId), amount, true), IntegerEntry(getKeyAssetAmount(assetId), newAssetTokenAmount)]
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+ }
139145 }
140146
141147
142148
143149 @Callable(i)
144150 func exchangeAssetToken (assetId,amount) = if (!(isDefined(value(i.payments))))
145151 then throw("need attach payment with NYAN-25")
146152 else {
147153 let payment = i.payments[0]
148154 [ScriptTransfer(Address(i.caller.bytes), amount, fromBase58String(assetId)), Burn(value(payment.assetId), payment.amount)]
149155 }
150156
151157
152158 @Verifier(tx)
153159 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
154160

github/deemru/w8io/169f3d6 
40.90 ms