SHA256
08 01 25
Сделал что бы при создании пользователя передавались три ключа пользователя. И имя блокчейна сделал через "-"
This commit is contained in:
+20
-8
@@ -5,9 +5,9 @@ import org.slf4j.LoggerFactory;
|
||||
import server.logic.ws_protocol.JSON.ConnectionContext;
|
||||
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
||||
import server.logic.ws_protocol.JSON.handlers.tempToTest.entyties.Net_AddUser_Request;
|
||||
import server.logic.ws_protocol.JSON.handlers.tempToTest.entyties.Net_AddUser_Response;
|
||||
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
||||
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
||||
import server.logic.ws_protocol.WireCodes;
|
||||
import shine.db.SqliteDbController;
|
||||
@@ -15,6 +15,7 @@ import shine.db.dao.BlockchainStateDAO;
|
||||
import shine.db.dao.SolanaUsersDAO;
|
||||
import shine.db.entities.BlockchainStateEntry;
|
||||
import shine.db.entities.SolanaUserEntry;
|
||||
import utils.blockchain.BlockchainNameUtil;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
@@ -34,13 +35,24 @@ public class Net_AddUser_Handler implements JsonMessageHandler {
|
||||
if (req.getLogin() == null || req.getLogin().isBlank()
|
||||
|| req.getBlockchainName() == null || req.getBlockchainName().isBlank()
|
||||
|| req.getSolanaKey() == null || req.getSolanaKey().isBlank()
|
||||
|| req.getBlockchainKey() == null || req.getBlockchainKey().isBlank()
|
||||
|| req.getDeviceKey() == null || req.getDeviceKey().isBlank()) {
|
||||
|
||||
return NetExceptionResponseFactory.error(
|
||||
req,
|
||||
WireCodes.Status.BAD_REQUEST,
|
||||
"BAD_FIELDS",
|
||||
"Некорректные поля: login/blockchainName/solanaKey/deviceKey"
|
||||
"Некорректные поля: login/blockchainName/solanaKey/blockchainKey/deviceKey"
|
||||
);
|
||||
}
|
||||
|
||||
// blockchainName должен быть вида: <login>-NNN
|
||||
if (!BlockchainNameUtil.isBlockchainNameMatchesLogin(req.getBlockchainName(), req.getLogin())) {
|
||||
return NetExceptionResponseFactory.error(
|
||||
req,
|
||||
WireCodes.Status.BAD_REQUEST,
|
||||
"BAD_BLOCKCHAIN_NAME",
|
||||
"blockchainName должен быть вида <login>-NNN (пример: anya-001)"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,13 +61,13 @@ public class Net_AddUser_Handler implements JsonMessageHandler {
|
||||
: req.getBchLimit();
|
||||
|
||||
try {
|
||||
byte[] blockchainKey32 = Base64.getDecoder().decode(req.getSolanaKey());
|
||||
byte[] blockchainKey32 = Base64.getDecoder().decode(req.getBlockchainKey());
|
||||
if (blockchainKey32.length != 32) {
|
||||
return NetExceptionResponseFactory.error(
|
||||
req,
|
||||
WireCodes.Status.BAD_REQUEST,
|
||||
"BAD_BLOCKCHAIN_KEY",
|
||||
"solanaKey должен быть Base64(32 bytes)"
|
||||
"blockchainKey должен быть Base64(32 bytes)"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,20 +99,20 @@ public class Net_AddUser_Handler implements JsonMessageHandler {
|
||||
);
|
||||
}
|
||||
|
||||
// 3. Создаём пользователя
|
||||
// 3. Создаём пользователя (solanaKey + deviceKey)
|
||||
SolanaUserEntry user = new SolanaUserEntry(
|
||||
req.getLogin(),
|
||||
req.getDeviceKey(),
|
||||
req.getSolanaKey(),
|
||||
req.getDeviceKey()
|
||||
);
|
||||
|
||||
usersDAO.insert(c, user);
|
||||
|
||||
// 4. Создаём INITIAL blockchain_state
|
||||
// 4. Создаём INITIAL blockchain_state (blockchainKey)
|
||||
BlockchainStateEntry st = new BlockchainStateEntry();
|
||||
st.setBlockchainName(req.getBlockchainName());
|
||||
st.setLogin(req.getLogin());
|
||||
st.setBlockchainKey(req.getSolanaKey()); // Base64(32)
|
||||
st.setBlockchainKey(req.getBlockchainKey()); // Base64(32)
|
||||
st.setLastGlobalNumber(-1);
|
||||
st.setLastGlobalHash(new byte[32]);
|
||||
st.setFileSizeBytes(0);
|
||||
|
||||
+12
@@ -14,6 +14,7 @@ import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||
* "login": "anya",
|
||||
* "blockchainName": "anya0001",
|
||||
* "solanaKey": "base64-ed25519-public-key-login",
|
||||
* "blockchainKey": "base64-ed25519-public-key-blockchain",
|
||||
* "deviceKey": "base64-ed25519-public-key-device",
|
||||
* "bchLimit": 1000000
|
||||
* }
|
||||
@@ -25,8 +26,16 @@ public class Net_AddUser_Request extends Net_Request {
|
||||
|
||||
private String login;
|
||||
private String blockchainName;
|
||||
|
||||
/** Ключ пользователя Solana (публичный ключ логина) */
|
||||
private String solanaKey;
|
||||
|
||||
/** Ключ блокчейна (публичный ключ блокчейна) */
|
||||
private String blockchainKey;
|
||||
|
||||
/** Ключ устройства (публичный ключ устройства) */
|
||||
private String deviceKey;
|
||||
|
||||
private Integer bchLimit;
|
||||
|
||||
public String getLogin() { return login; }
|
||||
@@ -38,6 +47,9 @@ public class Net_AddUser_Request extends Net_Request {
|
||||
public String getSolanaKey() { return solanaKey; }
|
||||
public void setSolanaKey(String solanaKey) { this.solanaKey = solanaKey; }
|
||||
|
||||
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; }
|
||||
|
||||
|
||||
+1
-1
@@ -17,4 +17,4 @@ import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||
*/
|
||||
public class Net_AddUser_Response extends Net_Response {
|
||||
// При необходимости сюда можно добавить, например, флаг created/updated и т.п.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user