SHA256
07 01 25
refactor: перевели хэши на BLOB и добавили поля block_hash / block_signature / edited_by_block_global_number и главное добавили тип блока изменение сообщение и сслку на последнее изменение в табл блокс
This commit is contained in:
@@ -9,11 +9,11 @@ public class BlockEntry {
|
||||
private String bchName;
|
||||
|
||||
private int blockGlobalNumber;
|
||||
private String blockGlobalPreHashe;
|
||||
private byte[] blockGlobalPreHashe;
|
||||
|
||||
private int blockLineIndex;
|
||||
private int blockLineNumber;
|
||||
private String blockLinePreHashe;
|
||||
private byte[] blockLinePreHashe;
|
||||
|
||||
private int msgType;
|
||||
private int msgSubType;
|
||||
@@ -23,24 +23,32 @@ public class BlockEntry {
|
||||
private String toLogin;
|
||||
private String toBchName;
|
||||
private Integer toBlockGlobalNumber;
|
||||
private String toBlockHashe;
|
||||
private byte[] toBlockHashe;
|
||||
|
||||
// новое
|
||||
private byte[] blockHash;
|
||||
private byte[] blockSignature;
|
||||
private Integer editedByBlockGlobalNumber;
|
||||
|
||||
public BlockEntry() {}
|
||||
|
||||
public BlockEntry(String login,
|
||||
String bchName,
|
||||
int blockGlobalNumber,
|
||||
String blockGlobalPreHashe,
|
||||
byte[] blockGlobalPreHashe,
|
||||
int blockLineIndex,
|
||||
int blockLineNumber,
|
||||
String blockLinePreHashe,
|
||||
byte[] blockLinePreHashe,
|
||||
int msgType,
|
||||
int msgSubType,
|
||||
byte[] blockByte,
|
||||
String toLogin,
|
||||
String toBchName,
|
||||
Integer toBlockGlobalNumber,
|
||||
String toBlockHashe) {
|
||||
byte[] toBlockHashe,
|
||||
byte[] blockHash,
|
||||
byte[] blockSignature,
|
||||
Integer editedByBlockGlobalNumber) {
|
||||
this.login = login;
|
||||
this.bchName = bchName;
|
||||
this.blockGlobalNumber = blockGlobalNumber;
|
||||
@@ -55,6 +63,9 @@ public class BlockEntry {
|
||||
this.toBchName = toBchName;
|
||||
this.toBlockGlobalNumber = toBlockGlobalNumber;
|
||||
this.toBlockHashe = toBlockHashe;
|
||||
this.blockHash = blockHash;
|
||||
this.blockSignature = blockSignature;
|
||||
this.editedByBlockGlobalNumber = editedByBlockGlobalNumber;
|
||||
}
|
||||
|
||||
public String getLogin() { return login; }
|
||||
@@ -66,8 +77,8 @@ public class BlockEntry {
|
||||
public int getBlockGlobalNumber() { return blockGlobalNumber; }
|
||||
public void setBlockGlobalNumber(int blockGlobalNumber) { this.blockGlobalNumber = blockGlobalNumber; }
|
||||
|
||||
public String getBlockGlobalPreHashe() { return blockGlobalPreHashe; }
|
||||
public void setBlockGlobalPreHashe(String blockGlobalPreHashe) { this.blockGlobalPreHashe = blockGlobalPreHashe; }
|
||||
public byte[] getBlockGlobalPreHashe() { return blockGlobalPreHashe; }
|
||||
public void setBlockGlobalPreHashe(byte[] blockGlobalPreHashe) { this.blockGlobalPreHashe = blockGlobalPreHashe; }
|
||||
|
||||
public int getBlockLineIndex() { return blockLineIndex; }
|
||||
public void setBlockLineIndex(int blockLineIndex) { this.blockLineIndex = blockLineIndex; }
|
||||
@@ -75,8 +86,8 @@ public class BlockEntry {
|
||||
public int getBlockLineNumber() { return blockLineNumber; }
|
||||
public void setBlockLineNumber(int blockLineNumber) { this.blockLineNumber = blockLineNumber; }
|
||||
|
||||
public String getBlockLinePreHashe() { return blockLinePreHashe; }
|
||||
public void setBlockLinePreHashe(String blockLinePreHashe) { this.blockLinePreHashe = blockLinePreHashe; }
|
||||
public byte[] getBlockLinePreHashe() { return blockLinePreHashe; }
|
||||
public void setBlockLinePreHashe(byte[] blockLinePreHashe) { this.blockLinePreHashe = blockLinePreHashe; }
|
||||
|
||||
public int getMsgType() { return msgType; }
|
||||
public void setMsgType(int msgType) { this.msgType = msgType; }
|
||||
@@ -96,6 +107,15 @@ public class BlockEntry {
|
||||
public Integer getToBlockGlobalNumber() { return toBlockGlobalNumber; }
|
||||
public void setToBlockGlobalNumber(Integer toBlockGlobalNumber) { this.toBlockGlobalNumber = toBlockGlobalNumber; }
|
||||
|
||||
public String getToBlockHashe() { return toBlockHashe; }
|
||||
public void setToBlockHashe(String toBlockHashe) { this.toBlockHashe = toBlockHashe; }
|
||||
public byte[] getToBlockHashe() { return toBlockHashe; }
|
||||
public void setToBlockHashe(byte[] toBlockHashe) { this.toBlockHashe = toBlockHashe; }
|
||||
|
||||
public byte[] getBlockHash() { return blockHash; }
|
||||
public void setBlockHash(byte[] blockHash) { this.blockHash = blockHash; }
|
||||
|
||||
public byte[] getBlockSignature() { return blockSignature; }
|
||||
public void setBlockSignature(byte[] blockSignature) { this.blockSignature = blockSignature; }
|
||||
|
||||
public Integer getEditedByBlockGlobalNumber() { return editedByBlockGlobalNumber; }
|
||||
public void setEditedByBlockGlobalNumber(Integer editedByBlockGlobalNumber) { this.editedByBlockGlobalNumber = editedByBlockGlobalNumber; }
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
// =======================
|
||||
// BlockchainStateEntry.java (НОВАЯ ВЕРСИЯ)
|
||||
// =======================
|
||||
package shine.db.entities;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -6,6 +9,11 @@ import java.util.Base64;
|
||||
/**
|
||||
* Агрегатная сущность текущего состояния блокчейна.
|
||||
* 1 строка = 1 blockchain_name, плюс состояние линий 0..7.
|
||||
*
|
||||
* ВАЖНО:
|
||||
* - hash-поля теперь храним как byte[] и допускаем NULL:
|
||||
* * NULL = "ещё не было ни одного блока" (genesis и т.п.)
|
||||
* * не подменяем на new byte[0], чтобы не терять смысл
|
||||
*/
|
||||
public final class BlockchainStateEntry {
|
||||
|
||||
@@ -18,16 +26,15 @@ public final class BlockchainStateEntry {
|
||||
private long fileSizeBytes;
|
||||
|
||||
private int lastGlobalNumber;
|
||||
private String lastGlobalHash;
|
||||
private byte[] lastGlobalHash; // nullable
|
||||
|
||||
private final int[] lastLineNumbers = new int[8];
|
||||
private final String[] lastLineHashes = new String[8];
|
||||
private final byte[][] lastLineHashes = new byte[8][]; // nullable elements
|
||||
|
||||
private long updatedAtMs;
|
||||
|
||||
public BlockchainStateEntry() {
|
||||
for (int i = 0; i < 8; i++) lastLineHashes[i] = "";
|
||||
this.lastGlobalHash = "";
|
||||
// hashes остаются null по умолчанию (genesis)
|
||||
}
|
||||
|
||||
public BlockchainStateEntry(String blockchainName,
|
||||
@@ -36,9 +43,9 @@ public final class BlockchainStateEntry {
|
||||
long sizeLimit,
|
||||
long fileSizeBytes,
|
||||
int lastGlobalNumber,
|
||||
String lastGlobalHash,
|
||||
byte[] lastGlobalHash,
|
||||
int[] lastLineNumbers,
|
||||
String[] lastLineHashes,
|
||||
byte[][] lastLineHashes,
|
||||
long updatedAtMs) {
|
||||
this.blockchainName = blockchainName;
|
||||
this.login = login;
|
||||
@@ -46,17 +53,16 @@ public final class BlockchainStateEntry {
|
||||
this.sizeLimit = sizeLimit;
|
||||
this.fileSizeBytes = fileSizeBytes;
|
||||
this.lastGlobalNumber = lastGlobalNumber;
|
||||
this.lastGlobalHash = lastGlobalHash == null ? "" : lastGlobalHash;
|
||||
this.lastGlobalHash = lastGlobalHash;
|
||||
|
||||
if (lastLineNumbers != null) {
|
||||
if (lastLineNumbers.length != 8) throw new IllegalArgumentException("lastLineNumbers must be len=8");
|
||||
System.arraycopy(lastLineNumbers, 0, this.lastLineNumbers, 0, 8);
|
||||
}
|
||||
|
||||
if (lastLineHashes != null) {
|
||||
if (lastLineHashes.length != 8) throw new IllegalArgumentException("lastLineHashes must be len=8");
|
||||
for (int i = 0; i < 8; i++) this.lastLineHashes[i] = lastLineHashes[i] == null ? "" : lastLineHashes[i];
|
||||
} else {
|
||||
for (int i = 0; i < 8; i++) this.lastLineHashes[i] = "";
|
||||
System.arraycopy(lastLineHashes, 0, this.lastLineHashes, 0, 8);
|
||||
}
|
||||
|
||||
this.updatedAtMs = updatedAtMs;
|
||||
@@ -92,8 +98,8 @@ public final class BlockchainStateEntry {
|
||||
public int getLastGlobalNumber() { return lastGlobalNumber; }
|
||||
public void setLastGlobalNumber(int lastGlobalNumber) { this.lastGlobalNumber = lastGlobalNumber; }
|
||||
|
||||
public String getLastGlobalHash() { return lastGlobalHash; }
|
||||
public void setLastGlobalHash(String lastGlobalHash) { this.lastGlobalHash = lastGlobalHash == null ? "" : lastGlobalHash; }
|
||||
public byte[] getLastGlobalHash() { return lastGlobalHash; }
|
||||
public void setLastGlobalHash(byte[] lastGlobalHash) { this.lastGlobalHash = lastGlobalHash; }
|
||||
|
||||
public int getLastLineNumber(int line) {
|
||||
checkLine(line);
|
||||
@@ -104,17 +110,22 @@ public final class BlockchainStateEntry {
|
||||
lastLineNumbers[line] = value;
|
||||
}
|
||||
|
||||
public String getLastLineHash(int line) {
|
||||
public byte[] getLastLineHash(int line) {
|
||||
checkLine(line);
|
||||
return lastLineHashes[line];
|
||||
}
|
||||
public void setLastLineHash(int line, String value) {
|
||||
public void setLastLineHash(int line, byte[] value) {
|
||||
checkLine(line);
|
||||
lastLineHashes[line] = value == null ? "" : value;
|
||||
lastLineHashes[line] = value;
|
||||
}
|
||||
|
||||
public int[] getLastLineNumbersCopy() { return Arrays.copyOf(lastLineNumbers, 8); }
|
||||
public String[] getLastLineHashesCopy() { return Arrays.copyOf(lastLineHashes, 8); }
|
||||
public int[] getLastLineNumbersCopy() {
|
||||
return Arrays.copyOf(lastLineNumbers, 8);
|
||||
}
|
||||
|
||||
public byte[][] getLastLineHashesCopy() {
|
||||
return Arrays.copyOf(lastLineHashes, 8);
|
||||
}
|
||||
|
||||
public long getUpdatedAtMs() { return updatedAtMs; }
|
||||
public void setUpdatedAtMs(long updatedAtMs) { this.updatedAtMs = updatedAtMs; }
|
||||
|
||||
Reference in New Issue
Block a user