Skip to content

Commit

Permalink
only save/export mixs when completed
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroleak committed Feb 18, 2020
1 parent 4e03292 commit eb70ad6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Tx0DataResponse tx0Data(
feeDiscountPercent = 0;
message = null;

if (scode != null) {
if (!StringUtils.isEmpty(scode)) {
log.warn("Invalid SCODE: " + scode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.lang.invoke.MethodHandles;
import java.util.Map.Entry;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutPoint;
import org.bitcoinj.core.TransactionOutput;
Expand Down Expand Up @@ -278,7 +280,7 @@ protected WhirlpoolServerConfig.ScodeSamouraiFeeConfig getScodeByFeePayload(byte

public WhirlpoolServerConfig.ScodeSamouraiFeeConfig getScodeConfigByScode(
String scode, long tx0Time) {
String scodeUpperCase = (scode != null ? scode.toUpperCase() : null);
String scodeUpperCase = (!StringUtils.isEmpty(scode) ? scode.toUpperCase() : null);
WhirlpoolServerConfig.ScodeSamouraiFeeConfig scodeConfig =
serverConfig.getSamouraiFees().getScodes().get(scodeUpperCase);
if (scodeConfig == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,6 @@ private void logMixStatus(Mix mix) {
+ " liquidities + "
+ mustMixQueued
+ " mustMixs)");

// update mix status in database
if (mix.getNbInputsMustMix() > 0) {
try {
dbService.saveMix(mix);
} catch (Exception e) {
log.error("", e);
}
}
}

protected synchronized boolean isRegisterOutputReady(Mix mix) {
Expand Down Expand Up @@ -540,11 +531,6 @@ public void changeMixStatus(String mixId, MixStatus mixStatus) {

// update mix status
mix.setMixStatusAndTime(mixStatus);
try {
dbService.saveMix(mix);
} catch (Exception e) {
log.error("", e);
}
mixLimitsService.onMixStatusChange(mix);

// notify users (ConfirmInputResponse was already sent when user joined mix)
Expand All @@ -562,14 +548,14 @@ public void changeMixStatus(String mixId, MixStatus mixStatus) {
log.error("", e);
}

__nextMix(mix.getPool());
onMixOver(mix);
} else if (mixStatus == MixStatus.FAIL) {
__nextMix(mix.getPool());
onMixOver(mix);
}
} catch (MixException e) {
log.error("Unexpected mix error", e);
if (mix != null) {
__nextMix(mix.getPool());
onMixOver(mix);
}
}
}
Expand Down Expand Up @@ -755,14 +741,10 @@ public void goFail(Mix mix, FailReason failReason, String failInfo) {
mix.setFailReason(failReason);
mix.setFailInfo(failInfo);
changeMixStatus(mix.getMixId(), MixStatus.FAIL);

exportService.exportMix(mix);
}

public void goSuccess(Mix mix) {
changeMixStatus(mix.getMixId(), MixStatus.SUCCESS);

exportService.exportMix(mix);
}

private synchronized void onClientDisconnect(String username) {
Expand Down Expand Up @@ -833,11 +815,36 @@ public Mix __nextMix(Pool pool) {
return mix;
}

private void onMixOver(Mix mix) {
// unmanage
try {
mixLimitsService.unmanage(mix);
} catch (Exception e) {
log.error("", e);
}

// save in database
try {
dbService.saveMix(mix);
} catch (Exception e) {
log.error("", e);
}

// export to CSV
try {
exportService.exportMix(mix);
} catch (Exception e) {
log.error("", e);
}

// start new mix
__nextMix(mix.getPool());
}

private synchronized void startMix(Mix mix) {
Pool pool = mix.getPool();
Mix currentMix = pool.getCurrentMix();
if (currentMix != null) {
mixLimitsService.unmanage(currentMix);
currentMixs.remove(currentMix.getMixId());
// TODO disconnect all clients (except liquidities?)
}
Expand Down

0 comments on commit eb70ad6

Please sign in to comment.