All Downloads are FREE. Search and download functionalities are using the official Maven repository.

form.lang.1.5.7.source-code.wallet.ride Maven / Gradle / Ivy

The newest version!
@Callable(i)
func deposit() = {
   let pmt = extract(i.payment)
   if (isDefined(pmt.asset)) then throw("can hodl waves only at the moment")
   else {
	  	let currentKey = toBase58String(i.caller.bytes)
	  	let currentAmount = match getInteger(this, currentKey) {
	  		case a:Int => a
	  		case _ => 0
	  	}
	  	let newAmount = currentAmount + pmt.amount
	  	WriteSet(List(DataEntry(currentKey, newAmount)))
   }
}

@Callable(i)
func withdraw(amount: Int) = {
	  	let currentKey = toBase58String(i.caller.bytes)
	  	let currentAmount = match getInteger(this, currentKey) {
	  		case a:Int => a
	  		case _ => 0
	  	}
		let newAmount = currentAmount - amount
	 if (amount < 0)
			then throw("Can't withdraw negative amount")
    else if (newAmount < 0)
			then throw("Not enough balance")
			else ScriptResult(
					WriteSet(List(DataEntry(currentKey, newAmount))),
					TransferSet(List(ScriptTransfer(i.caller, amount, unit)))
				)
	}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy