4 | | - | let separator = "__" |
---|
5 | | - | |
---|
6 | | - | @Callable(i) |
---|
7 | | - | func emitEvent (source_chain_idx,target_chain_idx,block_height,block_hash,tx_hash,source_asset,amount) = { |
---|
8 | | - | let amountInt = match parseBigInt(amount) { |
---|
9 | | - | case a: BigInt => |
---|
10 | | - | a |
---|
11 | | - | case _: Unit => |
---|
12 | | - | throw("incorrect amount") |
---|
13 | | - | case _ => |
---|
14 | | - | throw("Match error") |
---|
15 | | - | } |
---|
16 | | - | let eventLastIdx = match getInteger("EVENTS_LAST_IDX") { |
---|
17 | | - | case a: Int => |
---|
18 | | - | a |
---|
19 | | - | case _: Unit => |
---|
20 | | - | 0 |
---|
21 | | - | case _ => |
---|
22 | | - | throw("Match error") |
---|
23 | | - | } |
---|
24 | | - | let event = makeString([toString(source_chain_idx), toString(target_chain_idx), toString(block_height), block_hash, tx_hash, source_asset, toString(amountInt)], separator) |
---|
25 | | - | $Tuple2([StringEntry(("EVENTS__" + toString(eventLastIdx)), event), IntegerEntry("EVENTS_LAST_IDX", (eventLastIdx + 1))], unit) |
---|
26 | | - | } |
---|
29 | | - | |
---|
30 | | - | @Callable(i) |
---|
31 | | - | func depositInsurance () = { |
---|
32 | | - | let err = if ((size(i.payments) != 1)) |
---|
33 | | - | then throw("no payment") |
---|
34 | | - | else if ((i.payments[0].assetId == unit)) |
---|
35 | | - | then throw("payment is not WAVES") |
---|
36 | | - | else if ((0 >= i.payments[0].amount)) |
---|
37 | | - | then throw("zero payment") |
---|
38 | | - | else unit |
---|
39 | | - | if ((err == err)) |
---|
40 | | - | then $Tuple2([IntegerEntry(("INSURANCE_FREE__" + toBase58String(i.caller.bytes)), i.payments[0].amount)], unit) |
---|
41 | | - | else throw("Strict value is not equal to itself.") |
---|
42 | | - | } |
---|
43 | | - | |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | @Callable(i) |
---|
47 | | - | func withdrawInsurance () = { |
---|
48 | | - | let insurance = match getInteger(("INSURANCE_FREE__" + toBase58String(i.caller.bytes))) { |
---|
49 | | - | case a: Int => |
---|
50 | | - | if ((a > 0)) |
---|
51 | | - | then a |
---|
52 | | - | else throw("no free insurance") |
---|
53 | | - | case _ => |
---|
54 | | - | throw("no insurance") |
---|
55 | | - | } |
---|
56 | | - | $Tuple2([ScriptTransfer(i.caller, insurance, unit), IntegerEntry(("INSURANCE_FREE__" + toBase58String(i.caller.bytes)), 0)], unit) |
---|
57 | | - | } |
---|
58 | | - | |
---|
59 | | - | |
---|
60 | | - | @Verifier(tx) |
---|
61 | | - | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|