tx · Cg9BrVmCLztgL4NF8hgdXT8695XLfenzjSQqhWXjWi3S 3N1fcrWULKWACeWDuo3FpugKcoYC4xQ7uw8: -0.00600000 Waves 2022.07.15 12:44 [2140680] smart account 3N1fcrWULKWACeWDuo3FpugKcoYC4xQ7uw8 > SELF 0.00000000 Waves
{ "type": 13, "id": "Cg9BrVmCLztgL4NF8hgdXT8695XLfenzjSQqhWXjWi3S", "fee": 600000, "feeAssetId": null, "timestamp": 1657878288614, "version": 2, "chainId": 84, "sender": "3N1fcrWULKWACeWDuo3FpugKcoYC4xQ7uw8", "senderPublicKey": "48K83j8fKJeoBfJYe7BTpnr2VQg7uLGwyCrhmdghH3xZ", "proofs": [ "5SN8nEmAtqr2knhM6AA9ah3kkgiRZxqoU8nF2XuttUBDibrhZVPRmngg7dAud2XVcyGQNX3stV4L42eaaKvMxnSP" ], "script": "base64:BgIaCAISCQoHAQEBCAgICBIFCgMBBAESABIAEgALAAp0b2tlbl9uYW1lAhJBd2Vzb21lIHRva2VuIG5hbWUAEXRva2VuX2Rlc2NyaXB0aW9uAhlBd2Vzb21lIHRva2VuIGRlc2NyaXB0aW9uAA50b2tlbl9kZWNpbWFscwAIAAlzZXBhcmF0b3ICAl9fAAx3aXRuZXNzX3BrXzECCjEyMzEyMzEyMzEADHdpdG5lc3NfcGtfMgIKMTIzMTIzMTIzMQAMd2l0bmVzc19wa18zAgoxMjMxMjMxMjMxAA13aXRuZXNzX2NvdW50AAMABnJld2FyZAkAaAIACgkAbAYACgAABQ50b2tlbl9kZWNpbWFscwAAAAAFBERPV04BD3F1b3J1bUlzUmVhY2hlZAIIYXBwcm92ZWQFdG90YWwDCQBmAgUIYXBwcm92ZWQJAGkCBQV0b3RhbAACBgcBDWZpbmFsaXplRXZlbnQABAckbWF0Y2gwCQCiCAECBVRPS0VOAwkAAQIFByRtYXRjaDACBlN0cmluZwQBYQUHJG1hdGNoMAkAzAgCCQEHUmVpc3N1ZQMJANkEAQUBYQkAaAIFDXdpdG5lc3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UBaQZjYWxsZXIFYnl0ZXMDCQABAgUHJG1hdGNoMAIDSW50BAFhBQckbWF0Y2gwBQFhAAAJAJQKAgkAzAgCCQEMSW50ZWdlckVudHJ5AgkArAICAhBJTlNVUkFOQ0VfRlJFRV9fCQDYBAEICAUBaQZjYWxsZXIFYnl0ZXMJAGQCBQ1mcmVlSW5zdXJhbmNlCAkAkQMCCAUBaQhwYXltZW50cwAABmFtb3VudAUDbmlsBQR1bml0CQACAQIkU3RyaWN0IHZhbHVlIGlzIG5vdCBlcXVhbCB0byBpdHNlbGYuAWkBEXdpdGhkcmF3SW5zdXJhbmNlAAQJaW5zdXJhbmNlBAckbWF0Y2gwCQCfCAEJAKwCAgIQSU5TVVJBTkNFX0ZSRUVfXwkA2AQBCAgFAWkGY2FsbGVyBWJ5dGVzAwkAAQIFByRtYXRjaDACA0ludAQBYQUHJG1hdGNoMAMJAGYCBQFhAAAFAWEJAAIBAhFubyBmcmVlIGluc3VyYW5jZQkAAgECDG5vIGluc3VyYW5jZQkAlAoCCQDMCAIJAQ5TY3JpcHRUcmFuc2ZlcgMIBQFpBmNhbGxlcgUJaW5zdXJhbmNlBQR1bml0CQDMCAIJAQxJbnRlZ2VyRW50cnkCCQCsAgICEElOU1VSQU5DRV9GUkVFX18JANgEAQgIBQFpBmNhbGxlcgVieXRlcwAABQNuaWwFBHVuaXQBaQELY2xhaW1SZXdhcmQACQCUCgIFA25pbAUEdW5pdAECdHgBBnZlcmlmeQAJAPQDAwgFAnR4CWJvZHlCeXRlcwkAkQMCCAUCdHgGcHJvb2ZzAAAIBQJ0eA9zZW5kZXJQdWJsaWNLZXm4COMA", "height": 2140680, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 3ixB56zBRnQAPkDZWfNKGWva8vxtgTayLLCtvc6BtPPb Next: none Diff:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let token_name = "Awesome token name" | |
5 | + | ||
6 | + | let token_description = "Awesome token description" | |
7 | + | ||
8 | + | let token_decimals = 8 | |
9 | + | ||
4 | 10 | let separator = "__" | |
11 | + | ||
12 | + | let witness_pk_1 = "1231231231" | |
13 | + | ||
14 | + | let witness_pk_2 = "1231231231" | |
15 | + | ||
16 | + | let witness_pk_3 = "1231231231" | |
17 | + | ||
18 | + | let witness_count = 3 | |
19 | + | ||
20 | + | let reward = (10 * pow(10, 0, token_decimals, 0, 0, DOWN)) | |
21 | + | ||
22 | + | func quorumIsReached (approved,total) = if ((approved > (total / 2))) | |
23 | + | then true | |
24 | + | else false | |
25 | + | ||
26 | + | ||
27 | + | func finalizeEvent () = match getString("TOKEN") { | |
28 | + | case a: String => | |
29 | + | [Reissue(fromBase58String(a), (witness_count * reward), true), ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_1)), reward, fromBase58String(a)), ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_2)), reward, fromBase58String(a)), ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_3)), reward, fromBase58String(a))] | |
30 | + | case _ => | |
31 | + | let issue = Issue(token_name, token_description, (witness_count * reward), token_decimals, true) | |
32 | + | let assetId = calculateAssetId(issue) | |
33 | + | [StringEntry("TOKEN", toBase58String(assetId)), issue, ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_1)), reward, assetId), ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_2)), reward, assetId), ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_3)), reward, assetId)] | |
34 | + | } | |
35 | + | ||
5 | 36 | ||
6 | 37 | @Callable(i) | |
7 | 38 | func emitEvent (source_chain_idx,target_chain_idx,block_height,block_hash,tx_hash,source_asset,amount) = { | |
23 | 54 | } | |
24 | 55 | let event = makeString([toString(source_chain_idx), toString(target_chain_idx), toString(block_height), block_hash, tx_hash, source_asset, toString(amountInt)], separator) | |
25 | 56 | $Tuple2([StringEntry(("EVENTS__" + toString(eventLastIdx)), event), IntegerEntry("EVENTS_LAST_IDX", (eventLastIdx + 1))], unit) | |
57 | + | } | |
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | @Callable(i) | |
62 | + | func confirmEvent (event_id,result,status_code) = { | |
63 | + | let caller_pk = toBase58String(i.callerPublicKey) | |
64 | + | let err = if (containsElement([witness_pk_1, witness_pk_2, witness_pk_3], caller_pk)) | |
65 | + | then unit | |
66 | + | else throw("not witness") | |
67 | + | if ((err == err)) | |
68 | + | then { | |
69 | + | let prev_decision = match getBoolean(((("CONFIRM__" + toString(event_id)) + "__") + caller_pk)) { | |
70 | + | case a: Boolean => | |
71 | + | throw("already confirmed") | |
72 | + | case _ => | |
73 | + | unit | |
74 | + | } | |
75 | + | if ((prev_decision == prev_decision)) | |
76 | + | then { | |
77 | + | let event = match getString(("EVENTS__" + toString(event_id))) { | |
78 | + | case a: String => | |
79 | + | a | |
80 | + | case _ => | |
81 | + | throw("no such event") | |
82 | + | } | |
83 | + | if ((event == event)) | |
84 | + | then { | |
85 | + | let confirms_total = match getInteger((("CONFIRM__" + toString(event_id)) + "__TOTAL")) { | |
86 | + | case a: Int => | |
87 | + | a | |
88 | + | case _ => | |
89 | + | 0 | |
90 | + | } | |
91 | + | let confirms_approved = match getInteger((("CONFIRM__" + toString(event_id)) + "__APPROVE")) { | |
92 | + | case a: Int => | |
93 | + | if (result) | |
94 | + | then (a + 1) | |
95 | + | else a | |
96 | + | case _ => | |
97 | + | if (result) | |
98 | + | then 1 | |
99 | + | else 0 | |
100 | + | } | |
101 | + | let confirms_res = if (result) | |
102 | + | then match getInteger((("CONFIRM__" + toString(event_id)) + "__APPROVE")) { | |
103 | + | case a: Int => | |
104 | + | IntegerEntry((("CONFIRM__" + toString(event_id)) + "__APPROVE"), (a + 1)) | |
105 | + | case _ => | |
106 | + | IntegerEntry((("CONFIRM__" + toString(event_id)) + "__APPROVE"), 1) | |
107 | + | } | |
108 | + | else match getInteger((("CONFIRM__" + toString(event_id)) + "__DENY")) { | |
109 | + | case a: Int => | |
110 | + | IntegerEntry((("CONFIRM__" + toString(event_id)) + "__DENY"), (a + 1)) | |
111 | + | case _ => | |
112 | + | IntegerEntry((("CONFIRM__" + toString(event_id)) + "__DENY"), 1) | |
113 | + | } | |
114 | + | let finalization_res = if (quorumIsReached(confirms_approved, (confirms_total + 1))) | |
115 | + | then finalizeEvent() | |
116 | + | else nil | |
117 | + | $Tuple2((([BooleanEntry(((("CONFIRM__" + toString(event_id)) + "__") + caller_pk), result), IntegerEntry((("CONFIRM__" + toString(event_id)) + "__TOTAL"), (confirms_total + 1))] :+ confirms_res) ++ finalization_res), unit) | |
118 | + | } | |
119 | + | else throw("Strict value is not equal to itself.") | |
120 | + | } | |
121 | + | else throw("Strict value is not equal to itself.") | |
122 | + | } | |
123 | + | else throw("Strict value is not equal to itself.") | |
26 | 124 | } | |
27 | 125 | ||
28 | 126 | ||
65 | 163 | } | |
66 | 164 | ||
67 | 165 | ||
166 | + | ||
167 | + | @Callable(i) | |
168 | + | func claimReward () = $Tuple2(nil, unit) | |
169 | + | ||
170 | + | ||
68 | 171 | @Verifier(tx) | |
69 | 172 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
70 | 173 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 6 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | + | let token_name = "Awesome token name" | |
5 | + | ||
6 | + | let token_description = "Awesome token description" | |
7 | + | ||
8 | + | let token_decimals = 8 | |
9 | + | ||
4 | 10 | let separator = "__" | |
11 | + | ||
12 | + | let witness_pk_1 = "1231231231" | |
13 | + | ||
14 | + | let witness_pk_2 = "1231231231" | |
15 | + | ||
16 | + | let witness_pk_3 = "1231231231" | |
17 | + | ||
18 | + | let witness_count = 3 | |
19 | + | ||
20 | + | let reward = (10 * pow(10, 0, token_decimals, 0, 0, DOWN)) | |
21 | + | ||
22 | + | func quorumIsReached (approved,total) = if ((approved > (total / 2))) | |
23 | + | then true | |
24 | + | else false | |
25 | + | ||
26 | + | ||
27 | + | func finalizeEvent () = match getString("TOKEN") { | |
28 | + | case a: String => | |
29 | + | [Reissue(fromBase58String(a), (witness_count * reward), true), ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_1)), reward, fromBase58String(a)), ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_2)), reward, fromBase58String(a)), ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_3)), reward, fromBase58String(a))] | |
30 | + | case _ => | |
31 | + | let issue = Issue(token_name, token_description, (witness_count * reward), token_decimals, true) | |
32 | + | let assetId = calculateAssetId(issue) | |
33 | + | [StringEntry("TOKEN", toBase58String(assetId)), issue, ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_1)), reward, assetId), ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_2)), reward, assetId), ScriptTransfer(addressFromPublicKey(fromBase58String(witness_pk_3)), reward, assetId)] | |
34 | + | } | |
35 | + | ||
5 | 36 | ||
6 | 37 | @Callable(i) | |
7 | 38 | func emitEvent (source_chain_idx,target_chain_idx,block_height,block_hash,tx_hash,source_asset,amount) = { | |
8 | 39 | let amountInt = match parseBigInt(amount) { | |
9 | 40 | case a: BigInt => | |
10 | 41 | a | |
11 | 42 | case _: Unit => | |
12 | 43 | throw("incorrect amount") | |
13 | 44 | case _ => | |
14 | 45 | throw("Match error") | |
15 | 46 | } | |
16 | 47 | let eventLastIdx = match getInteger("EVENTS_LAST_IDX") { | |
17 | 48 | case a: Int => | |
18 | 49 | a | |
19 | 50 | case _: Unit => | |
20 | 51 | 0 | |
21 | 52 | case _ => | |
22 | 53 | throw("Match error") | |
23 | 54 | } | |
24 | 55 | let event = makeString([toString(source_chain_idx), toString(target_chain_idx), toString(block_height), block_hash, tx_hash, source_asset, toString(amountInt)], separator) | |
25 | 56 | $Tuple2([StringEntry(("EVENTS__" + toString(eventLastIdx)), event), IntegerEntry("EVENTS_LAST_IDX", (eventLastIdx + 1))], unit) | |
57 | + | } | |
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | @Callable(i) | |
62 | + | func confirmEvent (event_id,result,status_code) = { | |
63 | + | let caller_pk = toBase58String(i.callerPublicKey) | |
64 | + | let err = if (containsElement([witness_pk_1, witness_pk_2, witness_pk_3], caller_pk)) | |
65 | + | then unit | |
66 | + | else throw("not witness") | |
67 | + | if ((err == err)) | |
68 | + | then { | |
69 | + | let prev_decision = match getBoolean(((("CONFIRM__" + toString(event_id)) + "__") + caller_pk)) { | |
70 | + | case a: Boolean => | |
71 | + | throw("already confirmed") | |
72 | + | case _ => | |
73 | + | unit | |
74 | + | } | |
75 | + | if ((prev_decision == prev_decision)) | |
76 | + | then { | |
77 | + | let event = match getString(("EVENTS__" + toString(event_id))) { | |
78 | + | case a: String => | |
79 | + | a | |
80 | + | case _ => | |
81 | + | throw("no such event") | |
82 | + | } | |
83 | + | if ((event == event)) | |
84 | + | then { | |
85 | + | let confirms_total = match getInteger((("CONFIRM__" + toString(event_id)) + "__TOTAL")) { | |
86 | + | case a: Int => | |
87 | + | a | |
88 | + | case _ => | |
89 | + | 0 | |
90 | + | } | |
91 | + | let confirms_approved = match getInteger((("CONFIRM__" + toString(event_id)) + "__APPROVE")) { | |
92 | + | case a: Int => | |
93 | + | if (result) | |
94 | + | then (a + 1) | |
95 | + | else a | |
96 | + | case _ => | |
97 | + | if (result) | |
98 | + | then 1 | |
99 | + | else 0 | |
100 | + | } | |
101 | + | let confirms_res = if (result) | |
102 | + | then match getInteger((("CONFIRM__" + toString(event_id)) + "__APPROVE")) { | |
103 | + | case a: Int => | |
104 | + | IntegerEntry((("CONFIRM__" + toString(event_id)) + "__APPROVE"), (a + 1)) | |
105 | + | case _ => | |
106 | + | IntegerEntry((("CONFIRM__" + toString(event_id)) + "__APPROVE"), 1) | |
107 | + | } | |
108 | + | else match getInteger((("CONFIRM__" + toString(event_id)) + "__DENY")) { | |
109 | + | case a: Int => | |
110 | + | IntegerEntry((("CONFIRM__" + toString(event_id)) + "__DENY"), (a + 1)) | |
111 | + | case _ => | |
112 | + | IntegerEntry((("CONFIRM__" + toString(event_id)) + "__DENY"), 1) | |
113 | + | } | |
114 | + | let finalization_res = if (quorumIsReached(confirms_approved, (confirms_total + 1))) | |
115 | + | then finalizeEvent() | |
116 | + | else nil | |
117 | + | $Tuple2((([BooleanEntry(((("CONFIRM__" + toString(event_id)) + "__") + caller_pk), result), IntegerEntry((("CONFIRM__" + toString(event_id)) + "__TOTAL"), (confirms_total + 1))] :+ confirms_res) ++ finalization_res), unit) | |
118 | + | } | |
119 | + | else throw("Strict value is not equal to itself.") | |
120 | + | } | |
121 | + | else throw("Strict value is not equal to itself.") | |
122 | + | } | |
123 | + | else throw("Strict value is not equal to itself.") | |
26 | 124 | } | |
27 | 125 | ||
28 | 126 | ||
29 | 127 | ||
30 | 128 | @Callable(i) | |
31 | 129 | func depositInsurance () = { | |
32 | 130 | let err = if ((size(i.payments) != 1)) | |
33 | 131 | then throw("no payment") | |
34 | 132 | else if ((i.payments[0].assetId != unit)) | |
35 | 133 | then throw("payment is not WAVES") | |
36 | 134 | else if ((0 >= i.payments[0].amount)) | |
37 | 135 | then throw("zero payment") | |
38 | 136 | else unit | |
39 | 137 | if ((err == err)) | |
40 | 138 | then { | |
41 | 139 | let freeInsurance = match getInteger(("INSURANCE_FREE__" + toBase58String(i.caller.bytes))) { | |
42 | 140 | case a: Int => | |
43 | 141 | a | |
44 | 142 | case _ => | |
45 | 143 | 0 | |
46 | 144 | } | |
47 | 145 | $Tuple2([IntegerEntry(("INSURANCE_FREE__" + toBase58String(i.caller.bytes)), (freeInsurance + i.payments[0].amount))], unit) | |
48 | 146 | } | |
49 | 147 | else throw("Strict value is not equal to itself.") | |
50 | 148 | } | |
51 | 149 | ||
52 | 150 | ||
53 | 151 | ||
54 | 152 | @Callable(i) | |
55 | 153 | func withdrawInsurance () = { | |
56 | 154 | let insurance = match getInteger(("INSURANCE_FREE__" + toBase58String(i.caller.bytes))) { | |
57 | 155 | case a: Int => | |
58 | 156 | if ((a > 0)) | |
59 | 157 | then a | |
60 | 158 | else throw("no free insurance") | |
61 | 159 | case _ => | |
62 | 160 | throw("no insurance") | |
63 | 161 | } | |
64 | 162 | $Tuple2([ScriptTransfer(i.caller, insurance, unit), IntegerEntry(("INSURANCE_FREE__" + toBase58String(i.caller.bytes)), 0)], unit) | |
65 | 163 | } | |
66 | 164 | ||
67 | 165 | ||
166 | + | ||
167 | + | @Callable(i) | |
168 | + | func claimReward () = $Tuple2(nil, unit) | |
169 | + | ||
170 | + | ||
68 | 171 | @Verifier(tx) | |
69 | 172 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
70 | 173 |
github/deemru/w8io/026f985 56.62 ms ◑