Миграция PDA на client.key

This commit is contained in:
AidarKC
2026-06-22 21:57:09 +04:00
parent ba348dafb3
commit 5c92b6a734
133 changed files with 941 additions and 30531 deletions
File diff suppressed because it is too large Load Diff
@@ -1,20 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
OUTFILE="all_files.txt"
# очищаем или создаём файл
: > "$OUTFILE"
# собрать только *.java файлы и вывести их содержимое в файл
find . -type f -name "*.java" | sort | while read -r f; do
cat "$f" >> "$OUTFILE"
echo >> "$OUTFILE" # пустая строка-разделитель
done
# скопировать весь файл в буфер обмена (Wayland)
wl-copy < "$OUTFILE"
echo "Готово!"
echo "Все .java файлы собраны в $OUTFILE"
echo "Содержимое скопировано в буфер обмена (Wayland)"
@@ -140,7 +140,7 @@ public final class DatabaseInitializer {
// 1. solana_users
// ВАЖНО:
// - Все требуемые поля теперь лежат в solana_users:
// login, blockchain_name, solana_key, blockchain_key, device_key
// login, blockchain_name, solana_key, blockchain_key, client_key
// - Поиск по login в DAO сделан case-insensitive.
// - Для защиты от дублей "Anya" и "anya" добавляем COLLATE NOCASE на PRIMARY KEY.
st.executeUpdate("""
@@ -149,7 +149,7 @@ public final class DatabaseInitializer {
blockchain_name TEXT NOT NULL,
solana_key TEXT NOT NULL,
blockchain_key TEXT NOT NULL,
device_key TEXT NOT NULL
client_key TEXT NOT NULL
);
""");
@@ -238,7 +238,7 @@ public final class DatabaseInitializer {
param TEXT NOT NULL,
time_ms INTEGER NOT NULL,
value TEXT NOT NULL,
device_key TEXT,
client_key TEXT,
signature TEXT,
FOREIGN KEY (login) REFERENCES solana_users(login),
UNIQUE (login, param)
@@ -17,7 +17,7 @@ import java.util.List;
* - blockchain_name TEXT NOT NULL
* - solana_key TEXT NOT NULL
* - blockchain_key TEXT NOT NULL
* - device_key TEXT NOT NULL
* - client_key TEXT NOT NULL
*
* Правило работы с соединениями:
* - методы с Connection НЕ закрывают соединение
@@ -45,7 +45,7 @@ public final class SolanaUsersDAO {
public void insert(Connection c, SolanaUserEntry user) throws SQLException {
String sql = """
INSERT INTO solana_users (
login, blockchain_name, solana_key, blockchain_key, device_key
login, blockchain_name, solana_key, blockchain_key, client_key
) VALUES (?, ?, ?, ?, ?)
""";
@@ -54,7 +54,7 @@ public final class SolanaUsersDAO {
ps.setString(2, user.getBlockchainName());
ps.setString(3, user.getSolanaKey());
ps.setString(4, user.getBlockchainKey());
ps.setString(5, user.getDeviceKey());
ps.setString(5, user.getClientKey());
ps.executeUpdate();
}
}
@@ -126,7 +126,7 @@ public final class SolanaUsersDAO {
blockchain_name,
solana_key,
blockchain_key,
device_key
client_key
FROM solana_users
WHERE LOWER(login) = LOWER(?)
""";
@@ -155,7 +155,7 @@ public final class SolanaUsersDAO {
blockchain_name,
solana_key,
blockchain_key,
device_key
client_key
FROM solana_users
WHERE blockchain_name = ?
""";
@@ -184,7 +184,7 @@ public final class SolanaUsersDAO {
blockchain_name,
solana_key,
blockchain_key,
device_key
client_key
FROM solana_users
WHERE LOWER(login) LIKE ?
ORDER BY login
@@ -219,7 +219,7 @@ public final class SolanaUsersDAO {
e.setBlockchainName(rs.getString("blockchain_name"));
e.setSolanaKey(rs.getString("solana_key"));
e.setBlockchainKey(rs.getString("blockchain_key"));
e.setDeviceKey(rs.getString("device_key"));
e.setClientKey(rs.getString("client_key"));
return e;
}
@@ -7,7 +7,7 @@ import java.sql.*;
/**
* UserCreateDAO — атомарное добавление пользователя:
* - solana_users (login, blockchain_name, solana_key, blockchain_key, device_key)
* - solana_users (login, blockchain_name, solana_key, blockchain_key, client_key)
* - blockchain_state (blockchain_name, login, blockchain_key, size_limit, ... last_block_number=-1 ...)
*
* ВАЖНО:
@@ -39,7 +39,7 @@ public final class UserCreateDAO {
String blockchainName,
String solanaKey,
String blockchainKey,
String deviceKey,
String clientKey,
long sizeLimit,
long nowMs
) throws SQLException {
@@ -55,7 +55,7 @@ public final class UserCreateDAO {
u.setBlockchainName(blockchainName);
u.setSolanaKey(solanaKey);
u.setBlockchainKey(blockchainKey);
u.setDeviceKey(deviceKey);
u.setClientKey(clientKey);
usersDao.insert(c, u); // если login занят (NOCASE) или blockchainName (unique) -> constraint
@@ -43,14 +43,14 @@ public final class UserParamsDAO {
param,
time_ms,
value,
device_key,
client_key,
signature
) VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT(login, param)
DO UPDATE SET
time_ms = excluded.time_ms,
value = excluded.value,
device_key = excluded.device_key,
client_key = excluded.client_key,
signature = excluded.signature
WHERE users_params.time_ms < excluded.time_ms
""";
@@ -61,7 +61,7 @@ public final class UserParamsDAO {
ps.setLong(3, e.getTimeMs());
ps.setString(4, e.getValue());
if (e.getDeviceKey() != null) ps.setString(5, e.getDeviceKey());
if (e.getClientKey() != null) ps.setString(5, e.getClientKey());
else ps.setNull(5, Types.VARCHAR);
if (e.getSignature() != null) ps.setString(6, e.getSignature());
@@ -86,7 +86,7 @@ public final class UserParamsDAO {
param,
time_ms,
value,
device_key,
client_key,
signature
FROM users_params
WHERE login = ? COLLATE NOCASE AND param = ?
@@ -117,7 +117,7 @@ public final class UserParamsDAO {
param,
time_ms,
value,
device_key,
client_key,
signature
FROM users_params
WHERE login = ? COLLATE NOCASE
@@ -149,9 +149,9 @@ public final class UserParamsDAO {
e.setTimeMs(rs.getLong("time_ms"));
e.setValue(rs.getString("value"));
String dk = rs.getString("device_key");
String dk = rs.getString("client_key");
if (rs.wasNull()) dk = null;
e.setDeviceKey(dk);
e.setClientKey(dk);
String sig = rs.getString("signature");
if (rs.wasNull()) sig = null;
@@ -12,7 +12,7 @@ import java.util.Base64;
* - blockchain_name — TEXT NOT NULL
* - solana_key — TEXT NOT NULL
* - blockchain_key — TEXT NOT NULL
* - device_key — TEXT NOT NULL
* - client_key — TEXT NOT NULL
*/
public class SolanaUserEntry {
@@ -27,7 +27,7 @@ public class SolanaUserEntry {
private String blockchainKey;
/** Ключ устройства (публичный ключ устройства) */
private String deviceKey;
private String clientKey;
public SolanaUserEntry() {}
@@ -35,12 +35,12 @@ public class SolanaUserEntry {
String blockchainName,
String solanaKey,
String blockchainKey,
String deviceKey) {
String clientKey) {
this.login = login;
this.blockchainName = blockchainName;
this.solanaKey = solanaKey;
this.blockchainKey = blockchainKey;
this.deviceKey = deviceKey;
this.clientKey = clientKey;
}
public String getLogin() { return login; }
@@ -55,13 +55,13 @@ public class SolanaUserEntry {
public String getBlockchainKey() { return blockchainKey; }
public void setBlockchainKey(String blockchainKey) { this.blockchainKey = blockchainKey; }
public String getDeviceKey() { return deviceKey; }
public void setDeviceKey(String deviceKey) { this.deviceKey = deviceKey; }
public String getClientKey() { return clientKey; }
public void setClientKey(String clientKey) { this.clientKey = clientKey; }
// оставляю этот метод как утилиту (иногда удобно), но он работает только для deviceKey:
public byte[] getDeviceKeyByte() {
if (deviceKey == null) return null;
String s = deviceKey.trim();
// оставляю этот метод как утилиту (иногда удобно), но он работает только для clientKey:
public byte[] getClientKeyByte() {
if (clientKey == null) return null;
String s = clientKey.trim();
if (s.isEmpty()) return null;
try {
@@ -8,7 +8,7 @@ package shine.db.entities;
* - param TEXT NOT NULL
* - time_ms INTEGER NOT NULL
* - value TEXT NOT NULL
* - device_key TEXT NULL
* - client_key TEXT NULL
* - signature TEXT NULL
*/
public class UserParamEntry {
@@ -18,17 +18,17 @@ public class UserParamEntry {
private long timeMs;
private String value;
private String deviceKey;
private String clientKey;
private String signature;
public UserParamEntry() {}
public UserParamEntry(String login, String param, long timeMs, String value, String deviceKey, String signature) {
public UserParamEntry(String login, String param, long timeMs, String value, String clientKey, String signature) {
this.login = login;
this.param = param;
this.timeMs = timeMs;
this.value = value;
this.deviceKey = deviceKey;
this.clientKey = clientKey;
this.signature = signature;
}
@@ -44,8 +44,8 @@ public class UserParamEntry {
public String getValue() { return value; }
public void setValue(String value) { this.value = value; }
public String getDeviceKey() { return deviceKey; }
public void setDeviceKey(String deviceKey) { this.deviceKey = deviceKey; }
public String getClientKey() { return clientKey; }
public void setClientKey(String clientKey) { this.clientKey = clientKey; }
public String getSignature() { return signature; }
public void setSignature(String signature) { this.signature = signature; }