1, The core of data ledger design
1. Data ledger model
The core task of data ledger is to effectively organize and manage data. Therefore, it is necessary to define the data structure and the operation model of data processing.
JD Chain's data ledger model organizes business data in a "key value" structure, defines standard read-write operations, records data change history, maintains data integrity and non repudiation, and manages the proof of data existence.
2, Introduction to data ledger
The data ledger provides all participants with the underlying service functions of the blockchain, including blocks, accounts, configuration, storage, etc.
Block is the main part of JD Chain ledger, which contains transaction information and data snapshot hash value of transaction execution status, but does not store specific transaction operation and status data. JD Chain separates the ledger status from the contract and restricts the access of the contract to the ledger status to realize the separation of data and logic and provide stateless logic abstraction.
JD Chain manages the accounts in the blockchain system by refining account classification and hierarchical classification authorization, so as to achieve the purpose of logic clarity, business isolation and protection of relevant data content.
The configuration file includes key information, storage information and shared participant identity information, so that each node in JD Chain system can perform operations such as connecting other nodes, verifying information, storing and updating account books.
The storage format adopts simple KV data type, and the more mature NoSQL database is used to realize the persistent storage of account books, so that the blockchain system can support massive transactions.
3, List of contract examples
It provides the functions of creating user / data account / event account through contract, writing KV, publishing events, etc
1. Set KV
/** * Set KV * * @param address Data account address * @param key key * @param value value * @param version edition */ @ContractEvent(name = "setKVWithVersion") void setKVWithVersion(String address, String key, String value, long version); /** * Set KV based on the latest data version * * @param address Data account address * @param key key * @param value value */ @ContractEvent(name = "setKV") void setKV(String address, String key, String value);
2. Registered user, data account and event account
/** * Registered user * * @param seed Seed, not less than 32 characters */ @ContractEvent(name = "registerUser") String registerUser(String seed); /** * Registered data account * * @param seed Seed, not less than 32 characters */ @ContractEvent(name = "registerDataAccount") String registerDataAccount(String seed); /** * Register event account * * @param seed Seed, not less than 32 characters */ @ContractEvent(name = "registerEventAccount") String registerEventAccount(String seed);
4. Release event
/** * Publish event * * @param address Event account address * @param topic Message name * @param content content * @param sequence Maximum sequence number under the current message name (initially - 1) */ @ContractEvent(name = "publishEventWithSequence") void publishEventWithSequence(String address, String topic, String content, long sequence); /** * Publish event, based on the latest time sequence number * * @param address Event account address * @param topic Message name * @param content content */ @ContractEvent(name = "publishEvent") void publishEvent(String address, String topic, String content);
4, Supported data types
setText, character type
setInt64, long integer
setJSON, JSON string
setBytes, byte array
setTimestamp, timestamp, long integer
setXML, XML text
setImage, picture byte data
In essence, only String/Long/byte data types are supported. JSON/XML/Image/Timestamp plays the role of identification, which is used to expand scene requirements such as differentiated data display
The third parameter in setText("key1", "value1", - 1) is the data version. You need to pass in the highest data version of the current key1 in the JD Chain network, and pass in - 1 when writing for the first time.