├── .gitignore ├── README.md ├── design-en ├── JSON-RPC Interface interaction format and specification.md ├── README.md ├── c.Network design v1.3.md ├── e.Event Bus Design v1.3.md ├── g.Block Design v1.3.md ├── h.General protocol design v1.3.md ├── i.Account design v1.3.md ├── image │ ├── account-module │ │ ├── account-context.png │ │ ├── account-create-address.png │ │ ├── account-create-offline.png │ │ ├── account-export-keystore.png │ │ ├── account-export-prikey.png │ │ ├── account-functions.png │ │ ├── account-import-keystore.png │ │ ├── account-import-prikey.png │ │ ├── account-module.png │ │ └── account-remove-address.png │ ├── block-module │ │ ├── block-basic-validation.png │ │ ├── block-basic-validation1.png │ │ ├── block-basic-validation2.png │ │ ├── block-context.png │ │ ├── block-fork-chain.png │ │ ├── block-fork.png │ │ ├── block-functions.png │ │ ├── block-module-boot.png │ │ ├── block-module.png │ │ ├── block-monitoring.png │ │ ├── block-synchronization.png │ │ ├── block-synchronization2.png │ │ └── block-synchronization3.png │ ├── bridge-layer.png │ ├── bridge.png │ ├── cg-module │ │ └── cg-functions.png │ ├── chainModule │ │ ├── Chain Management.xmind │ │ ├── architecture.png │ │ ├── assetDestroy.png │ │ ├── assetDestroy0.png │ │ ├── assetRegister.png │ │ ├── assetRegister0.png │ │ ├── chain-context.png │ │ ├── chain-functions.png │ │ ├── chain-module.png │ │ ├── chain-off.png │ │ ├── chain-register.png │ │ ├── chainDestroy.png │ │ ├── chainDestroy0.png │ │ ├── chainOff.png │ │ ├── chainRegister.png │ │ ├── chainRegister0.png │ │ ├── structure.png │ │ ├── structure1.png │ │ ├── 主要结构.vsdx │ │ ├── 增加资产.vsdx │ │ ├── 注册链.vsdx │ │ ├── 注销资产.vsdx │ │ └── 注销链.vsdx │ ├── consensus-module │ │ ├── coinbase.png │ │ ├── consensus-constants.jpg │ │ ├── consensus-flow-5.png │ │ ├── consensus-func.png │ │ └── statics_en.png │ ├── eventbus │ │ ├── event-bus-content.png │ │ ├── event-bus-function.png │ │ ├── event-bus-main-flow.png │ │ ├── event-bus-model.png │ │ ├── event-bus-module.png │ │ └── event-bus-seq-flow.png │ ├── kernel │ │ ├── OOD.png │ │ └── structure.png │ ├── ledger │ │ ├── eth-transaction-flow.png │ │ ├── ledger-arch.png │ │ ├── ledger-flow-01.png │ │ ├── ledger-functions.png │ │ ├── ledger-service.png │ │ ├── leger-flow-01.png │ │ └── trx-validate-flow.png │ ├── modules.png │ ├── network-module │ │ ├── connectSelf-recieve.png │ │ ├── connectSelf.png │ │ ├── connection.png │ │ ├── connet-validate.png │ │ ├── createNodeGroup.png │ │ ├── crossPortDeliver.png │ │ ├── deleteNodeGroup.png │ │ ├── deleteNodeGroup2.png │ │ ├── discoverPeer.png │ │ ├── network-client-connection-heartbeats.png │ │ ├── network-client-connection-management.png │ │ ├── network-client-connection.png │ │ ├── network-context.png │ │ ├── network-functions-en.png │ │ ├── network-functions.png │ │ ├── network-module.png │ │ ├── network-node-mode.png │ │ ├── network-node-start.png │ │ ├── network-normal-start.png │ │ ├── network-seed-client-connection.png │ │ ├── network-seed-start.png │ │ ├── network-server-connection-heartbeats.png │ │ ├── network-server-connection-management.png │ │ ├── nodeManage.png │ │ ├── pingpong.png │ │ ├── recMessage.png │ │ ├── recMessage2.png │ │ ├── saveNodeIp.png │ │ ├── sendMsg1.png │ │ ├── sendMsg2.png │ │ ├── shutdown.png │ │ └── start.png │ ├── tools-rpc │ │ ├── rpc-heart-beat.png │ │ ├── rpc-interface-list.png │ │ ├── rpc-server-start.png │ │ └── rpc-struts.png │ ├── tools │ │ ├── db-tools-functions.png │ │ ├── java-tools-content.png │ │ ├── java-tools-functions.png │ │ └── java-tools-module.png │ └── tx-manager-module │ │ ├── tx-manager-architecture.png │ │ ├── tx-manager-context.png │ │ ├── tx-manager-ctos.png │ │ ├── tx-manager-ctosatellite.png │ │ ├── tx-manager-functional-architecture.png │ │ └── tx-manager-satellitetoc.png ├── j.Account Ledger Design v.13.md ├── m.Transaction management module design v1.3.md ├── n.Consensus module design v1.3.md ├── r.rpc-tool design v1.3.md └── y.chain manager design v1.3.md ├── design-zh-CHS ├── README.md ├── c.网络模块设计v1.3.md ├── e.事件总线模块设计v1.3.md ├── g.区块管理模块设计v1.3.md ├── h.通用协议设计v1.3.md ├── i.账户模块设计v1.3.md ├── image │ ├── account-module │ │ ├── account-context.png │ │ ├── account-create-address.png │ │ ├── account-create-offline.png │ │ ├── account-export-keystore.png │ │ ├── account-export-prikey.png │ │ ├── account-functions.png │ │ ├── account-import-keystore.png │ │ ├── account-import-prikey.png │ │ ├── account-module.png │ │ └── account-remove-address.png │ ├── block-module │ │ ├── block-basic-validation.png │ │ ├── block-basic-validation1.png │ │ ├── block-basic-validation2.png │ │ ├── block-context.png │ │ ├── block-fork-chain.png │ │ ├── block-fork.png │ │ ├── block-functions.png │ │ ├── block-module-boot.png │ │ ├── block-module.png │ │ ├── block-monitoring.png │ │ ├── block-synchronization.png │ │ ├── block-synchronization2.png │ │ └── block-synchronization3.png │ ├── bridge-layer.png │ ├── bridge.png │ ├── cg-module │ │ └── cg-functions.png │ ├── chainModule │ │ ├── assetDestroy.png │ │ ├── assetRegister.png │ │ ├── chain-context.png │ │ ├── chain-functions.png │ │ ├── chain-module.png │ │ ├── chain-off.png │ │ ├── chain-register.png │ │ ├── chainDestroy.png │ │ ├── chainOff.png │ │ ├── chainRegister.png │ │ ├── structure.png │ │ ├── 主要结构.vsdx │ │ ├── 增加资产.vsdx │ │ ├── 注册链.vsdx │ │ ├── 注销资产.vsdx │ │ └── 注销链.vsdx │ ├── consensus-module │ │ ├── coinbase.png │ │ ├── consensus-constants.jpg │ │ ├── consensus-flow-5.png │ │ ├── consensus-func.png │ │ ├── consensus-staticsReward.jpg │ │ └── statics_en.png │ ├── eventbus │ │ ├── event-bus-content.png │ │ ├── event-bus-function.png │ │ ├── event-bus-main-flow.png │ │ ├── event-bus-model.png │ │ ├── event-bus-module.png │ │ └── event-bus-seq-flow.png │ ├── kernel │ │ ├── OOD.png │ │ └── structure.png │ ├── ledger │ │ ├── eth-transaction-flow.png │ │ ├── ledger-arch.png │ │ ├── ledger-flow-01.png │ │ ├── ledger-functions.png │ │ ├── ledger-service.png │ │ └── trx-validate-flow.png │ ├── modules.png │ ├── network-module │ │ ├── connectSelf-recieve.png │ │ ├── connectSelf.png │ │ ├── connection.png │ │ ├── connet-add.png │ │ ├── connet-validate.png │ │ ├── createNodeGroup.png │ │ ├── createNodeGroup0.png │ │ ├── crossPortDeliver.png │ │ ├── deleteNodeGroup.png │ │ ├── deleteNodeGroup2.png │ │ ├── discoverPeer.png │ │ ├── network-client-connection-heartbeats.png │ │ ├── network-client-connection-management.png │ │ ├── network-client-connection.png │ │ ├── network-context.png │ │ ├── network-functions.png │ │ ├── network-module.png │ │ ├── network-node-mode.png │ │ ├── network-node-start.png │ │ ├── network-normal-start.png │ │ ├── network-seed-client-connection.png │ │ ├── network-seed-start.png │ │ ├── network-server-connection-heartbeats.png │ │ ├── network-server-connection-management.png │ │ ├── nodeManage.png │ │ ├── pingpong.png │ │ ├── recMessage.png │ │ ├── recMessage2.png │ │ ├── saveNodeIp.png │ │ ├── sendMsg1.png │ │ ├── sendMsg2.png │ │ ├── shutdown.png │ │ └── start.png │ ├── tools-rpc │ │ ├── Websocket-Tool-package.png │ │ ├── rpc-heart-beat.png │ │ ├── rpc-interface-list.png │ │ ├── rpc-server-start.png │ │ └── rpc-struts.png │ ├── tools │ │ ├── db-tools-functions.png │ │ ├── java-tools-content.png │ │ ├── java-tools-functions.png │ │ └── java-tools-module.png │ └── tx-manager-module │ │ ├── tx-manager-architecture.png │ │ ├── tx-manager-context.png │ │ ├── tx-manager-ctos.png │ │ ├── tx-manager-ctosatellite.png │ │ ├── tx-manager-functional-architecture.png │ │ └── tx-manager-satellitetoc.png ├── j.账本模块设计v.13.md ├── m.交易管理模块设计v1.3.md ├── n.共识模块设计v1.3.md ├── r.rpc-tool-websocket设计v1.3.md ├── y.链管理模块设计v1.3.md ├── z.协议升级模块设计v1.3.md └── 接口交互格式与规范 JSON-RPC.md └── nulstar ├── Article - Design Reasoning.pdf ├── Message Protocol-中文版.md ├── Message Protocol.pdf ├── Module Specification.docx ├── Module Specification.pdf ├── 交易类型字典.md └── 已确认的与Manager(Kernel)交互的字符串.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/macos,maven,jetbrains+iml 3 | 4 | ### JetBrains+iml ### 5 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 6 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 7 | 8 | # User-specific stuff: 9 | .idea/**/workspace.xml 10 | .idea/**/tasks.xml 11 | .idea/dictionaries 12 | 13 | # Sensitive or high-churn files: 14 | .idea/**/dataSources/ 15 | .idea/**/dataSources.ids 16 | .idea/**/dataSources.xml 17 | .idea/**/dataSources.local.xml 18 | .idea/**/sqlDataSources.xml 19 | .idea/**/dynamic.xml 20 | .idea/**/uiDesigner.xml 21 | 22 | # Gradle: 23 | .idea/**/gradle.xml 24 | .idea/**/libraries 25 | 26 | # CMake 27 | cmake-build-debug/ 28 | 29 | # Mongo Explorer plugin: 30 | .idea/**/mongoSettings.xml 31 | 32 | ## File-based project format: 33 | *.iws 34 | 35 | ## Plugin-specific files: 36 | 37 | # IntelliJ 38 | /out/ 39 | 40 | # mpeltonen/sbt-idea plugin 41 | .idea_modules/ 42 | 43 | # JIRA plugin 44 | atlassian-ide-plugin.xml 45 | 46 | # Cursive Clojure plugin 47 | .idea/replstate.xml 48 | 49 | # Ruby plugin and RubyMine 50 | /.rakeTasks 51 | 52 | # Crashlytics plugin (for Android Studio and IntelliJ) 53 | com_crashlytics_export_strings.xml 54 | crashlytics.properties 55 | crashlytics-build.properties 56 | fabric.properties 57 | 58 | ### JetBrains+iml Patch ### 59 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 60 | 61 | *.iml 62 | modules.xml 63 | .idea/misc.xml 64 | *.ipr 65 | 66 | ### JetBrains+all Patch ### 67 | # Ignores the whole idea folder 68 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 69 | 70 | .idea/ 71 | 72 | ### macOS ### 73 | *.DS_Store 74 | .AppleDouble 75 | .LSOverride 76 | 77 | # Icon must end with two \r 78 | Icon 79 | 80 | # Thumbnails 81 | ._* 82 | 83 | # Files that might appear in the root of a volume 84 | .DocumentRevisions-V100 85 | .fseventsd 86 | .Spotlight-V100 87 | .TemporaryItems 88 | .Trashes 89 | .VolumeIcon.icns 90 | .com.apple.timemachine.donotpresent 91 | 92 | # Directories potentially created on remote AFP share 93 | .AppleDB 94 | .AppleDesktop 95 | Network Trash Folder 96 | Temporary Items 97 | .apdisk 98 | 99 | ### Maven ### 100 | target/ 101 | pom.xml.tag 102 | pom.xml.releaseBackup 103 | pom.xml.versionsBackup 104 | pom.xml.next 105 | release.properties 106 | dependency-reduced-pom.xml 107 | buildNumber.properties 108 | .mvn/timing.properties 109 | 110 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 111 | !/.mvn/wrapper/maven-wrapper.jar 112 | 113 | # End of https://www.gitignore.io/api/macos,maven,jetbrains+iml 114 | 115 | # Nuls output 116 | # log 117 | logs/ 118 | 119 | # chain data 120 | data/ 121 | 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NULS2.0 Module Design Docs 2 | 3 | Here is the NULS2.0 module design document,This is history, not the latest. 4 | 5 | ### 6 | -------------------------------------------------------------------------------- /design-en/JSON-RPC Interface interaction format and specification.md: -------------------------------------------------------------------------------- 1 | ## JSON-RPC Interface interaction format and specification 2 | 3 | ### Request Body 4 | 5 | ```json 6 | { 7 | "cmd": "nuls_accounts", 8 | "params": ["param1", "param2"], 9 | "min_version": 1.0, 10 | } 11 | ``` 12 | 13 | - parameters 14 | 15 | | parameter | required | type | description | 16 | | ----------- | -------- | ------ | -------------------------------------------- | 17 | | cmd | true | string | The command to call | 18 | | params | true | array | parameters | 19 | | min_version | false | float | The minimum version of the interface to call | 20 | 21 | ### Response Body 22 | 23 | - success 24 | 25 | ```json 26 | { 27 | "code":0, 28 | "msg": "Success", 29 | "result": {} 30 | } 31 | ``` 32 | 33 | - returns 34 | 35 | | parameter | required | type | description | 36 | | :-------- | :------- | :----- | ------------------------------------------------------------ | 37 | | code | ture | int | The result status of the request, 0 means success. Otherwise return an error code | 38 | | msg | true | string | User-friendly request execution result description | 39 | | result | true | object | Method return value | 40 | 41 | ### Error Code 42 | 43 | #### JSON RPC Standard errors 44 | 45 | | Code | Possible Return message | Description | 46 | | --------- | ----------------------- | ------------------------------------------------------------ | 47 | | 0 | Success | Operation success | 48 | | 1 | Parse error | Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text. | 49 | | 2 | Invalid Request | The JSON sent is not a valid Request object. | 50 | | 3 | Method not found | The method does not exist / is not available. | 51 | | 4 | Invalid params | Invalid method parameter(s). | 52 | | 5 | Internal error | Internal JSON-RPC error. | 53 | | 6 | Unauthorized | Should be used when some action is not authorized, e.g. sending from a locked account. | 54 | | 7 | Action not allowed | Should be used when some action is not allowed, e.g. preventing an action, while another depending action is processing on, like sending again when a confirmation popup is shown to the user (?). | 55 | | 8 | Timeout | Should be used when an action timedout. | 56 | | 9 | Conflict | Should be used when an action conflicts with another (ongoing?) action. | 57 | | 10 | Execution error | Will contain a subset of custom errors in the data field. See below. | 58 | | 11 to 100 | `Server error` | Reserved for implementation-defined server-errors. | 59 | 60 | #### Custom error fields 61 | 62 | Custom error `10` can contain custom error(s) to further explain what went wrong. 63 | 64 | ```js 65 | { 66 | code: 10, 67 | msg: 'Execution error', 68 | } 69 | ``` 70 | 71 | -------------------------------------------------------------------------------- /design-en/README.md: -------------------------------------------------------------------------------- 1 | # nuls_2.0_docs 2 | nuls 2.0 documents 3 | 4 | Currently, these documents are translated from Chinese using google translation. The content may not be very accurate. We hope to use the power of the community to translate more accurate and readable documents. I hope to see these documents and pay attention to nuls. Development, community partners who want to do their best for nuls, can play your ability. Of course, the nuls community will also give certain rewards to those who contribute. -------------------------------------------------------------------------------- /design-en/e.Event Bus Design v1.3.md: -------------------------------------------------------------------------------- 1 | # Event bus module design document 2 | 3 | [TOC] 4 | 5 | ## 1. Overall description 6 | 7 | ### 1.1 Module Overview 8 | 9 | #### 1.1.1 Why should I have the Event Bus module? 10 | 11 | > The Event Bus Module is a functional module designed to receive and notify processing module events, managing all module events. 12 | 13 | #### 1.1.2 What is the "Event Bus"? 14 | 15 | > Provide event subscription, receiving, sending and other functions, which is an event transfer station between modules 16 | 17 | #### 1.1.3 Positioning of Event Bus in the System 18 | 19 | > The event module is an edge system that provides some major asynchronous messaging, which means that even without an event bus, the system can operate normally, is lightweight, and does not depend on other module systems. 20 | 21 | ### 1.2 Architecture 22 | ![event-bus-module](image/eventbus/event-bus-module.png) 23 | 24 | - The event bus module mainly contains 2 parts of interactive logic: 25 |   - Microservice registration and service information acquisition with the system core module. 26 |   - Event message creation, subscription, and forwarding management with other base modules. 27 | 28 | ## 2. functional design 29 | 30 | ### 2.1 Functional Architecture 31 | ![event-bus-content](image/eventbus/event-bus-content.png) 32 | 33 | ### 2.2 Module Service 34 | ![event-bus-model](image/eventbus/event-bus-model.png) 35 | 36 | > This module provides event subscriptions, event forwarding 37 | 38 | #### 2.2.1 Modifying system operating parameters 39 | 40 | > Only rely on the core system, the core system can start, stop, modify parameters, etc. of the event module system, 41 | 42 | ### 2.3 Module internal function 43 | ![event-bus-function](image/eventbus/event-bus-function.png) 44 | 45 | > Module internal work mainly includes, subscription manager, event manager, and forwarding manager. 46 | 47 | - Microservice interface information synchronization management 48 |   - for synchronizing the service interface with the kernel service management module 49 | - Event Storage Management (eventBus) 50 |   - Used to create event information, subscribe to other storage, and initialize the information when the module is restarted. 51 | - Event subscription management (subscribe) 52 |   - Maintain a "configuration table" for subscription events: including important parameters for all individual module subscriptions 53 | - Event forwarding management (dispatcher) 54 |   - The open interface is used for event reception, the receiving event is forwarded by subscription, and the forwarding call interface is obtained through the service information management interface. 55 | - Function Interface Management (rpc) 56 |   - Open query interface for external query 57 | ### 2.4 Event Bus Process 58 | 59 | * Event processing timing 60 | 61 | ![event-bus-seq-flow](image/eventbus/event-bus-seq-flow.png) 62 | 63 | - Event processing basic process 64 | 65 | ![event-bus-main-flow](image/eventbus/event-bus-main-flow.png) 66 | 67 | ### 2.5 Business Logic 68 | 69 | > Exception logic processing in case of event forwarding failure (such as network reason), according to the following two logics: 70 | 71 | - 1. Retaining event calls Repeat calls by queue until the forwarding is successful. 72 | - 2. Discard it directly after trying many times. (Tentatively 5 times) Retry every 10 seconds. 73 | 74 | ## 3. Interface Design 75 | 76 | ### 3.1 Module Interface 77 | #### 3.1.1 Event Theme Subscription 78 | > cmd: subscribe 79 | 80 | ##### Parameter Description (Request body) 81 | 82 | ```json 83 | { 84 |   "cmd": "subscribe", 85 | "min_version": 1.0, 86 |   "params":[ 87 |     "app.nuls.network.bandwidth",//topic event topic 88 |     "moduleId" //moduleId subscriber module id 89 |   ] 90 | } 91 | ``` 92 | ##### Return value description (Response content) 93 | 94 | ```json 95 | { 96 | "version": 1.2, 97 | "code": 0, 98 |   "msg": "reponse message.", // ​​information on failure 99 |   "result": { 100 |     "app_secret": "xxxxxxxxxxxx" // app_secret, temporarily not needed, may need to be verified later if it is not required to be called locally 101 |   } 102 | } 103 | ``` 104 | 105 | #### 3.1.2 Event Unsubscribe 106 | > cmd: unsubscribe 107 | 108 | ##### Parameter Description (request body) 109 | 110 | ```json 111 | { 112 | "cmd": "unsubscribe", 113 | "min_version": 1.0, 114 | "params":[ 115 |    "app.nuls.network.bandwidth", //topic event topic 116 |    "moduleId" //moduleId subscriber module id 117 |   ] 118 | } 119 | ``` 120 | 121 | ##### Return value description: (response content) 122 | 123 | ```json 124 | { 125 | "version": 1.2, 126 | "code": 0, 127 |   "msg": "reponse message.", // ​​information on failure 128 |   "result": { 129 |   } 130 | } 131 | ``` 132 | 133 | #### 3.1.3 Event Sending [Automatically Create Topic] 134 | > Do you keep a certain amount of time when no one is subscribed? 135 | 136 | > cmd: send 137 | 138 | ##### Parameter description (request body) 139 | 140 | ```json 141 | { 142 |  "cmd": "send", 143 | "min_version": 1.0, 144 |  "params":[ 145 |    "app.nuls.network.bandwidth",//topic event topic 146 |    "moduleId", //moduleId subscriber module id 147 |    {"key" : "data value"} // event to be sent, jsonObj 148 |  ] 149 | } 150 | ``` 151 | 152 | ##### return value description (response content) 153 | 154 | ```json 155 | { 156 | "version": 1.2, 157 | "code": 0, 158 |   "msg": "reponse message.", // ​​information on failure 159 |   "result": { 160 |   } 161 | } 162 | ``` 163 | #### 3.1.4 Event broadcast (push push or dispatcher) 164 | > I need each interface to provide an interface when subscribing to events. I can call it when I broadcast. I am using multithreading to remove your interface. You need to return the correct code, otherwise there will be a retry mechanism. 165 | 166 | ##### Parameter description (request body) 167 | 168 | ```json 169 | { 170 |  "cmd": "dispatcher", 171 | "min_version": 1.0, 172 |  "params":[ 173 |    {} //data event to be sent, payload 174 |  ] 175 | } 176 | ``` 177 | 178 | ##### return value description (response content) 179 | 180 | ```json 181 | { 182 | "version": 1.2, 183 |   "code": 0, // ​​must return correctly, do not need to tell you whether the business logic is wrong, as long as you receive it, tell me that you have successfully received it. 184 |   "msg": "reponse message.", // ​​information on failure 185 |   "result": { 186 |   } 187 | } 188 | ``` 189 | ### 3.2 Function Interface 190 | > The functional interface is the interface provided to the interface and command line tools 191 | 192 | #### Get event topic information 193 | > cmd: topics 194 | 195 | ##### Parameter description (request body) 196 | 197 | ```json 198 | { 199 |  "cmd": "topics", 200 | "min_version": 1.0, 201 |  "params":[] 202 | } 203 | ``` 204 | 205 | ##### Response Body (response content) 206 | 207 | ```json 208 | { 209 | "version": 1.2, 210 |   "code": 0, // ​​must return correctly, do not need to tell you whether the business logic is wrong, as long as you receive it, tell me that you have successfully received it. 211 |   "msg": "reponse message.", // ​​information on failure 212 |   "result": { 213 |     "topics":[{ 214 |         "topic": "", //topic id 215 |         "createTime":"", //Create time 216 |         "moduleId":"", // theme creator (module) Id 217 |         "subscribes":[//subscriber information 218 |             { 219 |                 "moduleId":"", //subscriber 220 |                 "subscribeTime":"" //Subscription time 221 |             } 222 |         ]} 223 |     ] 224 |   } 225 | } 226 | ``` 227 | 228 | #### Get event topic information (including all event information on this topic?) Every event I don't care about. 229 | > cmd : get_topic 230 | 231 | ## 4. Description of the event 232 | 233 | > does not depend on any events 234 | 235 | ## 5. agreement 236 | 237 | ### 5.1 Network Communication Protocol 238 | 239 | no 240 | 241 | ### 5.2 Trading Agreement 242 | 243 | ## 6. Module Configuration 244 | ### 6.1 Configuration Instructions 245 | > General support configuration, port, number of retries, retry time, thread pool size of default executor, network call timeout configuration, etc. 246 | ```yml 247 | Server: 248 |   Ip: 127.0.0.1 // local ip, used to provide services to other modules, you can not fill, the default is automatically obtained 249 |   Port: 8080 //The port that provides the service, you can leave it blank, the default is automatically obtained. 250 | ``` 251 | ### 6.2 Module Dependencies 252 | 253 | - Kernel module 254 |   - Module registration 255 |   - Module logout 256 |   - Module status escalation (heartbeat) 257 |   - Service interface data acquisition and timing update 258 | 259 | ## 7. Java-specific design 260 | 261 | > Core object class definition, storing data structures, ... 262 | 263 | ## 8. supplementary content 264 | 265 | > Required content not covered above -------------------------------------------------------------------------------- /design-en/h.General protocol design v1.3.md: -------------------------------------------------------------------------------- 1 | # Protocol design 2 | 3 | [TOC] 4 | 5 | ## Common standards 6 | 7 | ### Hashes 8 | 9 | Usually, when a hash is computed within Satellite-chain, it is computed twice. Most of the time [SHA-256](http://en.wikipedia.org/wiki/SHA-2) hashes are used, however [RIPEMD-160](http://en.wikipedia.org/wiki/RIPEMD) is also used when a shorter hash is desirable (for example when creating a NULS address). 10 | 11 | Example of double-SHA-256 encoding of string "nuls": 12 | 13 | ``` 14 | nuls 15 | 96cc377699e3289875d6d40da436110d692e823eb8900ae13a7107cb36c7310c (first round of sha-256) 16 | 7e0590c37ab91aacabdac1bedec9ff6acd609215d019e489cc0a5dcf38b7b055(second round of sha-256) 17 | 18 | ``` 19 | 20 | For NULS addresses (RIPEMD-160) this would give: 21 | 22 | ``` 23 | nuls 24 | 96cc377699e3289875d6d40da436110d692e823eb8900ae13a7107cb36c7310c (first round is sha-256) 25 | f8e8d1c6f1511c356effad8b986b0aa439a88c44(with ripemd-160) 26 | ``` 27 | 28 | ### Merkle Trees 29 | 30 | Merkle trees are binary trees of hashes. Merkle trees in NULS use a **double** SHA-256, the SHA-256 hash of the SHA-256 hash of something. 31 | 32 | If, when forming a row in the tree (other than the root of the tree), it would have an odd number of elements, the final double-hash is duplicated to ensure that the row has an even number of hashes. 33 | 34 | First form the bottom row of the tree with the ordered double-SHA-256 hashes of the byte streams of the transactions in the block. 35 | 36 | Then the row above it consists of half that number of hashes. Each entry is the double-SHA-256 of the 64-byte concatenation of the corresponding two hashes below it in the tree. 37 | 38 | This procedure repeats recursively until we reach a row consisting of just a single double-hash. This is the **Merkle root** of the tree. 39 | 40 | For example, imagine a block with three transactions *a*, *b* and *c*. The Merkle tree is: 41 | 42 | ``` 43 | d1 = dhash(a) 44 | d2 = dhash(b) 45 | d3 = dhash(c) 46 | d4 = dhash(c) # a, b, c are 3. that's an odd number, so we take the c twice 47 | 48 | d5 = dhash(d1 concat d2) 49 | d6 = dhash(d3 concat d4) 50 | 51 | d7 = dhash(d5 concat d6) 52 | 53 | ``` 54 | 55 | where 56 | 57 | ``` 58 | dhash(a) = sha256(sha256(a)) 59 | 60 | ``` 61 | 62 | *d7* is the Merkle root of the 3 transactions in this block. 63 | 64 | ### Addresses 65 | 66 | A NULS address is in fact the hash of a ECDSA public key, computed this way: 67 | 68 | ``` 69 | ChainId = 2 byte,The ID of the chain in which the account belongs. 70 | addressType = 1 byte,The type of the account,Example: 1 general account, 2 contract account…… 71 | pkh = 20 byte , RIPEMD-160(SHA-256(public key)) 72 | xor = 1 byte, XOR(chainId+addressType+pkh) 73 | address = Base58Encode(chainId+addressType+pkh+xor) 74 | ``` 75 | 76 | The address format of the non-nuls system is as follows: 77 | 78 | For example: bitcoin address, append two bytes of chainId before the address, followed by the original address of bitcoin, the address resolution method is determined according to the chain configuration 79 | 80 | ``` 81 | address = Base58Encode(chainId + originalAddressLength + originaAddress + xor) 82 | ``` 83 | 84 | ## Message Structre 85 | 86 | Satellite-chain uses custom messaging for communication over the TCP protocol. 87 | 88 | - Digital binary stream using little endian。 89 | - Floating point numbers convert to integers and transfer by little endian 90 | 91 | ### Message 92 | 93 | The message consists of a 24-byte header and payload. 94 | 95 | ``` 96 | *---------------------------------------------------------------* 97 | | Header(24 Byte) | Payload | 98 | *---------------------------------------------------------------* 99 | ``` 100 | 101 | #### message header 102 | 103 | The main role of the header is to indicate the payload length, verify data integrity, and solve TCP sticky packets. 104 | 105 | | Len | Fields | Data Type | Remark | 106 | | ---- | ------------- | --------- | ---------------------------------------- | 107 | | 4 | MagicNumber | uint32 | Packet valid flag | 108 | | 12 | command | char[12] | ASCII string identifying the packet content, NULL padded | 109 | | 4 | PayloadLength | uint32 | Length of payload in number of bytes | 110 | | 4 | checksum | uint32 | First 4 bytes of sha256(sha256(payload)) | 111 | | | | | | 112 | 113 | [^MagicNumber]: MagicNumber In addition to being validated as a valid check, it is also used for the division of the main network and test. 114 | 115 | ## Common Structre 116 | 117 | ### VarInt 118 | 119 | Variable-length integers that can be encoded based on the values expressed to save space. 120 | 121 | | Value | Len | Structure | 122 | | ------------- | ---- | ------------- | 123 | | < 0xfd | 1 | uint8 | 124 | | <= 0xffff | 3 | 0xfd + uint16 | 125 | | <= 0xffffffff | 5 | 0xfe + uint32 | 126 | | > 0xffffffff | 9 | 0xff + uint64 | 127 | 128 | ### VarString 129 | 130 | A variable-length byte stream consisting of a variable-length buffer. The string is encoded in UTF8. 131 | 132 | | Len | Fields | Data Type | Remark | 133 | | ------ | ------ | ------------- | -------------------- | 134 | | ? | length | VarInt | Length of the string | 135 | | length | value | uint8[length] | The string itself | 136 | 137 | ### VarByte 138 | 139 | Variable-length buffer, consistent with the VarString implementation. 140 | 141 | | Len | Fields | Data Type | Remark | 142 | | ------ | ------ | ------------ | ------------------------------------ | 143 | | ? | length | VarInt | Length of payload in number of bytes | 144 | | length | data | byte[length] | payload | 145 | 146 | ### Int48 147 | 148 | 6-byte number. 149 | 150 | ### Network address 151 | 152 | When a network address is needed somewhere, this structure is used. 153 | 154 | | Len | Fields | Data type | Remark | 155 | | ---- | ------ | --------- | ------------------------------------------------------------ | 156 | | 16 | IPv6/4 | char[16] | IPv6/4 address. Network byte order. The IPv4 address is written into the message as a 16 byte | 157 | | 2 | port1 | uint16 | port number, network byte order | 158 | | 2 | port2 | uint16 | port number,for cross-chain module | 159 | 160 | ## Block_headers 161 | 162 | | Len | Fields | Data Type | Remark | 163 | | ---- | ---------- | --------- | ------------------------------------------------------------ | 164 | | 4 | version | uint32 | version bumber | 165 | | 32 | preHash | byte[32] | | 166 | | 32 | merkleRoot | byte[32] | | 167 | | ? | stateRoot | VarByte | | 168 | | 4 | time | uint32 | second | 169 | | 2 | txCount | uint16 | | 170 | | ? | extends | VarByte | Different chains in this field can set different constraints | 171 | | ? | signature | Varbyte | | 172 | 173 | ## Transactions 174 | 175 | | Len | Fields | Data Type | Remark | 176 | | ---- | -------- | --------- | ------ | 177 | | 2 | type | uint16 | | 178 | | 4 | time | uint32 | | 179 | | ? | txData | VarByte | | 180 | | ? | coinData | VarByte | | 181 | | ? | remark | VarString | | 182 | | ? | sig | VarByte | | 183 | | | | | | 184 | 185 | Trading characteristics 186 | 187 | ``` 188 | Multiple account transfer 189 | Multi-asset transfer 190 | ``` 191 | 192 | coinData Structure description 193 | 194 | ``` 195 | froms://List, 196 | tos://List 197 | ``` 198 | 199 | CoinForm Structure description[40] 200 | 201 | ``` 202 | address: //byte[24] The address of the account 203 | assetsChainId://uint16 The id of the chain which Issued this asset 204 | assetsId: //uint16 asset id 205 | amount: //uint128,asset count 206 | nonce : //byte[8] The last eight bytes of the summary of the previous transaction(If the transaction is unlocked tx, the value here is the first eight bytes of hash that locks the transaction for that amount.) 207 | locked : //byte ,If the transaction is unlocked, the value here is 1, which means that the asset is locked, otherwise it is 0. 208 | ``` 209 | 210 | CoinTo Structure description[44] 211 | 212 | ``` 213 | address: //byte[24],transfer target 214 | assetsChainId://uint16 The id of the chain which Issued this asset 215 | assetsId: //uint16 asset id 216 | amount : //uint128,transfer amount 217 | lockTime://uint32,Unlock height or unlock time, -1 is permanent lock 218 | ``` 219 | 220 | tx fee 221 | 222 | ``` 223 | forms-tos The remaining part is the handling fee (the model supports multiple asset payment fees, and the constraints are determined by the economic model design) 224 | ``` 225 | 226 | ## Message Types 227 | 228 | Refer to each module design document 229 | 230 | 231 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /design-en/image/account-module/account-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/account-module/account-context.png -------------------------------------------------------------------------------- /design-en/image/account-module/account-create-address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/account-module/account-create-address.png -------------------------------------------------------------------------------- /design-en/image/account-module/account-create-offline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/account-module/account-create-offline.png -------------------------------------------------------------------------------- /design-en/image/account-module/account-export-keystore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/account-module/account-export-keystore.png -------------------------------------------------------------------------------- /design-en/image/account-module/account-export-prikey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/account-module/account-export-prikey.png -------------------------------------------------------------------------------- /design-en/image/account-module/account-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/account-module/account-functions.png -------------------------------------------------------------------------------- /design-en/image/account-module/account-import-keystore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/account-module/account-import-keystore.png -------------------------------------------------------------------------------- /design-en/image/account-module/account-import-prikey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/account-module/account-import-prikey.png -------------------------------------------------------------------------------- /design-en/image/account-module/account-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/account-module/account-module.png -------------------------------------------------------------------------------- /design-en/image/account-module/account-remove-address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/account-module/account-remove-address.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-basic-validation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-basic-validation.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-basic-validation1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-basic-validation1.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-basic-validation2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-basic-validation2.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-context.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-fork-chain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-fork-chain.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-fork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-fork.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-functions.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-module-boot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-module-boot.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-module.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-monitoring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-monitoring.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-synchronization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-synchronization.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-synchronization2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-synchronization2.png -------------------------------------------------------------------------------- /design-en/image/block-module/block-synchronization3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/block-module/block-synchronization3.png -------------------------------------------------------------------------------- /design-en/image/bridge-layer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/bridge-layer.png -------------------------------------------------------------------------------- /design-en/image/bridge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/bridge.png -------------------------------------------------------------------------------- /design-en/image/cg-module/cg-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/cg-module/cg-functions.png -------------------------------------------------------------------------------- /design-en/image/chainModule/Chain Management.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/Chain Management.xmind -------------------------------------------------------------------------------- /design-en/image/chainModule/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/architecture.png -------------------------------------------------------------------------------- /design-en/image/chainModule/assetDestroy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/assetDestroy.png -------------------------------------------------------------------------------- /design-en/image/chainModule/assetDestroy0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/assetDestroy0.png -------------------------------------------------------------------------------- /design-en/image/chainModule/assetRegister.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/assetRegister.png -------------------------------------------------------------------------------- /design-en/image/chainModule/assetRegister0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/assetRegister0.png -------------------------------------------------------------------------------- /design-en/image/chainModule/chain-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/chain-context.png -------------------------------------------------------------------------------- /design-en/image/chainModule/chain-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/chain-functions.png -------------------------------------------------------------------------------- /design-en/image/chainModule/chain-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/chain-module.png -------------------------------------------------------------------------------- /design-en/image/chainModule/chain-off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/chain-off.png -------------------------------------------------------------------------------- /design-en/image/chainModule/chain-register.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/chain-register.png -------------------------------------------------------------------------------- /design-en/image/chainModule/chainDestroy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/chainDestroy.png -------------------------------------------------------------------------------- /design-en/image/chainModule/chainDestroy0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/chainDestroy0.png -------------------------------------------------------------------------------- /design-en/image/chainModule/chainOff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/chainOff.png -------------------------------------------------------------------------------- /design-en/image/chainModule/chainRegister.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/chainRegister.png -------------------------------------------------------------------------------- /design-en/image/chainModule/chainRegister0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/chainRegister0.png -------------------------------------------------------------------------------- /design-en/image/chainModule/structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/structure.png -------------------------------------------------------------------------------- /design-en/image/chainModule/structure1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/structure1.png -------------------------------------------------------------------------------- /design-en/image/chainModule/主要结构.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/主要结构.vsdx -------------------------------------------------------------------------------- /design-en/image/chainModule/增加资产.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/增加资产.vsdx -------------------------------------------------------------------------------- /design-en/image/chainModule/注册链.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/注册链.vsdx -------------------------------------------------------------------------------- /design-en/image/chainModule/注销资产.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/注销资产.vsdx -------------------------------------------------------------------------------- /design-en/image/chainModule/注销链.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/chainModule/注销链.vsdx -------------------------------------------------------------------------------- /design-en/image/consensus-module/coinbase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/consensus-module/coinbase.png -------------------------------------------------------------------------------- /design-en/image/consensus-module/consensus-constants.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/consensus-module/consensus-constants.jpg -------------------------------------------------------------------------------- /design-en/image/consensus-module/consensus-flow-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/consensus-module/consensus-flow-5.png -------------------------------------------------------------------------------- /design-en/image/consensus-module/consensus-func.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/consensus-module/consensus-func.png -------------------------------------------------------------------------------- /design-en/image/consensus-module/statics_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/consensus-module/statics_en.png -------------------------------------------------------------------------------- /design-en/image/eventbus/event-bus-content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/eventbus/event-bus-content.png -------------------------------------------------------------------------------- /design-en/image/eventbus/event-bus-function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/eventbus/event-bus-function.png -------------------------------------------------------------------------------- /design-en/image/eventbus/event-bus-main-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/eventbus/event-bus-main-flow.png -------------------------------------------------------------------------------- /design-en/image/eventbus/event-bus-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/eventbus/event-bus-model.png -------------------------------------------------------------------------------- /design-en/image/eventbus/event-bus-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/eventbus/event-bus-module.png -------------------------------------------------------------------------------- /design-en/image/eventbus/event-bus-seq-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/eventbus/event-bus-seq-flow.png -------------------------------------------------------------------------------- /design-en/image/kernel/OOD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/kernel/OOD.png -------------------------------------------------------------------------------- /design-en/image/kernel/structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/kernel/structure.png -------------------------------------------------------------------------------- /design-en/image/ledger/eth-transaction-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/ledger/eth-transaction-flow.png -------------------------------------------------------------------------------- /design-en/image/ledger/ledger-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/ledger/ledger-arch.png -------------------------------------------------------------------------------- /design-en/image/ledger/ledger-flow-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/ledger/ledger-flow-01.png -------------------------------------------------------------------------------- /design-en/image/ledger/ledger-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/ledger/ledger-functions.png -------------------------------------------------------------------------------- /design-en/image/ledger/ledger-service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/ledger/ledger-service.png -------------------------------------------------------------------------------- /design-en/image/ledger/leger-flow-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/ledger/leger-flow-01.png -------------------------------------------------------------------------------- /design-en/image/ledger/trx-validate-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/ledger/trx-validate-flow.png -------------------------------------------------------------------------------- /design-en/image/modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/modules.png -------------------------------------------------------------------------------- /design-en/image/network-module/connectSelf-recieve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/connectSelf-recieve.png -------------------------------------------------------------------------------- /design-en/image/network-module/connectSelf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/connectSelf.png -------------------------------------------------------------------------------- /design-en/image/network-module/connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/connection.png -------------------------------------------------------------------------------- /design-en/image/network-module/connet-validate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/connet-validate.png -------------------------------------------------------------------------------- /design-en/image/network-module/createNodeGroup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/createNodeGroup.png -------------------------------------------------------------------------------- /design-en/image/network-module/crossPortDeliver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/crossPortDeliver.png -------------------------------------------------------------------------------- /design-en/image/network-module/deleteNodeGroup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/deleteNodeGroup.png -------------------------------------------------------------------------------- /design-en/image/network-module/deleteNodeGroup2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/deleteNodeGroup2.png -------------------------------------------------------------------------------- /design-en/image/network-module/discoverPeer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/discoverPeer.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-client-connection-heartbeats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-client-connection-heartbeats.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-client-connection-management.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-client-connection-management.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-client-connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-client-connection.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-context.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-functions-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-functions-en.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-functions.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-module.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-node-mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-node-mode.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-node-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-node-start.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-normal-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-normal-start.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-seed-client-connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-seed-client-connection.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-seed-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-seed-start.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-server-connection-heartbeats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-server-connection-heartbeats.png -------------------------------------------------------------------------------- /design-en/image/network-module/network-server-connection-management.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/network-server-connection-management.png -------------------------------------------------------------------------------- /design-en/image/network-module/nodeManage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/nodeManage.png -------------------------------------------------------------------------------- /design-en/image/network-module/pingpong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/pingpong.png -------------------------------------------------------------------------------- /design-en/image/network-module/recMessage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/recMessage.png -------------------------------------------------------------------------------- /design-en/image/network-module/recMessage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/recMessage2.png -------------------------------------------------------------------------------- /design-en/image/network-module/saveNodeIp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/saveNodeIp.png -------------------------------------------------------------------------------- /design-en/image/network-module/sendMsg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/sendMsg1.png -------------------------------------------------------------------------------- /design-en/image/network-module/sendMsg2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/sendMsg2.png -------------------------------------------------------------------------------- /design-en/image/network-module/shutdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/shutdown.png -------------------------------------------------------------------------------- /design-en/image/network-module/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/network-module/start.png -------------------------------------------------------------------------------- /design-en/image/tools-rpc/rpc-heart-beat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tools-rpc/rpc-heart-beat.png -------------------------------------------------------------------------------- /design-en/image/tools-rpc/rpc-interface-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tools-rpc/rpc-interface-list.png -------------------------------------------------------------------------------- /design-en/image/tools-rpc/rpc-server-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tools-rpc/rpc-server-start.png -------------------------------------------------------------------------------- /design-en/image/tools-rpc/rpc-struts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tools-rpc/rpc-struts.png -------------------------------------------------------------------------------- /design-en/image/tools/db-tools-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tools/db-tools-functions.png -------------------------------------------------------------------------------- /design-en/image/tools/java-tools-content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tools/java-tools-content.png -------------------------------------------------------------------------------- /design-en/image/tools/java-tools-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tools/java-tools-functions.png -------------------------------------------------------------------------------- /design-en/image/tools/java-tools-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tools/java-tools-module.png -------------------------------------------------------------------------------- /design-en/image/tx-manager-module/tx-manager-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tx-manager-module/tx-manager-architecture.png -------------------------------------------------------------------------------- /design-en/image/tx-manager-module/tx-manager-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tx-manager-module/tx-manager-context.png -------------------------------------------------------------------------------- /design-en/image/tx-manager-module/tx-manager-ctos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tx-manager-module/tx-manager-ctos.png -------------------------------------------------------------------------------- /design-en/image/tx-manager-module/tx-manager-ctosatellite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tx-manager-module/tx-manager-ctosatellite.png -------------------------------------------------------------------------------- /design-en/image/tx-manager-module/tx-manager-functional-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tx-manager-module/tx-manager-functional-architecture.png -------------------------------------------------------------------------------- /design-en/image/tx-manager-module/tx-manager-satellitetoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-en/image/tx-manager-module/tx-manager-satellitetoc.png -------------------------------------------------------------------------------- /design-en/j.Account Ledger Design v.13.md: -------------------------------------------------------------------------------- 1 | # Account Ledger module design document 2 | 3 | [TOC] 4 | 5 | ## 1. Overall description 6 | 7 | ### 1.1 Module Overview 8 | 9 | #### 1.1.1 Why do you have a "Ledger module"? 10 | 11 | > The ledger module is the data hub of the blockchain. The balances and transactions of all accounts are saved in the ledger module. 12 |   A network-wide account ledger is saved on each network node to ensure complete, open and transparent data, while ensuring that data cannot be tampered and traceable. 13 | 14 | #### 1.1.2 What should be done in the Ledger Module? 15 | 16 | > Provide data support for assembly transactions, mainly accounting and auditing, verify the legality of the transaction, such as: whether there is sufficient balance, whether to repeat payment (double flower) 17 | 18 | #### 1.1.3 Positioning of the "Ledger module" in the system 19 | 20 | > The ledger module is the data hub, which stores the result data of all existing transactions in the system. It does not depend on any business modules, and other modules depend on it as needed. 21 | #### 1.1.4 Explanation of terms in "Ledger module" 22 | 23 | - The random number of the transaction (nonce, a 32-bit hash value) 24 | - nonce: A scalar value equal to the number of transactions sent at this address, which will be included in every transaction initiated by the user. 25 | - Each transaction in the account needs to save the nonce (hash) of the previous transaction 26 | - Strictly speaking, a nonce is an attribute of the originating address (it only makes sense in the context of the sending address). However, the nonce is not explicitly stored in the blockchain as part of the account status. 27 | - The nonce value is also used to prevent incorrect calculation of account balances. For example, suppose an account has 10 NULS balances and signs two transactions, all of which cost 6 NULS with nonce 1 and nonce 2, respectively. Which of the two transactions is valid? In a blockchain distributed system, nodes may receive transactions out of order. Nonce forces transactions of any address to be processed in order, regardless of the interval, regardless of the order in which the nodes receive. This way, all nodes will calculate the same balance. The transaction paying 6 Ethereum will be successfully processed and the account balance will be reduced to 4 ether. Whenever it is received, all nodes believe that the transaction with nonce 2 is invalid. If a node receives a nonce 2 transaction first, it will hold it, but will not verify it until it receives and processes the nonce 1 transaction. 28 | - Use nonce to ensure that all nodes calculate the same balance and correctly sort the transactions, which is equivalent to the mechanism used in Bitcoin to prevent "double payment". However, because Ethereum tracks account balances and does not track individual coins separately (called UTXO in Bitcoin), "double payments" occur only when the account balance is incorrectly calculated. The nonce mechanism prevents this from happening. 29 | 30 | ### 1.2 Architecture 31 | > The core of the Ledger is assets management and ledger management. 32 | 33 | ![ledger-arch.png](image/ledger/ledger-arch.png) 34 | 35 | ## 2. functional design 36 | 37 | ### 2.1 Functional Architecture 38 | ![ledger-functions.png](image/ledger/ledger-functions.png) 39 | 40 | ### 2.2 Module Service 41 | #### 2.2.1 System Service of the Ledger Module 42 | ![ledger-service.png](image/ledger/ledger-service.png) 43 | 44 | > The RPC interface call provided by the ledger module. For detailed interface, please refer to the interface design section. 45 | 46 | #### 2.2.2 Modifying system operating parameters 47 | 48 | > Only rely on the core system, the core system can start, stop, modify parameters, etc. of the event module system, 49 | 50 | ### 2.3 Module internal function 51 | #### 2.3.1 Hot (online) transaction processing 52 | 53 | > Module internal work mainly includes asset management, obtaining account address balance and nonce, and verifying transaction coinData. 54 | 55 | - asset Management 56 | - Total assets of the account 57 | - Available assets 58 | - Freeze assets. For locked assets, separate record and locked asset information, including chain ID, asset ID, asset amount, lock time, lock height, etc. 59 | - In the asset unlocking process, when the user's locked asset time or height reaches the unlock condition, the account will unlock the asset information, accumulate the available balance, and delete the asset lock record of the local data. 60 | - Multi-asset situation, need to join chainId. 61 | - Get account address balance and nonce 62 | - Get account address balance 63 | - Get the account address nonce (the nonce is a hash value, meaning that the nonce of the first transaction is 0. Each transaction in the account will contain the nonce value of the previous transaction) 64 | - Verify the transaction 65 | - Double flower verification (nonce mechanism prevents double payment) 66 | - Transaction creator verification, verifying that the issuer of the transaction has sufficient balance to verify that the nonce of the transaction creator is legal 67 | - Continuous transaction verification 68 | - Function Interface Management (rpc) 69 | - rpc interface for use by other modules 70 | 71 | #### 2.3.2 Cold (offline) transaction processing 72 | > A cold wallet is an unconnected wallet, also called an offline wallet. A hot wallet is a wallet that keeps online, that is, an online wallet. Cold wallets are not more secure than hot wallets. 73 | 74 | > Since the cold wallet only signs the transaction information, the signed hex string is transmitted to the server through the hot wallet, and then the server performs unified transaction processing, so the client needs to perform the offline signature function. 75 | > The offline transaction system maintains the storage information of the nonce. After using a nonce, the nonce is saved in the business system. 76 | 77 | ### 2.4 Ledger flowcharts 78 | #### 2.4.1 Transfer Transaction Process 79 | 80 | - User enters the address of the transfer and the transferred address and the transferred amount 81 | - The system signs the transfer information by the private key of the transferred address (used to prove that the transaction was actually initiated by me) 82 | - The system verifies the transaction information 83 | - Balance verification 84 | - Fee verification 85 | - nonce continuity verification 86 | - Signature and input account verification 87 | - Put this transaction into the local TxPool (that is, the account unconfirmed trading pool) 88 | - Broadcast transaction information to other nodes 89 | - Packing blocks, verifying blocks 90 | - Confirm transaction 91 | - Update the balance of all accounts related (transferred or transferred) 92 | - Update the nonce corresponding to the account asset 93 | 94 | #### 2.4.2 Ordinary transaction process (reference example) 95 | 96 | ![eth-transaction-flow.png](image/ledger/eth-transaction-flow.png) 97 | 98 | #### 2.4.3 Transaction verification process 99 | 100 | ![trx-validate-flow.png](image/ledger/trx-validate-flow.png) 101 | 102 | ## 3.Interface design 103 | 104 | ### 3.1 Module core interaction interface 105 | 106 | #### 3.1.1 Get account balance 107 | 108 | > cmd: getBalance 109 | 110 | ##### Parameter Description (request) 111 | 112 | | Field | Required or not | type | desc | 113 | | ------------ | :-------------: | -----: | -----------------------------------: | 114 | | chainId | Y | int | Chain id of the interface call chain | 115 | | address | Y | String | The address to check the balance | 116 | | assetChainId | Y | int | Asset-initiated chain ID | 117 | | assetId | Y | int | Asset ID | 118 | 119 | ```json 120 | { 121 | 122 | "chainId":5, 123 | "address":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 124 | "assetChainId":34, 125 | "assetId":5, 126 | } 127 | ``` 128 | 129 | ##### Return value description (response) 130 | 131 | ```json 132 | { 133 | "available": "10000000000", 134 | "freeze": "200000000", 135 | "total": "12000000000" 136 | } 137 | ``` 138 | 139 | > remarks: 1NULS=10^8Na 140 | 141 | | Field | type | DESC | 142 | | --------- | :--------: | -----------------------: | 143 | | available | BigInteger | Available Balance | 144 | | freeze | BigInteger | freeze | 145 | | total | BigInteger | total = available+freeze | 146 | 147 | 148 | 149 | #### 3.1.2 Get the current account nonce value 150 | 151 | > cmd: getNonce 152 | > 153 | > 154 | 155 | ##### Parameter Description(request) 156 | 157 | | Field | Required or not | type | desc | 158 | | ------------ | :-------------: | -----: | -----------------------------------: | 159 | | chainId | Y | int | Chain id of the interface call chain | 160 | | address | Y | String | The address to check the balance | 161 | | assetChainId | Y | String | Asset-initiated chain ID | 162 | | assetId | Y | int | Asset ID | 163 | 164 | ```json 165 | { 166 | 167 | "chainId":5, 168 | "address":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 169 | "assetChainId":34, 170 | "assetId":5, 171 | } 172 | ``` 173 | 174 | ##### Return value description(response) 175 | 176 | ```json 177 | { 178 | "nonce":"xxxxxxxxxxx", 179 | "nonceType":1 180 | } 181 | ``` 182 | 183 | 184 | 185 | | Field | Type | Desc | 186 | | --------- | :----: | -----------------------------------------------------------: | 187 | | nonce | String | Spending transaction hash | 188 | | nonceType | int | 1The last transaction has been confirmed, 0 the transaction has not been confirmed | 189 | 190 | 191 | 192 | #### 3.1.3 Get balance and nonce value 193 | 194 | > cmd: getBalanceNonce 195 | 196 | ##### Parameter Description (request) 197 | 198 | ##### 199 | 200 | | Field | Required or not | type | desc | 201 | | ------------ | :-------------: | -----: | -----------------------------------: | 202 | | chainId | Y | int | Chain id of the interface call chain | 203 | | address | Y | String | The address to check the balance | 204 | | assetChainId | Y | String | Asset-initiated chain ID | 205 | | assetId | Y | int | Asset ID | 206 | 207 | ```json 208 | { 209 | 210 | "chainId":5, 211 | "address":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 212 | "assetChainId":"34", 213 | "assetId":"5", 214 | } 215 | ``` 216 | 217 | ##### Return value description:(response) 218 | 219 | ```json 220 | { 221 | "available": "10000000000", 222 | "nonce": "xxxxx" 223 | } 224 | ``` 225 | 226 | | Field | Type | Desc | 227 | | --------- | :--------: | -----------------------------------------------------------: | 228 | | available | BigInteger | User available balance | 229 | | nonce | String | A random value of the account that holds the hash of the user's last transaction. | 230 | | nonceType | int | 1The last transaction has been confirmed, 0 the transaction has not been confirmed | 231 | 232 | #### 3.1.4 Verify coinData 233 | 234 | > cmd: validateCoinData 235 | 236 | ##### Parameter Description (request) 237 | 238 | | Field | Required or not | Type | desc | 239 | | --------------- | :-------------: | ------: | ------------------------------------------: | 240 | | chainId | Y | int | Chain id of the interface call chain | 241 | | txHex | Y | String | Transaction hex stream | 242 | | isBatchValidate | Y | boolean | true batch validate,false per tx validate | 243 | 244 | ```json 245 | { 246 | "chainId": 458, 247 | "txHex": "xxxxxxxx", 248 | "isBatchValidate": "false" 249 | } 250 | ``` 251 | 252 | ##### Return value description:(response) 253 | 254 | ```json 255 | { 256 | "validateCode":1, 257 | "validateDesc":"success" 258 | } 259 | ``` 260 | 261 | | Field | Type | Desc | 262 | | ------------ | :----: | -----------------------------------------------------------: | 263 | | validateCode | int | 1 check pass, 2 orphan trade 3 double flower 4 other abnormalities | 264 | | validateDesc | String | Check return description | 265 | 266 | 267 | 268 | #### 3.1.5 Batch verification notify 269 | 270 | > cmd: bathValidateBegin 271 | 272 | ##### Parameter Description (request) 273 | 274 | | Field | Required or not | Type | desc | 275 | | ------- | :-------------: | ---: | -------: | 276 | | chainId | Y | int | chain Id | 277 | 278 | ```json 279 | { 280 | "chainId": 21 281 | } 282 | ``` 283 | 284 | ##### Return value description:(response) 285 | 286 | ```json 287 | { 288 | "value":1 289 | } 290 | ``` 291 | 292 | | Field | Type | Desc | 293 | | ----- | :--: | :----------: | 294 | | value | int | 1成功,0失败 | 295 | 296 | #### 297 | 298 | #### 3.1.6 Submit transactions 299 | 300 | > cmd: commitTx 301 | 302 | ##### Parameter Description (request) 303 | 304 | | Field | Required or not | Type | Desc | 305 | | ----------- | :-------------: | ------: | ------------------------------------: | 306 | | chainId | Y | int | Chain id of the interface call chain | 307 | | txHex | Y | String | Transaction hex stream | 308 | | isConfirmTx | Y | boolean | true: comfirm tx false: unconfirm tx | 309 | 310 | ```json 311 | { 312 | "chainId": 21, 313 | "txHex": "xxxxxxxx", 314 | "isConfirmTx": "true", 315 | } 316 | ``` 317 | 318 | ##### Return value description:(response) 319 | 320 | ```json 321 | { 322 | "value":1 323 | } 324 | ``` 325 | 326 | | Field | Type | Desc | 327 | | ----- | :--: | -----------------: | 328 | | value | int | 1Success,0 failed | 329 | 330 | 331 | 332 | #### 3.1.7 Rollback transaction 333 | 334 | > cmd: rollBackConfirmTx 335 | 336 | ##### Parameter Description (request) 337 | 338 | | Field | Required or not | Type | desc | 339 | | ----------- | :-------------: | ------: | -----------------------------------: | 340 | | chainId | Y | int | Chain id of the interface call chain | 341 | | txHex | Y | String | Transaction hex stream | 342 | | isConfirmTx | Y | boolean | true: comfirm tx false: unconfirm tx | 343 | 344 | ```json 345 | { 346 | "chainId": 21, 347 | "txHex": "xxxxxxxx" 348 | } 349 | ``` 350 | 351 | ##### Return value description:(response) 352 | 353 | ```json 354 | { 355 | "value":1 356 | } 357 | ``` 358 | 359 | | Field | Type | Desc | 360 | | ----- | :--: | -----------------: | 361 | | value | int | 1Success,0 failed | 362 | 363 | 364 | 365 | ### 3.2 Other interface 366 | 367 | #### 3.2.1 Obtain asset information based on asset id 368 | 369 | > cmd: getAsset 370 | 371 | ##### Parameter Description (request) 372 | 373 | | Field | Required or not | type | desc | 374 | | ------------ | :-------------: | -----: | -----------------------------------: | 375 | | chainId | Y | int | Chain id of the interface call chain | 376 | | assetChainId | Y | String | Asset-initiated chain ID | 377 | | assetId | Y | int | Asset ID | 378 | 379 | ```json 380 | { 381 | "chainId": 5, 382 | "assetChainId": 12, 383 | "assetId": 41 384 | } 385 | ``` 386 | 387 | ##### Return value description (response) 388 | 389 | ```json 390 | { 391 | "chainId": 5, 392 | "assetChainId": 12, 393 | "assetId": 41, 394 | "balance" : { 395 | "available": "10000000000", 396 | "freeze": "200000000", 397 | "total": "12000000000" 398 | } 399 | } 400 | ``` 401 | 402 | | Field | Type | Desc | 403 | | ----------------- | :--------: | ----------------------------------: | 404 | | chainId | int | The chain ID of the initiating call | 405 | | assetChainId | int | Asset-initiated chain id | 406 | | assetId | int | Asset ID | 407 | | balance.available | BigInteger | Available Balance | 408 | | balance.freeze | BigInteger | Freeze balance | 409 | | balance.total | BigInteger | total = available+freeze | 410 | 411 | 412 | 413 | ## 4. Description of the event 414 | 415 | > does not depend on any events 416 | 417 | ## 5. agreement 418 | 419 | ### 5.1 Network Communication Protocol 420 | 421 | NA 422 | 423 | ### 5.2 Trading Agreement 424 | 425 | ## 6. Module Configuration 426 | ### 6.1 Configuration Instructions 427 | 428 | ### 6.2 Module Dependencies 429 | 430 | - Kernel module 431 | - Module registration 432 | - Module logout 433 | - Module status escalation (heartbeat) 434 | - Service interface data acquisition and timing update 435 | 436 | ## 7. Java-specific design 437 | 438 | > Core object class definition, storing data structures, ... 439 | 440 | ## 8. supplementary content 441 | 442 | ### References Literature 443 | - [Proficient in Ethereum - Chapter 7 Transaction](https://github.com/inoutcode/ethereum_book/blob/master/%E7%AC%AC%E4%B8%83%E7%AB%A0.asciidoc) 444 | ``` 445 | 446 | ``` -------------------------------------------------------------------------------- /design-en/r.rpc-tool design v1.3.md: -------------------------------------------------------------------------------- 1 | # RPC-TOOL design document 2 | 3 | [TOC] 4 | 5 | ## 1. Overall description 6 | 7 | ### 1.1 summary 8 | 9 | #### 1.1.1 position of RPC-TOOL 10 | 11 | * NULS 2 according to function partition module, all modules are isolated and can run independently. 12 | * Interaction between modules through RPC call interface 13 | * As long as the module implements the required interface, it can be implemented in any language 14 | * Each module will use RPC, so it will be encapsulated into the same jar file 15 | 16 | 17 | 18 | #### 1.1.2 what will RPC-TOOL did 19 | 20 | Data interaction between modules is done through RPC-TOOL 21 | 22 | - RPC Server start 23 | - Register all CMD commands of the current module 24 | - Parsing the received CMD command 25 | - Returns the result by calling the corresponding method based on CMD 26 | - RPC Client start 27 | - Interacting with kernel 28 | 29 | 30 | 31 | #### 1.1.3 position 32 | 33 | [^说明]: 在系统中的定位,是什么角色,依赖哪些做哪些事情,可以被依赖用于做哪些事情 34 | 35 | RPC-TOOL is the underlying application, and any module will depend on RPC-TOOL. 36 | 37 | 38 | 39 | ## 2. functional design 40 | 41 | 42 | 43 | ## 3. interface design 44 | 45 | ### 3.1 interface 46 | 47 | #### status 48 | 49 | - Interface description 50 | Kernel will periodically push the status of the current system to each module, which is used for receiving 51 | 52 | - Request example 53 | ```json 54 | { 55 | "cmd":"status", 56 | "minVersion":1, 57 | "params":[ 58 | { 59 | "service":[ 60 | "a", 61 | "b", 62 | "c" 63 | ], 64 | "available":true, 65 | "modules":{ 66 | "moduleABC":{ 67 | "name":"moduleABC", 68 | "status":"READY", 69 | "available":false, 70 | "addr":"127.0.0.1", 71 | "port":19722, 72 | "rpcList":[ 73 | { 74 | "cmd":"shutdown", 75 | "version":1 76 | }, 77 | { 78 | "cmd":"cmd1", 79 | "version":1 80 | }, 81 | { 82 | "cmd":"conf_reset", 83 | "version":1 84 | }, 85 | { 86 | "cmd":"terminate", 87 | "version":1 88 | } 89 | ], 90 | "dependsModule":[ 91 | "m2", 92 | "m3" 93 | ] 94 | } 95 | } 96 | } 97 | ] 98 | } 99 | ``` 100 | 101 | - Request parameter specification 102 | 103 | | index | parameter | required | type | description | 104 | | ----- | :------------------ | :------- | :--- | ---------------------- | 105 | | 0 | modules_information | true | map | All module information | 106 | 107 | modules_information 108 | 109 | | parameter | required | type | description | 110 | | --------- | -------- | ----------------- | ---------------------- | 111 | | service | true | string[] | The dependent modules | 112 | | available | true | boolean | can start service? | 113 | | modules | true | map | All module information | 114 | 115 | module 116 | 117 | | parameter | required | type | description | 118 | | ------------- | -------- | -------- | --------------------- | 119 | | name | true | string | name | 120 | | status | true | string | status | 121 | | available | true | boolean | can start service? | 122 | | addr | true | string | ip address/host name | 123 | | port | true | int | port | 124 | | rpcList | true | list | cmd list | 125 | | dependsModule | true | string[] | The dependent modules | 126 | 127 | 128 | - Response example 129 | Failed 130 | 131 | ```json 132 | { 133 | "version": 1.2, 134 | "code":1, 135 | "msg" :"xxxxxxxxxxxxxxxxxx", 136 | "result":{} 137 | } 138 | ``` 139 | 140 | Success 141 | ```json 142 | { 143 | "version": 1.2, 144 | "code":0, 145 | "result":{} 146 | } 147 | ``` 148 | 149 | - Response field specification 150 | N/A 151 | 152 | 153 | 154 | #### shutdown 155 | 156 | - Interface description 157 | Kernel calls the interface to close the module (waiting for all the processing of the current business to complete) 158 | 159 | - Request example 160 | 161 | ```json 162 | { 163 | "cmd":"shutdown", 164 | "minVersion":1, 165 | "params":[] 166 | } 167 | ``` 168 | 169 | - Request parameter specification 170 | 171 | N/A 172 | 173 | - Response example 174 | Failed 175 | 176 | ```json 177 | { 178 | "version": 1.2, 179 | "code":1, 180 | "msg" :"xxxxxxxxxxxxxxxxxx", 181 | "result":{} 182 | } 183 | ``` 184 | 185 | Success 186 | 187 | ```json 188 | { 189 | "version": 1.2, 190 | "code":0, 191 | "result":{} 192 | } 193 | ``` 194 | 195 | - Response field specification 196 | N/A 197 | 198 | 199 | 200 | #### terminate 201 | 202 | - Interface description 203 | Kernel calls the interface to close the module (immediately terminates). 204 | 205 | - Request example 206 | 207 | ```json 208 | { 209 | "cmd":"terminate", 210 | "minVersion":1, 211 | "params":[] 212 | } 213 | ``` 214 | 215 | - Request parameter specification 216 | 217 | N/A 218 | 219 | - Response example 220 | Failed 221 | 222 | ```json 223 | { 224 | "version": 1.2, 225 | "code":1, 226 | "msg" :"xxxxxxxxxxxxxxxxxx", 227 | "result":{} 228 | } 229 | ``` 230 | 231 | Success 232 | 233 | ```json 234 | { 235 | "version": 1.2, 236 | "code":0, 237 | "result":{} 238 | } 239 | ``` 240 | 241 | - Response field specification 242 | N/A 243 | 244 | 245 | 246 | #### confGet 247 | 248 | - Interface description 249 | Kernel gets module configuration items 250 | 251 | - Request example 252 | 253 | ```json 254 | { 255 | "cmd":"confGet", 256 | "minVersion":1, 257 | "params":[] 258 | } 259 | ``` 260 | 261 | - Request parameter specification 262 | 263 | N/A 264 | 265 | - Response example 266 | Failed 267 | 268 | ```json 269 | { 270 | "version": 1.2, 271 | "code":1, 272 | "msg" :"xxxxxxxxxxxxxxxxxx", 273 | "result":{} 274 | } 275 | ``` 276 | 277 | Success 278 | 279 | ```json 280 | { 281 | "version": 1.2, 282 | "code":0, 283 | "result":{ 284 | "key1": "value1", 285 | "key2": "value2" 286 | } 287 | } 288 | ``` 289 | 290 | - Response field specification 291 | N/A 292 | 293 | 294 | 295 | #### confSet 296 | 297 | - Interface description 298 | Kernel sets module configuration items 299 | 300 | - Request example 301 | 302 | ```json 303 | { 304 | "cmd":"confSet", 305 | "minVersion":1, 306 | "params":[ 307 | { 308 | "key1":"value1", 309 | "key2":"value2" 310 | } 311 | ] 312 | } 313 | ``` 314 | 315 | - Request parameter specification 316 | 317 | N/A 318 | 319 | - Response example 320 | Failed 321 | 322 | ```json 323 | { 324 | "version": 1.2, 325 | "code":1, 326 | "msg" :"xxxxxxxxxxxxxxxxxx", 327 | "result":{} 328 | } 329 | ``` 330 | 331 | Success 332 | 333 | ```json 334 | { 335 | "version": 1.2, 336 | "code":0, 337 | "result":{} 338 | } 339 | ``` 340 | 341 | - Response field specification 342 | N/A 343 | 344 | 345 | 346 | #### confReset 347 | 348 | - Interface description 349 | Kernel restore template is configured as initial value. 350 | 351 | - Request example 352 | 353 | ```json 354 | { 355 | "cmd":"confReset", 356 | "minVersion":1, 357 | "params":[] 358 | } 359 | ``` 360 | 361 | - Request parameter specification 362 | 363 | N/A 364 | 365 | - Response example 366 | Failed 367 | 368 | ```json 369 | { 370 | "version": 1.2, 371 | "code":1, 372 | "msg" :"xxxxxxxxxxxxxxxxxx", 373 | "result":{} 374 | } 375 | ``` 376 | 377 | Success 378 | 379 | ```json 380 | { 381 | "version": 1.2, 382 | "code":0, 383 | "result":{} 384 | } 385 | ``` 386 | 387 | - Response field specification 388 | N/A 389 | 390 | 391 | 392 | 393 | 394 | ## 4. Event description 395 | 396 | 397 | 398 | 399 | ## 5. Protocol 400 | 401 | 402 | 403 | 404 | ## 6. Configuration 405 | 406 | 407 | 408 | ## 7. Java unique design 409 | 410 | ### Server 411 | - Start server 412 | ``` 413 | // Port is not necessary. If no port is specified, the system is allocated randomly 414 | BaseRpcServer server = new GrizzlyServer(RpcConstant.KERNEL_PORT); 415 | 416 | // Scan the package in which the CMD command is located 417 | server.scanPackage("io.nuls.rpc.mycmd"); 418 | 419 | // Initialization 420 | server.init("moduleName", "dependsModule, type is List"); 421 | 422 | // start 423 | server.start(); 424 | ``` 425 | 426 | - Custom CMD 427 | ``` 428 | // extends BaseCmd 429 | public class SomeCmd extends BaseCmd 430 | 431 | // Custom method to add annotation CmdInfo 432 | @CmdInfo(cmd = "cmd1", version = 1.0, preCompatible = true) 433 | public Object methodName(List params) { 434 | System.out.println("I'm version 1"); 435 | return success(); 436 | } 437 | 438 | Note: rpc-tool automatically transfers the Object[] transferred from client to List. 439 | ``` 440 | 441 | - There must be and only one CMD class to implement the KernelCmd interface. 442 | ``` 443 | // Implement interface 444 | public class SomeCmd extends BaseCmd implements KernelCmd 445 | 446 | /** 447 | * Receive all module information from kernel 448 | */ 449 | public Object status(List params); 450 | 451 | /** 452 | * Shut down service: after the existing business is completed 453 | */ 454 | public Object shutdown(List params); 455 | 456 | /** 457 | * Shut down service: close immediately, whether or not the business is completed. 458 | */ 459 | public Object terminate(List params); 460 | 461 | /** 462 | * Provide local configuration information 463 | */ 464 | public Object confGet(List params); 465 | 466 | /** 467 | * Update local configuration information 468 | */ 469 | public Object confSet(List params); 470 | 471 | /** 472 | * Reset local configuration information 473 | */ 474 | public Object confReset(List params); 475 | ``` 476 | 477 | ### Client 478 | - Provide module information to kernel 479 | ``` 480 | RpcClient.versionToKernel(); 481 | ``` 482 | 483 | - call rpc 484 | ``` 485 | // CMD corresponds to one interface. 486 | String jsonStr = RpcClient.callSingleRpc("shutdown", params, minVersion); 487 | 488 | // CMD corresponds to multiple interfaces. 489 | String jsonStr = RpcClient.callMultiplyRpc("shutdown", params, minVersion); 490 | 491 | note: 492 | params is instance of Object[] 493 | ``` 494 | 495 | ### Data exchange 496 | - Request 497 | ``` 498 | { 499 | "cmd": "shutdown", 500 | "minVersion": 1.0, //根据自己需要传最低版本号 501 | "params": [], 502 | } 503 | ``` 504 | 505 | - Response(success and failure are the same) 506 | ``` 507 | { 508 | "code":0, 509 | "msg": " This property is only available when failed", 510 | "version": "Actually called version", 511 | "result": {} 512 | } 513 | ``` 514 | 515 | 516 | ### Other 517 | 1. BaseCmd has a default implementation of the status method, so if you don't have a specific requirement, you just need to do the following: 518 | ``` 519 | @Override 520 | @CmdInfo(cmd = RpcConstant.STATUS, version = 1.0, preCompatible = true) 521 | public Object status(List params){ 522 | return super.status(params); 523 | } 524 | ``` 525 | 526 | 2. There are ways to return to success and failure in BaseCmd. 527 | success: 528 | 529 | ``` 530 | protected Object success(double version) { 531 | return success(version, null); 532 | } 533 | 534 | protected Object success(double version, Object result) { 535 | Map map = new HashMap<>(16); 536 | map.put("code", 0); 537 | map.put("msg", SUCCESS); 538 | map.put("version", version); 539 | map.put("result", result); 540 | return map; 541 | } 542 | ``` 543 | 544 | fail: 545 | ``` 546 | protected Object fail(String code, String msg, double version, Object result) { 547 | Map map = new HashMap<>(16); 548 | map.put("code", code); 549 | map.put("msg", msg); 550 | map.put("version", version); 551 | map.put("result", result); 552 | return map; 553 | } 554 | ``` 555 | 556 | 557 | 558 | ## 8. supplementary content 559 | 560 | -------------------------------------------------------------------------------- /design-zh-CHS/README.md: -------------------------------------------------------------------------------- 1 | # nuls_2.0_docs 2 | nuls 2.0 documents 3 | -------------------------------------------------------------------------------- /design-zh-CHS/e.事件总线模块设计v1.3.md: -------------------------------------------------------------------------------- 1 | # 事件总线模块设计文档 2 | 3 | [TOC] 4 | 5 | ## 一、总体描述 6 | 7 | ### 1.1 模块概述 8 | 9 | #### 1.1.1 为什么要有《事件总线》模块 10 | 11 | > 事件总线模块是专门用来接收及通知处理模块事件的功能性模块,管理着所有模块事件。 12 | 13 | #### 1.1.2 《事件总线》要做什么 14 | 15 | > 提供事件的订阅、接收、发送等功能,是模块间的事件中转站 16 | 17 | #### 1.1.3 《事件总线》在系统中的定位 18 | 19 | > 事件模块是一个边缘系统,提供主要一些异步的消息发送,也就说,即使没有事件总线,系统一样可以正常运行,比较轻量级,而且不依赖其他模块系统。 20 | 21 | ### 1.2 架构图 22 | ![event-bus-module](image/eventbus/event-bus-module.png) 23 | 24 | - 事件总线模块主要含2部分交互逻辑: 25 | - 与系统核心模块的微服务注册与服务信息获取。 26 | - 与其他基础模块间的事件消息创建、订阅、转发管理。 27 | 28 | ## 二、功能设计 29 | 30 | ### 2.1 功能架构图 31 | ![event-bus-content](image/eventbus/event-bus-content.png) 32 | 33 | ### 2.2 模块服务 34 | ![event-bus-model](image/eventbus/event-bus-model.png) 35 | 36 | > 该模块提供事件的订阅,事件的转发 37 | 38 | #### 2.2.1 修改系统运行参数 39 | 40 | > 只依赖核心系统,核心系统可以对事件模块系统的启动,停止,参数修改等, 41 | 42 | ### 2.3 模块内部功能 43 | ![event-bus-function](image/eventbus/event-bus-function.png) 44 | 45 | > 模块内部工能主要包含,订阅管理器,事件管理器,转发管理器。 46 | 47 | - 微服务接口信息同步管理 48 | - 用于与kernel服务治理模块之间的服务接口同步 49 | - 事件储存管理(eventBus) 50 | - 用于进行事件信息的创建,订阅等储存,并且在模块重启是进行信息的初始化。 51 | - 事件订阅管理(subscribe) 52 | - 维护订阅事件的“配置表”:包括所有各个模块订阅的重要参数 53 | - 事件转发管理(dispatcher) 54 | - 开放接口用于事件的接收,对接收事件按订阅进行转发,转发调用接口通过服务信息管理接口获得 55 | - 功能接口管理(rpc) 56 | - 开放查询接口供外部查询 57 | ### 2.4 事件总线流程 58 | 59 | * 事件处理时序 60 | 61 | ![event-bus-seq-flow](image/eventbus/event-bus-seq-flow.png) 62 | 63 | - 事件处理基本流程 64 | 65 | ![event-bus-main-flow](image/eventbus/event-bus-main-flow.png) 66 | 67 | ### 2.5 业务逻辑 68 | 69 | > 在事件转发失败(比如网络原因)情况下进行的异常逻辑处理 ,按以下2种逻辑处理: 70 | 71 | - 1、保留事件调用 按队列重复调用,直到转发成功。 72 | - 2、尝试多次后直接丢弃,(暂定5次)每10秒后重试一次。 73 | 74 | ## 三、接口设计 75 | 76 | ### 3.1 模块接口 77 | #### 3.1.1 事件主题订阅 78 | > cmd: subscribe 79 | 80 | ##### 参数说明 (request body) 81 | 82 | ```json 83 | { 84 | "cmd": "subscribe", 85 | "min_version": "1.0", 86 | "params":[ 87 | "app.nuls.network.bandwidth",//topic 事件主题 88 | "moduleId" //moduleId订阅者模块id 89 | ] 90 | } 91 | ``` 92 | ##### 返回值说明 (response content) 93 | 94 | ```json 95 | { 96 | "version": "1.0", 97 | "code": 0,//操作码 98 | "msg": "reponse message.",//失败时的信息 99 | "result": { 100 | "app_secret": "xxxxxxxxxxxx" // app_secret,暂时不需要,后期如果需要不是本机调用可能需要验证 101 | } 102 | } 103 | ``` 104 | 105 | #### 3.1.2 事件取消订阅 106 | > cmd: unsubscribe 107 | 108 | ##### 参数说明 (request body) 109 | 110 | ```json 111 | { 112 | "cmd": "unsubscribe", 113 | "min_version": "1.0", 114 | "params":[ 115 | "app.nuls.network.bandwidth", //topic 事件主题 116 | "moduleId" //moduleId订阅者模块id 117 | ] 118 | } 119 | ``` 120 | 121 | ##### 返回值说明:(response content) 122 | 123 | ```json 124 | { 125 | "version": "1.0", 126 | "code": 0, //操作码 127 | "msg": "reponse message.",//失败时的信息 128 | "result": { 129 | } 130 | } 131 | ``` 132 | 133 | #### 3.1.3 事件发送【自动创建topic】 134 | > 在没人订阅情况下是否保留一定时间? 135 | 136 | > cmd: send 137 | 138 | ##### 参数说明(request body) 139 | 140 | ```json 141 | { 142 | "cmd": "send", 143 | "min_version": "1.0", 144 | "params":[ 145 | "app.nuls.network.bandwidth",//topic 事件主题 146 | "moduleId", //moduleId订阅者模块id 147 | {"key" : "data value"} // 需要发送的事件,jsonObj 148 | ] 149 | } 150 | ``` 151 | 152 | ##### 返回值说明(response content) 153 | 154 | ```json 155 | { 156 | "version": "1.0", 157 | "code": 0, //操作码 158 | "msg": "reponse message.",//失败时的信息 159 | "result": { 160 | } 161 | } 162 | ``` 163 | #### 3.1.4 事件广播(推送push or dispatcher) 164 | > 需要每个接口在订阅事件时提供接口,我在广播时调用即可,我这里是多线程去掉你们接口,你们需要返回正确的code,否则会有走重试机制 165 | 166 | ##### 参数说明(request body) 167 | 168 | ```json 169 | { 170 | "cmd": "dispatcher", 171 | "min_version": "1.0", 172 | "params":[ 173 | {} //data 需要发送的事件,payload 174 | ] 175 | } 176 | ``` 177 | 178 | ##### 返回值说明(response content) 179 | 180 | ```json 181 | { 182 | "version": "1.0", 183 | "code": 0, //一定要正确返回,不要需要告诉你业务逻辑是否出错,你只要接收到了就告诉我你成功接收到了即可。 184 | "msg": "reponse message.",//失败时的信息 185 | "result": { 186 | } 187 | } 188 | ``` 189 | ### 3.2 功能接口 190 | > 功能接口是提供给界面和命令行工具使用的接口 191 | 192 | #### 获取事件主题信息 193 | > cmd: topics 194 | 195 | ##### 参数说明(request body) 196 | 197 | ```json 198 | { 199 | "cmd": "topics", 200 | "min_version": "1.0", 201 | "params":[] 202 | } 203 | ``` 204 | 205 | ##### 返回值说明(response content) 206 | 207 | ```json 208 | { 209 | "version": "1.0", 210 | "code": 0, //一定要正确返回,不要需要告诉你业务逻辑是否出错,你只要接收到了就告诉我你成功接收到了即可。 211 | "msg": "reponse message.",//失败时的信息 212 | "result": { 213 | "topics":[{ 214 | "topic": "", //主题id 215 | "createTime":"", //创建时间 216 | "moduleId":"", //主题创建者(模块)Id 217 | "subscribes":[//订阅者信息 218 | { 219 | "moduleId":"", //订阅者 220 | "subscribeTime":"" //订阅时间 221 | } 222 | ]} 223 | ] 224 | } 225 | } 226 | ``` 227 | 228 | #### 获取事件主题信息(包含该主题上所有事件信息?) 每个事件其实我不关心的。 229 | > cmd : get_topic 230 | 231 | ## 四、事件说明 232 | 233 | > 不依赖任何事件 234 | 235 | ## 五、协议 236 | 237 | ### 5.1 网络通讯协议 238 | 239 | 无 240 | 241 | ### 5.2 交易协议 242 | 243 | ## 六、模块配置 244 | ### 6.1 配置说明 245 | > 一般支持性配置,端口,重试次数,重试时间,默认执行器的线程池大小,网络调用超时配置等。 246 | ```yml 247 | server: 248 | ip: 127.0.0.1 //本机ip,用于提供服务给其他模块,可以不填,默认自动获取 249 | port: 8080 //提供服务的端口,可以不填,默认自动获取 250 | ``` 251 | ### 6.2 模块依赖关系 252 | 253 | - 内核模块 254 | - 模块注册 255 | - 模块注销 256 | - 模块状态上报(心跳) 257 | - 服务接口数据获取及定时更新 258 | 259 | ## 七、Java特有的设计 260 | 261 | > 核心对象类定义,存储数据结构,...... 262 | 263 | ## 八、补充内容 264 | 265 | > 上面未涉及的必须的内容 266 | 267 | -------------------------------------------------------------------------------- /design-zh-CHS/h.通用协议设计v1.3.md: -------------------------------------------------------------------------------- 1 | # Protocol design 2 | 3 | [TOC] 4 | 5 | ## Common standards 6 | 7 | ### Hashes 8 | 9 | Usually, when a hash is computed within Satellite-chain, it is computed twice. Most of the time [SHA-256](http://en.wikipedia.org/wiki/SHA-2) hashes are used, however [RIPEMD-160](http://en.wikipedia.org/wiki/RIPEMD) is also used when a shorter hash is desirable (for example when creating a NULS address). 10 | 11 | Example of double-SHA-256 encoding of string "nuls": 12 | 13 | ``` 14 | nuls 15 | 96cc377699e3289875d6d40da436110d692e823eb8900ae13a7107cb36c7310c (first round of sha-256) 16 | 7e0590c37ab91aacabdac1bedec9ff6acd609215d019e489cc0a5dcf38b7b055(second round of sha-256) 17 | 18 | ``` 19 | 20 | For NULS addresses (RIPEMD-160) this would give: 21 | 22 | ``` 23 | nuls 24 | 96cc377699e3289875d6d40da436110d692e823eb8900ae13a7107cb36c7310c (first round is sha-256) 25 | f8e8d1c6f1511c356effad8b986b0aa439a88c44(with ripemd-160) 26 | ``` 27 | 28 | ### Merkle Trees 29 | 30 | Merkle trees are binary trees of hashes. Merkle trees in NULS use a **double** SHA-256, the SHA-256 hash of the SHA-256 hash of something. 31 | 32 | If, when forming a row in the tree (other than the root of the tree), it would have an odd number of elements, the final double-hash is duplicated to ensure that the row has an even number of hashes. 33 | 34 | First form the bottom row of the tree with the ordered double-SHA-256 hashes of the byte streams of the transactions in the block. 35 | 36 | Then the row above it consists of half that number of hashes. Each entry is the double-SHA-256 of the 64-byte concatenation of the corresponding two hashes below it in the tree. 37 | 38 | This procedure repeats recursively until we reach a row consisting of just a single double-hash. This is the **Merkle root** of the tree. 39 | 40 | For example, imagine a block with three transactions *a*, *b* and *c*. The Merkle tree is: 41 | 42 | ``` 43 | d1 = dhash(a) 44 | d2 = dhash(b) 45 | d3 = dhash(c) 46 | d4 = dhash(c) # a, b, c are 3. that's an odd number, so we take the c twice 47 | 48 | d5 = dhash(d1 concat d2) 49 | d6 = dhash(d3 concat d4) 50 | 51 | d7 = dhash(d5 concat d6) 52 | 53 | ``` 54 | 55 | where 56 | 57 | ``` 58 | dhash(a) = sha256(sha256(a)) 59 | 60 | ``` 61 | 62 | *d7* is the Merkle root of the 3 transactions in this block. 63 | 64 | ### Addresses 65 | 66 | A NULS address is in fact the hash of a ECDSA public key, computed this way: 67 | 68 | ``` 69 | ChainId = 2 byte,The ID of the chain in which the account belongs. 70 | addressType = 1 byte,The type of the account,Example: 1 general account, 2 contract account…… 71 | pkh = 20 byte , RIPEMD-160(SHA-256(public key)) 72 | xor = 1 byte, XOR(chainId+addressType+pkh) 73 | address = Base58Encode(chainId+addressType+pkh+xor) 74 | ``` 75 | 76 | 非nuls体系的地址格式如下: 77 | 78 | 例如:比特币地址,在地址之前追加两个字节的chainId,之后跟随比特币的原始地址,地址解析方式根据链配置决定 79 | 80 | ``` 81 | address = Base58Encode(chainId+原始地址长度+原始地址+xor) 82 | ``` 83 | 84 | ## Message Structre 85 | 86 | Satellite-chain uses custom messaging for communication over the TCP protocol. 87 | 88 | - Digital binary stream using little endian。 89 | - Floating point numbers convert to integers and transfer by little endian 90 | 91 | ### Message 92 | 93 | The message consists of a 24-byte header and payload. 94 | 95 | ``` 96 | *---------------------------------------------------------------* 97 | | Header(24 Byte) | Payload | 98 | *---------------------------------------------------------------* 99 | ``` 100 | 101 | #### message header 102 | 103 | The main role of the header is to indicate the payload length, verify data integrity, and solve TCP sticky packets. 104 | 105 | | Len | Fields | Data Type | Remark | 106 | | ---- | ------------- | --------- | ---------------------------------------- | 107 | | 4 | MagicNumber | uint32 | Packet valid flag | 108 | | 12 | command | char[12] | ASCII string identifying the packet content, NULL padded | 109 | | 4 | PayloadLength | uint32 | Length of payload in number of bytes | 110 | | 4 | checksum | uint32 | First 4 bytes of sha256(sha256(payload)) | 111 | | | | | | 112 | 113 | [^MagicNumber]: MagicNumber In addition to being validated as a valid check, it is also used for the division of the main network and test. 114 | 115 | ## Common Structre 116 | 117 | ### VarInt 118 | 119 | Variable-length integers that can be encoded based on the values expressed to save space. 120 | 121 | | Value | Len | Structure | 122 | | ------------- | ---- | ------------- | 123 | | < 0xfd | 1 | uint8 | 124 | | <= 0xffff | 3 | 0xfd + uint16 | 125 | | <= 0xffffffff | 5 | 0xfe + uint32 | 126 | | > 0xffffffff | 9 | 0xff + uint64 | 127 | 128 | ### VarString 129 | 130 | A variable-length byte stream consisting of a variable-length buffer. The string is encoded in UTF8. 131 | 132 | | Len | Fields | Data Type | Remark | 133 | | ------ | ------ | ------------- | -------------------- | 134 | | ? | length | VarInt | Length of the string | 135 | | length | value | uint8[length] | The string itself | 136 | 137 | ### VarByte 138 | 139 | Variable-length buffer, consistent with the VarString implementation. 140 | 141 | | Len | Fields | Data Type | Remark | 142 | | ------ | ------ | ------------ | ------------------------------------ | 143 | | ? | length | VarInt | Length of payload in number of bytes | 144 | | length | data | byte[length] | payload | 145 | 146 | ### Int48 147 | 148 | 6-byte number. 149 | 150 | ### Network address 151 | 152 | When a network address is needed somewhere, this structure is used. 153 | 154 | | Len | Fields | Data type | Remark | 155 | | ---- | ------ | --------- | ------------------------------------------------------------ | 156 | | 16 | IPv6/4 | char[16] | IPv6/4 address. Network byte order. The IPv4 address is written into the message as a 16 byte | 157 | | 2 | port1 | uint16 | port number, network byte order | 158 | | 2 | port2 | uint16 | port number,for cross-chain module | 159 | 160 | ## Block_headers 161 | 162 | | Len | Fields | Data Type | Remark | 163 | | ---- | ---------- | --------- | ---------------------------------- | 164 | | 4 | version | uint32 | version bumber | 165 | | 32 | preHash | byte[32] | | 166 | | 32 | merkleRoot | byte[32] | | 167 | | ? | stateRoot | VarByte | | 168 | | 4 | time | uint32 | second | 169 | | 2 | txCount | uint16 | | 170 | | ? | extends | VarByte | 本字段内容不同的链可设置不同的约束 | 171 | | ? | signature | Varbyte | | 172 | 173 | [^ 注]: 可以考虑是否添加stateRoot字段适配智能合约 174 | 175 | ## Transactions 176 | 177 | | Len | Fields | Data Type | Remark | 178 | | ---- | -------- | --------- | ------------------------ | 179 | | 2 | type | uint16 | 交易类型 | 180 | | 4 | time | uint32 | 时间,精确到秒 | 181 | | ? | txData | VarByte | 业务数据 | 182 | | ? | coinData | VarByte | 资产数据 | 183 | | ? | remark | VarString | 备注 | 184 | | ? | sig | VarByte | 只包含签名,不包含pubkey | 185 | | | | | | 186 | 187 | 交易特性 188 | 189 | ``` 190 | 多账户转出 191 | 多账户转入 192 | 多资产转账 193 | ``` 194 | 195 | coinData结构 196 | 197 | ``` 198 | froms://List格式, 199 | tos://List格式 200 | ``` 201 | 202 | CoinForm结构[40] 203 | 204 | ``` 205 | address: //byte[24] 账户地址 206 | assetsChainId://uint16 资产发行链的id 207 | assetsId: //uint16 资产id 208 | amount: //uint128,转出数量 209 | nonce : //byte[8] 交易顺序号,前一笔交易的hash的后8个字节 210 | locked : //byte 是否是锁定状态(locktime:-1),1代表锁定,0代表非锁定 211 | ``` 212 | 213 | CoinTo结构[44] 214 | 215 | ``` 216 | address: //byte[24],目标地址 217 | assetsChainId://uint16 资产发行链的id 218 | assetsId: //uint16 资产id 219 | amount : //uint128,转账金额 220 | lockTime://uint32,解锁高度或解锁时间,-1为永久锁定 221 | ``` 222 | 223 | 手续费 224 | 225 | ``` 226 | forms-tos剩余的部分就是手续费(模型中支持多种资产缴纳手续费,约束条件由经济模型设计决定) 227 | ``` 228 | 229 | ## Message Types 230 | 231 | 参考各个模块 232 | 233 | 234 | 235 | 236 | 237 | -------------------------------------------------------------------------------- /design-zh-CHS/image/account-module/account-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/account-module/account-context.png -------------------------------------------------------------------------------- /design-zh-CHS/image/account-module/account-create-address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/account-module/account-create-address.png -------------------------------------------------------------------------------- /design-zh-CHS/image/account-module/account-create-offline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/account-module/account-create-offline.png -------------------------------------------------------------------------------- /design-zh-CHS/image/account-module/account-export-keystore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/account-module/account-export-keystore.png -------------------------------------------------------------------------------- /design-zh-CHS/image/account-module/account-export-prikey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/account-module/account-export-prikey.png -------------------------------------------------------------------------------- /design-zh-CHS/image/account-module/account-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/account-module/account-functions.png -------------------------------------------------------------------------------- /design-zh-CHS/image/account-module/account-import-keystore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/account-module/account-import-keystore.png -------------------------------------------------------------------------------- /design-zh-CHS/image/account-module/account-import-prikey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/account-module/account-import-prikey.png -------------------------------------------------------------------------------- /design-zh-CHS/image/account-module/account-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/account-module/account-module.png -------------------------------------------------------------------------------- /design-zh-CHS/image/account-module/account-remove-address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/account-module/account-remove-address.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-basic-validation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-basic-validation.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-basic-validation1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-basic-validation1.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-basic-validation2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-basic-validation2.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-context.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-fork-chain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-fork-chain.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-fork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-fork.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-functions.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-module-boot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-module-boot.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-module.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-monitoring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-monitoring.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-synchronization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-synchronization.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-synchronization2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-synchronization2.png -------------------------------------------------------------------------------- /design-zh-CHS/image/block-module/block-synchronization3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/block-module/block-synchronization3.png -------------------------------------------------------------------------------- /design-zh-CHS/image/bridge-layer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/bridge-layer.png -------------------------------------------------------------------------------- /design-zh-CHS/image/bridge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/bridge.png -------------------------------------------------------------------------------- /design-zh-CHS/image/cg-module/cg-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/cg-module/cg-functions.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/assetDestroy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/assetDestroy.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/assetRegister.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/assetRegister.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/chain-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/chain-context.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/chain-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/chain-functions.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/chain-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/chain-module.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/chain-off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/chain-off.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/chain-register.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/chain-register.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/chainDestroy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/chainDestroy.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/chainOff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/chainOff.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/chainRegister.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/chainRegister.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/structure.png -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/主要结构.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/主要结构.vsdx -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/增加资产.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/增加资产.vsdx -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/注册链.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/注册链.vsdx -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/注销资产.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/注销资产.vsdx -------------------------------------------------------------------------------- /design-zh-CHS/image/chainModule/注销链.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/chainModule/注销链.vsdx -------------------------------------------------------------------------------- /design-zh-CHS/image/consensus-module/coinbase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/consensus-module/coinbase.png -------------------------------------------------------------------------------- /design-zh-CHS/image/consensus-module/consensus-constants.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/consensus-module/consensus-constants.jpg -------------------------------------------------------------------------------- /design-zh-CHS/image/consensus-module/consensus-flow-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/consensus-module/consensus-flow-5.png -------------------------------------------------------------------------------- /design-zh-CHS/image/consensus-module/consensus-func.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/consensus-module/consensus-func.png -------------------------------------------------------------------------------- /design-zh-CHS/image/consensus-module/consensus-staticsReward.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/consensus-module/consensus-staticsReward.jpg -------------------------------------------------------------------------------- /design-zh-CHS/image/consensus-module/statics_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/consensus-module/statics_en.png -------------------------------------------------------------------------------- /design-zh-CHS/image/eventbus/event-bus-content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/eventbus/event-bus-content.png -------------------------------------------------------------------------------- /design-zh-CHS/image/eventbus/event-bus-function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/eventbus/event-bus-function.png -------------------------------------------------------------------------------- /design-zh-CHS/image/eventbus/event-bus-main-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/eventbus/event-bus-main-flow.png -------------------------------------------------------------------------------- /design-zh-CHS/image/eventbus/event-bus-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/eventbus/event-bus-model.png -------------------------------------------------------------------------------- /design-zh-CHS/image/eventbus/event-bus-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/eventbus/event-bus-module.png -------------------------------------------------------------------------------- /design-zh-CHS/image/eventbus/event-bus-seq-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/eventbus/event-bus-seq-flow.png -------------------------------------------------------------------------------- /design-zh-CHS/image/kernel/OOD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/kernel/OOD.png -------------------------------------------------------------------------------- /design-zh-CHS/image/kernel/structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/kernel/structure.png -------------------------------------------------------------------------------- /design-zh-CHS/image/ledger/eth-transaction-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/ledger/eth-transaction-flow.png -------------------------------------------------------------------------------- /design-zh-CHS/image/ledger/ledger-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/ledger/ledger-arch.png -------------------------------------------------------------------------------- /design-zh-CHS/image/ledger/ledger-flow-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/ledger/ledger-flow-01.png -------------------------------------------------------------------------------- /design-zh-CHS/image/ledger/ledger-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/ledger/ledger-functions.png -------------------------------------------------------------------------------- /design-zh-CHS/image/ledger/ledger-service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/ledger/ledger-service.png -------------------------------------------------------------------------------- /design-zh-CHS/image/ledger/trx-validate-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/ledger/trx-validate-flow.png -------------------------------------------------------------------------------- /design-zh-CHS/image/modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/modules.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/connectSelf-recieve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/connectSelf-recieve.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/connectSelf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/connectSelf.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/connection.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/connet-add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/connet-add.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/connet-validate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/connet-validate.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/createNodeGroup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/createNodeGroup.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/createNodeGroup0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/createNodeGroup0.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/crossPortDeliver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/crossPortDeliver.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/deleteNodeGroup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/deleteNodeGroup.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/deleteNodeGroup2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/deleteNodeGroup2.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/discoverPeer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/discoverPeer.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-client-connection-heartbeats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-client-connection-heartbeats.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-client-connection-management.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-client-connection-management.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-client-connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-client-connection.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-context.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-functions.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-module.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-node-mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-node-mode.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-node-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-node-start.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-normal-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-normal-start.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-seed-client-connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-seed-client-connection.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-seed-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-seed-start.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-server-connection-heartbeats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-server-connection-heartbeats.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/network-server-connection-management.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/network-server-connection-management.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/nodeManage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/nodeManage.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/pingpong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/pingpong.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/recMessage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/recMessage.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/recMessage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/recMessage2.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/saveNodeIp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/saveNodeIp.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/sendMsg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/sendMsg1.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/sendMsg2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/sendMsg2.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/shutdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/shutdown.png -------------------------------------------------------------------------------- /design-zh-CHS/image/network-module/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/network-module/start.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tools-rpc/Websocket-Tool-package.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tools-rpc/Websocket-Tool-package.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tools-rpc/rpc-heart-beat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tools-rpc/rpc-heart-beat.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tools-rpc/rpc-interface-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tools-rpc/rpc-interface-list.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tools-rpc/rpc-server-start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tools-rpc/rpc-server-start.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tools-rpc/rpc-struts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tools-rpc/rpc-struts.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tools/db-tools-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tools/db-tools-functions.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tools/java-tools-content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tools/java-tools-content.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tools/java-tools-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tools/java-tools-functions.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tools/java-tools-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tools/java-tools-module.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tx-manager-module/tx-manager-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tx-manager-module/tx-manager-architecture.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tx-manager-module/tx-manager-context.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tx-manager-module/tx-manager-context.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tx-manager-module/tx-manager-ctos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tx-manager-module/tx-manager-ctos.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tx-manager-module/tx-manager-ctosatellite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tx-manager-module/tx-manager-ctosatellite.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tx-manager-module/tx-manager-functional-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tx-manager-module/tx-manager-functional-architecture.png -------------------------------------------------------------------------------- /design-zh-CHS/image/tx-manager-module/tx-manager-satellitetoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/design-zh-CHS/image/tx-manager-module/tx-manager-satellitetoc.png -------------------------------------------------------------------------------- /design-zh-CHS/j.账本模块设计v.13.md: -------------------------------------------------------------------------------- 1 | # 账本模块设计文档 2 | 3 | [TOC] 4 | 5 | ## 一、总体描述 6 | 7 | ### 1.1 模块概述 8 | 9 | #### 1.1.1 为什么要有《账本模块》 10 | 11 | > 账本模块是区块链的数据中枢,所有账户的余额、交易都保存在账本模块中, 12 | 每一个全网节点上都会保存一个全网账本,保证了数据的完整、公开、透明,同时保证了数据不可篡改、可追溯 13 | 14 | #### 1.1.2 《账本模块》要做什么 15 | 16 | > 为组装交易提供数据支撑,主要就是记账和查账,验证交易的合法性,如:是否有充足的余额,是否重复支付(双花) 17 | 18 | #### 1.1.3 《账本模块》在系统中的定位 19 | 20 | > 账本模块是数据中枢,保存系统所有存在交易的结果数据,它不依赖任何业务模块,其他模块按需依赖它。 21 | #### 1.1.4 《账本模块》中名词解释 22 | - 交易的随机数(nonce,一个32位hash值) 23 | - nonce:与此地址发送的交易数量相等的标量值,用户发起的每一笔交易中都会包含该nonce。 24 | - 在该账户每笔交易都需要保存前一笔交易的nonce(hash) 25 | - 严格地说,nonce是始发地址的一个属性(它只在发送地址的上下文中有意义)。但是,该nonce并未作为账户状态的一部分显式存储在区块链中。 26 | - nonce值也用于防止帐户余额的错误计算。例如,假设一个账户有10个NULS的余额,并且签署了两个交易,都花费6个NULS,分别具有nonce 1和nonce 2。这两笔交易中哪一笔有效?在区块链分布式系统中,节点可能无序地接收交易。nonce强制任何地址的交易按顺序处理,不管间隔时间如何,无论节点接收到的顺序如何。这样,所有节点都会计算相同的余额。支付6以太币的交易将被成功处理,账户余额减少到4 ether。无论什么时候收到,所有节点都认为与带有nonce 2的交易无效。如果一个节点先收到nonce 2的交易,会持有它,但在收到并处理完nonce 1的交易之前不会验证它。 27 | - 使用nonce确保所有节点计算相同的余额,并正确地对交易进行排序,相当于比特币中用于防止“双重支付”的机制。但是,因为以太坊跟踪账户余额并且不会单独跟踪独立的币(在比特币中称为UTXO),所以只有在账户余额计算错误时才会发生“双重支付”。nonce机制可以防止这种情况发生。 28 | 29 | ### 1.2 架构图 30 | > 账本的核心还是资产管理和记账管理。 31 | 32 | ![ledger-arch.png](image/ledger/ledger-arch.png) 33 | 34 | ## 二、功能设计 35 | 36 | ### 2.1 功能架构图 37 | ![ledger-functions.png](image/ledger/ledger-functions.png) 38 | 39 | ### 2.2 模块服务 40 | #### 2.2.1 账本模块的系统服务 41 | ![ledger-service.png](image/ledger/ledger-service.png) 42 | 43 | > 账本模块提供的RPC的接口调用,详细接口请参照接口设计部分。 44 | 45 | #### 2.2.2 修改系统运行参数 46 | 47 | > 只依赖核心系统,核心系统可以对事件模块系统的启动,停止,参数修改等, 48 | 49 | ### 2.3 模块内部功能 50 | #### 2.3.1 热(在线)交易处理 51 | 52 | > 模块内部工能主要包含,资产管理,获取账户地址余额和nonce,验证交易coinData。 53 | 54 | - 资产管理 55 | - 账户的总资产 56 | - 可用资产 57 | - 冻结资产,对于有锁定的资产,需要单独记录以及锁定的资产信息,包含链ID,资产ID,资产金额,锁定时间,锁定高度等 58 | - 资产解锁流程,当用户的锁定资产时间或者高度达到解锁条件,账本会把该资产信息解锁,累计到可用余额,并删除本地数据的资产锁定记录。 59 | - 多资产情况,需要加入chainId. 60 | - 获取账户地址余额和nonce 61 | - 获取账户地址余额 62 | - 获取账户地址nonce(该nonce是一个交易hash值的后八位,意味着第一个交易的nonce是0.以后该账户的每一笔支出交易都会包含前一笔交易的nonce值 ) 63 | - 验证交易 64 | - 双花验证(nonce机制阻止双重支付) 65 | - 交易创建者验证,验证交易发出者是否拥有足够的余额,验证交易创建者的nonce是否合法 66 | - 连续交易验证 67 | - 功能接口管理(rpc) 68 | - 提供给其他模块使用的rpc接口 69 | 70 | #### 2.3.2 冷(离线)交易处理 71 | > 冷钱包就是不连网的钱包,也叫离线钱包。热钱包就是保持联网上线的钱包,也就是在线钱包。冷钱包不联网会比热钱包更安全。 72 | 73 | > 由于冷钱包只对交易信息进行签名,在通过热钱包传输签名后的hex字符串到服务端, 然后服务端再进行统一的交易处理, 所以客户端就需要做到离线签名的功能, 74 | > 离线交易系统中维护nonce的存储信息,使用一个nonce之后,在业务系统中对nonce进行保存处理。 75 | 76 | > 离线交易大部分都是有交易所自己处理,我们需要存储全网账户的账本数据 77 | 78 | ### 2.4 账本流程 79 | #### 2.4.1 转账交易流程 80 | 81 | - 用户输入转账的地址和转入的地址和转出的金额 82 | - 系统通过转出的地址的私钥对转账信息进行签名(用于证明这笔交易确实有本人发起) 83 | - 系统对交易信息进行验证 84 | - 余额验证 85 | - 手续费验证 86 | - nonce连续性验证 87 | - 签名与input账户验证 88 | - 把这笔交易入到本地的TxPool中(就是账本未确认交易池) 89 | - 把交易信息广播给其它节点 90 | - 打包区块,验证区块 91 | - 确认交易 92 | - 更新相关(转入或者转出)的所有账户的余额 93 | - 更新账户资产对应的nonce 94 | 95 | #### 2.4.2 普通交易流程(参考实例) 96 | 97 | ![eth-transaction-flow.png](image/ledger/eth-transaction-flow.png) 98 | 99 | #### 2.4.3 交易验证流程 100 | 101 | ![trx-validate-flow.png](image/ledger/trx-validate-flow.png) 102 | 103 | ## 三、接口设计 104 | 105 | ### 3.1 模块核心交互接口 106 | 107 | #### 3.1.1 获取账户余额 108 | 109 | > cmd: getBalance 110 | 111 | ##### 参数说明 (request) 112 | 113 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 114 | | ------------ | :------: | -------: | ---------------: | 115 | | chainId | Y | int | 接口调用链的链id | 116 | | address | Y | String | 要查询余额的地址 | 117 | | assetChainId | Y | int | 资产发起的链ID | 118 | | assetId | Y | int | 资产ID | 119 | 120 | ```json 121 | { 122 | 123 | "chainId":5, 124 | "address":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 125 | "assetChainId":34, 126 | "assetId":5, 127 | } 128 | ``` 129 | 130 | ##### 返回值说明 (response) 131 | 132 | ```json 133 | { 134 | "available": "10000000000", 135 | "freeze": "200000000", 136 | "total": "12000000000" 137 | } 138 | ``` 139 | 140 | > 说明: 1NULS=10^8Na 141 | 142 | | 字段 | 数据类型 | 描述信息 | 143 | | --------- | :--------: | ----------------------------------: | 144 | | available | BigInteger | 可用余额 | 145 | | freeze | BigInteger | 冻结余额 | 146 | | total | BigInteger | 总资产余额 total = available+freeze | 147 | 148 | #### 3.1.2 获取当前账户nonce值 149 | 150 | > cmd: getNonce 151 | > 152 | 153 | ##### 参数说明 (request) 154 | 155 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 156 | | ------------ | :------: | -------: | ---------------: | 157 | | chainId | Y | int | 接口调用链的链id | 158 | | address | Y | String | 要查询余额的地址 | 159 | | assetChainId | Y | String | 资产发起的链ID | 160 | | assetId | Y | int | 资产ID | 161 | 162 | ```json 163 | { 164 | 165 | "chainId":5, 166 | "address":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 167 | "assetChainId":34, 168 | "assetId":5, 169 | } 170 | ``` 171 | 172 | ##### 返回值说明 (response) 173 | 174 | ```json 175 | { 176 | "nonce":"xxxxxxxxxxx", 177 | "nonceType":1 178 | } 179 | ``` 180 | 181 | 182 | 183 | | 字段 | 数据类型 | 描述信息 | 184 | | --------- | :------: | -------------------------------: | 185 | | nonce | String | 上笔支出交易hash | 186 | | nonceType | int | 1上笔交易已确认,0上笔交易未确认 | 187 | 188 | 189 | 190 | #### 3.1.3 获取余额与nonce值 191 | 192 | > cmd: getBalanceNonce 193 | 194 | ##### 参数说明 (request) 195 | 196 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 197 | | ------------ | :------: | -------: | ---------------: | 198 | | chainId | Y | int | 接口调用链的链id | 199 | | address | Y | String | 要查询余额的地址 | 200 | | assetChainId | Y | String | 资产发起的链ID | 201 | | assetId | Y | String | 资产ID | 202 | 203 | ```json 204 | { 205 | 206 | "chainId":5, 207 | "address":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", 208 | "assetChainId":"34", 209 | "assetId":"5", 210 | } 211 | ``` 212 | 213 | ##### 返回值说明:(response) 214 | 215 | ```json 216 | { 217 | "available": "10000000000", 218 | "nonce": "xxxxx" 219 | } 220 | ``` 221 | 222 | | 字段 | 数据类型 | 描述信息 | 223 | | --------- | :--------: | ------------------------------------------------: | 224 | | available | BigInteger | 用户可用余额 | 225 | | nonce | String | 账户的随机值,保存用户上一笔交易的hash 前byte。 | 226 | | nonceType | int | 1 :nonce 取自已确认交易,0 :nonce取自未确认交易 | 227 | 228 | #### 3.1.4 验证coinData 229 | 230 | > cmd: verifyCoinData 231 | 232 | ##### 参数说明 (request) 233 | 234 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 235 | | ------- | :------: | -------: | ---------------: | 236 | | chainId | Y | int | 接口调用链的链id | 237 | | txHex | Y | String | 交易16进制流 | 238 | 239 | ```json 240 | { 241 | "chainId": 458, 242 | "txHex": "xxxxxxxx" 243 | } 244 | ``` 245 | 246 | ##### 返回值说明:(response) 247 | 248 | ```json 249 | 失败下情况下,统一返回fail错误码。 250 | 成功下: 251 | { 252 | "orphan":true 253 | } 254 | ``` 255 | 256 | | 字段 | 数据类型 | 描述信息 | 257 | | ------ | :------: | :-----------: | 258 | | orphan | boolean | true 孤儿交易 | 259 | 260 | 261 | #### 3.1.5 批量校验通知 262 | 263 | > cmd: bathValidateBegin 264 | 265 | ##### 参数说明 (request) 266 | 267 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 268 | | ------- | :------: | -------: | ---------------: | 269 | | chainId | Y | int | 接口调用链的链Id | 270 | 271 | ```json 272 | { 273 | "chainId": 21 274 | } 275 | ``` 276 | 277 | ##### 返回值说明:(response) 278 | 279 | ```json 280 | { 281 | "value":1 282 | } 283 | ``` 284 | 285 | | 字段 | 数据类型 | 描述信息 | 286 | | ----- | :------: | -----------: | 287 | | value | int | 1成功,0失败 | 288 | 289 | #### 3.1.6 提交未确认交易 290 | 291 | > cmd: commitUnconfirmedTx 292 | 293 | ##### 参数说明 (request) 294 | 295 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 296 | | ------- | :------: | -------: | ---------------: | 297 | | chainId | Y | int | 接口调用链的链Id | 298 | | txHex | Y | String | 交易16进制流 | 299 | 300 | ```json 301 | { 302 | "chainId": 21, 303 | "txHex": "xxxxxxxx" 304 | } 305 | ``` 306 | 307 | ##### 返回值说明:(response) 308 | 309 | ```json 310 | 失败下情况下,统一返回fail错误码。 311 | 312 | 成功下: 313 | { 314 | "orphan":true 315 | } 316 | ``` 317 | 318 | | 字段 | 数据类型 | 描述信息 | 319 | | ------ | :------: | :-------------: | 320 | | orphan | boolean | true 为孤儿交易 | 321 | 322 | #### 3.1.7 批量提交未确认交易 323 | 324 | > cmd: commitBatchUnconfirmedTxs 325 | 326 | ##### 参数说明 (request) 327 | 328 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 329 | | ------- | :------: | -------: | ---------------: | 330 | | chainId | Y | int | 接口调用链的链Id | 331 | | txList | Y | String | 交易Hex值列表 | 332 | 333 | ```json 334 | { 335 | "chainId": 21, 336 | "txList": "[xxxxxxxx,yyyyyyyyy]" 337 | } 338 | ``` 339 | 340 | ##### 返回值说明:(response) 341 | 342 | ```json 343 | { 344 | "orphan":"[xxxxxxxx,yyyyyyyyy]", 345 | "fail":"[aaaaaaaa,bbbbbbbbb]" 346 | } 347 | ``` 348 | 349 | | 字段 | 数据类型 | 描述信息 | 350 | | ------ | :----------: | :--------------: | 351 | | orphan | List | 返回孤儿交易列表 | 352 | | fail | List | 返回失败交易列表 | 353 | 354 | 355 | 356 | #### 3.1.8 提交区块交易 357 | 358 | > cmd: commitBlockTxs 359 | 360 | ##### 参数说明 (request) 361 | 362 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 363 | | ----------- | :------: | -------: | --------------------: | 364 | | chainId | Y | int | 接口调用链的链Id | 365 | | txHexList | Y | array | 交易列表 交易16进制流 | 366 | | blockHeight | Y | long | 区块高度 | 367 | 368 | ```json 369 | { 370 | "chainId": 21, 371 | "txHex": "[xxxxxxxx,yyyyyyyy]", 372 | "blockHeight": 25 373 | } 374 | ``` 375 | 376 | ##### 返回值说明:(response) 377 | 378 | ```json 379 | { 380 | "value":true 381 | } 382 | ``` 383 | 384 | | 字段 | 数据类型 | 描述信息 | 385 | | ----- | :------: | ------------------: | 386 | | value | int | true成功,false失败 | 387 | 388 | 389 | 390 | #### 3.1.9 回滚未确认交易 391 | 392 | > cmd: rollBackUnconfirmTx 393 | 394 | ##### 参数说明 (request) 395 | 396 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 397 | | ------- | :------: | -------: | ---------------: | 398 | | chainId | Y | int | 接口调用链的链Id | 399 | | txHex | Y | String | 交易16进制流 | 400 | 401 | ```json 402 | { 403 | "chainId": 21, 404 | "txHex": "xxxxxxxx" 405 | } 406 | ``` 407 | 408 | ##### 返回值说明:(response) 409 | 410 | ```json 411 | { 412 | "value":1 413 | } 414 | ``` 415 | 416 | | 字段 | 数据类型 | 描述信息 | 417 | | ----- | :------: | -----------: | 418 | | value | int | 1成功,0失败 | 419 | 420 | #### 3.1.10 回滚区块交易 421 | 422 | > cmd: rollBackBlockTxs 423 | 424 | ##### 参数说明 (request) 425 | 426 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 427 | | ----------- | :------: | -------: | ---------------: | 428 | | chainId | Y | int | 接口调用链的链Id | 429 | | blockHeight | Y | long | 区块高度 | 430 | 431 | ```json 432 | { 433 | "chainId": 21, 434 | "blockHeight": 25 435 | } 436 | ``` 437 | 438 | ##### 返回值说明:(response) 439 | 440 | ```json 441 | { 442 | "value":1 443 | } 444 | ``` 445 | 446 | | 字段 | 数据类型 | 描述信息 | 447 | | ----- | :------: | -----------: | 448 | | value | int | 1成功,0失败 | 449 | 450 | #### 3.1.11 整区块校验 451 | 452 | > cmd: blockValidate 453 | 454 | ##### 参数说明 (request) 455 | 456 | | 字段 | 是否必填 | 数据类型 | 描述信息 | 457 | | ----------- | :------: | -------: | ---------------: | 458 | | chainId | Y | int | 接口调用链的链Id | 459 | | txList | Y | String | 交易Hex值列表 | 460 | | blockHeight | Y | long | 区块高度 | 461 | 462 | ```json 463 | { 464 | "chainId": 21, 465 | "txList": "[xxxxxxxx,yyyyyyyyy]", 466 | "blockHeight":20 467 | } 468 | ``` 469 | 470 | ##### 返回值说明:(response) 471 | 472 | ```json 473 | { 474 | "value":true 475 | } 476 | ``` 477 | 478 | | 字段 | 数据类型 | 描述信息 | 479 | | ----- | :------: | :------------------: | 480 | | value | boolean | true成功,false 失败 | 481 | 482 | 483 | 484 | ### 3.2 其他接口 485 | 486 | #### 3.2.1 根据资产id获取资产信息 487 | > cmd: getAsset 488 | 489 | ##### 参数说明 (request) 490 | 491 | | 字段 | 是否可选 | 数据类型 | 描述信息 | 492 | |----------|:-------------:|--------:|--------:| 493 | | chainId | Y | int | 接口调用所在链链Id | 494 | | assetChainId | Y | int |资产发起链的链ID | 495 | | assetId | Y | int |资产ID | 496 | 497 | ```json 498 | { 499 | "chainId": 5, 500 | "assetChainId": 12, 501 | "assetId": 41 502 | } 503 | ``` 504 | ##### 返回值说明 (response) 505 | 506 | ```json 507 | { 508 | "chainId": 5, 509 | "assetChainId": 12, 510 | "assetId": 41, 511 | "balance" : { 512 | "available": "10000000000", 513 | "freeze": "200000000", 514 | "total": "12000000000" 515 | } 516 | } 517 | ``` 518 | 519 | | 字段 | 数据类型 | 描述信息 | 520 | |----------|:-------------:|------:| 521 | | chainId | int | 发起调用的链ID | 522 | | assetChainId | int | 资产发起的链链id | 523 | | assetId | int | 资产ID | 524 | | balance.available | BigInteger | 可用余额 | 525 | | balance.freeze | BigInteger | 冻结余额 | 526 | | balance.total | BigInteger | 总资产余额 total = available+freeze | 527 | 528 | 529 | 530 | ## 四、事件说明 531 | 532 | > 不依赖任何事件 533 | 534 | ## 五、协议 535 | 536 | ### 5.1 网络通讯协议 537 | 538 | 无 539 | 540 | ### 5.2 交易协议 541 | 542 | 无 543 | 544 | ## 六、模块配置 545 | ### 6.1 配置说明 546 | 547 | ### 6.2 模块依赖关系 548 | 549 | - 内核模块 550 | - 模块注册 551 | 552 | - 模块注销 553 | 554 | - 模块状态上报(心跳) 555 | 556 | - 服务接口数据获取及定时更新 557 | - 网络模块 558 | 559 | 560 | ## 七、Java特有的设计 561 | 562 | > 核心对象类定义,存储数据结构,...... 563 | 564 | ## 八、补充内容 565 | 566 | ### 参考资料文献资料 567 | - [精通以太坊-第七章 交易](https://github.com/inoutcode/ethereum_book/blob/master/%E7%AC%AC%E4%B8%83%E7%AB%A0.asciidoc) 568 | 569 | -------------------------------------------------------------------------------- /design-zh-CHS/r.rpc-tool-websocket设计v1.3.md: -------------------------------------------------------------------------------- 1 | # Websocket-Tool设计文档——第四版 2 | 3 | [TOC] 4 | 5 | 6 | 7 | 8 | ## 写在最前的话 9 | ``` 10 | 如果想知道websocket的具体设计,请逐步阅读本文档 11 | 12 | 如果只想知道如何使用,请跳转到章节《7.1 如何使用》 13 | ``` 14 | 15 | 16 | ## 一、总体描述 17 | 18 | ### 1.1 概述 19 | 20 | #### 1.1.1 为什么要有《Websocket-Tool》 21 | 22 | [^说明]: 介绍的存在的原因 23 | 24 | * NULS 2.0根据功能划分模块,所有模块隔离,可以独立运行。 25 | * 模块间通过《Websocket-Tool》调用接口 26 | * 模块只要实现了规定接口,可以用任何语言实现 27 | * 模块可以分布式部署 28 | * 《Websocket-Tool》会打包成jar包,供各模块引用 29 | 30 | 31 | 32 | #### 1.1.2 《Websocket-Tool》要做什么 33 | 34 | [^说明]: 要做些什么事情,达到什么目的,目标是让非技术人员了解要做什么事情 35 | 36 | 所有模块间的接口调用都通过《Websocket-Tool》进行 37 | 38 | - 启动Websocket Server 39 | - 注册当前模块的所有cmd命令 40 | - 把当前模块信息汇报给kernel 41 | - 接收从kernel推送的所有模块信息 42 | - 启动Websocket Client 43 | - 维护调用过程产生的数据 44 | - 封装所有数据中间处理过程,各模块只需要关心 45 | - 输入 46 | - 输出 47 | - 各模块通过尽可能简单的方式调用cmd命令 48 | 49 | 50 | 51 | #### 1.1.3 《Websocket-Tool》在系统中的定位 52 | 53 | [^说明]: 在系统中的定位,是什么角色,依赖哪些做哪些事情,可以被依赖用于做哪些事情 54 | 55 | 《Websocket-Tool》是底层框架,任何模块都会依赖 56 | 57 | 《Websocket-Tool》维护各模块基础信息,但是不涉及具体业务 58 | 59 | 60 | 61 | ## 二、功能设计 62 | 63 | ### 2.1 架构图 64 | 65 | [^说明]: 说明的功能设计,可以有层级关系,可以通过图形的形式展示,并用文字进行说明。 66 | 67 | 68 | 69 | ## 三、接口设计 70 | 71 | 72 | 73 | ## 四、事件说明 74 | 75 | 76 | 77 | ## 五、协议 78 | 79 | ### 5.1 通信协议 – Json/WebSockets 80 | 81 | 微服务的行为不像标准的客户端 - 服务器基础设施,因为每个微服务同时是客户端和服务器,因此需要全双工通信协议,这允许实现特殊类型的发布 - 订阅模式; 在这个实现中,方法只能被调用一次,然后调用者可以通过两种不同的方式接收不断的更新: 82 | 83 | - 基于事件:当方法在预定义数量的事件之后发送通知时 84 | - 基于时间:当方法在预定义的秒数后发送通知时 85 | 86 | WebSocket是一种成熟的选项,可以本机提供全双工连接,其他选项如标准Json-RPC不提供双向通道。 87 | 消息将使用JSon格式进行编码,因为它是最广泛用于消息交换的,并且易于调试。 88 | 89 | ### 5.2 消息结构 90 | 91 | 所有消息都有一个由5个字段组成的公共基础结构: 92 | 93 | - MessageID:这是一个标识请求的字符串。 它的长度不应超过256个字符 94 | - Timestamp:自纪元以来的秒数(1970年1月1日格林威治标准时间00:00:00) 95 | - TimeZone:发起请求的时区,它应为介于-12和12之间的数字 96 | - MessageType:消息类型,这些在第3节中指定 97 | - MessageData:保存消息有效负载的Json对象 98 | 99 | 示例: 100 | 101 | ```json 102 | { 103 | "MessageID":"45sdj8jcf8899ekffEFefee", 104 | "Timestamp":"1542102459", 105 | "TimeZone":"-4", 106 | "MessageType":"NegotiateConnection", 107 | "MessageData":{ 108 | "CompressionRate":"3", 109 | "CompressionAlgorithm":"zlib" 110 | } 111 | } 112 | ``` 113 | 114 | ### 5.3 Message Types 115 | 116 | 目前只定义了9种类型的消息:NegotiateConnection, NegotiateConnectionResponse, Request, Unsubscribe, Response, Ack, Notificatioin, RegisterCompoundMethod, UnregisterCompoundMethod 117 | 118 | 119 | 120 | #### 5.3.1 NegotiateConnection 121 | 122 | 这应该是在与微服务建立连接时应该发送的第一个对象,只有在协商成功时,服务才可以处理其他请求,否则应该收到状态设置为0(失败)的NegotiateConnectionResponse对象并立即断开连接。 123 | 124 | 它由两个字段组成: 125 | 126 | - CompressionAlgorithm(默认值:zlib):一个String,表示如果CompressionRate大于0,将用于接收和发送消息的算法。默认为zlib,大多数开发语言中都有支持的库。 127 | - CompressionRate:0到9之间的一个整数,用于建立应为此连接发送和接收消息的压缩级别。 0表示没有压缩,而9表示最大压缩 128 | 129 | 示例: 130 | 131 | ```json 132 | { 133 | "messageId":"1", 134 | "timestamp":"1543133816985", 135 | "timezone":"9", 136 | "messageType":"NegotiateConnection", 137 | "messageData":{ 138 | "protocolVersion":"1.0", 139 | "compressionAlgorithm":"zlib", 140 | "compressionRate":"0" 141 | } 142 | } 143 | ``` 144 | 145 | 146 | 147 | #### 5.3.2 NegotiateConnectionResponse 148 | 149 | 仅在响应先前传入的NegotiateConnection消息时发送此类消息。 它由两个字段组成: 150 | 151 | - NegotiationStatus:无符号的小整数值,如果协商失败则为0,如果成功则为1 152 | - NegotiationComment:一个字符串值,用于描述拒绝连接时出现了什么问题。 153 | 154 | 示例: 155 | 156 | ```json 157 | { 158 | "MessageID":"45sdj8jcf8899ekffEFefee", 159 | "Timestamp":"1542102459", 160 | "TimeZone":"-4", 161 | "MessageType":"NegotiateConnectionReponse", 162 | "MessageData":{ 163 | "NegotiationStatus":"0", 164 | "NegotiationComment":"Incompatible protocol version" 165 | } 166 | } 167 | ``` 168 | 169 | 170 | 171 | #### 5.3.3 Request 172 | 173 | 调用者服务必须发送一个Request对象来执行Nulstar网络内某些服务提供的方法。 174 | 175 | 如果在单个请求对象中包含两个或更多方法,则应按顺序执行方法,然后发送一个response包喊所有回执信息,如果其中一个请求失败,则整个操作被视为失败。 176 | 177 | 它由六个字段组成: 178 | 179 | - RequestAck(默认值:0):这是一个布尔值 180 | 181 | - 0:发出的请求只需要一条Response消息,如果它订阅了该函数,那么它可能会有很多响应消息 182 | - 1:发出的请求需要Ack和Response(译者注:有的请求可能需要一段时间处理,不会立刻返回Response,但是我要确保对方接收到了我的请求),如果它订阅了该函数,那么它可能会有很多响应消息 183 | 184 | - SubscriptionEventCounter(默认值:0):这是一个无符号整数,指定目标方法发送Response的值的`改变次数`。不管这个值是多少,总会立刻发送一个Response。如果是0,则不再继续发送,如果是2,则每改变两次就发送。以此类推。 185 | 186 | - SubscriptionPeriod(默认值:0):这是一个无符号整数,指定目标方法发送Response的时间间隔。不管这个值是多少,总会立刻发送一个Response。如果是0,则不再继续发送,如果是2,则每2秒都会检测是否发送。以此类推。 187 | 188 | - SubscriptionRange:如果请求的事件返回的是一个数字,则定义何时返回这个数字。 189 | 这是一个字符串,表示将触发响应的条件。 字符串是一对带符号的十进制数,第一个是下限,第二个是上限,如果不可用则为空。 如果该对分别以“(”或“)”开始或结束,则表示该数字不包括在内,如果该对分别以“[”或“]”开始或结束,则表示该数字包括在内。 190 | 191 | 示例:假设我们只希望仅在余额等于或大于1000时收到通知。然后,getbalance请求应以“[1000,)”字符串作为SubscriptionRange参数发送 192 | 193 | - ResponseMaxSize(默认值:0):无符号整数,指定方法应返回的最大对象数,值为零(默认值)表示无限制。只针对返回结果为List有效,指定的是返回的记录个数。 194 | 195 | - RequestMethods:一个数组,包含所请求的所有方法及其各自的参数 196 | 197 | 示例: 198 | 199 | ```json 200 | { 201 | "messageId":"3", 202 | "timestamp":"1543133968578", 203 | "timezone":"9", 204 | "messageType":"Request", 205 | "messageData":{ 206 | "requestAck":"0", 207 | "subscriptionEventCounter":"0", 208 | "subscriptionPeriod":"5", 209 | "subscriptionRange":"0", 210 | "responseMaxSize":"0", 211 | "requestMethods":{ 212 | "getHeight":{ 213 | "paramName":"value", 214 | "version":"1.0" 215 | } 216 | } 217 | } 218 | } 219 | ``` 220 | 221 | 222 | 223 | #### 5.3.4 Unsubscribe 224 | 225 | 当服务不再希望从其订阅的方法接收响应时,它必须向目标服务发送Unsubscribe消息。 226 | 227 | 它由一个字段组成: 228 | 229 | - UnsubscribeMethods:一个数组,包含调用者想要取消订阅的所有方法 230 | 231 | 示例: 232 | 233 | ```json 234 | { 235 | "messageId":"4", 236 | "timestamp":"1543134296019", 237 | "timezone":"9", 238 | "messageType":"Unsubscribe", 239 | "messageData":{ 240 | "unsubscribeMethods":[ 241 | "getHeight" 242 | ] 243 | } 244 | } 245 | ``` 246 | 247 | 248 | 249 | #### 5.3.5 Response 250 | 251 | 当目标服务完成处理请求时,应该发送响应以及操作结果。 252 | 253 | 它由六个字段组成: 254 | 255 | - RequestID:这是引用的原始Request消息请求ID 256 | - ResponseProcessingTime:目标服务处理请求所用的时间(以毫秒为单位) 257 | - ResponseStatus:响应状态,如果成功则为1,否则为0 258 | - ResponseComment:一个字符串,可以提供有关该过程结果的更多说明 259 | - ResponseMaxSize:响应包含每个请求的最大对象数 260 | - ResponseData:一个对象数组,包含已处理方法的结果,每个请求一个对象 261 | 262 | 示例: 263 | 264 | ```json 265 | { 266 | "messageId":"9", 267 | "timestamp":"1543134299030", 268 | "timezone":"9", 269 | "messageType":"Response", 270 | "messageData":{ 271 | "requestId":"5", 272 | "responseProcessingTime":"1", 273 | "responseStatus":"1", 274 | "responseComment":"Congratulations! Processing completed!", 275 | "responseMaxSize":"0", 276 | "responseData":{ 277 | "getHeight":"getHeight->1.3" 278 | } 279 | } 280 | } 281 | ``` 282 | 283 | 284 | 285 | #### 3.5.6 Ack 286 | 287 | 其唯一目的是通知呼叫者已成功接收请求。 288 | 289 | 它由一个字段组成: 290 | 291 | - RequestID:这是引用的原始Request消息请求ID 292 | 293 | 示例: 294 | 295 | ```json 296 | { 297 | "MessageID":"45sdj8jcf8899ekffEFefee", 298 | "Timestamp":"1542102459", 299 | "TimeZone":"-4", 300 | "MessageType":"Ack", 301 | "MessageData":{ 302 | "RequestID":"sdj8jcf8899ekffEFefee" 303 | } 304 | } 305 | ``` 306 | 307 | 308 | 309 | #### 3.5.7 Notification 310 | 311 | 当需要将某些事件通知给连接的组件而不期望响应消息时(例如,即将对服务执行升级时),将发送此消息类型。 通知将信息推送到其他组件,因此通知只应由Manager,Controller和Connector模块使用 312 | 313 | 它由四个字段组成: 314 | 315 | - NotificationAck :(默认值:0):这是一个布尔值 316 | - 0:发出的通知不期望任何类型的消息作为回执 317 | - 1:发出的通知需要一条Ack消息 318 | - NotificationType:通知的类别,每个服务都可以定义自己的类型,因此不需要接收方处理此字段 319 | - NotificationComment:字符串注释,提供有关通知原因的更多信息 320 | - NotificationData:与通知相关的数据,接收方不需要处理此字段 321 | 322 | 示例: 323 | 324 | ```json 325 | { 326 | "MessageID":"45sdj8jcf8899ekffEFefee", 327 | "Timestamp":"1542102459", 328 | "TimeZone":"-4", 329 | "MessageType":"Notification", 330 | "MessageData":{ 331 | "NotificationAck":"1", 332 | "NotificationType":"SystemUpgrade", 333 | "NotificationComment":"A system upgrade is about to be performed!", 334 | "NotificationData":{ 335 | "Date":"2018-11-11", 336 | "Time":"23:00:00", 337 | "NewVersion":"1.1.6" 338 | } 339 | } 340 | } 341 | ``` 342 | 343 | 344 | 345 | #### 3.5.8 RegisterCompoundMethod 346 | 347 | 请求可以由多个方法组成,使用此消息类型,我们注册一个虚拟方法,该方法将按顺序执行其各个实际方法,如果其子方法之一失败,则虚方法返回失败。 348 | 349 | 某些子方法可能共享相同的参数名称,因此可以创建别名,如示例中所示。 350 | 351 | 它由三个字段组成: 352 | 353 | - CompoundMethodName:这是标识虚方法的字符串 354 | - CompoundMethodDescription:描述方法功能,在查询API以获取帮助时将提供描述 355 | - CompoundMethods:这是一个数组,包含构成虚方法的各自参数别名的方法 356 | 357 | 示例: 358 | 359 | ```json 360 | { 361 | "MessageID":"45sdj8jcf8899ekffEFefee", 362 | "Timestamp":"1542102459", 363 | "TimeZone":"-4", 364 | "MessageType":"RegisterCompoundMethod", 365 | "MessageData":{ 366 | "CompoundMethodName":"GetMyInfo", 367 | "CompoundMethodDescription":"Get useful information.", 368 | "CompoundMethods":{ 369 | "GetBalance":{ 370 | "Address":"GetBalanceAddress" 371 | }, 372 | "GetHeight":{ 373 | 374 | } 375 | } 376 | } 377 | } 378 | ``` 379 | 380 | 在该示例中,正在注册一个名为GetMyInfo的虚方法,它由GetBalance和GetHeight方法组成,还为Address参数创建了一个名为GetBalanceAddress的别名。 381 | GetMyInfo的请求可以作为标准方法发送。 382 | 383 | (我确实没看懂这个的意义在哪,感觉就是单纯为了多这么个功能,有疑问请直接找Berzeck或者坚哥,哈哈) 384 | 385 | 386 | 387 | #### 3.5.9 UnregisterCompoundMethod 388 | 389 | 此消息类型用于取消注册复合(虚拟)方法。 390 | 391 | 它由一个字段组成: 392 | 393 | - UnregisterCompoundMethodName:这是标识虚方法的字符串。 如果它为空,则应取消注册调用者注册的所有虚拟方法 394 | 395 | 示例: 396 | 397 | ```json 398 | { 399 | "MessageID":"45sdj8jcf8899ekffEFefee", 400 | "Timestamp":"1542102459", 401 | "TimeZone":"-4", 402 | "MessageType":"UnregisterCompoundMethod", 403 | "MessageData":{ 404 | "UnregisterCompoundMethodName":"GetMyInfo" 405 | } 406 | } 407 | ``` 408 | 409 | 410 | 411 | ### 5.4 具体细节 412 | 413 | - 传输过程的所有属性都是string类型 414 | 415 | - 如果是boolean类型,"1"代表true,"0"代表false 416 | 417 | - 当调用一个方法的时候,调用者需要知道:提供方法的角色,以及方法的使用方式 418 | 419 | - 注册的时候,Role1有method1,Role2有method2,如何定义? 420 | 答:不需要定义,这是写在文档中的。 421 | apiMethods = Role1Methods + Role2Methods。因此注册的时候不需要知道每个Role都包含什么方法,这些应该在文档中体现。 422 | 423 | - 注册接口的字符串格式 424 | 425 | ```json 426 | { 427 | "messageId":"2", 428 | "timestamp":"1543204508986", 429 | "timezone":"9", 430 | "messageType":"Request", 431 | "messageData":{ 432 | "requestAck":"0", 433 | "subscriptionEventCounter":"0", 434 | "subscriptionPeriod":"0", 435 | "subscriptionRange":"0", 436 | "responseMaxSize":"0", 437 | "requestMethods":{ 438 | "registerAPI":{ 439 | "apiMethods":[ 440 | { 441 | "methodName":"getHeight", 442 | "methodDescription":"test getHeight 1.1", 443 | "methodMinEvent":"0", 444 | "methodMinPeriod":"0", 445 | "methodScope":"private", 446 | "parameters":[ 447 | { 448 | "parameterName":"aaa", 449 | "parameterType":"int", 450 | "parameterValidRange":"(1,100]", 451 | "parameterValidRegExp":"" 452 | }, 453 | { 454 | "parameterName":"bbb", 455 | "parameterType":"string", 456 | "parameterValidRange":"", 457 | "parameterValidRegExp":"^[A-Za-z0-9\\-]+$" 458 | } 459 | ] 460 | }, 461 | { 462 | "methodName":"getHeight", 463 | "methodDescription":"test getHeight 2.0", 464 | "methodMinEvent":"0", 465 | "methodMinPeriod":"0", 466 | "methodScope":"private", 467 | "parameters":[ 468 | 469 | ] 470 | } 471 | ], 472 | "dependencies":{ 473 | "Role_Ledger":"1.1" 474 | }, 475 | "connectionInformation":{ 476 | "IP":"192.168.1.65", 477 | "Port":"17733" 478 | }, 479 | "moduleDomain":"nuls.io", 480 | "moduleRoles":{ 481 | "cm":[ 482 | "1.1", 483 | "1.2" 484 | ] 485 | }, 486 | "moduleVersion":"1.2", 487 | "moduleAbbreviation":"cm", 488 | "moduleName":"Chain Manager" 489 | } 490 | } 491 | } 492 | } 493 | ``` 494 | 495 | - Manager返回各模块连接信息的字符串格式 496 | 497 | ```json 498 | { 499 | "messageId":"8", 500 | "timestamp":"1543204714006", 501 | "timezone":"9", 502 | "messageType":"Response", 503 | "messageData":{ 504 | "requestId":"2", 505 | "responseProcessingTime":"1", 506 | "responseStatus":"1", 507 | "responseComment":"Congratulations! Processing completed!", 508 | "responseMaxSize":"0", 509 | "responseData":{ 510 | "registerAPI":{ 511 | "Dependencies":{ 512 | "test":{ 513 | "APIVersion":[ 514 | "1.0" 515 | ], 516 | "IP":"192.168.1.65", 517 | "Port":"14694" 518 | }, 519 | "ke":{ 520 | "APIVersion":null, 521 | "IP":"192.168.1.65", 522 | "Port":"8887" 523 | }, 524 | "cm":{ 525 | "APIVersion":[ 526 | "1.1", 527 | "1.2" 528 | ], 529 | "IP":"192.168.1.65", 530 | "Port":"17733" 531 | } 532 | } 533 | } 534 | } 535 | } 536 | } 537 | ``` 538 | 539 | 540 | 541 | 542 | 543 | ## 六、配置 544 | 545 | 546 | 547 | ## 七、Java特有的设计 548 | 549 | [^说明]: 核心对象类定义,存储数据结构,...... 550 | 551 | ### 7.1 设计 552 | 553 | > io.nuls.rpc 554 | > 555 | > > client 556 | > > 557 | > > > `ClientProcessor`:处理服务器消息的线程 558 | > > > 559 | > > > `ClientRuntime`:客户端运行时需要的数据,方法 560 | > > > 561 | > > > `CmdDispatcher`:发送消息的入口类 562 | > > > 563 | > > > `WsClient`:与其他模块建立连接的对象 564 | > > 565 | > > cmd 566 | > > 567 | > > > cmd_package_1 568 | > > > 569 | > > > cmd_package_2 570 | > > > 571 | > > > `BaseCmd`:所有对外提供方法的类的父类,提供success, failed方法返回Response对象 572 | > > 573 | > > info 574 | > > 575 | > > > `Constants`:常量 576 | > > > 577 | > > > `HostInfo`:获取IP地址,随机获得端口 578 | > > 579 | > > model 580 | > > 581 | > > > message 582 | > > > 583 | > > > > `Message`:所有消息都应该用该对象进行传输 584 | > > > > 585 | > > > > `MessageType`:消息类型(包含以下9种) 586 | > > > > 587 | > > > > `Ack`:确认收到消息 588 | > > > > 589 | > > > > `NegotiateConnection`:握手 590 | > > > > 591 | > > > > `NegotiateConnectionResponse`:回复握手 592 | > > > > 593 | > > > > `Notification`:通知 594 | > > > > 595 | > > > > `Request`:请求调用远程方法 596 | > > > > 597 | > > > > `Response`:回复Request 598 | > > > > 599 | > > > > `Unsubscribe`:取消订阅 600 | > > > > 601 | > > > > `RegisterCompoundMethod`:订阅多个远程方法 602 | > > > > 603 | > > > > `UnregisterCompoundMethod`:取消订阅多个远程方法 604 | > > > 605 | > > > `CmdAnnotation`:注解类,有该注解的方法可以对外提供接口 606 | > > > 607 | > > > `Parameter`:注解类,用以描述对外提供接口的参数信息 608 | > > > 609 | > > > `Parameters`:注解类,Parameter的集合 610 | > > > 611 | > > > `CmdDetail`:对外提供的方法的具体信息 612 | > > > 613 | > > > `CmdParameter`:对外提供的方法的参数信息 614 | > > > 615 | > > > `ModuleE`:枚举类型,NULS2.0基础架构下的模块信息 616 | > > > 617 | > > > `RegisterApi`:一个模块对外提供的所有方法的合集 618 | > > 619 | > > server 620 | > > 621 | > > > `CmdHandler`:根据Request消息,调用正确的方法 622 | > > > 623 | > > > `ServerProcessor`:处理客户端消息的线程 624 | > > > 625 | > > > `ServerRuntime`:服务器运行时需要的参数,方法 626 | > > > 627 | > > > `WsServer`:与WsClient连接的服务器对象 628 | 629 | 630 | 631 | ### 7.2 如何使用 632 | 633 | Websocket-Tool会做成JAR包供各模块引用 634 | 635 | 636 | 637 | #### 7.2.1 测试专用:模拟kernel 638 | 639 | 非常重要! 640 | 641 | 各模块接口是在kernel中进行维护,但是kernel由社区成员开发,因此这一部分是内部测试的模拟代码,可以直接复制使用,无需额外操作。 642 | 643 | (test/java/io.nuls.test.WsKernel) 644 | 645 | ```java 646 | @Test 647 | public void kernel() throws Exception { 648 | // url: "ws://127.0.0.1:8887" 649 | WsServer.mockKernel(); 650 | } 651 | ``` 652 | 653 | 654 | 655 | #### 7.2.2 自定义cmd 656 | 657 | scope的值:public,private,admin 658 | 659 | - public:暴露出去,第三方应用/平台也能调用的公开接口 660 | - private:只有模块间内部才能调用的接口 661 | - admin:专门为管理员设计的特定接口(管理员定义在在Berzeck的connector中,我们并不需要关心) 662 | 663 | ```java 664 | /* 665 | * 该类所在的包需要通过7.1.3中的方法进行扫描 666 | */ 667 | public class MyCmd extends BaseCmd { 668 | 669 | @CmdAnnotation(cmd = "getHeight", version = 1.0, scope = "private", minEvent = 0, minPeriod = 0, 670 | description = "test getHeight 1.0") 671 | @Parameter(parameterName = "aaa", parameterType = "int", parameterValidRange = "(1,100]", parameterValidRegExp = "") 672 | @Parameter(parameterName = "bbb", parameterType = "string") 673 | public Object getHeight1(Map map) { 674 | Log.info("getHeight version 1"); 675 | // success 676 | return success("Here is your real return value"); 677 | // 预定义错误 678 | return failed(ErrorCode); 679 | // 非预定义错误 680 | return failed(String) 681 | } 682 | } 683 | ``` 684 | 685 | 686 | 687 | #### 7.2.3 启动Server 688 | 689 | ```java 690 | // Start server instance 691 | WsServer.getInstance(ModuleE.CM) 692 | .moduleRoles(new String[]{"1.0", "2.4"}) 693 | .moduleVersion("1.2") 694 | .dependencies(ModuleE.LG.abbr, "1.1") 695 | .dependencies(ModuleE.BL.abbr, "2.1") 696 | .scanPackage("io.nuls.rpc.cmd.test") 697 | .connect("ws://127.0.0.1:8887"); 698 | 699 | // Get information from kernel 700 | CmdDispatcher.syncKernel(); 701 | ``` 702 | 703 | 704 | 705 | #### 7.2.4 为kernel提供的接口 706 | 707 | 现阶段忽略! 708 | 709 | ```java 710 | 711 | ``` 712 | 713 | 714 | 715 | #### 7.2.5 调用cmd 716 | 717 | ```java 718 | /* 719 | 单元测试专用:单元测试时需要告知内核地址,以及同步接口列表 720 | 如果不是单元测试,在模块中进行连调测试,下面两句话是不需要的 721 | */ 722 | WsServer.mockModule(); 723 | /* 724 | 单元测试专用结束 725 | */ 726 | 727 | 728 | // Build params map 729 | Map params = new HashMap<>(); 730 | // Version information ("1.1" or 1.1 is both available) 731 | params.put(Constants.VERSION_KEY_STR, "1.0"); 732 | params.put("paramName", "value"); 733 | 734 | // 可以看成是一个同步方法,发送Request,获得Response 735 | Response response = CmdDispatcher.requestAndResponse(ModuleE.CM.abbr, "getHeight", params); 736 | 737 | // 发送Request,当有Response的时候会自动调用预设的方法,返回的messageId是为了取消订阅 738 | String messageId = CmdDispatcher.requestAndInvoke(ModuleE.CM.abbr, "getHeight", params, "1", InvokeMethod.class, "invokeGetHeight2"); 739 | 740 | // 与requestAndInvoke一样,但是必须在收到Ack之后才会返回messageId 741 | String messageId = CmdDispatcher.requestAndInvokeWithAck(ModuleE.CM.abbr, "getHeight", params, "1", InvokeMethod.class, "invokeGetHeight2"); 742 | 743 | // 取消订阅 744 | CmdDispatcher.unsubscribe(messageId); 745 | System.out.println("我已经取消了订阅"); 746 | 747 | ``` 748 | 749 | 750 | 751 | 752 | 753 | ## 八、补充内容 754 | 755 | [^说明]: 上面未涉及的必须的内容 756 | 757 | -------------------------------------------------------------------------------- /design-zh-CHS/z.协议升级模块设计v1.3.md: -------------------------------------------------------------------------------- 1 | # 协议升级模块设计文档 2 | 3 | [TOC] 4 | 5 | ## 一、总体描述 6 | 7 | ### 1.1 模块概述 8 | 9 | #### 1.1.1 为什么要有《协议升级》模块 10 | 11 | ​ 不同的协议版本支持的交易类型、消息类型不同,为了管理区块链网络的版本,需要提供完善的版本管理功能。 12 | 13 | #### 1.1.2 《协议升级》要做什么 14 | 15 | - 解析区块头中的版本信息,进行动态统计、升级、回退 16 | - 为其他模块提供版本支持的交易类型、消息类型、版本信息查询服务 17 | 18 | #### 1.1.3 《协议升级》在系统中的定位 19 | 20 | 协议升级是底层模块之一,以下分功能讨论模块依赖情况 21 | 22 | 依赖 23 | 24 | * 区块管理模块-初始化本地协议版本信息 25 | 26 | 被依赖 27 | 28 | * 所有关心消息处理、交易处理的模块 29 | 30 | ### 1.2 架构图 31 | 32 | ​ 补充图片 33 | 34 | ## 二、功能设计 35 | 36 | ### 2.1 功能架构图 37 | 38 | ​ 补充图片 39 | 40 | ### 2.2 模块服务 41 | 42 | #### 2.2.1 获取当前主网版本信息 43 | 44 | * 接口说明 45 | 46 | 根据链ID查询DB得到主网版本信息 47 | 48 | * 请求示例 49 | 50 | ``` 51 | { 52 | "cmd": "currentMainnetVersion", 53 | "minVersion":"1.1", 54 | "params": ["888"] 55 | } 56 | ``` 57 | 58 | * 请求参数说明 59 | 60 | | index | parameter | required | type | description | 61 | | ----- | --------- | -------- | ------- | :---------: | 62 | | 0 | chainId | true | Long | 链ID | 63 | 64 | * 返回示例 65 | 66 | Failed 67 | 68 | ``` 69 | { 70 | "version": 1.2, 71 | "code": 1, 72 | "msg": "error message", 73 | "result": {} 74 | } 75 | ``` 76 | 77 | Success 78 | 79 | ``` 80 | { 81 | "version": 1.2, 82 | "code": 0, 83 | "result": { 84 | "chainId": "888", 85 | "versionInfo": { 86 | "major": "1", 87 | "minor": "1", 88 | "percent": "80",//固定值 89 | "slice": "100",//固定值 90 | "waitCount": "240"//固定值 91 | } 92 | } 93 | } 94 | ``` 95 | 96 | * 返回字段说明 97 | 98 | | parameter | type | description | 99 | | --------- | --------- | ------------------------------------------ | 100 | | chainId | Integer | 链ID | 101 | | major | Integer | 主版本号 | 102 | | minor | Integer | 次版本号 | 103 | | percent | Integer | 有效比例 | 104 | | slice | Integer | 最小统计片断长度 | 105 | | waitCount | Integer | 连续确认次数 | 106 | 107 | #### 2.2.2 获取当前本地版本信息 108 | 109 | * 接口说明 110 | 111 | 根据链ID查询DB得到本地版本信息 112 | 113 | * 请求示例 114 | 115 | ``` 116 | { 117 | "cmd": "currentLocalVersion", 118 | "minVersion":"1.1", 119 | "params": ["888"] 120 | } 121 | ``` 122 | 123 | * 请求参数说明 124 | 125 | | index | parameter | required | type | description | 126 | | ----- | --------- | -------- | ------- | :---------: | 127 | | 0 | chainId | true | Long | 链ID | 128 | 129 | * 返回示例 130 | 131 | Failed 132 | 133 | ``` 134 | { 135 | "version": 1.2, 136 | "code":1, 137 | "msg" :"xxxxxxxxxxxxxxxxxx", 138 | "result":{} 139 | } 140 | ``` 141 | 142 | Success 143 | 144 | ``` 145 | { 146 | "version": 1.2, 147 | "code": 0, 148 | "result": { 149 | "chainId": "888", 150 | "versionInfo": { 151 | "major": "1", 152 | "minor": "1", 153 | "percent": "80", 154 | "slice": "100", 155 | "waitCount": "240" 156 | } 157 | } 158 | } 159 | ``` 160 | 161 | * 返回字段说明 162 | 163 | 参考2.2.1 164 | 165 | #### 2.2.3 根据区块高度获取版本统计信息 166 | 167 | - 接口说明 168 | 169 | 根据链ID查询DB得到本地版本信息 170 | 171 | - 请求示例 172 | 173 | ``` 174 | { 175 | "cmd": "statisticsInfo", 176 | "minVersion":"1.1", 177 | "params": ["888", "888"] 178 | } 179 | ``` 180 | 181 | - 请求参数说明 182 | 183 | | index | parameter | required | type | description | 184 | | ----- | --------- | -------- | ---- | :---------: | 185 | | 0 | chainId | true | Long | 链ID | 186 | | 1 | height | true | Long | 区块高度 | 187 | 188 | - 返回示例 189 | 190 | Failed 191 | 192 | ``` 193 | { 194 | "version": 1.2, 195 | "code":1, 196 | "msg" :"xxxxxxxxxxxxxxxxxx", 197 | "result":{} 198 | } 199 | ``` 200 | 201 | Success 202 | 203 | ``` 204 | { 205 | "version": 1.2, 206 | "code": 0, 207 | "result": { 208 | "chainId": "888", 209 | "statisticsInfo": { 210 | "major": "1", 211 | "minor": "1", 212 | "percent": "80", 213 | "slice": "100", 214 | "count": "240" 215 | } 216 | } 217 | } 218 | ``` 219 | 220 | - 返回字段说明 221 | 222 | 参考2.2.1 223 | 224 | ### 2.3 模块内部功能 225 | 226 | #### 2.3.1 模块启动 227 | 228 | * 功能说明: 229 | 230 | 启动协议升级模块 231 | 232 | * 流程描述 233 | 234 | 补充图片 235 | 236 | 1.RPC服务初始化 237 | 238 | 2.初始化通用数据库 239 | 240 | 3.加载配置信息 241 | 242 | 4.初始化各链数据库 243 | 244 | 5.等待依赖模块就绪 245 | * 依赖服务 246 | 247 | 工具模块、内核模块 248 | 249 | #### 2.3.2 版本升级 250 | 251 | * 功能说明: 252 | 253 | 每保存一个区块或者回滚一个区块时,都会读取区块头中的版本号,动态统计版本比例信息,决定是否进行协议升级。主版本号不允许跨版本升级,次版本号允许跨版本升级 254 | 255 | * 流程描述 256 | 257 | 每100个区块为一个统计区间,统计区块头中版本号的分布比例,并且保存到数据库(key=height, value=版本信息,连续确认次数等等) 258 | 259 | - 版本占比大于某个阈值(必须大于50%)时,就能确定该统计区间内的版本号,当连续260个统计区间内的占比最大版本号保持连续时,主网执行协议升级。 260 | 261 | - 如果没有版本号占比大于阈值,沿用当前生效版本号作为当前区间的版本号 262 | 263 | - 如果中途有统计区间版本号波动,则重新开始统计 264 | 265 | 模拟几种场景: 266 | 267 | waitCount(连续确认次数) 268 | 269 | 1. ##### 正常升级(中途统计没有波动) 270 | 271 | 起始区块高度1000,协议版本号=1.0 272 | 273 | 1001-1100高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=1 274 | 275 | 1101-1200高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=2 276 | 277 | 。 278 | 279 | 。 280 | 281 | 。 282 | 283 | 27001-27100高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=260 284 | 285 | 从27101区块开始新协议生效 286 | 287 | 2. ##### 正常升级(中途统计有波动) 288 | 289 | 起始区块高度1000,协议版本号=1.0 290 | 291 | 1001-1100高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=1 292 | 293 | 1101-1200高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=2 294 | 295 | 1201-1300高度区间内的区块统计,占比80%的区块协议版本号=1.0,waitCount=0 296 | 297 | 1301-1400高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=1 298 | 299 | 。 300 | 301 | 。 302 | 303 | 。 304 | 305 | 27301-27400高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=260 306 | 307 | 从27401区块开始新协议生效 308 | 309 | 3. ##### 异常升级(先回滚,中途统计没有波动) 310 | 311 | 主链 312 | 313 | 起始区块高度1000,协议版本号=1.0 314 | 315 | 1001-1100高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=1 316 | 317 | 1101-1200高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=2 318 | 319 | 。 320 | 321 | 。 322 | 323 | 。 324 | 325 | 27001-27100高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=260 326 | 327 | 从27101区块开始新协议生效 328 | 329 | 分叉链 330 | 331 | 起始区块高度1000,协议版本号=1.0,分叉高度1211 332 | 333 | 1001-1100高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=1 334 | 335 | 1101-1200高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=2 336 | 337 | 1201-1300高度区间内的区块统计,占比80%的区块协议版本号=1.0,waitCount=0 338 | 339 | 1301-1400高度区间内的区块统计,占比80%的区块协议版本号=1.0,waitCount=0 340 | 341 | 分叉链切换第一步 342 | 343 | ​ 回滚到分叉点 344 | 345 | ​ 1001-1100高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=1 346 | 347 | ​ 1101-1200高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=2 348 | 349 | ​ 1201-1211高度区间内的区块统计,区块数量不足100,不统计 350 | 351 | ​ 添加新的区块 352 | 353 | ​ 1001-1100高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=1 354 | 355 | ​ 1101-1200高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=2 356 | 357 | ​ 1201-1300高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=3 358 | 359 | ​ 。 360 | 361 | ​ 。 362 | 363 | ​ 。 364 | 365 | ​ 27001-27100高度区间内的区块统计,占比80%的区块协议版本号=1.1,waitCount=260 366 | 367 | ​ 从27101区块开始新协议生效 368 | 369 | 4. ##### 异常升级(先回滚,中途统计有波动) 370 | 371 | 与第三种情况类似 372 | 373 | * 依赖服务 374 | 375 | 工具模块的数据库工具 376 | 377 | #### 2.3.3 延迟升级 378 | 379 | - 功能说明: 380 | 381 | 为了处理升级过程中发现新协议有BUG的情况 382 | 383 | - 流程描述 384 | 385 | ​ 假定当前版本号为1.0,待升级版本号1.1,但是1.1版本升级过程中发现了BUG 386 | 387 | ​ 通过降低新协议1.1比例来重置协议升级过程,使得主网版本持续定留在旧版本1.0,修复新协议1.1BUG后,再重启升级过程。 388 | 389 | - 依赖服务 390 | 391 | 工具模块的数据库工具 392 | 393 | #### 2.3.4 版本信息推送 394 | 395 | - 功能说明: 396 | 397 | 每个统计区间的最后一个区块接收完毕时,主动通知各模块当前生效的协议版本信息,主要是通知交易管理模块有效的交易类型及有效的交易验证器,通知网络模块有效的消息类型及消息处理器。 398 | 399 | - 流程描述 400 | 401 | 402 | 403 | - 依赖服务 404 | 405 | 工具模块的数据库工具 406 | 407 | ## 三、事件说明 408 | 409 | ### 3.1 发布的事件 410 | 411 | #### 3.1.1 协议升级 412 | 413 | 说明:协议版本升级,发布该事件 414 | 415 | event_topic : "versionUpadte", 416 | 417 | ``` 418 | data:{ 419 | chainId 420 | major 421 | minor 422 | height 423 | } 424 | ``` 425 | 426 | ### 3.2 订阅的事件 427 | 428 | ​ 略 429 | 430 | ## 四、协议 431 | 432 | ### 4.1 网络通讯协议 433 | 434 | ​ 略 435 | 436 | ### 4.2 消息协议 437 | 438 | ​ 略 439 | 440 | ## 五、模块配置 441 | 442 | ``` 443 | [ 444 | { 445 | "name": "supportTxTypes", 446 | "remark": "支持的交易类型", 447 | "readOnly": "true", 448 | "value": "1,2,3,4,5" 449 | }, 450 | { 451 | "name": "supportMessageTypes", 452 | "remark": "支持的消息类型", 453 | "readOnly": "true", 454 | "value": "1,2,3,4,5" 455 | } 456 | ] 457 | ``` 458 | 459 | ## 六、Java特有的设计 460 | 461 | - BlockHeader对象新增字段 462 | > | `字段名称` | `字段类型` | `说明` | 463 | > | ------------------- | ---------- | ---------- | 464 | > | blockMajor | byte | 区块主版本号 | 465 | > | blockMinor | byte | 区块次版本号 | 466 | > | mainnetMajor | byte | 主网主版本号 | 467 | > | mainnetMinor | byte | 主网次版本号 | 468 | 469 | - BlockChainVersion对象设计 470 | > | `字段名称` | `字段类型` | `说明` | 471 | > | ------------------- | ---------- | ---------- | 472 | > | major | byte | 主版本号 | 473 | > | minor | byte | 次版本号 | 474 | 475 | ## 七、补充内容 476 | 477 | 1. 不同协议版本的消息是否处理由网络模块判断?还是由各个消息的注册模块判断 478 | 2. 不同协议版本的交易是否处理由交易模块判断?还是由各个交易的注册模块判断 479 | 3. 协议支持的消息类型、交易类型、交易处理器由配置文件初始化?还是由各模块来注册? 480 | 4. 是否允许版本回退?由1.1版本回退到1.0-------------------不予许 481 | 5. 不支持POW -------------------------------------------------------------------------------- /design-zh-CHS/接口交互格式与规范 JSON-RPC.md: -------------------------------------------------------------------------------- 1 | ## 接口交互格式与规范 JSON-RPC 2 | 3 | ### Request Body 4 | 5 | ```json 6 | { 7 | "cmd": "nuls_accounts", 8 | "params": ["param1", "param2"], 9 | "min_version": 1.0, 10 | } 11 | ``` 12 | 13 | - 请求参数 14 | 15 | | 参数 | 必选 | 类型 | 说明 | 16 | | ----------- | ----- | ------ | -------------- | 17 | | cmd | true | string | 执行的 Command | 18 | | params | true | array | 命令参数表 | 19 | | min_version | false | float | 兼容的最低版本 | 20 | 21 | ### Response Body 22 | 23 | - success 24 | 25 | ```json 26 | { 27 | "code":0, 28 | "msg": "Success", 29 | "result": {} 30 | } 31 | ``` 32 | 33 | - 响应参数 34 | 35 | | 参数 | 必选 | 类型 | 说明 | 36 | | :----- | :--- | :----- | --------------------------------------- | 37 | | code | ture | int | 请求想要状态,成功返回0。否则返回错误码 | 38 | | msg | true | string | 用户友好的请求执行结果描述 | 39 | | result | true | object | 方法返回值 | 40 | 41 | ### Error Code 42 | 43 | #### JSON RPC Standard errors 44 | 45 | | Code | Possible Return message | Description | 46 | | --------- | ----------------------- | ------------------------------------------------------------ | 47 | | 0 | Success | Operation success | 48 | | 1 | Parse error | Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text. | 49 | | 2 | Invalid Request | The JSON sent is not a valid Request object. | 50 | | 3 | Method not found | The method does not exist / is not available. | 51 | | 4 | Invalid params | Invalid method parameter(s). | 52 | | 5 | Internal error | Internal JSON-RPC error. | 53 | | 6 | Unauthorized | Should be used when some action is not authorized, e.g. sending from a locked account. | 54 | | 7 | Action not allowed | Should be used when some action is not allowed, e.g. preventing an action, while another depending action is processing on, like sending again when a confirmation popup is shown to the user (?). | 55 | | 8 | Timeout | Should be used when an action timedout. | 56 | | 9 | Conflict | Should be used when an action conflicts with another (ongoing?) action. | 57 | | 10 | Execution error | Will contain a subset of custom errors in the data field. See below. | 58 | | 11 to 100 | `Server error` | Reserved for implementation-defined server-errors. | 59 | 60 | #### Custom error fields 61 | 62 | Custom error `10` can contain custom error(s) to further explain what went wrong. 63 | 64 | ```js 65 | { 66 | code: 10, 67 | msg: 'Execution error', 68 | } 69 | ``` 70 | 71 | -------------------------------------------------------------------------------- /nulstar/Article - Design Reasoning.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/nulstar/Article - Design Reasoning.pdf -------------------------------------------------------------------------------- /nulstar/Message Protocol-中文版.md: -------------------------------------------------------------------------------- 1 | # Nulstar MESSAGE PROTOCOL 2 | 3 | ##### V 1.1 4 | 5 | 6 | 7 | ## 1] 通信协议 – Json/WebSockets 8 | 9 | 微服务的行为不像标准的客户端 - 服务器基础设施,因为每个微服务同时是客户端和服务器,因此需要全双工通信协议,这允许实现特殊类型的发布 - 订阅模式; 在这个实现中,方法只能被调用一次,然后调用者可以通过两种不同的方式接收不断的更新: 10 | 11 | - 基于事件:当方法在预定义数量的事件之后发送通知时 12 | - 基于时间:当方法在预定义的秒数后发送通知时 13 | 14 | WebSocket是一种成熟的选项,可以本机提供全双工连接,其他选项如标准Json-RPC不提供双向通道。 15 | 消息将使用JSon格式进行编码,因为它是最广泛用于消息交换的,并且易于调试。 16 | 17 | 18 | 19 | ## 2] 消息结构 20 | 21 | 所有消息都有一个由六个字段组成的公共基础结构: 22 | 23 | - ProtocolVersion:表示调用者需要服务理解的协议版本,它由两个数字(主要和次要)组成,遵循语义规则,这意味着如果主要数字不同,则拒绝连接,如果次要数量不同则 可以建立成功的连接 24 | - MessageID:这是一个标识请求的字符串。 它的长度不应超过256个字符 25 | - Timestamp:自纪元以来的秒数(1970年1月1日格林威治标准时间00:00:00) 26 | - TimeZone:发起请求的时区,它应为介于-12和12之间的数字 27 | - MessageType:消息类型,这些在第3节中指定 28 | - MessageData:保存消息有效负载的Json对象 29 | 30 | 示例: 31 | 32 | ```json 33 | { 34 | "ProtocolVersion":"1.0", 35 | "MessageID":"45sdj8jcf8899ekffEFefee", 36 | "Timestamp":"1542102459", 37 | "TimeZone":"-4", 38 | "MessageType":"NegotiateConnection", 39 | "MessageData":{ 40 | "CompressionRate":"3", 41 | "CompressionAlgorithm":"zlib" 42 | } 43 | } 44 | ``` 45 | 46 | 47 | 48 | ## 3] Message Types 49 | 50 | 目前只定义了9种类型的消息:NegotiateConnection, NegotiateConnectionResponse, Request, Unsubscribe, Response, Ack, Notificatioin, RegisterCompoundMethod, UnregisterCompoundMethod。 51 | 52 | #### 3.1] NegotiateConnection 53 | 54 | 这应该是在与微服务建立连接时应该发送的第一个对象,只有在协商成功时,服务才可以处理其他请求,否则应该收到状态设置为0(失败)的NegotiateConnectionResponse对象并立即断开连接。 55 | 56 | 它由两个字段组成: 57 | 58 | - CompressionAlgorithm(默认值:zlib):一个String,表示如果CompressionRate大于0,将用于接收和发送消息的算法。默认为zlib,大多数开发语言中都有支持的库。 59 | - CompressionRate:0到9之间的一个整数,用于建立应为此连接发送和接收消息的压缩级别。 0表示没有压缩,而9表示最大压缩 60 | 61 | 示例: 62 | 63 | ```json 64 | { 65 | "ProtocolVersion":"1.0", 66 | "MessageID":"45sdj8jcf8899ekffEFefee", 67 | "Timestamp":"1542102459", 68 | "TimeZone":"-4", 69 | "MessageType":"NegotiateConnection", 70 | "MessageData":{ 71 | "CompressionAlgorithm":"zlib", 72 | "CompressionRate":"3" 73 | } 74 | } 75 | ``` 76 | 77 | 78 | 79 | #### 3.2] NegotiateConnectionResponse 80 | 81 | 仅在响应先前传入的NegotiateConnection消息时发送此类消息。 它由两个字段组成: 82 | 83 | - NegotiationStatus:无符号的小整数值,如果协商失败则为0,如果成功则为1 84 | - NegotiationComment:一个字符串值,用于描述拒绝连接时出现了什么问题。 85 | 86 | 示例: 87 | 88 | ```json 89 | { 90 | "ProtocolVersion":"1.0", 91 | "MessageID":"45sdj8jcf8899ekffEFefee", 92 | "Timestamp":"1542102459", 93 | "TimeZone":"-4", 94 | "MessageType":"NegotiateConnectionReponse", 95 | "MessageData":{ 96 | "NegotiationStatus":"0", 97 | "NegotiationComment":"Incompatible protocol version" 98 | } 99 | } 100 | ``` 101 | 102 | 103 | 104 | #### 3.3] Request 105 | 106 | 调用者服务必须发送一个Request对象来执行Nulstar网络内某些服务提供的方法。 107 | 108 | 如果在单个请求对象中包含两个或更多方法,则应按顺序执行方法,然后发送一个response包喊所有回执信息,如果其中一个请求失败,则整个操作被视为失败。 109 | 110 | 它由六个字段组成: 111 | 112 | - RequestAck(默认值:false):这是一个布尔值 113 | 114 | - false:发出的请求只需要一条Response消息,如果它订阅了该函数,那么它可能会有很多响应消息 115 | - true:发出的请求需要Ack和Response(译者注:有的请求可能需要一段时间处理,不会立刻返回Response,但是我要确保对方接收到了我的请求),如果它订阅了该函数,那么它可能会有很多响应消息 116 | 117 | - SubscriptionEventCounter(默认值:0):这是一个无符号整数,指定目标方法发送Response的区块间隔。不管这个值是多少,总会立刻发送一个Response。如果是0,则不再继续发送,如果是2,则每2个块都会检测是否发送。以此类推。 118 | 119 | - SubscriptionPeriod(默认值:0):这是一个无符号整数,指定目标方法发送Response的时间间隔。不管这个值是多少,总会立刻发送一个Response。如果是0,则不再继续发送,如果是2,则每2秒都会检测是否发送。以此类推。 120 | 121 | - SubscriptionRange:如果请求的事件返回的是一个数字,则定义何时返回这个数字。 122 | 这是一个字符串,表示将触发响应的条件。 字符串是一对带符号的十进制数,第一个是下限,第二个是上限,如果不可用则为空。 如果该对分别以“(”或“)”开始或结束,则表示该数字不包括在内,如果该对分别以“[”或“]”开始或结束,则表示该数字包括在内。 123 | 124 | 示例:假设我们只希望仅在余额等于或大于1000时收到通知。然后,getbalance请求应以“[1000,)”字符串作为SubscriptionRange参数发送 125 | 126 | - ResponseMaxSize(默认值:0):无符号整数,指定方法应返回的最大对象数,值为零(默认值)表示无限制 127 | - RequestMethods:一个数组,包含所请求的所有方法及其各自的参数 128 | 129 | 示例: 130 | 131 | ```json 132 | { 133 | "ProtocolVersion":"1.0", 134 | "MessageID":"45sdj8jcf8899ekffEFefee", 135 | "Timestamp":"1542102459", 136 | "TimeZone":"-4", 137 | "MessageType":"Request", 138 | "MessageData":{ 139 | "RequestAck":"0", 140 | "SubscriptionEventCounter":"3", 141 | "SubscriptionPeriod":"0", 142 | "SubscriptionRange":"0", 143 | "ResponseMaxSize":"0", 144 | "RequestMethods":{ 145 | "GetBalance":{ 146 | "Address":"N234rFr4Rtgg5ref4$45tgg5f43335emcnd" 147 | }, 148 | "GetHeight":{ 149 | 150 | } 151 | } 152 | } 153 | } 154 | ``` 155 | 156 | 157 | 158 | #### 3.4] Unsubscribe 159 | 160 | 当服务不再希望从其订阅的方法接收响应时,它必须向目标服务发送Unsubscribe消息。 161 | 162 | 它由一个字段组成: 163 | 164 | - UnsubscribeMethods:一个数组,包含调用者想要取消订阅的所有方法 165 | 166 | 示例: 167 | 168 | ```json 169 | { 170 | "ProtocolVersion":"1.0", 171 | "MessageID":"45sdj8jcf8899ekffEFefee", 172 | "Timestamp":"1542102459", 173 | "TimeZone":"-4", 174 | "MessageType":"Unsubscribe", 175 | "MessageData":{ 176 | "UnsubscribeMethods":[ 177 | "GetBalance", 178 | "GetHeight" 179 | ] 180 | } 181 | } 182 | ``` 183 | 184 | 185 | 186 | #### 3.5] Response 187 | 188 | 当目标服务完成处理请求时,应该发送响应以及操作结果。 189 | 190 | 它由六个字段组成: 191 | 192 | - RequestID:这是引用的原始Request消息请求ID 193 | - ResponseProcessingTime:目标服务处理请求所用的时间(以毫秒为单位) 194 | - ResponseStatus:响应状态,如果成功则为1,否则为0 195 | - ResponseComment:一个字符串,可以提供有关该过程结果的更多说明 196 | - ResponseMaxSize:响应包含每个请求的最大对象数 197 | - ResponseData:一个对象数组,包含已处理方法的结果,每个请求一个对象 198 | 199 | 示例: 200 | 201 | ```json 202 | { 203 | "ProtocolVersion":"1.0", 204 | "MessageID":"767345sdfgsd99qwe", 205 | "Timestamp":"1542102459", 206 | "TimeZone":"-4", 207 | "MessageType":"Response", 208 | "MessageData":{ 209 | "RequestID":"45sdj8jcf8899ekffEFefee", 210 | "ResponseProcessingTime":"13", 211 | "ResponseStatus":"1", 212 | "ResponseComment":"Congratulations! Processing completed!", 213 | "ResponseMaxSize":"0", 214 | "ResponseData":{ 215 | "getBalance":{ 216 | "Balance":"25000" 217 | }, 218 | "getHeight":{ 219 | "Height":"45454655454" 220 | } 221 | } 222 | } 223 | } 224 | ``` 225 | 226 | 227 | 228 | 229 | 230 | #### 3.6] Ack 231 | 232 | 当RequestType为2或3时,将发送此消息类型(请参阅第3.3节)。 其唯一目的是通知呼叫者已成功接收请求。 233 | 234 | 它由一个字段组成: 235 | 236 | - RequestID:这是引用的原始Request消息请求ID 237 | 238 | 示例: 239 | 240 | ```json 241 | { 242 | "ProtocolVersion":"1.0", 243 | "MessageID":"45sdj8jcf8899ekffEFefee", 244 | "Timestamp":"1542102459", 245 | "TimeZone":"-4", 246 | "MessageType":"Ack", 247 | "MessageData":{ 248 | "RequestID":"sdj8jcf8899ekffEFefee" 249 | } 250 | } 251 | ``` 252 | 253 | 254 | 255 | 256 | 257 | #### 3.7] Notification 258 | 259 | 当需要将某些事件通知给连接的组件而不期望响应消息时(例如,即将对服务执行升级时),将发送此消息类型。 通知将信息推送到其他组件,因此通知只应由Manager,Controller和Connector模块使用 260 | 261 | 它由四个字段组成: 262 | 263 | - NotificationAck :(默认值:false):这是一个布尔值 264 | - false:发出的通知不期望任何类型的消息作为回执 265 | - true:发出的通知需要一条Ack消息 266 | - NotificationType:通知的类别,每个服务都可以定义自己的类型,因此不需要接收方处理此字段 267 | - NotificationComment:字符串注释,提供有关通知原因的更多信息 268 | - NotificationData:与通知相关的数据,接收方不需要处理此字段 269 | 270 | 示例: 271 | 272 | ```json 273 | { 274 | "ProtocolVersion":"1.0", 275 | "MessageID":"45sdj8jcf8899ekffEFefee", 276 | "Timestamp":"1542102459", 277 | "TimeZone":"-4", 278 | "MessageType":"Notification", 279 | "MessageData":{ 280 | "NotificationAck":"1", 281 | "NotificationType":"SystemUpgrade", 282 | "NotificationComment":"A system upgrade is about to be performed!", 283 | "NotificationData":{ 284 | "Date":"2018-11-11", 285 | "Time":"23:00:00", 286 | "NewVersion":"1.1.6" 287 | } 288 | } 289 | } 290 | ``` 291 | 292 | 293 | 294 | 295 | 296 | #### 3.8] RegisterCompoundMethod 297 | 298 | 如3.3中所述,请求可以由多个方法组成,使用此消息类型,我们注册一个虚拟方法,该方法将按顺序执行其各个实际方法,如果其子方法之一失败,则虚方法返回失败。 299 | 300 | 某些子方法可能共享相同的参数名称,因此可以创建别名,如示例中所示。 301 | 302 | 它由三个字段组成: 303 | 304 | - CompoundMethodName:这是标识虚方法的字符串 305 | - CompoundMethodDescription:描述方法功能,在查询API以获取帮助时将提供描述 306 | - CompoundMethods:这是一个数组,包含构成虚方法的各自参数别名的方法 307 | 308 | 示例: 309 | 310 | ```json 311 | { 312 | "ProtocolVersion":"1.0", 313 | "MessageID":"45sdj8jcf8899ekffEFefee", 314 | "Timestamp":"1542102459", 315 | "TimeZone":"-4", 316 | "MessageType":"RegisterCompoundMethod", 317 | "MessageData":{ 318 | "CompoundMethodName":"GetMyInfo", 319 | "CompoundMethodDescription":"Get useful information.", 320 | "CompoundMethods":{ 321 | "GetBalance":{ 322 | "Address":"GetBalanceAddress" 323 | }, 324 | "GetHeight":{ 325 | 326 | } 327 | } 328 | } 329 | } 330 | ``` 331 | 332 | 在该示例中,正在注册一个名为GetMyInfo的虚方法,它由GetBalance和GetHeight方法组成,还为Address参数创建了一个名为GetBalanceAddress的别名。 333 | GetMyInfo的请求可以作为标准方法发送。 334 | 335 | (我确实没看懂这个的意义在哪,感觉就是单纯为了多这么个功能,有疑问请直接找Berzeck或者坚哥,哈哈) 336 | 337 | 338 | 339 | #### 3.9] UnregisterCompoundMethod 340 | 341 | 此消息类型用于取消注册复合(虚拟)方法。 342 | 343 | 它由一个字段组成: 344 | 345 | - UnregisterCompoundMethodName:这是标识虚方法的字符串。 如果它为空,则应取消注册调用者注册的所有虚拟方法 346 | 347 | 示例: 348 | 349 | ```json 350 | { 351 | "ProtocolVersion":"1.0", 352 | "MessageID":"45sdj8jcf8899ekffEFefee", 353 | "Timestamp":"1542102459", 354 | "TimeZone":"-4", 355 | "MessageType":"UnregisterCompoundMethod", 356 | "MessageData":{ 357 | "UnregisterCompoundMethodName":"GetMyInfo" 358 | } 359 | } 360 | ``` 361 | 362 | -------------------------------------------------------------------------------- /nulstar/Message Protocol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/nulstar/Message Protocol.pdf -------------------------------------------------------------------------------- /nulstar/Module Specification.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/nulstar/Module Specification.docx -------------------------------------------------------------------------------- /nulstar/Module Specification.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nuls-io/nuls-v2-design-docs/b3579b2fc3083cce6899b4a643bf9add7d2bb088/nulstar/Module Specification.pdf -------------------------------------------------------------------------------- /nulstar/交易类型字典.md: -------------------------------------------------------------------------------- 1 | 2 | ## 交易类型字典 3 | > 采用模块化方式后,不在限定开发语言,不管你是使用java、c++、js、golang等, 4 | > 网络传输交易类型使用整型数值,交易字典变量名尽可能按照如下表格来定义,方便快速搜索和代码阅读。 5 | 6 | ### 公共交易类型 7 | 8 | |交易类型 | 交易变量名 |说明 | 9 | |---- |----------------------|---------------| 10 | |1 |TX_TYPE_COINBASE |Coinbase,共识奖励交易 | 11 | |2 |TX_TYPE_TRANSFER |转账交易| 12 | |3 |TX_TYPE_ACCOUNT_ALIAS |设置账户别名交易| 13 | 14 | ### 共识模块 15 | 16 | |交易类型 | 交易变量名 |说明 | 17 | |---- |----------------------|---------------| 18 | |4 |TX_TYPE_REGISTER_AGENT|创建共识节点交易| 19 | |5 |TX_TYPE_JOIN_CONSENSUS|委托交易| 20 | |6 |TX_TYPE_CANCEL_DEPOSIT|撤销委托交易| 21 | |7 |TX_TYPE_YELLOW_PUNISH |黄牌警告交易| 22 | |8 |TX_TYPE_RED_PUNISH |红牌警告交易| 23 | |9 |TX_TYPE_STOP_AGENT |注销共识节点交易| 24 | |10 |TX_TYPE_CROSS_CHAIN_TRANSFER |跨链转账交易 | 25 | 26 | ### 链管理模块 27 | 28 | |交易类型 | 交易变量名 |说明 | 29 | |---- |-------------------------------- |---------------| 30 | |11 |TX_TYPE_REGISTER_CHAIN_AND_ASSET |注册链交易| 31 | |12 |TX_TYPE_DESTROY_ASSET_AND_CHAIN |链注销交易| 32 | |13 |TX_TYPE_ADD_ASSET_TO_CHAIN |增加链资产交易| 33 | |14 |TX_TYPE_REMOVE_ASSET_FROM_CHAIN |移除链资产交易| 34 | 35 | ### 智能合约 36 | 37 | |交易类型 | 交易变量名 |说明 | 38 | |---- |------------------------ |---------------| 39 | |100 |TX_TYPE_CREATE_CONTRACT |创建智能合约交易| 40 | |101 |TX_TYPE_CALL_CONTRACT |调用智能合约交易| 41 | |102 |TX_TYPE_DELETE_CONTRACT |删除智能合约交易| 42 | |103 |TX_TYPE_CONTRACT_TRANSFER|向合约地址转账交易| 43 | -------------------------------------------------------------------------------- /nulstar/已确认的与Manager(Kernel)交互的字符串.md: -------------------------------------------------------------------------------- 1 | ## Module向Manager发送握手信息 2 | 3 | ```json 4 | { 5 | "MessageID":"1542345820430", 6 | "Timestamp":"542345820", 7 | "TimeZone":"-4", 8 | "MessageType":"NegotiateConnection", 9 | "MessageData":{ 10 | "CompressionRate":"0", 11 | "CompressionAlgorithm":"zlib" 12 | } 13 | } 14 | ``` 15 | 16 | 17 | 18 | 19 | 20 | ## Manager向Module发送握手确认信息 21 | 22 | ```json 23 | { 24 | "MessageID":"1542345821232", 25 | "Timestamp":"542345821", 26 | "TimeZone":"-4", 27 | "MessageType":"NegotiateConnectionReponse", 28 | "MessageData":{ 29 | "NegotiationStatus":"1", 30 | "NegotiationComment":"Connection successful!" 31 | } 32 | } 33 | ``` 34 | 35 | 36 | 37 | 38 | 39 | ## Module向Manager注册方法 40 | 41 | ```json 42 | { 43 | "messageId":2, 44 | "timestamp":1542782457264, 45 | "timezone":9, 46 | "messageType":"Request", 47 | "messageData":{ 48 | "subscriptionEventCounter":0, 49 | "subscriptionPeriod":0, 50 | "subscriptionRange":"", 51 | "responseMaxSize":0, 52 | "requestMethods":{ 53 | "registerAPI":{ 54 | "apiMethods":[ 55 | { 56 | "methodName":"getHeight", 57 | "methodDescription":"test getHeight 1.0", 58 | "methodMinEvent":0, 59 | "methodMinPeriod":0, 60 | "methodScope":"private", 61 | "parameters":[ 62 | { 63 | "parameterName":"aaa", 64 | "parameterType":"int", 65 | "parameterValidRange":"", 66 | "parameterValidRegExp":"" 67 | }, 68 | { 69 | "parameterName":"bbb", 70 | "parameterType":"string", 71 | "parameterValidRange":"", 72 | "parameterValidRegExp":"" 73 | } 74 | ], 75 | "version":1 76 | }, 77 | { 78 | "methodName":"getHeight", 79 | "methodDescription":"test getHeight 1", 80 | "methodMinEvent":0, 81 | "methodMinPeriod":0, 82 | "methodScope":"private", 83 | "parameters":[ 84 | 85 | ], 86 | "version":2 87 | }, 88 | { 89 | "methodName":"getHeight", 90 | "methodDescription":"test getHeight 1", 91 | "methodMinEvent":1, 92 | "methodMinPeriod":10, 93 | "methodScope":"public", 94 | "parameters":[ 95 | 96 | ], 97 | "version":1.3 98 | } 99 | ], 100 | "serviceSupportedAPIVersions":[ 101 | 102 | ], 103 | "serviceDomain":null, 104 | "serviceName":null, 105 | "serviceRole":null, 106 | "serviceVersion":null, 107 | "abbr":"cm", 108 | "name":"Chain Manager", 109 | "address":"192.168.1.65", 110 | "port":14922 111 | } 112 | } 113 | } 114 | } 115 | ``` 116 | 117 | --------------------------------------------------------------------------------