Newer
Older
Simon Könnecke
committed
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
38
package fucoin.actions.transaction;
import akka.actor.ActorRef;
import akka.actor.UntypedActorContext;
import fucoin.wallet.AbstractWallet;
public class ActionPrepareDistributedCommittedTransfer extends Transaction {
private ActorRef source;
private ActorRef target;
private int amount;
private long timestamp;
private long id;
public ActionPrepareDistributedCommittedTransfer(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, AbstractWallet wallet) {
boolean granted = amount > 0 &&
//sender is supervisor(bank) has always money
(sender.compareTo(source) == 0
//sender is unknown, might be valid
|| (wallet.amounts.containsKey(source)
//sender have enough money
&& wallet.amounts.getOrDefault(source, 0) >= amount));
sender.tell(new ActionPrepareDistributedCommittedTransferAnswer(source, target, amount, timestamp, granted, id), self);
}
}