Browse Source

Combined account balance fixes needed for unit tests

pull/67/head
catbref 4 years ago
parent
commit
136188339d
  1. 6
      src/main/java/org/qortal/account/Account.java
  2. 4
      src/main/java/org/qortal/payment/Payment.java
  3. 3
      src/main/java/org/qortal/repository/hsqldb/HSQLDBAssetRepository.java

6
src/main/java/org/qortal/account/Account.java

@ -77,6 +77,12 @@ public class Account {
throw new DataException(message);
}
// Delete account balance record instead of setting balance to zero
if (balance.signum() == 0) {
this.repository.getAccountRepository().delete(this.address, assetId);
return;
}
// Can't have a balance without an account - make sure it exists!
this.repository.getAccountRepository().ensureAccount(this.buildAccountData());

4
src/main/java/org/qortal/payment/Payment.java

@ -250,8 +250,10 @@ public class Payment {
* For QORT amounts only: If recipient's last reference is this transaction's signature, then they can't have made any transactions of their own
* (which would have changed their last reference) thus this is their first reference so remove it.
*/
if ((alwaysUninitializeRecipientReference || assetId == Asset.QORT) && Arrays.equals(recipient.getLastReference(), signature))
if ((alwaysUninitializeRecipientReference || assetId == Asset.QORT) && Arrays.equals(recipient.getLastReference(), signature)) {
recipient.setLastReference(null);
this.repository.getAccountRepository().delete(recipient.getAddress(), assetId);
}
}
}

3
src/main/java/org/qortal/repository/hsqldb/HSQLDBAssetRepository.java

@ -188,6 +188,9 @@ public class HSQLDBAssetRepository implements AssetRepository {
public void delete(long assetId) throws DataException {
try {
this.repository.delete("Assets", "asset_id = ?", assetId);
// Also delete account balances that refer to asset
this.repository.delete("AccountBalances", "asset_id = ?", assetId);
} catch (SQLException e) {
throw new DataException("Unable to delete asset from repository", e);
}

Loading…
Cancel
Save