use account::Account;
use types::{ProcessError, ProcessResult};
use utils::IfNotFound;
pub fn transfer(sender: &Account, recipient: &Account, amount: u64) -> ProcessResult<()> {
sender.set_u64(
"balance",
match sender
.get_u64("balance")
.if_not_found(|| 0u64)?
.checked_sub(amount)
{
Some(v) => v,
None => return Err(ProcessError::Custom("not enough balance".into())),
},
)?;
recipient.set_u64(
"balance",
match recipient
.get_u64("balance")
.if_not_found(|| 0u64)?
.checked_add(amount)
{
Some(v) => v,
None => return Err(ProcessError::Overflow),
},
)?;
Ok(())
}