package fucoin.actions.transaction; import akka.actor.ActorRef; import akka.actor.UntypedActorContext; import fucoin.Wallet; public class ActionPrepareDistributedCommitedTransfer extends Transaction { private ActorRef source; private ActorRef target; private int amount; private long timestamp; private long id; public ActionPrepareDistributedCommitedTransfer(ActorRef source, ActorRef target, int amount, long timestamp, long id) { this.source = source; this.target = target; this.amount = amount; this.timestamp = timestamp; this.id = id; } @Override protected void onAction(ActorRef sender, ActorRef self, UntypedActorContext context, Wallet wallet) { boolean granted = amount > 0 && (sender.compareTo(source) == 0 //sender is supervisor(bank) has always money || (wallet.amounts.containsKey(source) //sender is unknown, might be valid && wallet.amounts.getOrDefault(source, 0) >= amount)); //sender have enough money sender.tell(new ActionPrepareDistributedCommitedTransferAnswer(source, target, amount, timestamp, granted, id), self); } }