Save public keys from CHAT transactions so they can be fetched via API.

This commit is contained in:
catbref 2020-05-20 15:53:43 +01:00
parent 9c48343581
commit 5f4b66e5b0
3 changed files with 16 additions and 3 deletions

View File

@ -52,6 +52,10 @@ public class Account {
return new AccountData(this.address);
}
public void ensureAccount() throws DataException {
this.repository.getAccountRepository().ensureAccount(this.buildAccountData());
}
// Balance manipulations - assetId is 0 for QORT
public long getConfirmedBalance(long assetId) throws DataException {
@ -77,7 +81,7 @@ public class Account {
}
// Can't have a balance without an account - make sure it exists!
this.repository.getAccountRepository().ensureAccount(this.buildAccountData());
this.ensureAccount();
AccountBalanceData accountBalanceData = new AccountBalanceData(this.address, assetId, balance);
this.repository.getAccountRepository().save(accountBalanceData);

View File

@ -143,9 +143,9 @@ public class HSQLDBAccountRepository implements AccountRepository {
@Override
public void ensureAccount(AccountData accountData) throws DataException {
String sql = "INSERT IGNORE INTO Accounts (account) VALUES (?)"; // MySQL syntax
String sql = "INSERT IGNORE INTO Accounts (account, public_key) VALUES (?, ?)"; // MySQL syntax
try {
this.repository.checkedExecuteUpdateCount(sql, accountData.getAddress());
this.repository.checkedExecuteUpdateCount(sql, accountData.getAddress(), accountData.getPublicKey());
} catch (SQLException e) {
throw new DataException("Unable to ensure minimal account in repository", e);
}

View File

@ -794,6 +794,15 @@ public abstract class Transaction {
repository.getTransactionRepository().save(transactionData);
repository.getTransactionRepository().unconfirmTransaction(transactionData);
/*
* If CHAT transaction then ensure there's at least a skeleton account so people
* can retrieve sender's public key using address, even if all their messages
* expire.
*/
if (transactionData.getType() == TransactionType.CHAT)
this.getCreator().ensureAccount();
repository.saveChanges();
return ValidationResult.OK;