mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-23 04:36:50 +00:00
Improved trade bot backups so that the current order being bought is included.
This should fix any key recovery issues if the node crashes or otherwise fails when buying an offer.
This commit is contained in:
@@ -201,7 +201,7 @@ public class DogecoinACCTv1TradeBot implements AcctTradeBot {
|
||||
TradeBot.updateTradeBotState(repository, tradeBotData, () -> String.format("Built AT %s. Waiting for deployment", atAddress));
|
||||
|
||||
// Attempt to backup the trade bot data
|
||||
TradeBot.backupTradeBotData(repository);
|
||||
TradeBot.backupTradeBotData(repository, null);
|
||||
|
||||
// Return to user for signing and broadcast as we don't have their Qortal private key
|
||||
try {
|
||||
@@ -276,7 +276,8 @@ public class DogecoinACCTv1TradeBot implements AcctTradeBot {
|
||||
crossChainTradeData.expectedForeignAmount, xprv58, null, lockTimeA, receivingPublicKeyHash);
|
||||
|
||||
// Attempt to backup the trade bot data
|
||||
TradeBot.backupTradeBotData(repository);
|
||||
// Include tradeBotData as an additional parameter, since it's not in the repository yet
|
||||
TradeBot.backupTradeBotData(repository, Arrays.asList(tradeBotData));
|
||||
|
||||
// Check we have enough funds via xprv58 to fund P2SH to cover expectedForeignAmount
|
||||
long p2shFee;
|
||||
|
@@ -201,7 +201,7 @@ public class DogecoinACCTv2TradeBot implements AcctTradeBot {
|
||||
TradeBot.updateTradeBotState(repository, tradeBotData, () -> String.format("Built AT %s. Waiting for deployment", atAddress));
|
||||
|
||||
// Attempt to backup the trade bot data
|
||||
TradeBot.backupTradeBotData(repository);
|
||||
TradeBot.backupTradeBotData(repository, null);
|
||||
|
||||
// Return to user for signing and broadcast as we don't have their Qortal private key
|
||||
try {
|
||||
@@ -276,7 +276,8 @@ public class DogecoinACCTv2TradeBot implements AcctTradeBot {
|
||||
crossChainTradeData.expectedForeignAmount, xprv58, null, lockTimeA, receivingPublicKeyHash);
|
||||
|
||||
// Attempt to backup the trade bot data
|
||||
TradeBot.backupTradeBotData(repository);
|
||||
// Include tradeBotData as an additional parameter, since it's not in the repository yet
|
||||
TradeBot.backupTradeBotData(repository, Arrays.asList(tradeBotData));
|
||||
|
||||
// Check we have enough funds via xprv58 to fund P2SH to cover expectedForeignAmount
|
||||
long p2shFee;
|
||||
|
@@ -212,7 +212,7 @@ public class LitecoinACCTv1TradeBot implements AcctTradeBot {
|
||||
TradeBot.updateTradeBotState(repository, tradeBotData, () -> String.format("Built AT %s. Waiting for deployment", atAddress));
|
||||
|
||||
// Attempt to backup the trade bot data
|
||||
TradeBot.backupTradeBotData(repository);
|
||||
TradeBot.backupTradeBotData(repository, null);
|
||||
|
||||
// Return to user for signing and broadcast as we don't have their Qortal private key
|
||||
try {
|
||||
@@ -287,7 +287,8 @@ public class LitecoinACCTv1TradeBot implements AcctTradeBot {
|
||||
crossChainTradeData.expectedForeignAmount, xprv58, null, lockTimeA, receivingPublicKeyHash);
|
||||
|
||||
// Attempt to backup the trade bot data
|
||||
TradeBot.backupTradeBotData(repository);
|
||||
// Include tradeBotData as an additional parameter, since it's not in the repository yet
|
||||
TradeBot.backupTradeBotData(repository, Arrays.asList(tradeBotData));
|
||||
|
||||
// Check we have enough funds via xprv58 to fund P2SH to cover expectedForeignAmount
|
||||
long p2shFee;
|
||||
|
@@ -201,7 +201,7 @@ public class LitecoinACCTv2TradeBot implements AcctTradeBot {
|
||||
TradeBot.updateTradeBotState(repository, tradeBotData, () -> String.format("Built AT %s. Waiting for deployment", atAddress));
|
||||
|
||||
// Attempt to backup the trade bot data
|
||||
TradeBot.backupTradeBotData(repository);
|
||||
TradeBot.backupTradeBotData(repository, null);
|
||||
|
||||
// Return to user for signing and broadcast as we don't have their Qortal private key
|
||||
try {
|
||||
@@ -276,7 +276,8 @@ public class LitecoinACCTv2TradeBot implements AcctTradeBot {
|
||||
crossChainTradeData.expectedForeignAmount, xprv58, null, lockTimeA, receivingPublicKeyHash);
|
||||
|
||||
// Attempt to backup the trade bot data
|
||||
TradeBot.backupTradeBotData(repository);
|
||||
// Include tradeBotData as an additional parameter, since it's not in the repository yet
|
||||
TradeBot.backupTradeBotData(repository, Arrays.asList(tradeBotData));
|
||||
|
||||
// Check we have enough funds via xprv58 to fund P2SH to cover expectedForeignAmount
|
||||
long p2shFee;
|
||||
|
@@ -31,6 +31,7 @@ import org.qortal.gui.SysTray;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.repository.Repository;
|
||||
import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.repository.hsqldb.HSQLDBImportExport;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.transaction.PresenceTransaction;
|
||||
import org.qortal.transaction.PresenceTransaction.PresenceType;
|
||||
@@ -267,11 +268,11 @@ public class TradeBot implements Listener {
|
||||
return secret;
|
||||
}
|
||||
|
||||
/*package*/ static void backupTradeBotData(Repository repository) {
|
||||
/*package*/ static void backupTradeBotData(Repository repository, List<TradeBotData> additional) {
|
||||
// Attempt to backup the trade bot data. This an optional step and doesn't impact trading, so don't throw an exception on failure
|
||||
try {
|
||||
LOGGER.info("About to backup trade bot data...");
|
||||
repository.exportNodeLocalData();
|
||||
HSQLDBImportExport.backupTradeBotStates(repository, additional);
|
||||
} catch (DataException e) {
|
||||
LOGGER.info(String.format("Repository issue when exporting trade bot data: %s", e.getMessage()));
|
||||
}
|
||||
|
@@ -28,9 +28,9 @@ public class HSQLDBImportExport {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(Bootstrap.class);
|
||||
|
||||
public static void backupTradeBotStates(Repository repository) throws DataException {
|
||||
HSQLDBImportExport.backupCurrentTradeBotStates(repository);
|
||||
HSQLDBImportExport.backupArchivedTradeBotStates(repository);
|
||||
public static void backupTradeBotStates(Repository repository, List<TradeBotData> additional) throws DataException {
|
||||
HSQLDBImportExport.backupCurrentTradeBotStates(repository, additional);
|
||||
HSQLDBImportExport.backupArchivedTradeBotStates(repository, additional);
|
||||
|
||||
LOGGER.info("Exported sensitive/node-local data: trade bot states");
|
||||
}
|
||||
@@ -47,14 +47,23 @@ public class HSQLDBImportExport {
|
||||
/**
|
||||
* Backs up the trade bot states currently in the repository, without combining them with past ones
|
||||
* @param repository
|
||||
* @param additional - any optional extra trade bot states to include in the backup
|
||||
* @throws DataException
|
||||
*/
|
||||
private static void backupCurrentTradeBotStates(Repository repository) throws DataException {
|
||||
private static void backupCurrentTradeBotStates(Repository repository, List<TradeBotData> additional) throws DataException {
|
||||
try {
|
||||
Path backupDirectory = HSQLDBImportExport.getExportDirectory(true);
|
||||
|
||||
// Load current trade bot data
|
||||
List<TradeBotData> allTradeBotData = repository.getCrossChainRepository().getAllTradeBotData();
|
||||
|
||||
|
||||
// Add any additional entries if specified
|
||||
if (additional != null && !additional.isEmpty()) {
|
||||
allTradeBotData.addAll(additional);
|
||||
}
|
||||
|
||||
// Convert them to JSON objects
|
||||
JSONArray currentTradeBotDataJson = new JSONArray();
|
||||
for (TradeBotData tradeBotData : allTradeBotData) {
|
||||
JSONObject tradeBotDataJson = tradeBotData.toJson();
|
||||
@@ -82,14 +91,22 @@ public class HSQLDBImportExport {
|
||||
* Backs up the trade bot states currently in the repository to a separate "archive" file,
|
||||
* making sure to combine them with any unique states already present in the archive.
|
||||
* @param repository
|
||||
* @param additional - any optional extra trade bot states to include in the backup
|
||||
* @throws DataException
|
||||
*/
|
||||
private static void backupArchivedTradeBotStates(Repository repository) throws DataException {
|
||||
private static void backupArchivedTradeBotStates(Repository repository, List<TradeBotData> additional) throws DataException {
|
||||
try {
|
||||
Path backupDirectory = HSQLDBImportExport.getExportDirectory(true);
|
||||
|
||||
// Load current trade bot data
|
||||
List<TradeBotData> allTradeBotData = repository.getCrossChainRepository().getAllTradeBotData();
|
||||
|
||||
// Add any additional entries if specified
|
||||
if (additional != null && !additional.isEmpty()) {
|
||||
allTradeBotData.addAll(additional);
|
||||
}
|
||||
|
||||
// Convert them to JSON objects
|
||||
JSONArray allTradeBotDataJson = new JSONArray();
|
||||
for (TradeBotData tradeBotData : allTradeBotData) {
|
||||
JSONObject tradeBotDataJson = tradeBotData.toJson();
|
||||
@@ -263,7 +280,7 @@ public class HSQLDBImportExport {
|
||||
* @param jsonString
|
||||
* @return Triple<String, String, JSONArray> (type, dataset, data)
|
||||
*/
|
||||
private static Triple<String, String, JSONArray> parseJSONString(String jsonString) throws DataException {
|
||||
public static Triple<String, String, JSONArray> parseJSONString(String jsonString) throws DataException {
|
||||
String type = null;
|
||||
String dataset = null;
|
||||
JSONArray data = null;
|
||||
|
@@ -471,7 +471,7 @@ public class HSQLDBRepository implements Repository {
|
||||
|
||||
@Override
|
||||
public void exportNodeLocalData() throws DataException {
|
||||
HSQLDBImportExport.backupTradeBotStates(this);
|
||||
HSQLDBImportExport.backupTradeBotStates(this, null);
|
||||
HSQLDBImportExport.backupMintingAccounts(this);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user