-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.ride
24 lines (21 loc) · 853 Bytes
/
wallet.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
{-# STDLIB_VERSION 5 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
@Callable(i)
func deposit() = {
let pmt = if i.payments.size() > 0 then i.payments[0] else throw("At least one payment expected")
let assetId = if pmt.assetId.isDefined() then pmt.assetId.value() else throw("Only WAVES payment accepted")
[ IntegerEntry(i.caller.toString(), pmt.amount) ]
}
@Callable(i)
func withdraw(amount: Int) = {
let address = i.caller.toString()
let current = this.getInteger(address).valueOrErrorMessage("You don't have a deposit")
let amt = if amount > 0 || amount > current then amount else throw("Amount to withdraw must be more than 0 and less than current deposit")
if amount == current then [
DeleteEntry(address)
] else [
IntegerEntry(address, current - amount),
ScriptTransfer(i.caller, amount, unit)
]
}