SHA256
Нормализовать ключ free-блокчейна в Base64
This commit is contained in:
+4
-1
@@ -8,6 +8,7 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
/** Только верифицированный сертификат. Локальная БД — проекция Arweave/Solana. */
|
/** Только верифицированный сертификат. Локальная БД — проекция Arweave/Solana. */
|
||||||
public final class VerifiedFreeRegistrationImporter {
|
public final class VerifiedFreeRegistrationImporter {
|
||||||
@@ -113,7 +114,9 @@ public final class VerifiedFreeRegistrationImporter {
|
|||||||
VALUES (?, 1, ?, 100000, 0, -1, ?, ?)
|
VALUES (?, 1, ?, 100000, 0, -1, ?, ?)
|
||||||
""")) {
|
""")) {
|
||||||
insert.setString(1, login);
|
insert.setString(1, login);
|
||||||
insert.setString(2, Base58Util.encode(cert.blockchainKey()));
|
// blockchain_state — runtime-слой: его ключ всегда Base64(32),
|
||||||
|
// как и у пользователей, импортированных из Solana PDA.
|
||||||
|
insert.setString(2, Base64.getEncoder().encodeToString(cert.blockchainKey()));
|
||||||
insert.setBytes(3, new byte[32]);
|
insert.setBytes(3, new byte[32]);
|
||||||
insert.setLong(4, now);
|
insert.setLong(4, now);
|
||||||
insert.executeUpdate();
|
insert.executeUpdate();
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public final class DatabaseInitializer {
|
|||||||
public static final int SCHEMA_VERSION_35 = 35;
|
public static final int SCHEMA_VERSION_35 = 35;
|
||||||
public static final int SCHEMA_VERSION_36 = 36;
|
public static final int SCHEMA_VERSION_36 = 36;
|
||||||
public static final int SCHEMA_VERSION_37 = 37;
|
public static final int SCHEMA_VERSION_37 = 37;
|
||||||
|
public static final int SCHEMA_VERSION_38 = 38;
|
||||||
public static final String POSTGRES_SCHEMA_RESOURCE = "postgres/schema_v1.sql";
|
public static final String POSTGRES_SCHEMA_RESOURCE = "postgres/schema_v1.sql";
|
||||||
public static final String POSTGRES_MIGRATION_V31_RESOURCE = "postgres/migration_v31.sql";
|
public static final String POSTGRES_MIGRATION_V31_RESOURCE = "postgres/migration_v31.sql";
|
||||||
public static final String POSTGRES_MIGRATION_V32_RESOURCE = "postgres/migration_v32.sql";
|
public static final String POSTGRES_MIGRATION_V32_RESOURCE = "postgres/migration_v32.sql";
|
||||||
@@ -36,6 +37,7 @@ public final class DatabaseInitializer {
|
|||||||
public static final String POSTGRES_MIGRATION_V35_RESOURCE = "postgres/migration_v35.sql";
|
public static final String POSTGRES_MIGRATION_V35_RESOURCE = "postgres/migration_v35.sql";
|
||||||
public static final String POSTGRES_MIGRATION_V36_RESOURCE = "postgres/migration_v36.sql";
|
public static final String POSTGRES_MIGRATION_V36_RESOURCE = "postgres/migration_v36.sql";
|
||||||
public static final String POSTGRES_MIGRATION_V37_RESOURCE = "postgres/migration_v37.sql";
|
public static final String POSTGRES_MIGRATION_V37_RESOURCE = "postgres/migration_v37.sql";
|
||||||
|
public static final String POSTGRES_MIGRATION_V38_RESOURCE = "postgres/migration_v38.sql";
|
||||||
|
|
||||||
private DatabaseInitializer() {}
|
private DatabaseInitializer() {}
|
||||||
|
|
||||||
@@ -155,10 +157,15 @@ public final class DatabaseInitializer {
|
|||||||
runSqlScript(conn, POSTGRES_MIGRATION_V37_RESOURCE);
|
runSqlScript(conn, POSTGRES_MIGRATION_V37_RESOURCE);
|
||||||
currentVersion = readCurrentSchemaVersion(conn);
|
currentVersion = readCurrentSchemaVersion(conn);
|
||||||
}
|
}
|
||||||
if (currentVersion != SCHEMA_VERSION_37) {
|
if (currentVersion == SCHEMA_VERSION_37) {
|
||||||
throw new SQLException(
|
runSqlScript(conn, POSTGRES_MIGRATION_V38_RESOURCE);
|
||||||
"Unsupported SHiNE DB v2 schema version: expected 37, found " + currentVersion);
|
currentVersion = readCurrentSchemaVersion(conn);
|
||||||
}
|
}
|
||||||
|
if (currentVersion != SCHEMA_VERSION_38) {
|
||||||
|
throw new SQLException(
|
||||||
|
"Unsupported SHiNE DB v2 schema version: expected 38, found " + currentVersion);
|
||||||
|
}
|
||||||
|
normalizeBlockchainStateKeysToBase64(conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,6 +245,38 @@ public final class DatabaseInitializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* blockchain_state — runtime-проекция: публичный blockchain key хранится
|
||||||
|
* строго как Base64(32). Ранний импорт free-регистраций ошибочно сохранял
|
||||||
|
* Base58, поэтому нормализация выполняется идемпотентно при старте.
|
||||||
|
*/
|
||||||
|
private static void normalizeBlockchainStateKeysToBase64(Connection conn) throws SQLException {
|
||||||
|
record StateKey(String login, int forkNumber, String key) {}
|
||||||
|
List<StateKey> entries = new ArrayList<>();
|
||||||
|
try (Statement st = conn.createStatement();
|
||||||
|
ResultSet rs = st.executeQuery("SELECT login, fork_number, blockchain_key FROM blockchain_state_store")) {
|
||||||
|
while (rs.next()) {
|
||||||
|
entries.add(new StateKey(rs.getString("login"), rs.getInt("fork_number"), rs.getString("blockchain_key")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try (var update = conn.prepareStatement("""
|
||||||
|
UPDATE blockchain_state_store
|
||||||
|
SET blockchain_key = ?
|
||||||
|
WHERE login = ? AND fork_number = ?
|
||||||
|
""")) {
|
||||||
|
for (StateKey entry : entries) {
|
||||||
|
String normalized = KeyEncodingUtil.normalizeKeyToBase64_32(entry.key());
|
||||||
|
if (normalized == null || normalized.equals(entry.key())) continue;
|
||||||
|
update.setString(1, normalized);
|
||||||
|
update.setString(2, entry.login());
|
||||||
|
update.setInt(3, entry.forkNumber());
|
||||||
|
update.addBatch();
|
||||||
|
}
|
||||||
|
update.executeBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void runSqlScript(Connection conn, String resourcePath) throws SQLException {
|
private static void runSqlScript(Connection conn, String resourcePath) throws SQLException {
|
||||||
String sqlScript = loadClasspathResource(resourcePath);
|
String sqlScript = loadClasspathResource(resourcePath);
|
||||||
List<String> statements = splitSqlStatements(sqlScript);
|
List<String> statements = splitSqlStatements(sqlScript);
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
-- v38: blockchain_state_store.blockchain_key — runtime Base64(32).
|
||||||
|
-- Исторические Base58-значения нормализуются Java bootstrapper-ом,
|
||||||
|
-- поскольку PostgreSQL не содержит встроенного корректного Base58 decoder.
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
UPDATE db_schema_version
|
||||||
|
SET schema_version = 38,
|
||||||
|
updated_at_ms = CAST(EXTRACT(EPOCH FROM clock_timestamp()) * 1000 AS BIGINT)
|
||||||
|
WHERE id = 1;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
client.version=1.20.10
|
client.version=1.20.10
|
||||||
server.version=1.16.9
|
server.version=1.16.10
|
||||||
|
|||||||
Reference in New Issue
Block a user