1 | | - | {-# STDLIB_VERSION 2 #-} |
---|
2 | | - | {-# CONTENT_TYPE EXPRESSION #-} |
---|
3 | | - | let me = tx.sender |
---|
4 | | - | let oracle = extract(addressFromString("3NCzaYTNDGtR8zf9yfcqePFjCqFx9S5zhs4")) |
---|
5 | | - | let minWithdrawFee = 500000 |
---|
6 | | - | let registerBetTxFee = 500000 |
---|
7 | | - | match tx { |
---|
8 | | - | case withdrawTx: TransferTransaction => |
---|
9 | | - | let txId = extract(getString(me, (toBase58String(tx.proofs[1]) + "_withdraw"))) |
---|
10 | | - | match transactionById(tx.proofs[1]) { |
---|
11 | | - | case paymentTx: TransferTransaction => |
---|
12 | | - | let isPaymentTookPlace = if ((txId == toBase58String(tx.id))) |
---|
13 | | - | then sigVerify(tx.bodyBytes, tx.proofs[0], paymentTx.senderPublicKey) |
---|
14 | | - | else false |
---|
15 | | - | let feesKey = (toBase58String(tx.proofs[1]) + "_withdraw_fees") |
---|
16 | | - | let dataTxsFees = extract(getInteger(me, feesKey)) |
---|
17 | | - | let guessUnit = getBinary(me, toBase58String(tx.proofs[1])) |
---|
18 | | - | let correctAmount = if (!(isDefined(guessUnit))) |
---|
19 | | - | then ((paymentTx.amount - dataTxsFees) - withdrawTx.fee) |
---|
20 | | - | else { |
---|
21 | | - | let guess = extract(guessUnit) |
---|
22 | | - | let type = take(guess, 1) |
---|
23 | | - | let val = drop(guess, 1) |
---|
24 | | - | let key = extract(getString(me, (toBase58String(tx.proofs[1]) + "_round"))) |
---|
25 | | - | let valComplex = extract(getBinary(oracle, key)) |
---|
26 | | - | let koeff = if ((type == drop(toBytes(0), 7))) |
---|
27 | | - | then 36 |
---|
28 | | - | else if ((type == drop(toBytes(1), 7))) |
---|
29 | | - | then 2 |
---|
30 | | - | else if ((type == drop(toBytes(2), 7))) |
---|
31 | | - | then 2 |
---|
32 | | - | else if ((type == drop(toBytes(3), 7))) |
---|
33 | | - | then 2 |
---|
34 | | - | else if ((type == drop(toBytes(4), 7))) |
---|
35 | | - | then 3 |
---|
36 | | - | else if ((type == drop(toBytes(5), 7))) |
---|
37 | | - | then 3 |
---|
38 | | - | else 0 |
---|
39 | | - | ((((paymentTx.amount - registerBetTxFee) * koeff) - dataTxsFees) - withdrawTx.fee) |
---|
40 | | - | } |
---|
41 | | - | if (if (if (isPaymentTookPlace) |
---|
42 | | - | then true |
---|
43 | | - | else throw("There was no bet")) |
---|
44 | | - | then if ((withdrawTx.amount == correctAmount)) |
---|
45 | | - | then true |
---|
46 | | - | else throw(("Amount is incorrect. Correct amount is " + toString(correctAmount))) |
---|
47 | | - | else false) |
---|
48 | | - | then if (if (!(isDefined(withdrawTx.feeAssetId))) |
---|
49 | | - | then !(isDefined(withdrawTx.assetId)) |
---|
50 | | - | else false) |
---|
51 | | - | then true |
---|
52 | | - | else throw("Withdraw and fee must be in WAVES") |
---|
53 | | - | else false |
---|
54 | | - | case _ => |
---|
55 | | - | false |
---|
56 | | - | } |
---|
57 | | - | case dtx: DataTransaction => |
---|
58 | | - | if ((size(dtx.data) == 3)) |
---|
59 | | - | then { |
---|
60 | | - | let minBet = 50000000 |
---|
61 | | - | let maxSumBet = 1000000000 |
---|
62 | | - | let paymentTxIdStr = extract(dtx.data[0].key) |
---|
63 | | - | let guessStr = extract(getString(dtx.data, paymentTxIdStr)) |
---|
64 | | - | let paymentRoundKey = (paymentTxIdStr + "_round") |
---|
65 | | - | let paymentRound = extract(getString(dtx.data, paymentRoundKey)) |
---|
66 | | - | let sumBetsOld = if (isDefined(getInteger(me, (paymentRound + "_betsSum")))) |
---|
67 | | - | then extract(getInteger(me, (paymentRound + "_betsSum"))) |
---|
68 | | - | else 0 |
---|
69 | | - | let sumBetsNew = extract(getInteger(dtx.data, (paymentRound + "_betsSum"))) |
---|
70 | | - | let itsTooLate = isDefined(getString(me, (paymentRound + "_stop"))) |
---|
71 | | - | let isPaymentAlreadyMentioned = isDefined(getString(me, paymentTxIdStr)) |
---|
72 | | - | let paymentTx = transactionById(fromBase58String(paymentTxIdStr)) |
---|
73 | | - | match paymentTx { |
---|
74 | | - | case paymentTx: TransferTransaction => |
---|
75 | | - | let isDtxSignedByPayer = sigVerify(dtx.bodyBytes, dtx.proofs[0], paymentTx.senderPublicKey) |
---|
76 | | - | let correctSumBets = ((sumBetsOld + paymentTx.amount) - dtx.fee) |
---|
77 | | - | if (if (if (if (if (if (if (if ((addressFromRecipient(paymentTx.recipient) == me)) |
---|
78 | | - | then true |
---|
79 | | - | else throw("Incorrect recipient of the payment")) |
---|
80 | | - | then if (!(isPaymentAlreadyMentioned)) |
---|
81 | | - | then true |
---|
82 | | - | else throw("This transfer is already used as a bet") |
---|
83 | | - | else false) |
---|
84 | | - | then if ((sumBetsNew == correctSumBets)) |
---|
85 | | - | then true |
---|
86 | | - | else throw(("Wrong value for Sum of Bets. Must be " + toString(correctSumBets))) |
---|
87 | | - | else false) |
---|
88 | | - | then if ((maxSumBet > sumBetsNew)) |
---|
89 | | - | then true |
---|
90 | | - | else throw(((("Maximum amount of bets for round " + toString(maxSumBet)) + ". With your bet it's ") + toString(sumBetsNew))) |
---|
91 | | - | else false) |
---|
92 | | - | then if ((dtx.fee == registerBetTxFee)) |
---|
93 | | - | then true |
---|
94 | | - | else throw(("Fee of bet registration data transaction must be " + toString(registerBetTxFee))) |
---|
95 | | - | else false) |
---|
96 | | - | then if (((paymentTx.amount - registerBetTxFee) >= minBet)) |
---|
97 | | - | then true |
---|
98 | | - | else throw(((("Your Bet amount is less then minimal bet " + toString(minBet)) + ". Payment amount for such bet must be ") + toString((minBet + registerBetTxFee)))) |
---|
99 | | - | else false) |
---|
100 | | - | then if (!(isDefined(paymentTx.feeAssetId))) |
---|
101 | | - | then true |
---|
102 | | - | else throw("Paymnet must be in WAVES") |
---|
103 | | - | else false) |
---|
104 | | - | then if (!(itsTooLate)) |
---|
105 | | - | then true |
---|
106 | | - | else throw("It's too late to play this round. Try next one") |
---|
107 | | - | else false |
---|
108 | | - | case _ => |
---|
109 | | - | false |
---|
110 | | - | } |
---|
111 | | - | } |
---|
112 | | - | else if ((size(dtx.data) == 2)) |
---|
113 | | - | then { |
---|
114 | | - | let isDataCountOk = (size(dtx.data) == 2) |
---|
115 | | - | let paymentTxIdStr = dropRight(extract(dtx.data[0].key), 9) |
---|
116 | | - | let feesKey = (paymentTxIdStr + "_withdraw_fees") |
---|
117 | | - | let paymentTx = transactionById(fromBase58String(paymentTxIdStr)) |
---|
118 | | - | let newFees = extract(getInteger(dtx.data, feesKey)) |
---|
119 | | - | let oldFeesUnit = getInteger(me, feesKey) |
---|
120 | | - | let oldFees = if (isDefined(oldFeesUnit)) |
---|
121 | | - | then extract(oldFeesUnit) |
---|
122 | | - | else 0 |
---|
123 | | - | let isFeeCorrect = (newFees == (oldFees + dtx.fee)) |
---|
124 | | - | let withdrawTxIdUnit = getString(me, paymentTxIdStr) |
---|
125 | | - | let isPaymentAlreadyMentioned = isDefined(withdrawTxIdUnit) |
---|
126 | | - | let withdrawTransactionId = fromBase58String(extract(withdrawTxIdUnit)) |
---|
127 | | - | match paymentTx { |
---|
128 | | - | case paymentTx: TransferTransaction => |
---|
129 | | - | let isDtxSignedByPayer = sigVerify(dtx.bodyBytes, dtx.proofs[0], paymentTx.senderPublicKey) |
---|
130 | | - | if (if (if (if (if ((addressFromRecipient(paymentTx.recipient) == me)) |
---|
131 | | - | then if (!(isPaymentAlreadyMentioned)) |
---|
132 | | - | then true |
---|
133 | | - | else !(isDefined(transactionById(withdrawTransactionId))) |
---|
134 | | - | else false) |
---|
135 | | - | then isDtxSignedByPayer |
---|
136 | | - | else false) |
---|
137 | | - | then isFeeCorrect |
---|
138 | | - | else false) |
---|
139 | | - | then isDataCountOk |
---|
140 | | - | else false) |
---|
141 | | - | then { |
---|
142 | | - | let guess = extract(getBinary(me, paymentTxIdStr)) |
---|
143 | | - | let type = take(guess, 1) |
---|
144 | | - | let key = extract(getString(me, (paymentTxIdStr + "_round"))) |
---|
145 | | - | let valComplex = extract(getBinary(oracle, key)) |
---|
146 | | - | let koeff = if ((type == drop(toBytes(0), 7))) |
---|
147 | | - | then 36 |
---|
148 | | - | else if ((type == drop(toBytes(1), 7))) |
---|
149 | | - | then 2 |
---|
150 | | - | else if ((type == drop(toBytes(2), 7))) |
---|
151 | | - | then 2 |
---|
152 | | - | else if ((type == drop(toBytes(3), 7))) |
---|
153 | | - | then 2 |
---|
154 | | - | else if ((type == drop(toBytes(4), 7))) |
---|
155 | | - | then 3 |
---|
156 | | - | else if ((type == drop(toBytes(5), 7))) |
---|
157 | | - | then 3 |
---|
158 | | - | else 0 |
---|
159 | | - | let valReal = if ((type == drop(toBytes(0), 7))) |
---|
160 | | - | then drop(take(valComplex, 2), 1) |
---|
161 | | - | else if ((type == drop(toBytes(1), 7))) |
---|
162 | | - | then drop(take(valComplex, 3), 2) |
---|
163 | | - | else if ((type == drop(toBytes(2), 7))) |
---|
164 | | - | then drop(take(valComplex, 4), 3) |
---|
165 | | - | else if ((type == drop(toBytes(3), 7))) |
---|
166 | | - | then drop(take(valComplex, 5), 4) |
---|
167 | | - | else if ((type == drop(toBytes(4), 7))) |
---|
168 | | - | then drop(take(valComplex, 6), 5) |
---|
169 | | - | else if ((type == drop(toBytes(5), 7))) |
---|
170 | | - | then drop(take(valComplex, 7), 6) |
---|
171 | | - | else throw("Incorrect type of guess provided") |
---|
172 | | - | let isWin = (drop(guess, 1) == valReal) |
---|
173 | | - | let isMoneyStillEnough = ((((paymentTx.amount - registerBetTxFee) * koeff) + minWithdrawFee) > newFees) |
---|
174 | | - | if (if (isWin) |
---|
175 | | - | then true |
---|
176 | | - | else throw("You didn't guess")) |
---|
177 | | - | then if (isMoneyStillEnough) |
---|
178 | | - | then true |
---|
179 | | - | else throw("Not enough money for withdraw") |
---|
180 | | - | else false |
---|
181 | | - | } |
---|
182 | | - | else false |
---|
183 | | - | case _ => |
---|
184 | | - | false |
---|
185 | | - | } |
---|
186 | | - | } |
---|
187 | | - | else false |
---|
| 1 | + | {-# STDLIB_VERSION 3 #-} |
---|
| 2 | + | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
| 3 | + | {-# CONTENT_TYPE DAPP #-} |
---|
| 4 | + | let answersCount = 20 |
---|
| 5 | + | |
---|
| 6 | + | let answers = ["It is certain.", "It is decidedly so.", "Without a doubt.", "Yes - definitely.", "You may rely on it.", "As I see it, yes.", "Most likely.", "Outlook good.", "Yes.", "Signs point to yes.", "Reply hazy, try again.", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Don't count on it.", "My reply is no.", "My sources say no.", "Outlook not so good.", "Very doubtful."] |
---|
| 7 | + | |
---|
| 8 | + | func getAnswer (question,previousAnswer) = { |
---|
| 9 | + | let hash = sha256(toBytes((question + previousAnswer))) |
---|
| 10 | + | let index = toInt(hash) |
---|
| 11 | + | answers[(index % answersCount)] |
---|
| 12 | + | } |
---|
| 13 | + | |
---|
| 14 | + | |
---|
| 15 | + | func getPreviousAnswer (address) = match getString(this, (address + "_a")) { |
---|
| 16 | + | case a: String => |
---|
| 17 | + | a |
---|