Skip to content
Snippets Groups Projects
Unverified Commit 27eff81c authored by David Bohn's avatar David Bohn
Browse files

Merge branch 'dev-group3' of...

Merge branch 'dev-group3' of git.imp.fu-berlin.de:DistributedSystems4Students/FUCoin into dev-group3
parents c470bf47 b35ca25f
No related branches found
No related tags found
1 merge request!5Configuration system
......@@ -24,7 +24,7 @@ import java.util.*;
public class Main {
private static ActorSystem cSystem;
static {
......
......@@ -42,11 +42,6 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction {
wallet.addLogMsg("ActionCommitDistributedCommittedTransfer is granted? " + granted);
if (granted) {
Integer sourceAmount = wallet.amounts.getOrDefault(source, 0);
Integer targetAmount = wallet.amounts.getOrDefault(target, 0);
wallet.amounts.put(source, sourceAmount - amount);
wallet.amounts.put(target, targetAmount + amount);
if (source.compareTo(self) == 0) {
wallet.setAmount(wallet.getAmount() - amount);
wallet.addTransactionLogMessageSuccess("Sent " + amount + " FUC to " + target.path().name());
......@@ -58,6 +53,12 @@ public class ActionCommitDistributedCommittedTransfer extends ClientAction {
} else {
wallet.addLogMsg("abort transaction with id" + id);
// rollback
Integer sourceAmount = wallet.amounts.getOrDefault(source, 0);
Integer targetAmount = wallet.amounts.getOrDefault(target, 0);
wallet.amounts.put(source, sourceAmount + amount);
wallet.amounts.put(target, targetAmount - amount);
if (source.compareTo(self) == 0) {
wallet.addTransactionLogMessageFail("Failed to send " + amount + " FUC to " + target.path().name() + " (Commit has not been granted)");
}
......
......@@ -32,6 +32,13 @@ public class ActionPrepareDistributedCommittedTransfer extends Transaction {
//sender have enough money
&& wallet.amounts.getOrDefault(source, 0) >= amount));
// precautionly update own ledger to prevent double spending (respectively agreeing)
Integer sourceAmount = wallet.amounts.getOrDefault(source, 0);
Integer targetAmount = wallet.amounts.getOrDefault(target, 0);
wallet.amounts.put(source, sourceAmount - amount);
wallet.amounts.put(target, targetAmount + amount);
sender.tell(new ActionPrepareDistributedCommittedTransferAnswer(source, target, amount, timestamp, granted, id), self);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment