Fix bug with failed offer removal. Fix reduced fees to avoid negative amounts

This commit is contained in:
Manfred Karrer 2015-12-31 19:27:47 +01:00
parent 860ffd2aff
commit be108a3035
7 changed files with 26 additions and 11 deletions

View file

@ -50,7 +50,7 @@ public class FeePolicy {
public static final Coin DUST = Coin.valueOf(546);
//TODO for testing
public static final Coin CREATE_OFFER_FEE = Coin.valueOf(10000); // 0.0001 BTC 0.1% of 1 BTC about 0.2 EUR @ 200 EUR/BTC
public static final Coin CREATE_OFFER_FEE = Coin.valueOf(40000); // 0.0001 BTC 0.1% of 1 BTC about 0.2 EUR @ 200 EUR/BTC
//public static final Coin CREATE_OFFER_FEE = Coin.valueOf(100000); // 0.001 BTC 0.1% of 1 BTC about 0.2 EUR @ 200 EUR/BTC
public static final Coin TAKE_OFFER_FEE = CREATE_OFFER_FEE;
//TODO for testing

View file

@ -141,6 +141,7 @@ public class TradeWalletService {
public Transaction createTradingFeeTx(AddressEntry addressEntry, Coin tradingFee, String feeReceiverAddresses)
throws InsufficientMoneyException, AddressFormatException {
Transaction tradingFeeTx = new Transaction(params);
Preconditions.checkArgument(tradingFee.compareTo(FeePolicy.TX_FEE) > 0);
Coin outPutAmount = tradingFee.subtract(FeePolicy.TX_FEE);
tradingFeeTx.addOutput(outPutAmount, new Address(params, feeReceiverAddresses));

View file

@ -220,23 +220,37 @@ public class OpenOfferManager {
public void onRemoveOpenOffer(Offer offer, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
Optional<OpenOffer> openOfferOptional = findOpenOffer(offer.getId());
if (openOfferOptional.isPresent())
if (openOfferOptional.isPresent()) {
onRemoveOpenOffer(openOfferOptional.get(), resultHandler, errorMessageHandler);
} else {
log.warn("Offer was not found in our list of open offers. We still try to remove it from the offerbook.");
errorMessageHandler.handleErrorMessage("Offer was not found in our list of open offers. " +
"We still try to remove it from the offerbook.");
onRemoveOffer(offer);
}
}
public void onRemoveOpenOffer(OpenOffer openOffer, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
offerBookService.removeOffer(openOffer.getOffer(),
Offer offer = openOffer.getOffer();
offerBookService.removeOffer(offer,
() -> {
openOffer.getOffer().setState(Offer.State.REMOVED);
offer.setState(Offer.State.REMOVED);
openOffer.setState(OpenOffer.State.CANCELED);
openOffers.remove(openOffer);
closedTradableManager.add(openOffer);
//disposeCheckOfferAvailabilityRequest(offer);
resultHandler.handleResult();
},
errorMessageHandler);
}
// That should not be needed, but there are cases where the openOffer is removed but the offer still in the
// offerbook
public void onRemoveOffer(Offer offer) {
offerBookService.removeOffer(offer,
() -> offer.setState(Offer.State.REMOVED),
null);
}
public void reserveOpenOffer(OpenOffer openOffer) {
openOffer.setState(OpenOffer.State.RESERVED);
}