mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-30 09:05:52 +00:00
ATData no longer needs deploySignature as a link back to DeployATTransaction, but does need creator and creation [timestamp]. "creation" is critical for ordering ATs when creating/validating blocks. Similar changes to ATStateData, adding creation, stateHash (for quicker comparison with blocks received over the network), and fees incurred by running AT on that block. Also added more explicit constructors for different scenarios. BlockData upgraded from simplistic "atBytes" to use ATStateData (above) which has details on ATs run for that block, fees incurred, and a hash of the AT's state. atCount added to keep track of how many ATs ran. ATTransactions essentially reuse the GenesisAccount's publickey as creator/sender as they're brought into existence by the Qora code rather than an end user. ATTransactionData updated to reflect this and the AT's address used as a "sender" field. Account tidied up with respect to CIYAM ATs and setConfirmedBalance ensures there is a corresponding record in Accounts (DB table). Account, and subclasses, don't need "throws DataException" on constructor any more. Fixed bug in Asset Order matching where the matching engine would give up after first potential match instead of trying others. Lots more work on CIYAM AT, albeit mainly blind importing of old v1 ATs from static JSON file as they're all dead and new v2 implementation is not backwards compatible. More work on Blocks, mostly AT stuff, but also fork-based corruption prevention using fix from Qora v1. Payment-related transactions (multipayment, etc.) always expect/use non-null (albeit maybe empty) list of PaymentData when validating, processing or orphaning. Mainly a change in HSQLDBTransactionRepository.getPayments() Payment.isValid(byte[], PaymentData, BigDecimal, boolean isZeroAmountValid) didn't pass on isZeroAmountValid to called method - whoops! Lots of work on ATTransactions themselves. MessageTransactions incorrectly assumed the optional payment was always in Qora. Now fixed to use the transaction's provided assetId. Mass of fixes/additions to HSQLDBATRepository, especially fixing incorrect reference to Assets DB table! In HSQLDBDatabaseUpdates, bump QoraAmount type from DECIMAL(19,8) to DECIMAL(27,8) to allow for huge asset quantities. You WILL have to rebuild your database!
111 lines
3.3 KiB
Java
111 lines
3.3 KiB
Java
package repository.hsqldb;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
|
|
import data.account.AccountBalanceData;
|
|
import data.account.AccountData;
|
|
import repository.AccountRepository;
|
|
import repository.DataException;
|
|
|
|
public class HSQLDBAccountRepository implements AccountRepository {
|
|
|
|
protected HSQLDBRepository repository;
|
|
|
|
public HSQLDBAccountRepository(HSQLDBRepository repository) {
|
|
this.repository = repository;
|
|
}
|
|
|
|
// General account
|
|
|
|
@Override
|
|
public void create(String address) throws DataException {
|
|
HSQLDBSaver saveHelper = new HSQLDBSaver("Accounts");
|
|
|
|
saveHelper.bind("account", address);
|
|
|
|
try {
|
|
saveHelper.execute(this.repository);
|
|
} catch (SQLException e) {
|
|
throw new DataException("Unable to create account in repository", e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public AccountData getAccount(String address) throws DataException {
|
|
try (ResultSet resultSet = this.repository.checkedExecute("SELECT reference FROM Accounts WHERE account = ?", address)) {
|
|
if (resultSet == null)
|
|
return null;
|
|
|
|
return new AccountData(address, resultSet.getBytes(1));
|
|
} catch (SQLException e) {
|
|
throw new DataException("Unable to fetch account info from repository", e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void save(AccountData accountData) throws DataException {
|
|
HSQLDBSaver saveHelper = new HSQLDBSaver("Accounts");
|
|
|
|
saveHelper.bind("account", accountData.getAddress()).bind("reference", accountData.getReference());
|
|
|
|
try {
|
|
saveHelper.execute(this.repository);
|
|
} catch (SQLException e) {
|
|
throw new DataException("Unable to save account info into repository", e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void delete(String address) throws DataException {
|
|
// NOTE: Account balances are deleted automatically by the database thanks to "ON DELETE CASCADE" in AccountBalances' FOREIGN KEY
|
|
// definition.
|
|
try {
|
|
this.repository.delete("Accounts", "account = ?", address);
|
|
} catch (SQLException e) {
|
|
throw new DataException("Unable to delete account from repository", e);
|
|
}
|
|
}
|
|
|
|
// Account balances
|
|
|
|
@Override
|
|
public AccountBalanceData getBalance(String address, long assetId) throws DataException {
|
|
try (ResultSet resultSet = this.repository.checkedExecute("SELECT balance FROM AccountBalances WHERE account = ? and asset_id = ?", address, assetId)) {
|
|
if (resultSet == null)
|
|
return null;
|
|
|
|
BigDecimal balance = resultSet.getBigDecimal(1).setScale(8);
|
|
|
|
return new AccountBalanceData(address, assetId, balance);
|
|
} catch (SQLException e) {
|
|
throw new DataException("Unable to fetch account balance from repository", e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void save(AccountBalanceData accountBalanceData) throws DataException {
|
|
HSQLDBSaver saveHelper = new HSQLDBSaver("AccountBalances");
|
|
|
|
saveHelper.bind("account", accountBalanceData.getAddress()).bind("asset_id", accountBalanceData.getAssetId()).bind("balance",
|
|
accountBalanceData.getBalance());
|
|
|
|
try {
|
|
saveHelper.execute(this.repository);
|
|
} catch (SQLException e) {
|
|
throw new DataException("Unable to save account balance into repository", e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void delete(String address, long assetId) throws DataException {
|
|
try {
|
|
this.repository.delete("AccountBalances", "account = ? and asset_id = ?", address, assetId);
|
|
} catch (SQLException e) {
|
|
throw new DataException("Unable to delete account balance from repository", e);
|
|
}
|
|
}
|
|
|
|
}
|