mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-13 19:12:33 +00:00
Fix fetching asset-related transactions from DB where asset might not exist.
Some asset-related transactions (CREATE_ASSET_ORDER and TRANSFER_ASSET) also try to fetch asset names at the same time. If one of these transactions, and a corresponding ISSUE_ASSET transaction, have been orphaned then it's possible that the asset no longer exists. Thus the SQL "JOIN" fails during transaction retrieval, causing an error. Changing the table-join to "LEFT OUTER JOIN" makes the asset name aspect optional. Repercussions might be nameless assets when fetching transaction info via API.
This commit is contained in:
parent
3b3888ae0d
commit
c597f11c37
@ -18,10 +18,11 @@ public class HSQLDBCreateAssetOrderTransactionRepository extends HSQLDBTransacti
|
|||||||
}
|
}
|
||||||
|
|
||||||
TransactionData fromBase(BaseTransactionData baseTransactionData) throws DataException {
|
TransactionData fromBase(BaseTransactionData baseTransactionData) throws DataException {
|
||||||
|
// LEFT OUTER JOIN because asset might not exist (e.g. if ISSUE_ASSET & CREATE_ASSET_ORDER are both unconfirmed)
|
||||||
String sql = "SELECT have_asset_id, amount, want_asset_id, price, HaveAsset.asset_name, WantAsset.asset_name "
|
String sql = "SELECT have_asset_id, amount, want_asset_id, price, HaveAsset.asset_name, WantAsset.asset_name "
|
||||||
+ "FROM CreateAssetOrderTransactions "
|
+ "FROM CreateAssetOrderTransactions "
|
||||||
+ "JOIN Assets AS HaveAsset ON HaveAsset.asset_id = have_asset_id "
|
+ "LEFT OUTER JOIN Assets AS HaveAsset ON HaveAsset.asset_id = have_asset_id "
|
||||||
+ "JOIN Assets AS WantAsset ON WantAsset.asset_id = want_asset_id "
|
+ "LEFT OUTER JOIN Assets AS WantAsset ON WantAsset.asset_id = want_asset_id "
|
||||||
+ "WHERE signature = ?";
|
+ "WHERE signature = ?";
|
||||||
|
|
||||||
try (ResultSet resultSet = this.repository.checkedExecute(sql, baseTransactionData.getSignature())) {
|
try (ResultSet resultSet = this.repository.checkedExecute(sql, baseTransactionData.getSignature())) {
|
||||||
|
@ -28,6 +28,7 @@ import org.qora.repository.hsqldb.HSQLDBRepository;
|
|||||||
import org.qora.repository.hsqldb.HSQLDBSaver;
|
import org.qora.repository.hsqldb.HSQLDBSaver;
|
||||||
import org.qora.transaction.Transaction.ApprovalStatus;
|
import org.qora.transaction.Transaction.ApprovalStatus;
|
||||||
import org.qora.transaction.Transaction.TransactionType;
|
import org.qora.transaction.Transaction.TransactionType;
|
||||||
|
import org.qora.utils.Base58;
|
||||||
|
|
||||||
import static org.qora.transaction.Transaction.TransactionType.*;
|
import static org.qora.transaction.Transaction.TransactionType.*;
|
||||||
|
|
||||||
@ -938,7 +939,7 @@ public class HSQLDBTransactionRepository implements TransactionRepository {
|
|||||||
|
|
||||||
if (transactionData == null)
|
if (transactionData == null)
|
||||||
// Something inconsistent with the repository
|
// Something inconsistent with the repository
|
||||||
throw new DataException("Unable to fetch unconfirmed transaction from repository?");
|
throw new DataException(String.format("Unable to fetch unconfirmed transaction %s from repository?", Base58.encode(signature)));
|
||||||
|
|
||||||
transactions.add(transactionData);
|
transactions.add(transactionData);
|
||||||
} while (resultSet.next());
|
} while (resultSet.next());
|
||||||
|
@ -18,7 +18,8 @@ public class HSQLDBTransferAssetTransactionRepository extends HSQLDBTransactionR
|
|||||||
}
|
}
|
||||||
|
|
||||||
TransactionData fromBase(BaseTransactionData baseTransactionData) throws DataException {
|
TransactionData fromBase(BaseTransactionData baseTransactionData) throws DataException {
|
||||||
String sql = "SELECT recipient, asset_id, amount, asset_name FROM TransferAssetTransactions JOIN Assets USING (asset_id) WHERE signature = ?";
|
// LEFT OUTER JOIN because asset might not exist (e.g. if ISSUE_ASSET & TRANSFER_ASSET are both unconfirmed)
|
||||||
|
String sql = "SELECT recipient, asset_id, amount, asset_name FROM TransferAssetTransactions LEFT OUTER JOIN Assets USING (asset_id) WHERE signature = ?";
|
||||||
|
|
||||||
try (ResultSet resultSet = this.repository.checkedExecute(sql, baseTransactionData.getSignature())) {
|
try (ResultSet resultSet = this.repository.checkedExecute(sql, baseTransactionData.getSignature())) {
|
||||||
if (resultSet == null)
|
if (resultSet == null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user