Newer
Older
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
39
40
41
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) {
//log("wallet.amounts:"+wallet.amounts);
//log("amount:"+amount);
//log("source:"+source);
//log("check if "+source.path().name()+" has more than "+amount+" he has now "+wallet.amounts.getOrDefault(source,0));
//log("and sender.compareTo(source)==0?"+sender.compareTo(source));
boolean granted = sender.compareTo(source)==0 //sender is supervisor(bank) has allways money
||(wallet.amounts.containsKey(source) //sender is unknown, might be valid
&&wallet.amounts.getOrDefault(source,0)>=amount) ; //sender have enough money
//log("granted?:"+granted);
//log("contains?:"+wallet.amounts.containsKey(source) );
sender.tell(new ActionPrepareDistributedCommitedTransferAnswer(source, target, amount,timestamp,granted,id),self);
}
}