-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwallet2.ride
executable file
·37 lines (35 loc) · 1.08 KB
/
wallet2.ride
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{-# STDLIB_VERSION 3 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
@Callable(i)
func deposit() = {
let pmt = i.payment.value()
let amt = if (isDefined(pmt.assetId))
then throw("no custom tokens for this demo")
else pmt.amount
let key = i.caller.bytes.toBase58String()
let currentAmount = match getInteger(this, key) {
case x:Int => x
case _ => 0
}
let newAmount = currentAmount + amt
WriteSet([DataEntry(key, newAmount)])
}
@Callable(i)
func withdraw(amt: Int) = {
let key = i.caller.bytes.toBase58String()
let currentAmount = match getInteger(this, key) {
case x:Int => x
case _ => 0
}
if (amt <= 0)
then throw("can't withdraw negative")
else if(amt > currentAmount)
then throw("can't withdraw more than own")
else {
ScriptResult(
WriteSet([DataEntry(key, currentAmount - amt)]),
TransferSet([ScriptTransfer(i.caller, amt, unit)])
)
}
}