Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump failed delayedtx #4029

Merged
merged 2 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions core/src/main/java/bisq/core/trade/DumpDelayedPayoutTx.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.trade;

import bisq.common.config.Config;
import bisq.common.storage.JsonFileManager;
import bisq.common.util.Utilities;

import javax.inject.Inject;
import javax.inject.Named;

import java.io.File;

import java.util.stream.Collectors;

public class DumpDelayedPayoutTx {
private final boolean dumpDelayedPayoutTxs;
private final JsonFileManager jsonFileManager;

@Inject
DumpDelayedPayoutTx(@Named(Config.STORAGE_DIR) File storageDir,
@Named(Config.DUMP_DELAYED_PAYOUT_TXS) boolean dumpDelayedPayoutTxs) {
this.dumpDelayedPayoutTxs = dumpDelayedPayoutTxs;
jsonFileManager = new JsonFileManager(storageDir);
}

static class DelayedPayoutHash {
String tradeId;
String delayedPayoutTx;

DelayedPayoutHash(String tradeId, String delayedPayoutTx) {
this.tradeId = tradeId;
this.delayedPayoutTx = delayedPayoutTx;
}
}

public void maybeDumpDelayedPayoutTxs(TradableList<Trade> tradableList, String fileName) {
if (!dumpDelayedPayoutTxs)
return;

var delayedPayoutHashes = tradableList.stream()
.map(trade -> new DelayedPayoutHash(trade.getId(),
Utilities.bytesAsHexString(trade.getDelayedPayoutTxBytes())))
.collect(Collectors.toList());
jsonFileManager.writeToDisc(Utilities.objectToJson(delayedPayoutHashes), fileName);
}

}
41 changes: 5 additions & 36 deletions core/src/main/java/bisq/core/trade/TradeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@
import bisq.network.p2p.SendMailboxMessageListener;

import bisq.common.ClockWatcher;
import bisq.common.config.Config;
import bisq.common.crypto.KeyRing;
import bisq.common.handlers.ErrorMessageHandler;
import bisq.common.handlers.FaultHandler;
import bisq.common.handlers.ResultHandler;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.storage.JsonFileManager;
import bisq.common.storage.Storage;
import bisq.common.util.Utilities;

import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Coin;
Expand All @@ -75,7 +72,6 @@
import org.bitcoinj.core.TransactionConfidence;

import javax.inject.Inject;
import javax.inject.Named;

import com.google.common.util.concurrent.FutureCallback;

Expand All @@ -90,8 +86,6 @@

import org.spongycastle.crypto.params.KeyParameter;

import java.io.File;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -147,8 +141,7 @@ public class TradeManager implements PersistedDataHost {
private final LongProperty numPendingTrades = new SimpleLongProperty();
@Getter
private final ObservableList<Trade> tradesWithoutDepositTx = FXCollections.observableArrayList();
private final boolean dumpDelayedPayoutTxs;
private final JsonFileManager jsonFileManager;
private final DumpDelayedPayoutTx dumpDelayedPayoutTx;


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -176,8 +169,7 @@ public TradeManager(User user,
DaoFacade daoFacade,
ClockWatcher clockWatcher,
Storage<TradableList<Trade>> storage,
@Named(Config.STORAGE_DIR) File storageDir,
@Named(Config.DUMP_DELAYED_PAYOUT_TXS) boolean dumpDelayedPayoutTxs) {
DumpDelayedPayoutTx dumpDelayedPayoutTx) {
this.user = user;
this.keyRing = keyRing;
this.btcWalletService = btcWalletService;
Expand All @@ -197,7 +189,7 @@ public TradeManager(User user,
this.refundAgentManager = refundAgentManager;
this.daoFacade = daoFacade;
this.clockWatcher = clockWatcher;
this.dumpDelayedPayoutTxs = dumpDelayedPayoutTxs;
this.dumpDelayedPayoutTx = dumpDelayedPayoutTx;

tradableListStorage = storage;

Expand Down Expand Up @@ -233,9 +225,6 @@ public TradeManager(User user,
}
}
});

jsonFileManager = new JsonFileManager(storageDir);

}

@Override
Expand All @@ -247,7 +236,8 @@ public void readPersisted() {
if (offer != null)
offer.setPriceFeedService(priceFeedService);
});
maybeDumpDelayedPayoutTxs();

dumpDelayedPayoutTx.maybeDumpDelayedPayoutTxs(tradableList, "delayed_payout_txs_pending");
}


Expand Down Expand Up @@ -793,25 +783,4 @@ else if (now.after(halfTradePeriodDate))
public void persistTrades() {
tradableList.persist();
}

@SuppressWarnings("InnerClassMayBeStatic")
class DelayedPayoutHash {
String tradeId;
String delayedPayoutTx;
DelayedPayoutHash(String tradeId, String delayedPayoutTx) {
this.tradeId = tradeId;
this.delayedPayoutTx = delayedPayoutTx;
}
}

private void maybeDumpDelayedPayoutTxs() {
if (!dumpDelayedPayoutTxs)
return;

var delayedPayoutHashes = tradableList.stream()
.map(trade -> new DelayedPayoutHash(trade.getId(),
Utilities.bytesAsHexString(trade.getDelayedPayoutTxBytes())))
.collect(Collectors.toList());
jsonFileManager.writeToDisc(Utilities.objectToJson(delayedPayoutHashes), "delayed_payout_txs");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.offer.Offer;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.trade.DumpDelayedPayoutTx;
import bisq.core.trade.TradableList;
import bisq.core.trade.Trade;

Expand All @@ -44,17 +45,19 @@ public class FailedTradesManager implements PersistedDataHost {
private final PriceFeedService priceFeedService;
private final BtcWalletService btcWalletService;
private final Storage<TradableList<Trade>> tradableListStorage;
private final DumpDelayedPayoutTx dumpDelayedPayoutTx;

@Inject
public FailedTradesManager(KeyRing keyRing,
PriceFeedService priceFeedService,
BtcWalletService btcWalletService,
Storage<TradableList<Trade>> storage) {
Storage<TradableList<Trade>> storage,
DumpDelayedPayoutTx dumpDelayedPayoutTx) {
this.keyRing = keyRing;
this.priceFeedService = priceFeedService;
this.btcWalletService = btcWalletService;
tradableListStorage = storage;

this.dumpDelayedPayoutTx = dumpDelayedPayoutTx;
}

@Override
Expand All @@ -67,6 +70,8 @@ public void readPersisted() {

trade.setTransientFields(tradableListStorage, btcWalletService);
});

dumpDelayedPayoutTx.maybeDumpDelayedPayoutTxs(failedTrades, "delayed_payout_txs_failed");
}

public void add(Trade trade) {
Expand Down