2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | func a (b) = { |
---|
5 | | - | let c = { |
---|
6 | | - | let d = getString(this, b) |
---|
7 | | - | if ($isInstanceOf(d, "String")) |
---|
8 | | - | then { |
---|
9 | | - | let e = d |
---|
10 | | - | e |
---|
11 | | - | } |
---|
12 | | - | else throw("First address not set!") |
---|
13 | | - | } |
---|
14 | | - | c |
---|
15 | | - | } |
---|
16 | | - | |
---|
17 | | - | |
---|
18 | | - | func f (b) = { |
---|
19 | | - | let c = { |
---|
20 | | - | let d = getString(this, b) |
---|
21 | | - | if ($isInstanceOf(d, "String")) |
---|
22 | | - | then { |
---|
23 | | - | let e = d |
---|
24 | | - | e |
---|
25 | | - | } |
---|
26 | | - | else "" |
---|
27 | | - | } |
---|
28 | | - | c |
---|
29 | | - | } |
---|
30 | | - | |
---|
31 | | - | |
---|
32 | | - | func g (b) = { |
---|
33 | | - | let h = { |
---|
34 | | - | let d = getInteger(this, b) |
---|
35 | | - | if ($isInstanceOf(d, "Int")) |
---|
36 | | - | then { |
---|
37 | | - | let i = d |
---|
38 | | - | i |
---|
39 | | - | } |
---|
40 | | - | else 0 |
---|
41 | | - | } |
---|
42 | | - | h |
---|
43 | | - | } |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | func j (k) = { |
---|
47 | | - | let l = a("firstAddress") |
---|
48 | | - | let m = a("secondAddress") |
---|
49 | | - | if (if ((l != k)) |
---|
50 | | - | then (m != k) |
---|
51 | | - | else false) |
---|
52 | | - | then throw(("Method call from invalid account: " + k)) |
---|
53 | | - | else true |
---|
54 | | - | } |
---|
55 | | - | |
---|
56 | | - | |
---|
57 | | - | @Callable(n) |
---|
58 | | - | func claimCheating (o,p,q,r,s,t) = { |
---|
59 | | - | let k = toBase58String(n.caller.bytes) |
---|
60 | | - | let u = j(k) |
---|
61 | | - | let v = ((((o + toString(p)) + q) + toString(r)) + toString(s)) |
---|
62 | | - | let w = a((k + "_counterpart")) |
---|
63 | | - | let x = sigVerify(fromBase58String(v), fromBase58String(t), fromBase58String(w)) |
---|
64 | | - | let y = g("timestamp") |
---|
65 | | - | if (if (if (u) |
---|
66 | | - | then x |
---|
67 | | - | else false) |
---|
68 | | - | then (s > y) |
---|
69 | | - | else false) |
---|
70 | | - | then TransferSet([ScriptTransfer(n.caller, (p + r), unit)]) |
---|
71 | | - | else throw("Wrong signature or timestamp not newer!") |
---|
72 | | - | } |
---|
73 | | - | |
---|
74 | | - | |
---|
75 | | - | |
---|
76 | | - | @Callable(n) |
---|
77 | | - | func confirmClose () = { |
---|
78 | | - | let k = toBase58String(n.caller.bytes) |
---|
79 | | - | let u = j(k) |
---|
80 | | - | let z = getString(this, "closing_initiated_by") |
---|
81 | | - | if (if ((k != z)) |
---|
82 | | - | then u |
---|
83 | | - | else false) |
---|
84 | | - | then { |
---|
85 | | - | let l = a("firstAddress") |
---|
86 | | - | let m = a("secondAddress") |
---|
87 | | - | let h = g(l) |
---|
88 | | - | let A = g(m) |
---|
89 | | - | TransferSet([ScriptTransfer(Address(fromBase58String(l)), h, unit), ScriptTransfer(Address(fromBase58String(m)), A, unit)]) |
---|
90 | | - | } |
---|
91 | | - | else throw("Initiator can not confirm closing of the channel!") |
---|
92 | | - | } |
---|
93 | | - | |
---|
94 | | - | |
---|
95 | | - | |
---|
96 | | - | @Callable(n) |
---|
97 | | - | func closeAfterTimelock () = { |
---|
98 | | - | let k = toBase58String(n.caller.bytes) |
---|
99 | | - | let u = j(k) |
---|
100 | | - | let B = g("timelock") |
---|
101 | | - | if (if ((height > B)) |
---|
102 | | - | then u |
---|
103 | | - | else false) |
---|
104 | | - | then { |
---|
105 | | - | let l = a("firstAddress") |
---|
106 | | - | let m = a("secondAddress") |
---|
107 | | - | let h = g(l) |
---|
108 | | - | let A = g(m) |
---|
109 | | - | TransferSet([ScriptTransfer(Address(fromBase58String(l)), h, unit), ScriptTransfer(Address(fromBase58String(m)), A, unit)]) |
---|
110 | | - | } |
---|
111 | | - | else throw("Timelock still valid!") |
---|
112 | | - | } |
---|
113 | | - | |
---|
114 | | - | |
---|
115 | | - | |
---|
116 | | - | @Callable(n) |
---|
117 | | - | func initialClosing (o,p,q,r,s,t) = { |
---|
118 | | - | let k = toBase58String(n.caller.bytes) |
---|
119 | | - | let u = j(k) |
---|
120 | | - | let v = ((((o + toString(p)) + q) + toString(r)) + toString(s)) |
---|
121 | | - | let w = a((k + "_counterpart")) |
---|
122 | | - | let x = sigVerify(toBytes(v), toBytes(t), toBytes(w)) |
---|
123 | | - | let C = g("timelockPeriod") |
---|
124 | | - | if (if (x) |
---|
125 | | - | then u |
---|
126 | | - | else false) |
---|
127 | | - | then WriteSet([DataEntry(o, p), DataEntry(q, r), DataEntry("closing_initiated_by", k), DataEntry("timestamp", s), DataEntry("timelock", (height + C))]) |
---|
128 | | - | else throw("Wrong signature!") |
---|
129 | | - | } |
---|
130 | | - | |
---|
131 | | - | |
---|
132 | | - | |
---|
133 | | - | @Callable(n) |
---|
134 | | - | func fund () = { |
---|
135 | | - | let k = toBase58String(n.caller.bytes) |
---|
136 | | - | let u = j(k) |
---|
137 | | - | let D = extract(n.payment) |
---|
138 | | - | let E = (k + "_amount") |
---|
139 | | - | let F = g(E) |
---|
140 | | - | if (u) |
---|
141 | | - | then if ((F != 0)) |
---|
142 | | - | then throw("User has already funded payment channel!") |
---|
143 | | - | else WriteSet([DataEntry(E, (F + D.amount))]) |
---|
144 | | - | else throw("Wrong account tries to fund channel!") |
---|
145 | | - | } |
---|
146 | | - | |
---|
147 | | - | |
---|
148 | | - | |
---|
149 | | - | @Callable(n) |
---|
150 | | - | func init (l,G,m,H,C) = { |
---|
151 | | - | let I = f((l + "_counterpart")) |
---|
152 | | - | let J = f((m + "_counterpart")) |
---|
153 | | - | if (if ((I != "")) |
---|
154 | | - | then true |
---|
155 | | - | else (J != "")) |
---|
156 | | - | then throw("Contract already initiated!") |
---|
157 | | - | else WriteSet([DataEntry("firstAddress", l), DataEntry("secondAddress", m), DataEntry((l + "_counterpart"), H), DataEntry((m + "_counterpart"), G), DataEntry("timelockPeriod", C)]) |
---|
158 | | - | } |
---|
159 | | - | |
---|
160 | | - | |
---|
161 | | - | @Verifier(K) |
---|
162 | | - | func L () = { |
---|
163 | | - | let d = K |
---|
164 | | - | true |
---|
165 | | - | } |
---|
166 | | - | |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let PubKey1 = base58'854p8BYzrj6yBPRPmfQur3oF1Rjc1AJ548qRp5FT5kDa' |
---|
| 4 | + | let PubKey2 = base58'DKGFPozLrsiR8NM4NJzqQaBYC8NyGYjuw2hDYicQVjco' |
---|
| 5 | + | let sig1 = if (sigVerify(tx.bodyBytes, tx.proofs[0], PubKey1)) |
---|
| 6 | + | then 1 |
---|
| 7 | + | else 0 |
---|
| 8 | + | let sig2 = if (sigVerify(tx.bodyBytes, tx.proofs[1], PubKey2)) |
---|
| 9 | + | then 1 |
---|
| 10 | + | else 0 |
---|
| 11 | + | ((sig1 + sig2) > 0) |
---|