Move dump delaytx to separate class

This commit is contained in:
sqrrm 2020-03-05 18:28:08 +01:00
parent a926f2b260
commit 40fb1ab49f
No known key found for this signature in database
GPG key ID: 45235F9EF87089EC
2 changed files with 49 additions and 23 deletions

View file

@ -0,0 +1,45 @@
/*
* 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.storage.JsonFileManager;
import bisq.common.util.Utilities;
import java.util.stream.Collectors;
class DumpDelayedPayoutTx {
static class DelayedPayoutHash {
String tradeId;
String delayedPayoutTx;
DelayedPayoutHash(String tradeId, String delayedPayoutTx) {
this.tradeId = tradeId;
this.delayedPayoutTx = delayedPayoutTx;
}
}
static void dumpDelayedPayoutTxs(TradableList<Trade> tradableList, JsonFileManager jsonFileManager,
String fileName) {
var delayedPayoutHashes = tradableList.stream()
.map(trade -> new DelayedPayoutHash(trade.getId(),
Utilities.bytesAsHexString(trade.getDelayedPayoutTxBytes())))
.collect(Collectors.toList());
jsonFileManager.writeToDisc(Utilities.objectToJson(delayedPayoutHashes), fileName);
}
}

View file

@ -66,7 +66,6 @@ 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;
@ -247,7 +246,10 @@ public class TradeManager implements PersistedDataHost {
if (offer != null)
offer.setPriceFeedService(priceFeedService);
});
maybeDumpDelayedPayoutTxs();
if (dumpDelayedPayoutTxs){
DumpDelayedPayoutTx.dumpDelayedPayoutTxs(tradableList, jsonFileManager, "delayed_payout_txs");
}
}
@ -793,25 +795,4 @@ public class TradeManager implements PersistedDataHost {
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");
}
}