# BDware SDK
In addition to using the visual smart contract online IDE, users can also use the WebSocket interface, Http interface, Bash interface to start and run the contract.

- - -

## WebSocketSDK download and installation
The contract SDK provides a javascript version and a Java version of the client.

The download links of Java client are :[java source](./_static/BDWareJavaClient.zip) and [jar](./_static/BDWareConfigTool.zip) refer to Readme.md and test cases in java_Source.

The javascript download link is :[js SDK](./_static/js/createWS.js) Built-in SM2 encryption library link :[sm2 SDK](./_static/js/sm2.js)

### Establish a connection
Establish a WebSocket connection to the node server.

#### parameter

|field    |value|
| ---------- | ------------------------------------------------------------ |
| url        |If `http` is used, the prefix is `ws://`, for example, `"ws://localhost:1717/SCIDE/SCExecutor"`. If `https` is used, the prefix is `wss://`.|
| msgHandler |The callback function after receiving the server WebSocket reply can be written by the user, or refer to the example provided below|

#### Sample request


```javascript
var url = "ws://127.0.0.1:1717/SCIDE/SCExecutor";//与Slave节点建立连接
//var url = "ws://127.0.0.1:1718/NodeCenterWS";//与Manager节点建立连接
var msgHandler = function(m){
  console.log("recmsg:");
  console.log(m);
};
var onOpenHandler=undefined;
wssocket = createWssocket(url,onOpenHandler,msgHandler);
```

#### Result


```
{
  receiveSeg: [Function (anonymous)],
  isSending: false,
  sendList: [],
  monitor: [Function (anonymous)],
  send: [Function (anonymous)],
  sendNextSegment: [Function (anonymous)],
  isOpen: [Function (anonymous)]
}
```



### ping

`ping` Server test

#### parameter

|field| 值   |
| ------ | ---- |
|action| ping |

#### Sample request


```
var request = {};
request.action = "ping";
wssocket.send(JSON.stringify(request));
```

#### Result


```
{
    "action":"pong"
}
```

### The login

When using the Websocket interface to invoke the interface that requires permission, either to connect to CenterPortal or NodePortal, **The login** must be performed first. The login process has 3 steps:

- The client establishes a connection to the server and sends {“action”:“getSessionID”} (implemented in onOpenHandler).
- After receiving the request, the server returns a result similar to {“action”:“onGetSessionID”,“session”:”-4959947809200104526_session”} to the client
- After receiving the onGetSessionID, the client signs the sessionID with the local public and private keys and invokes the login interface
- The server returns the onLogin result, and the data field returns the role corresponding to the public key.

- - -

## User Role Division

### Role division of contract nodes

In contract node (NodePortal. HTML) is divided into NodeManager/ContractProvider/ContractInstanceManager/ContractUser four types of roles.

| 角色                    |instructions|
| ----------------------- | ------------------------------------------------------------ |
| NodeManager             |The administrator of the node has rights to manage users and configure nodes|
| ContractProvider        |Have the rights to edit contract, develop contract code, run debugging and so on|
| ContractInstanceManager |Have the rights to start, stop, and configure I/O of the contract instance|
| ContractUser            |Have the rights to view the list of contract instances and call the contract|
| Anonymous               |Anonymous users, can be called the contract, can apply for to become ContractProvider/InstanceManager role|


|interface  | 说明                 |role|
| ------------------------------- | -------------------- | ----------------------------------------- |
| changeDumpPeriod                | 设置备份周期         |ContractInstanceManager;|
| createLedger                    | 创建账本             |ContractInstanceManager;|
|dumpContract                   | 手动备份             |ContractInstanceManager;|
| deleteMemoryFile                | 删除镜像             |ContractInstanceManager;|
| forkContract                    | 迁移合约             |ContractInstanceManager;|
| getDumpPeriod                   | 获取备份周期         |ContractInstanceManager;|
|killAllContract                | 停止全部实例         |ContractInstanceManager;|
|killContractProcess            | 停止某一实例         |ContractInstanceManager;|
|listMemoryFiles                | 列取某一实例的镜像   |ContractInstanceManager;|
| loadMemory                      | 加载镜像             |ContractInstanceManager;|
| queryContractInstanceDOI        | 查询合约实例信息     |ContractInstanceManager;|
| rebuildHashIndex                |                      |ContractInstanceManager;|
| setPermission                   |                      |ContractProvider;ContractInstanceManager;|
| startContract                   | Start the contract             |ContractInstanceManager;|
| startContractBatched            | 废弃                 |ContractInstanceManager;|
| startContractByYPK              | 启动合约             |ContractInstanceManager;|
|startContractInTempZips        | 废弃                 |ContractInstanceManager;|
| startContractP2PTrustfully      | 启动合约（集群模式） |ContractInstanceManager;|
| updateContract                  |                      |ContractInstanceManager;|
| connectTo                       | 连接合约实例输出流   |ContractInstanceManager;ContractUser;|
| countContractLogGroupByAction   |                      |ContractInstanceManager;ContractUser;|
| countContractLogGroupByCategory |                      |ContractInstanceManager;ContractUser;|
| getLastLog                      | 查询日志             |ContractInstanceManager;ContractUser;|
| getLog                          | 查询日志             |ContractInstanceManager;ContractUser;|
| getLogSize                      | 查询日志             |ContractInstanceManager;ContractUser;|
| listAllContractProcess          |                      |ContractInstanceManager;ContractUser;|
|listContractProcess  | 查询合约实例列表     |ContractInstanceManager;ContractUser;|
| listLeakContractProcess         |                      |ContractInstanceManager;ContractUser;|
| queryContractLogByDate          |                      |ContractInstanceManager;ContractUser;|
|queryContractLogByKey    |                      |ContractInstanceManager;ContractUser;|
| queryContractLogByOffset        |                      |ContractInstanceManager;ContractUser;|
| queryContractLogDetail          |                      |ContractInstanceManager;ContractUser;|
|queryContractLogSize       |                      |ContractInstanceManager;ContractUser;|
|queryNodeLogByDate   |                      |ContractInstanceManager;ContractUser;|
| queryNodeLogByOffset            |                      |ContractInstanceManager;ContractUser;|
|queryNodeLogSize   |                      |ContractInstanceManager;ContractUser;|
| rebuildContractLogIndex         |                      |ContractInstanceManager;ContractUser;|
| rebuildNodeLogIndex             |                      |ContractInstanceManager;ContractUser;|
| changePublic                    |                      |ContractProvider;|
| createFile                      | 新建文件             |ContractProvider;|
| deleteFile                      | 删除文件             |ContractProvider;|
| distributeContract              |                      |ContractProvider;|
|downloadContract               |                      |ContractProvider;|
| downloadContractFromOtherHost   |                      |ContractProvider;|
| generateAnnotationSample        |                      |ContractProvider;|
| generateAppDataAnalysis         |                      |ContractProvider;|
| generateAppDataSource           |                      |ContractProvider;|
| generateBDCoinEventProject      |                      |ContractProvider;|
| generateBDCoinProject           |                      |ContractProvider;|
| generateBiddingExample          |                      |ContractProvider;|
| generateCSVProject              |                      |ContractProvider;|
| generateContractExecutor        |                      |ContractProvider;|
| generateDAC4BDOA                |                      |ContractProvider;|
| generateDAC4BDOA_persist        |                      |ContractProvider;|
| generateDACSample               |                      |ContractProvider;|
| generateEmptyProject            |                      |ContractProvider;|
| generateEventPublisher          |                      |ContractProvider;|
| generateEventSubscriber         |                      |ContractProvider;|
| generateGasExample              |                      |ContractProvider;|
| generateHello                   |                      |ContractProvider;|
| generateHttpExample             |                      |ContractProvider;|
| generateIncentives              |                      |ContractProvider;|
| generateJSONExample             |                      |ContractProvider;|
| generateLedgerExample           |                      |ContractProvider;|
| generateLedgerProject           |                      |ContractProvider;|
| generateLicenceManager          |                      |ContractProvider;|
| generateLoggerExample           |                      |ContractProvider;|
| generateMySQLExample            |                      |ContractProvider;|
| generateMySQLProject            |                      |ContractProvider;|
| generatePostgreSQLSample        |                      |ContractProvider;|
| generateReadme                  |                      |ContractProvider;|
| generateRenderSample            |                      |ContractProvider;|
| generateRocksDBSample           |                      |ContractProvider;|
| generateSM2Example              |                      |ContractProvider;|
| generateStaticResource          |                      |ContractProvider;|
| generateTFLinux                 |                      |ContractProvider;|
| generategenerateTFMac           |                      |ContractProvider;|
| getProject                      |                      |ContractProvider;|
| getTemplateList                 |                      |ContractProvider;|
| importContractInstanceCodeByDOI |                      |ContractProvider;|
| listFile                        |                      |ContractProvider;|
| listProject                     |                      |ContractProvider;|
| listProjectPermission           |                      |ContractProvider;|
| listProjects                    |                      |ContractProvider;|
| renameFile                      |                      |ContractProvider;|
| saveFile                        |                      |ContractProvider;|
| startContractAsDebug            |                      |ContractProvider;|
| uploadFile                      |                      |ContractProvider;|
| compile                         |                      |ContractProvider;ContractInstanceManager;|
| evaluates                       |                      |ContractProvider;ContractInstanceManager;|
| executeContractP2PTrustfully    |                      |ContractProvider;ContractInstanceManager;|
|getCodeByID                    | 查询代码             |ContractProvider;ContractInstanceManager;|
|getControlFlowByFileName       |                      |ContractProvider;ContractInstanceManager;|
| getGasValue                     |                      |ContractProvider;ContractInstanceManager;|
| listCompiledFiles               |                      |ContractProvider;ContractInstanceManager;|
| queryContractResourceInfo       |                      |ContractProvider;ContractInstanceManager;|
| queryFreeResourceInfo           |                      |ContractProvider;ContractInstanceManager;|
|staticVerifyContract           |                      |ContractProvider;ContractInstanceManager;|
|writeDyjs                 |                      |ContractProvider;ContractInstanceManager;|
| authNodeRole                    | 授权角色             |NodeManager;|
| changeBDledger                  | 修改账本配置         |NodeManager;|
| changeIpPort                    |                      |NodeManager;|
| changeNodeCenter                | 修改集群地址         |NodeManager;|
| changeNodeName                  |                      |NodeManager;|
| changeIpPort                    |                      |NodeManager;|
| changeDOIPConfig                |                      |NodeManager;|
| changeYJSPath                   |                      |NodeManager;|
| countNodeLogGroupByCategory     |                      |NodeManager;|
| countRole                       |                      |NodeManager;|
| deleteRole                      |                      |NodeManager;|
| downloadUUID                    | 废弃                 |NodeManager;|
| getEncodedUUID                  | 废弃                 |NodeManager;|
| getPeerID                       |                      |NodeManager;|
| listAllAuthRole                 |                      |NodeManager;|
| listNodeInfos                   |                      |NodeManager;|
| listUnAuthRole                  |                      |NodeManager;|
| loadConfig                      |                      |NodeManager;|
| loadNodeConfig                  |                      |NodeManager;|
| lockEdit                        |                      |NodeManager;|
| unlockEdit                      |                      |NodeManager;|
| updateConfig                    |                      |NodeManager;|
| uploadLicence                   |                      |NodeManager;|
| applyNodeRole                   | 申请角色             |Any role|
|executeContract  | Call the contract             |Any role|
| getConnCount                    |                      |Any role|
| getHashAbstractLocally          |                      |Any role|
| getHashLocally                  |                      |Any role|
| getNodeRoleDeprecated           | 查询当前角色         |Any role|
|getSessionID  |                      |Any role|
| listAdapters                    |                      |Any role|
| listTheContractProcess          |                      |Any role|
|login  | 登录                 |Any role|
| longStr                         |                      |Any role|
| ping                            |                      |Any role|
|queryDataByHash|                      |Any role|
| queryDataByHashLocally          |                      |Any role|
| queryHashByOffset               |                      |Any role|
|queryHashByRequestID       |                      |Any role|
|queryHashSize               |                      |Any role|
| queryLedgers                    |                      |Any role|
| queryRole                       |                      |Any role|
| queryTransactionByHash          |                      |Any role|
| sendTransaction                 |                      |Any role|
| setLogStage                     |                      |Any role|

### Contract access center role division

There are two roles: CenterManager and NodeManager. CenterManager has permissions on cluster Settings. NodeManager can add and delete nodes.

| 接口                          | 说明         | 角色                       |
| ----------------------------- | ------------ | -------------------------- |
|authNodeManager|              | CenterManager;             |
|countActionLogByCategory|              | CenterManager;             |
|countCMLogByCategory|              | CenterManager;             |
|delete|              | CenterManager;             |
|listAllUsers|              | CenterManager;             |
|listApplyList|              | CenterManager;             |
|listLicence|              | CenterManager;             |
|queryActionLog|              | CenterManager;             |
|queryCMLog|              | CenterManager;             |
|updateLicence|              | CenterManager;             |
|addNode|              | CenterManager;NodeManager; |
|changeNCFile|              | CenterManager;NodeManager; |
|changeOtherNC|              | CenterManager;NodeManager; |
|createTrustUnit| 创建可信集群 | CenterManager;NodeManager; |
|deleteTrustUnit|              | CenterManager;NodeManager; |
|getNCFile|              | CenterManager;NodeManager; |
|getNodeTrustUnits|              | CenterManager;NodeManager; |
|getOtherNC|              | CenterManager;NodeManager; |
|listContractProcess          |              | CenterManager;NodeManager; |
|listMultiPointContractProcess|              | CenterManager;NodeManager; |
|listNodes|              | CenterManager;NodeManager; |
|listTrustUnits|              | CenterManager;NodeManager; |
|queryUserStat|              | CenterManager;NodeManager; |
|stopMultiPointContractProcess|              | CenterManager;NodeManager; |
|applyRole|              | NodeManager;               |
|executeContract  | 调用合约     | 任意角色                   |
|executeContractTrustfully|              | 任意角色                   |
|getManagerPubkey|              | 任意角色                   |
|getNodeRole|              | 任意角色                   |
|getNodeSessionID|              | 任意角色                   |
|getRole|              | 任意角色                   |
| getSessionID                  |              | 任意角色                   |
| login                         | 登录         | 任意角色                   |

- - -

## Contract node Http interface

`http://xxx.xxx.xxx.xxx:1717/SCIDE/SCManager` is the URL of the server that provides Http interface services( `xxx.xxx.xxx.xxx:1717` is the IP and port number of the BDWare SCIDE operation), the user can add field parameters after the URL, The following functions are complete: `http://xxx.xxx.xxx.xxx:18000/SCIDE/SCManager` is the server that provides Http interface services

URL (<GT R="228"/> is the IP and port number of BDWare SCIDE operation), the user can complete the following functions by adding field parameters after the URL:


### User Management

#### ping

`ping` Server test

##### methods

GET

##### parameter


| 字段   | 值   |
| ------ | ---- |
|action| ping |

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=ping
```

##### Result


```json
{"data":"pong"}
```


### Contract code management class


#### Download Contract Item

##### methods

GET

##### parameter


| 字段        |value|
| ----------- | ---------------- |
| action      | downloadContract |
|projectName| 合约项目名       |
|isPrivate| 是否在私有目录下 |
| pubKey      |The user’s public key|
| timestamp   |The time stamp|
| sign        |The signature|


##### Sample request


```
http://127.0.0.1:18000/SCIDE/CMManager?action=downloadContract&projectName=BDCoin&isPrivate=false&pubKey=0480204f4ef341359a5f64fcb11baf9ca2e6706ac20cba3
8b7ff78aa631e97346086e2d48fac2ba7f5b75ccbd19ebf495c0e6f9934d69e3b083da4d42e46c991e0c2ea8bb45d59f31f46d0ec700fb01f2fdd275
```

#### Upload a file

##### methods

POST


##### parameter


| 字段      |value|
| --------- | ---------------- |
| path      |File upload path|
| fileName  |File name to be uploaded|
|isPrivate| 是否在私有目录下 |
| order     |The number of packets|
| count     |Total number of packets|
| timestamp |The time stamp|
| sign      |The signature|


##### Sample request



```
http://127.0.0.1:18000/SCIDE/Upload?path=/TEST/TEST.yjs&fileName=WechatIMG15.jpeg&isPrivate=true&order=0&count=3&pubKey=0480204f4ef341359a5f64fcb11baf9ca2e6706ac20cba36ca83066870cf2c1d5de6df67e24e68dde7934af9b31d94a6084281db3d32d5ce42ab8f75bf799aca05&sign=dd867469f5adf9986e4ea6215febeae50c7d4c3836d002cf8c17050dfca031fd2595ffa8646e9eeae53150d2cbaea690e27d818eaf5cea3632ee1b69c3307a4b631e97346086e2d48fac2ba7f5b75ccbd19ebf495c0e6f9934d69e3b083da4d42e46c991e0c2ea8bb45d59f31f46d0ec700fb01f2fdd275
```

##### Result


```json
{"status":"true","data":"success"}
```

#### Save the contract script

Send a request to the server to save the contract script content locally to the server.

##### methods

GET


##### parameter

| 字段    |value|
| ------- | -------------- |
| action  | writeDyjs      |
|target| 合约脚本文件名 |
| content |Contract Script Content|

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=writeDyjs&target=testyjs.yjs&content=contract%20shortc%7B%0A%09export%20function%20main(arg)%7B%0A%09%09return%20arg.length%3B%09%0A%09%7D%0A%7D
```

##### Result


```json
{
    "status": false,
    "action": "onWriteDyjs",
    "data": "success"
}
```

Subsequent users can start and invoke the contract.







### Contract instance management class

#### Querying the contract process

Sends a request to the server for all the contract processes that have been started on the server.

##### methods

GET

##### parameter

| 字段   |value|
| ------ | ------------------- |
| action | listContractProcess |

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=listContractProcess
```

##### Result


```json
{
    "status": false,
    "action": "onListContractProcess",
    "data": "[\n  {\n    \"id\": \"-562752842\",\n    \"name\": \"shortc\",\n    \"port\": \"1626\",\n    \"times\": \"0 \",\n    \"traffic\": \"32.00 B\",\n    \"storage\": \"0.00 B\",\n    \"contractStatus\": \"Ready\"\n  }\n]"
}
```


#### 启动合约

Send a request to the server to start a contract.

##### methods

GET

##### parameter

| 字段   |value|
| ------ | --------------------------------- |
| action |startContract|
| script |Contract script content, need to do URIEncode|

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=startContract&script=contract%20shortc%7B%0A%09export%20function%20main(arg)%7B%0A%09%09return%20arg.length%3B%09%0A%09%7D%0A%7D
```

##### Result


```json
{
    "data": "{\"status\":\"Success\",\"result\":\"\"}",
    "action": "onStartContract",
    "cid": "-562752842",
    "executeTime": 1187
}
```



#### 调用合约

Send a request to the server to invoke a contract.

##### methods

GET

##### parameter

| 字段                 |value|
| -------------------- | --------------------------- |
| action               | executeContract             |
|contractID          |Contract ID|
| withDynamicAnalysis |True /false Indicates whether to perform dynamic analysis|
| operation            |The name of the method that calls the contract|
| arg                  |Call the parameters of the contract|
| pubkey              |Optionally, caller public key|
| signature           |Optional, sign|


Pubkey is the public key of SM2. The calculation method is as follows:


```javascript
//sm2 可从sm2.js中加载获得。
signature = sm2.doSignature(contractID+"|"+operation+"|"+arg+"|"+pubkey,privateKey);
```

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=executeContract&contractID=-620602333&operation=main&arg=hhh
```

##### Result


```json
{
    "data": "{\"status\":\"Success\",\"result\":\"3\"}",
    "action": "onExecuteResult",
    "executeTime": "13"
}
```




#### Bulk start contract

Send a request to the server to start a series of contracts that hold the contract script in the server.

##### methods

GET

##### parameter

| 字段     |value|
| -------- | ------------------------------------ |
| action   |startContractBatched|
| fileList |List of contract script files (Json array,URLEncode)|

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=startContractBatched&fileList=%5B%20%22EventPuber.yjs%22%2C%20%22EventSuber.yjs%22%2C%20%22LicenceManager.yjs%22%20%5D

```

##### Result


```json
{"EventPuber.yjs":"{\"status\":\"Success\",\"result\":\"\"}","LicenceManager.yjs":"{\"status\":\"Success\",\"result\":\"\"}","EventSuber.yjs":"{\"status\":\"Success\",\"result\":\"\"}","action":"onStartContract"}

```




#### Start the Zip package contract

Send a request to the server to start the contract wrapped in the `zip` format in the server.

##### methods

GET

##### parameter

| 字段      |value|
| --------- | ----------------------- |
| action    | startContractInTempZips |
| owner     |Caller’s public key|
| path      |Zip file name of the contract (path and)|
| signature |Caller signature|

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=startContractInTempZips&owner=0475c7b061f32477c1e228dd04143daf58a5574dc3f6b02bd2857cc794eb92bfe98606dc314049e77fd8714f57a5a481cb470cc759e688fe60d40fc87092165e55&path=traceTest.zip&signature=650d3cad50509682937c253d84da99230e8ea1bcfb9b10f6d18f8888c7c4b6b4%2C72231a6daa078a3ce657c0a2ed38251b7db56cf725beaf86780d4c240b19ccc2

```

##### Result


```json
{"data":"verify failed","action":"onStartContract"}

```




#### Get the contract code

Send a request to the server for the script code for an ID contract.

##### methods

GET

##### parameter

| 字段       |value|
| ---------- | ----------- |
| action     | getCodeByID |
| contractID | 合约ID      |

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=getCodeByID&contractID=814046805

```

##### Result


```json
{"status":true,"action":"onCodeResult","data":"@LogType(\"Arg\")\ncontract EventSuberAtCHQ{\n\t\n  \texport function init(arg){\n\t\tvar result \u003d YancloudUtil.subscribe(\"EventPuberAt3966\",\"abc\",handler);\n       // print(\"Handler:\"+handler);\n  \t \n  \t\treturn result;\n\t}\n  \texport function handler(e){\n        var ret \u003d \"ReceiveEvent:\";\n\t\tret+\u003d\"\\n\";\n      \tprint(ret);\n      \tret+\u003dYancloudUtil.executeContract(\"EventPuberAt3966\",\"notify\",\"success\");\n      \tprint(ret);\n        return ret;\n\t}\n}\n"}

```




#### Save contract status

Send a request to the server to get the state transition log of the node server.

##### methods

GET

##### parameter

| 字段       |value|
| ---------- | ------------ |
| action     | dumpContract |
| contractID |Contract ID or contract Name=|

##### Sample request


```
http://127.0.0.1:18000/SCIDE/SCManager?action=dumpContract&contractID=counter&pubKey=040461417efe01423ba603f71c689387e8aac4aa2a6f7cddfaf22c1d22c40222f7669a054e7ec2e8533b04ccbc7a0e6655ac4ae4acef81a2b1822ec6cabcaf6c1f&sign=3045022004ffd1346b936196f5b13953d2f3e11823a0d0a2d2f6fecea258cef8e20d99c0022100bbc219ed1f56799ba28a763b9e9e47063164e7ceecfbfa752de42f44551ffb83

```

##### Result


```json
{"data":"success","size":"3.76 KB","time":"0.03s"}

```




#### Gets a list of contracted memory files

Send a request to the server for a list of all memory files in a subfolder.

##### methods

GET

##### parameter

| 字段   |value|
| ------ | --------------- |
| action | listMemoryFiles |
| contractID |Contract Id or contract Name|

##### Sample request


```
http://127.0.0.1:18000/SCIDE/SCManager?action=listMemoryFiles&contractID=-247468535&pubKey=040461417efe01423ba603f71c689387e8aac4aa2a6f7cddfaf22c1d22c40222f7669a054e7ec2e8533b04ccbc7a0e6655ac4ae4acef81a2b1822ec6cabcaf6c1f&sign=3045022075c7268e888b0efdef167a3f4dfc6589d771c6be41b3c0a1dc12d057e811f395022100d44f460d0cc3643e169ef08231e75a1e895646c53295c0ef1d15c3b462a53d6b

```

##### Result


```json
{"data":["2020-09-23.18:40:38","2020-09-24.16:03:41","2020-09-24.16:58:39","2020-09-24.18:25:47","2020-09-24.18:32:37","2020-09-24.20:54:41","2020-09-24.20:57:39","2020-09-24.21:31:07","2020-09-24.21:32:09","2020-09-24.21:36:11","2020-09-28.15:29:15","2020-09-28.20:28:29","2020-09-28.20:39:46","2020-09-28.21:45:31","2020-09-28.21:49:18","2020-09-28.22:27:34","2020-09-28.22:31:09","2020-09-28.22:32:49","2020-10-07.16:51:06","2020-10-07.16:51:23","2020-10-25.21:09:10","2020-12-14.19:06:53","2021-02-02.10:28:56","2021-02-02.10:31:13"],"action":"onListMemoryFiles"}

```

#### To stop the contract

Send a request to the server to stop a contract.

##### methods

GET

##### parameter

| 字段       |value|
| ---------- | ------------------- |
| action     | killContractProcess |
| id         |Contract ID|
| *requestID |Request ID, String type|

`*` Indicates that the value is optional

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=killContractProcess&id=-1759263594

```

##### Result


```json
{"status":false,"action":"onListContractProcess","data":"[\n  {\n    \"id\": \"-65051856\",\n    \"name\": \"EventSuber\",\n    \"port\": \"1631\",\n    \"times\": \"0 \",\n    \"traffic\": \"32.00 B\",\n    \"storage\": \"0.00 B\",\n    \"contractStatus\": \"Ready\"\n  },\n  {\n    \"id\": \"814046805\",\n    \"name\": \"EventSuberAtCHQ\",\n    \"port\": \"1630\",\n    \"times\": \"0 \",\n    \"traffic\": \"32.00 B\",\n    \"storage\": \"0.00 B\",\n    \"contractStatus\": \"Ready\"\n  },\n  {\n    \"id\": \"2023975189\",\n    \"name\": \"LicenceService\",\n    \"port\": \"1632\",\n    \"times\": \"0 \",\n    \"traffic\": \"32.00 B\",\n    \"storage\": \"0.00 B\",\n    \"contractStatus\": \"Ready\"\n  },\n  {\n    \"id\": \"-620602333\",\n    \"name\": \"shortc\",\n    \"port\": \"1627\",\n    \"times\": \"0 \",\n    \"traffic\": \"0.00 B\",\n    \"storage\": \"0.00 B\",\n    \"contractStatus\": \"Ready\"\n  }\n]"}

```




#### Termination of all contracts

Send a request to the server to stop all contracts started on the server.

##### methods

GET

##### parameter

| 字段   |value|
| ------ | --------------- |
| action | killAllContract |

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=killAllContract

```

##### Result


```json
{"status":false,"action":"onKillAllContract","data":"Kill:7357,7541,7548,7555,7584,7585,7591,7598,7609,7612,8440,8442,8444,8521,"}

```

#### Static analysis contract

Send a request to the server to statically analyze the contract script.

##### methods

GET

##### parameter

| 字段       |value|
| ---------- | -------------------- |
| action     | staticVerifyContract |
| contractid |Contract ID|
| script     |Request ID, String type|

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=staticVerifyContract&contractid=943728900&script=contract%20shortc%7B%0A%09export%20function%20main(arg)%7B%0A%09%09return%20arg.length%3B%09%0A%09%7D%0A%7D&path=static.yjs

```

##### Result


```json
{"data":"{\"status\":\"Success\",\"result\":\"{\\\"main\\\":\\\"Ret:arg \\\"}\"}","action":"onExecuteResult","cid":"943728900","executeTime":54}

```



#### Gets the contract static analysis flow

Send a request to the server for a static analysis Control Flow of a contract.

##### methods

GET

##### parameter

| 字段   |value|
| ------ | ------------------------ |
| action | getControlFlowByFileName |
| path   |Contract ID|

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=getControlFlowByFileName&path=EventSuber.yjs

```

##### Result


```json
{"init":{"blocks":[{"type":"Continuous","name":"B0","stmts":["\u003dL0\u003d","aload 0","invokevirtual wrp/jdk/nashorn/internal/runtime/ScriptFunction getScope ()Lwrp/jdk/nashorn/internal/runtime/ScriptObject;"],"original":""},{"type":"Continuous","name":"B1","stmts":["\u003dL1\u003d","astore 4"],"original":""},{"type":"Continuous","name":"B2","stmts":["\u003dL2\u003d","aload 4","invokedynamic dyn:getProp|getElem|getMethod:YancloudUtil (Ljava/lang/Object;)Ljava/lang/Object; HANDLE:wrp/jdk/nashorn/internal/runtime/linker/Bootstrap.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;I)Ljava/lang/invoke/CallSite; (6) 5 "],"original":"\t\tvar result \u003d YancloudUtil.subscribe(\"XiaomiSmartHomeAtPKU\",\"onAirPurifierModeChange\",handler);"},{"type":"Continuous","name":"B3","stmts":["dup","invokedynamic dyn:getMethod|getProp|getElem:subscribe (Ljava/lang/Object;)Ljava/lang/Object; HANDLE:wrp/jdk/nashorn/internal/runtime/linker/Bootstrap.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;I)Ljava/lang/invoke/CallSite; (6) 0 "],"original":"\t\tvar result \u003d YancloudUtil.subscribe(\"XiaomiSmartHomeAtPKU\",\"onAirPurifierModeChange\",handler);"},{"type":"Continuous","name":"B4","stmts":["swap","ldc XiaomiSmartHomeAtPKU","ldc onAirPurifierModeChange","aload 4","invokedynamic dyn:getProp|getElem|getMethod:handler (Ljava/lang/Object;)Ljava/lang/Object; HANDLE:wrp/jdk/nashorn/internal/runtime/linker/Bootstrap.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;I)Ljava/lang/invoke/CallSite; (6) 5 "],"original":"\t\tvar result \u003d YancloudUtil.subscribe(\"XiaomiSmartHomeAtPKU\",\"onAirPurifierModeChange\",handler);"},{"type":"Continuous","name":"B5","stmts":["invokedynamic dyn:call:\\\u003dYancloudUtil\\,subscribe (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; HANDLE:wrp/jdk/nashorn/internal/runtime/linker/Bootstrap.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;I)Ljava/lang/invoke/CallSite; (6) 0 "],"original":"\t\tvar result \u003d YancloudUtil.subscribe(\"XiaomiSmartHomeAtPKU\",\"onAirPurifierModeChange\",handler);"},{"type":"Continuous","name":"B6","stmts":["\u003dL3\u003d","astore 5"],"original":"\t\tvar result \u003d YancloudUtil.subscribe(\"XiaomiSmartHomeAtPKU\",\"onAirPurifierModeChange\",handler);"},{"type":"Continuous","name":"B7","stmts":["\u003dL4\u003d","aload 5","areturn"],"original":"  \t\treturn result;"},{"type":"Continuous","name":"B8","stmts":["\u003dL5\u003d"],"original":"  \t\treturn result;"},{"type":"Continuous","name":"B9","stmts":["\u003dL6\u003d"],"original":"  \t\treturn result;"}],"edges":[{"from":"B0","to":"B1","label":{"label":"e"}},{"from":"B1","to":"B2","label":{"label":"e"}},{"from":"B2","to":"B3","label":{"label":"e"}},{"from":"B3","to":"B4","label":{"label":"e"}},{"from":"B4","to":"B5","label":{"label":"e"}},{"from":"B5","to":"B6","label":{"label":"e"}},{"from":"B6","to":"B7","label":{"label":"e"}},{"from":"B7","to":"B9","label":{"label":"e"}}]},"handler":{"blocks":[{"type":"Continuous","name":"B0","stmts":["\u003dL0\u003d","aload 0","invokevirtual wrp/jdk/nashorn/internal/runtime/ScriptFunction getScope ()Lwrp/jdk/nashorn/internal/runtime/ScriptObject;"],"original":""},{"type":"Continuous","name":"B1","stmts":["\u003dL1\u003d","astore 4"],"original":""},{"type":"Continuous","name":"B2","stmts":["\u003dL2\u003d","ldc ReceiveEvent:","aload 2","invokedynamic dyn:getProp|getElem|getMethod:content (Ljava/lang/Object;)Ljava/lang/Object; HANDLE:wrp/jdk/nashorn/internal/runtime/linker/Bootstrap.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;I)Ljava/lang/invoke/CallSite; (6) 0 "],"original":"        var ret \u003d \"ReceiveEvent:\"+e.content+\" \"+e.type;"},{"type":"Continuous","name":"B3","stmts":["invokestatic wrp/jdk/nashorn/internal/runtime/ScriptRuntime ADD (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"],"original":"        var ret \u003d \"ReceiveEvent:\"+e.content+\" \"+e.type;"},{"type":"Continuous","name":"B4","stmts":["ldc  ","invokestatic wrp/jdk/nashorn/internal/runtime/ScriptRuntime ADD (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"],"original":"        var ret \u003d \"ReceiveEvent:\"+e.content+\" \"+e.type;"},{"type":"Continuous","name":"B5","stmts":["aload 2","invokedynamic dyn:getProp|getElem|getMethod:type (Ljava/lang/Object;)Ljava/lang/Object; HANDLE:wrp/jdk/nashorn/internal/runtime/linker/Bootstrap.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;I)Ljava/lang/invoke/CallSite; (6) 0 "],"original":"        var ret \u003d \"ReceiveEvent:\"+e.content+\" \"+e.type;"},{"type":"Continuous","name":"B6","stmts":["invokestatic wrp/jdk/nashorn/internal/runtime/ScriptRuntime ADD (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"],"original":"        var ret \u003d \"ReceiveEvent:\"+e.content+\" \"+e.type;"},{"type":"Continuous","name":"B7","stmts":["\u003dL3\u003d","astore 5"],"original":"        var ret \u003d \"ReceiveEvent:\"+e.content+\" \"+e.type;"},{"type":"Continuous","name":"B8","stmts":["\u003dL4\u003d","aload 4","invokedynamic dyn:getMethod|getProp|getElem:print (Ljava/lang/Object;)Ljava/lang/Object; HANDLE:wrp/jdk/nashorn/internal/runtime/linker/Bootstrap.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;I)Ljava/lang/invoke/CallSite; (6) 5 "],"original":"      \tprint(ret);"},{"type":"Continuous","name":"B9","stmts":["getstatic wrp/jdk/nashorn/internal/runtime/ScriptRuntime UNDEFINED Lwrp/jdk/nashorn/internal/runtime/Undefined;","aload 5","invokedynamic dyn:call:print (Ljava/lang/Object;Lwrp/jdk/nashorn/internal/runtime/Undefined;Ljava/lang/Object;)Ljava/lang/Object; HANDLE:wrp/jdk/nashorn/internal/runtime/linker/Bootstrap.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;I)Ljava/lang/invoke/CallSite; (6) 5 "],"original":"      \tprint(ret);"},{"type":"Continuous","name":"B10","stmts":["pop"],"original":"      \tprint(ret);"},{"type":"Continuous","name":"B11","stmts":["\u003dL5\u003d","aload 5","areturn"],"original":"        return ret;"},{"type":"Continuous","name":"B12","stmts":["\u003dL6\u003d"],"original":"        return ret;"},{"type":"Continuous","name":"B13","stmts":["\u003dL7\u003d"],"original":"        return ret;"}],"edges":[{"from":"B0","to":"B1","label":{"label":"e"}},{"from":"B1","to":"B2","label":{"label":"e"}},{"from":"B2","to":"B3","label":{"label":"e"}},{"from":"B3","to":"B4","label":{"label":"e"}},{"from":"B4","to":"B5","label":{"label":"e"}},{"from":"B5","to":"B6","label":{"label":"e"}},{"from":"B6","to":"B7","label":{"label":"e"}},{"from":"B7","to":"B8","label":{"label":"e"}},{"from":"B8","to":"B9","label":{"label":"e"}},{"from":"B9","to":"B10","label":{"label":"e"}},{"from":"B10","to":"B11","label":{"label":"e"}},{"from":"B11","to":"B13","label":{"label":"e"}}]}}

```

### Log Viewing Class

#### Contract log — Number of queries

##### methods

GET

WhencontractNameis empty or not passed in, the number of items queried for the entire contract


##### parameter

| 字段         |value|
| ------------ | ------------------------ |
| action       | queryContractLogSize     |
|contractName| 字符串，非必须，合约名称 |

##### Sample request


```
http://127.0.0.1:18000/SCIDE/CMManager?action=queryContractLogSize&contractName=NanningDataSource
```

##### Result


```json
{
    "size": 12,
    "action": "onQueryContractLogSize",
    "status": "success"
}

```

#### Contract log — Query by date

##### methods

GET

##### parameter

| 字段         |value|
| ------------ | ------------------------------------- |
| action       |queryContractLogByDate|
| start        |Long, must, start time|
| end          |Long, not required. If end is not used, the current time is default|
| contractName |String, not required, contract name|


##### Sample request


```
http://127.0.0.1:18000/SCIDE/CMManager?action=queryContractLogByDate&start=1597296300272&end=1597296305747
```

##### Returns the result


```json
{
    "data": [
        {
            "action": "executeContract",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "contractID": "-1382208250",
            "contractName": "NanningDataSource",
            "function": "getMainFrame",
            "costTime": "2493",
            "totalGas": "0",
            "executionGas": "0",
            "extraGas": "0",
            "date": 1597296300272,
            "key": "-8590335427581967208"
        },
        {
            "action": "executeContract",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "contractID": "-1382208250",
            "contractName": "NanningDataSource",
            "function": "loadResource",
            "costTime": "732",
            "totalGas": "0",
            "executionGas": "0",
            "extraGas": "0",
            "date": 1597296301030,
            "key": "849660532962309239"
        },
        {
            "action": "executeContract",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "contractID": "-1382208250",
            "contractName": "NanningDataSource",
            "function": "loadResource",
            "costTime": "4580",
            "totalGas": "0",
            "executionGas": "0",
            "extraGas": "0",
            "date": 1597296305745,
            "key": "-8003529429500512736"
        },
        {
            "action": "executeContract",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "contractID": "-1382208250",
            "contractName": "NanningDataSource",
            "function": "loadResource",
            "costTime": "4551",
            "totalGas": "0",
            "executionGas": "0",
            "extraGas": "0",
            "date": 1597296305746,
            "key": "7604666709899222357"
        },
        {
            "action": "executeContract",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "contractID": "-1382208250",
            "contractName": "NanningDataSource",
            "function": "loadResource",
            "costTime": "6",
            "totalGas": "0",
            "executionGas": "0",
            "extraGas": "0",
            "date": 1597296305751,
            "key": "-7561786202695627022"
        }
    ],
    "action": "onQueryRecentContractLog"
}
```

#### Contract log — Queried by offset

##### methods

GET

##### parameter

| 字段         |value|
| ------------ | --------------------------------------------- |
| action       |queryContractLogByOffset|
| count        |Long: required. Gets the number of logs|
| offset       |Long, not required. If there is no offset, the latest count bar is returned by default|
| contractName |String, not required, contract name|

##### Sample request


```
http://127.0.0.1:18000/SCIDE/CMManager?action=queryContractLogByOffset&count=5&contractName=NanningDataSource
```

##### Returns the result


```json
{
    "data": [
        {
            "action": "executeContract",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "contractID": "-1382208250",
            "contractName": "NanningDataSource",
            "function": "loadResource",
            "costTime": "4",
            "totalGas": "0",
            "executionGas": "0",
            "extraGas": "0",
            "date": 1597296305842,
            "key": "-2390672423847654148"
        },
        {
            "action": "executeContract",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "contractID": "-1382208250",
            "contractName": "NanningDataSource",
            "function": "isOwner",
            "costTime": "4",
            "totalGas": "0",
            "executionGas": "0",
            "extraGas": "0",
            "date": 1597296305868,
            "key": "6056586201629372511"
        },
        {
            "action": "executeContract",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "contractID": "-1382208250",
            "contractName": "NanningDataSource",
            "function": "getApplyList",
            "costTime": "6",
            "totalGas": "0",
            "executionGas": "0",
            "extraGas": "0",
            "date": 1597296305893,
            "key": "3882409580676458151"
        },
        {
            "action": "executeContract",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "contractID": "-1382208250",
            "contractName": "NanningDataSource",
            "function": "getAcceptList",
            "costTime": "4",
            "totalGas": "0",
            "executionGas": "0",
            "extraGas": "0",
            "date": 1597296305908,
            "key": "-3437513873417136535"
        },
        {
            "action": "executeContract",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "contractID": "-1382208250",
            "contractName": "NanningDataSource",
            "function": "analysisByIndustry",
            "costTime": "6",
            "totalGas": "0",
            "executionGas": "0",
            "extraGas": "0",
            "signature": "4c2cef1756b2b591ab7eead19d67331e2294c7ba765c72298733c306ada0b6e84afbb6c7b9dba48b9843236ebe67aecb4af09fe58a51eef0e2e89b9f3e5cad02",
            "arg": " {\"year\":2018,\"category\":\"工业\",\"indexType\":\"营业额\"}",
            "date": 1597296314654,
            "key": "203156239086062402"
        }
    ],
    "action": "onQueryRecentContractLog"
}
```

#### Contract log — Query by key

##### methods

GET

##### parameter

| 字段   |value|
| ------ | --------------------------- |
| action | queryContractLogByKey       |
| key    |Long: Must, the key corresponding to the log|

##### Sample request


```
http://127.0.0.1:18000/SCIDE/CMManager?action=queryContractLogByKey&key=203156239086062402
```

##### Returns the result


```json
{
    "data": {
        "action": "executeContract",
        "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
        "contractID": "-1382208250",
        "contractName": "NanningDataSource",
        "function": "analysisByIndustry",
        "costTime": "6",
        "totalGas": "0",
        "executionGas": "0",
        "extraGas": "0",
        "signature": "4c2cef1756b2b591ab7eead19d67331e2294c7ba765c72298733c306ada0b6e84afbb6c7b9dba48b9843236ebe67aecb4af09fe58a51eef0e2e89b9f3e5cad02",
        "arg": " {\"year\":2018,\"category\":\"工业\",\"indexType\":\"营业额\"}",
        "date": 1597296314654
    },
    "action": "onQueryContractLogByKey"
}
```

#### Contract log — Counts the number of calls by time period

##### methods

GET

##### parameter

| 字段     |value|
| -------- | -------------------------------------------------------- |
| action   |countContractLogGroupByCategory|
| start    |Long, must, start time|
| end      |Not required. End time. Default is current|
| interval |Long, not necessary, statistical interval|
| category |If not required, the contract name is concatenated with a comma, and all contract calls are counted when not passed in|

##### Sample request


```
http://127.0.0.1:18000/SCIDE/CMManager?action=countContractLogGroupByCategory&start=1596758400000&interval=86400000
```

##### Returns the result


```json
{
    "start": 1596758400000,
    "interval": 86400000,
    "action": "onCountContractLogGroupByCategory",
    "data": [
        0,
        0,
        0,
        0,
        0,
        0,
        43,
        14
    ]
}
```

#### Ledger log — Number of queries

Query the number of logs recorded in the ledger of the node

##### methods

GET

##### parameter

| 字段         |value|
| ------------ | ---------------- |
| action       | queryHashSize    |
| contractName | 非必须，合约名称 |



##### Sample request


```
http://127.0.0.1:18000/SCIDE/CMManager?action=queryHashSize&contractName=NanningDataSource
```

##### Returns the result


```json
{
    "count": "2",
    "action": "onQueryHashSize"
}
```


#### Ledger log — Query by offset

Query the hash list of x logs that pass this node to the ledger

##### methods

GET

##### parameter

| 字段         |value|
| ------------ | ----------------------------------------------------------- |
| action       |queryHashByOffset|
| count        |Integer, mandatory, indicates the number of items|
| offset       |An integer, not required, representing an offset. If offset is not passed, the latest count bar is returned by default|
| contractName |A character string, not required, indicating the contract name|

##### Sample request


```
http://127.0.0.1:18000/SCIDE/CMManager?action=queryHashByOffset&count=1&contractName=NanningDataSource
```

##### Returns the result


```json
{
    "data": [
        {
            "hash": "3a6c60621907146b77146c1f2d48700e47520173",
            "date": 1597296314658
        }
    ],
    "action": "onQueryHash",
    "status": "success"
}
```

#### Ledger log — Query details based on hash

Query log content based on hash

##### methods

GET

##### parameter

| 字段   |value|
| ------ | ------------------------------- |
| action | queryDataByHash                 |
| hash   |String, available by queryHashByOffset|

##### Sample request


```
http://127.0.0.1:18000/SCIDE/CMManager?action=queryDataByHash&count=1&contractName=NanningDataSource&hash=3a6c60621907146b77146c1f2d48700e47520173
```

##### Returns the result


```json
{
    "from": "0x3034643139323433323966373263656431343866",
    "to": "0x65786563757465436f6e74726163740000000000",
    "data": "1597296314655 --> {\"extraGas\":\"0\",\"totalGas\":\"0\",\"executionGas\":\"0\",\"signature\":\"4c2cef1756b2b591ab7eead19d67331e2294c7ba765c72298733c306ada0b6e84afbb6c7b9dba48b9843236ebe67aecb4af09fe58a51eef0e2e89b9f3e5cad02\",\"costTime\":\"6\",\"arg\":\" {\\\\\\\"year\\\\\\\":2018,\\\\\\\"category\\\\\\\":\\\\\\\"工业\\\\\\\",\\\\\\\"indexType\\\\\\\":\\\\\\\"营业额\\\\\\\"}\",\"contractID\":\"-1382208250\",\"action\":\"analysisByIndustry\",\"pubKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}",
    "requestID": "1597296314629_6067",
    "action": "onQueryDataByHash"
}
```

#### Ledger log — Queries the Hash according to requestID

Query log contents by requestID. The developer must ensure the uniqueness of requestID

##### methods

GET

##### parameter

| 字段      |value|
| --------- | ------------------------ |
| action    | queryHashByRequestID     |
| requestID |A string that is generated when the call is made|

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=queryHashByRequestID&requestID=0987654321ab
```

#### Node Logs — Number of queries

##### methods

GET

##### parameter

| 字段     |value|
| -------- | ---------------------------- |
| action   | queryNodeLogSize             |
| category |Not required, not passed in to query the full situation|

The options include ping, startContract, and saveFile.

##### Sample request


``` 
http://127.0.0.1:18000/SCIDE/CMManager?action=queryNodeLogSize

http://127.0.0.1:18000/SCIDE/CMManager?action=queryNodeLogSize&category=login
```

##### Returns the result


```json
{
    "size": 177,
    "action": "onQueryNodeLogSize",
    "status": "success"
}
```

#### Node logs — Query by date

##### methods

GET

##### parameter

| 字段     |value|
| -------- | ---------------------------- |
| action   | queryNodeLogByDate           |
| start    |Long, must, start date|
| end      |Long, not necessary|
| category |Not required, not passed in to query the full situation|

##### Sample request


``` 
http://127.0.0.1:18000/SCIDE/CMManager?action=queryNodeLogByDate&start=1597376006441

http://127.0.0.1:18000/SCIDE/CMManager?action=queryNodeLogByDate&start=1596758400000&category=login
```

##### Returns the result


```json
{
    "data": [
        {
            "action": "listAllAuthRole",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "status": "accept",
            "date": 1597376006438,
            "key": "387355870552374748"
        },
        {
            "action": "listUnAuthRole",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "status": "accept",
            "date": 1597376006441,
            "key": "4772693258708933626"
        },
        {
            "action": "countRole",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "status": "accept",
            "date": 1597376006444,
            "key": "-6425375229108830572"
        },
        {
            "action": "loadNodeConfig",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "status": "accept",
            "date": 1597376006448,
            "key": "-6602401010405792959"
        },
        {
            "action": "getPeerID",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "status": "accept",
            "date": 1597376006449,
            "key": "-7006776427870311552"
        }
    ],
    "action": "onQueryNodeLogByDate"
}
```

#### Node log — Query by offset

##### methods

GET

##### parameter

| 字段         |value|
| ------------ | --------------------------------------------- |
| action       |queryNodeLogByOffset|
| count        |Long: required. Gets the number of logs|
| offset       |Long, not required. If there is no offset, the latest count bar is returned by default|
| contractName |String, not required, contract name|

##### Sample request


``` 
http://127.0.0.1:18000/SCIDE/CMManager?action=queryNodeLogByOffset&count=5
```

##### Returns the result


```json
{
    "data": [
        {
            "action": "listAllAuthRole",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "status": "accept",
            "date": 1597376006438,
            "key": "387355870552374748"
        },
        {
            "action": "listUnAuthRole",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "status": "accept",
            "date": 1597376006441,
            "key": "4772693258708933626"
        },
        {
            "action": "countRole",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "status": "accept",
            "date": 1597376006444,
            "key": "-6425375229108830572"
        },
        {
            "action": "loadNodeConfig",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "status": "accept",
            "date": 1597376006448,
            "key": "-6602401010405792959"
        },
        {
            "action": "getPeerID",
            "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
            "status": "accept",
            "date": 1597376006449,
            "key": "-7006776427870311552"
        }
    ],
    "action": "onQueryNodeLogByOffset"
}
```

#### Node Log — Collects statistics on invocation times by time range

##### methods

GET

##### parameter

| 字段     |value|
| -------- | -------------------------------------------------- |
| action   |countLogGroupByCategory|
| start    |Long, must, start time|
| end      |Not required. End time. Default is current|
| interval |Long, not necessary, statistical interval|
| category |Action is concatenated with commas if not required, and counts all calls when not passed|

In the category, Action is the action collection of the NodePortal interface. The value can be ping, startContract, and saveFile.

##### Sample request


```
http://127.0.0.1:18000/SCIDE/CMManager?action=countNodeLogGroupByCategory&start=1596758400000&interval=86400000

http://127.0.0.1:18000/SCIDE/CMManager?action=countNodeLogGroupByCategory&start=1596758400000&interval=86400000&category=ping,startContract
```

##### Returns the result


```json
{
    "start": 1596758400000,
    "interval": 86400000,
    "action": "onCountNodeLogGroupByCategory",
    "data": [
        0,
        0,
        0,
        0,
        0,
        0,
        912,
        761
    ]
}
```





#### Example Output historical logs

Send a request to the server for the TimeTravel log of the contract on the node server.

##### methods

GET

##### parameter

| 字段   |value|
| ------ | ------------------ |
| action |printTimeTravelLog|

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=printTimeTravelLog

```

##### Result


```json
{"status":false,"data":"[CMActions] memory dir \u003d /Users/oliveds/docs/SmartContract/contractExamples/memoryDumps/aa\n[CMActions] memory dir \u003d /Users/oliveds/docs/SmartContract/contractExamples/memoryDumps/aa_1572335939893.dyjs\n[CMActions] memory dir \u003d /Users/oliveds/docs/SmartContract/contractExamples/memoryDumps/memoryDumps\n[CMActions] memory dir \u003d /Users/oliveds/docs/SmartContract/contractExamples/memoryDumps\n[CMActions] memory dir \u003d /Users/oliveds/docs/SmartContract/contractExamples/memoryDumps\n[CMActions] memory dir \u003d /Users/oliveds/docs/SmartContract/contractExamples/memoryDumps/.\n[CMActions] memory dir \u003d /Users/oliveds/docs/SmartContract/contractExamples/memoryDumps/.\n"}

```





#### Example Output node transfer logs

Send a request to the server to get the state transition log of the node server.

##### methods

GET

##### parameter

| 字段   |value|
| ------ | ---------------- |
| action |printTransferLog|

##### Sample request


```
http://127.0.0.1:1717/SCIDE/SCManager?action=printTransferLog

```

##### Result


```json
{"status":false,"data":""}

```



### Template generation class




## The ledger Http interface

``` {.yaml}
type: google.api.Service
config_version: 3

http:
  rules:
    - selector: bdware.bdledger.api.Node.ClientVersion
      get: /v0/node/version
    - selector: bdware.bdledger.api.Ledger.CreateLedger
      post: /v0/ledgers
      body: "*"
    - selector: bdware.bdledger.api.Ledger.GetLedgers
      get: /v0/ledgers
    - selector: bdware.bdledger.api.Ledger.SendTransaction
      post: /v0/ledgers/{ledger}/transactions
      body: "*"
    - selector: bdware.bdledger.api.Query.GetBlockByHash
      get: /v0/ledgers/{ledger}/block
    - selector: bdware.bdledger.api.Query.GetBlocks
      post: /v0/ledgers/{ledger}/blocks/query
      body: "*"
    - selector: bdware.bdledger.api.Query.CountBlocks
      post: /v0/ledgers/{ledger}/blocks/count
      body: "*"
    - selector: bdware.bdledger.api.Query.GetRecentBlocks
      get: /v0/ledgers/{ledger}/blocks/recent
    - selector: bdware.bdledger.api.Query.GetTransactionByHash
      get: /v0/ledgers/{ledger}/transaction
    - selector: bdware.bdledger.api.Query.GetTransactionByBlockHashAndIndex
      get: /v0/ledgers/{ledger}/block/transaction
    - selector: bdware.bdledger.api.Query.GetTransactions
      post: /v0/ledgers/{ledger}/transactions/query
      body: "*"
    - selector: bdware.bdledger.api.Query.CountTransactions
      post: /v0/ledgers/{ledger}/transactions/count
      body: "*"
```

> **Note**
>
> Request/Response data of **bytes** type should/will be encoded with
> [Base64](https://tools.ietf.org/html/rfc4648#section-4).

> **Note**
>
> When using hash strings in URL, they need to be encoded with
> [encodeURIComponent](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent).

### Ledger information class

#### Node.ClientVersion{#_node_clientversion}

Get BDLedger node version

    GET http://{{IP}}:{{PORT}}/v0/node/version

##### Return the sample


``` {.json}
{
  "version": "dev-210119.a88bf4eb"
}
```
#### Ledger.CreateLedger{#_ledger_createledger}

Create a new ledger

    POST http://{{IP}}:{{PORT}}/v0/ledgers

##### Sample request


``` {.json}
{
  "name": "test"
}
```

##### Return the sample


``` {.json}
{
  "ok": true
}
```

#### Ledger.GetLedgers{#_ledger_getledgers}
 
Get all ledgers

    GET http://{{IP}}:{{PORT}}/v0/ledgers

##### Return the sample


``` {.json}
{
  "ledgers": [
    "default",
    "test"
  ]
}
```

#### Ledger.SendTransaction{#_ledger_sendtransaction}
 
Send a new transaction

    POST http://{{IP}}:{{PORT}}/v0/ledgers/test/transactions

##### Sample request


``` {.json}
{
  "transaction": {
    "type": 0,
    "from": "8A3K/vANyv7wDcr+8A3K/vANyv4=",
    "nonce": 52,
    "data": "lQItWZKS5hlUn6V/DMKKwvZXxvM="
  }
}
```

##### Return the sample


``` {.json}
{
  "hash": "VQBeA5Ee0Y5hqEileoQuYMHbOSE="
}
```

### Query classes

#### Query.GetBlockByHash{#_query_getblockbyhash}

Get a block identified by its hash

    GET http://{{IP}}:{{PORT}}/v0/ledgers/test/block?hash=LSKr%2BK079Ax%2BrKdlyYN5ze2YGzo%3D

**hash** has to be encoded with[encodeURIComponent](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)

##### Return the sample


``` {.json}
{
  "block": {
    "hash": "LSKr+K079Ax+rKdlyYN5ze2YGzo=",
    "creator": "",
    "nonce": "0",
    "parentHashes": [
      "fLX5pMY8M1qSAGZdKT1rWBkdEMo=",
      "rk0DWMaUpRG82yVX+cFhbfhPFdw=",
      "3XkwkuMBearq8uavN76Te7Zdpl8="
    ],
    "witnesses": [],
    "timestamp": "1611038043",
    "size": "0",
    "transactionCount": 1,
    "transactionsRoot": "VQBeA5Ee0Y5hqEileoQuYMHbOSE=",
    "transactions": [
      {
        "blockHash": "",
        "blockTimestamp": "0",
        "index": 0,
        "hash": "VQBeA5Ee0Y5hqEileoQuYMHbOSE=",
        "type": "RECORD",
        "from": "8A3K/vANyv7wDcr+8A3K/vANyv4=",
        "nonce": "0",
        "to": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
        "data": "lQItWZKS5hlUn6V/DMKKwvZXxvM="
      }
    ],
    "transactionHashes": [
      "VQBeA5Ee0Y5hqEileoQuYMHbOSE="
    ]
  }
}
```

#### Query.GetBlocks{#_query_getblocks}
 
Get blocks in a timestamp range

    POST http://{{IP}}:{{PORT}}/v0/ledgers/test/blocks/query


``` {.protobuf}
enum IncludeTransactions {
  NONE = 0; // Don't include transaction data
  HASH = 1; // Include transactions hashes
  FULL = 2; // Include full transactions
}
```

Requirement: asciimath: \ [\ “start \ _timestamp \” ⇐ \ ’end \ _timestamp \ \]”

If only **end\_timestamp** is not specified, orasciimath:\[\“end\_timestamp\”-\“start\_timestamp\”\>\“query.maxDuration\”\],then **end\_timestamp** will be set toasciimath:\[\“start\_timestamp\”+\“query.maxDuration\”\].

If only **start\_timestamp** is not specified, then **start\_timestamp**will be set to asciimath:\[\“end\_timestamp\”-\“query.maxDuration\”\].

In all cases, **start\_timestamp** will never be earlier than thegenesis block’s timestamp, and **end\_timestamp** will never be laterthan the current timestamp when the node process the query request.

##### Sample request

``` {.json}
{
  "start_timestamp": 1611038000,
  "end_timestamp": 1611039000,
  "include_transactions": 0
}
```

##### Return the sample


``` {.json}
{
  "blocks": [
    {
      "hash": "LSKr+K079Ax+rKdlyYN5ze2YGzo=",
      "creator": "",
      "nonce": "0",
      "parentHashes": [
        "fLX5pMY8M1qSAGZdKT1rWBkdEMo=",
        "rk0DWMaUpRG82yVX+cFhbfhPFdw=",
        "3XkwkuMBearq8uavN76Te7Zdpl8="
      ],
      "witnesses": [],
      "timestamp": "1611038043",
      "size": "0",
      "transactionCount": 1,
      "transactionsRoot": "VQBeA5Ee0Y5hqEileoQuYMHbOSE=",
      "transactions": [],
      "transactionHashes": []
    }
  ],
  "startTimestamp": "1611038043",
  "endTimestamp": "1611038043"
}
```

##### Request Example 2


``` {.json}
{
  "start_timestamp": 1611038000,
  "end_timestamp": 1611039000,
  "include_transactions": 1
}
```

##### Return to Example 2


``` {.json}
{
  "blocks": [
    {
      "hash": "LSKr+K079Ax+rKdlyYN5ze2YGzo=",
      "creator": "",
      "nonce": "0",
      "parentHashes": [
        "fLX5pMY8M1qSAGZdKT1rWBkdEMo=",
        "rk0DWMaUpRG82yVX+cFhbfhPFdw=",
        "3XkwkuMBearq8uavN76Te7Zdpl8="
      ],
      "witnesses": [],
      "timestamp": "1611038043",
      "size": "0",
      "transactionCount": 1,
      "transactionsRoot": "VQBeA5Ee0Y5hqEileoQuYMHbOSE=",
      "transactions": [],
      "transactionHashes": [
        "VQBeA5Ee0Y5hqEileoQuYMHbOSE="
      ]
    }
  ],
  "startTimestamp": "1611038043",
  "endTimestamp": "1611038043"
}
```

**Request body 3.**


``` {.json}
{
  "start_timestamp": 1611038000,
  "end_timestamp": 1611039000,
  "include_transactions": 2
}
```

**Response 3.**


``` {.json}
{
  "blocks": [
    {
      "hash": "LSKr+K079Ax+rKdlyYN5ze2YGzo=",
      "creator": "",
      "nonce": "0",
      "parentHashes": [
        "fLX5pMY8M1qSAGZdKT1rWBkdEMo=",
        "rk0DWMaUpRG82yVX+cFhbfhPFdw=",
        "3XkwkuMBearq8uavN76Te7Zdpl8="
      ],
      "witnesses": [],
      "timestamp": "1611038043",
      "size": "0",
      "transactionCount": 1,
      "transactionsRoot": "VQBeA5Ee0Y5hqEileoQuYMHbOSE=",
      "transactions": [
        {
          "blockHash": "",
          "blockTimestamp": "0",
          "index": 0,
          "hash": "VQBeA5Ee0Y5hqEileoQuYMHbOSE=",
          "type": "RECORD",
          "from": "8A3K/vANyv7wDcr+8A3K/vANyv4=",
          "nonce": "0",
          "to": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
          "data": "lQItWZKS5hlUn6V/DMKKwvZXxvM="
        }
      ],
      "transactionHashes": [
        "VQBeA5Ee0Y5hqEileoQuYMHbOSE="
      ]
    }
  ],
  "startTimestamp": "1611038043",
  "endTimestamp": "1611038043"
}
```

#### Query.CountBlocks{#_query_countblocks}

Count all blocks in a ledger, or blocks in a timestamp range

    POST http://{{IP}}:{{PORT}}/v0/ledgers/test/blocks/count

Requirement: asciimath: \ [\ “start \ _timestamp \” ⇐ \ ’end \ _timestamp \ \]”

If neither **start\_timestamp** nor **end\_timestamp** is specified,then count all blocks in the specified ledger.

If only **end\_timestamp** is not specified, then count all blocks withtimestamps later than **start\_timestamp**.

If only **start\_timestamp** is not specified, then count all blockswith timestamps earlier than **end\_timestamp**.

In all cases, **start\_timestamp** will never be earlier than thegenesis block’s timestamp, and **end\_timestamp** will never be laterthan the current timestamp when the node process the query request.

##### Sample request


``` {.json}
{}
```

##### Return the sample


``` {.json}
{
  "count": "5",
  "startTimestamp": "0",
  "endTimestamp": "1611039957"
}
```

##### Request Example 2


``` {.json}
{
  "start_timestamp": 1611038000,
  "end_timestamp": 1611039000
}
```

##### Return to Example 2


``` {.json}
{
  "count": "1",
  "startTimestamp": "1611038000",
  "endTimestamp": "1611039000"
}
```

#### Query.GetRecentBlocks{#_query_getrecentblocks}

Get recent **count** blocks (Only support IncludeTransactions=NONE fornow)

    GET http://{{IP}}:{{PORT}}/v0/ledgers/test/blocks/recent?count=2

##### Return the sample


``` {.json}
{
  "blocks": [
    {
      "hash": "LSKr+K079Ax+rKdlyYN5ze2YGzo=",
      "creator": "",
      "nonce": "0",
      "parentHashes": [
        "fLX5pMY8M1qSAGZdKT1rWBkdEMo=",
        "rk0DWMaUpRG82yVX+cFhbfhPFdw=",
        "3XkwkuMBearq8uavN76Te7Zdpl8="
      ],
      "witnesses": [],
      "timestamp": "1611038043",
      "size": "0",
      "transactionCount": 1,
      "transactionsRoot": "VQBeA5Ee0Y5hqEileoQuYMHbOSE=",
      "transactions": [],
      "transactionHashes": []
    },
    {
      "hash": "rk0DWMaUpRG82yVX+cFhbfhPFdw=",
      "creator": "",
      "nonce": "0",
      "parentHashes": [
        "fLX5pMY8M1qSAGZdKT1rWBkdEMo=",
        "3XkwkuMBearq8uavN76Te7Zdpl8=",
        "8pZPR74OALIbps5XFb4dL/s0j0M="
      ],
      "witnesses": [],
      "timestamp": "1610968019",
      "size": "0",
      "transactionCount": 1,
      "transactionsRoot": "LuxttCm/pSHVMOKF0sJExk+DJXc=",
      "transactions": [],
      "transactionHashes": []
    }
  ],
  "startTimestamp": "1610968019",
  "endTimestamp": "1611038043"
}
```

#### Query.GetTransactionByHash{#_query_gettransactionbyhash}

Get a transaction identified by its hash

    GET http://{{IP}}:{{PORT}}/v0/ledgers/test/transaction?hash=VQBeA5Ee0Y5hqEileoQuYMHbOSE%3D

**hash** has to be encoded with[encodeURIComponent](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)

#### Return the sample


``` {.json}
{
  "transaction": {
    "blockHash": "LSKr+K079Ax+rKdlyYN5ze2YGzo=",
    "blockTimestamp": "1611038043",
    "index": 0,
    "hash": "VQBeA5Ee0Y5hqEileoQuYMHbOSE=",
    "type": "RECORD",
    "from": "8A3K/vANyv7wDcr+8A3K/vANyv4=",
    "nonce": "0",
    "to": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
    "data": "lQItWZKS5hlUn6V/DMKKwvZXxvM="
  }
}
```

#### Query.GetTransactionByBlockHashAndIndex{#_query_gettransactionbyblockhashandindex}

Get a transaction identified by hash of the block it belongs to and itsindex inside the block

    GET http://{{IP}}:{{PORT}}/v0/ledgers/test/block/transaction?blockHash=LSKr%2BK079Ax%2BrKdlyYN5ze2YGzo%3D&index=0

**blockHash** has to be encoded with[encodeURIComponent](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)

#### Return the sample


``` {.json}
{
  "transaction": {
    "blockHash": "LSKr+K079Ax+rKdlyYN5ze2YGzo=",
    "blockTimestamp": "1611038043",
    "index": 0,
    "hash": "VQBeA5Ee0Y5hqEileoQuYMHbOSE=",
    "type": "RECORD",
    "from": "8A3K/vANyv7wDcr+8A3K/vANyv4=",
    "nonce": "0",
    "to": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
    "data": "lQItWZKS5hlUn6V/DMKKwvZXxvM="
  }
}
```

#### Query.GetTransactions{#_query_gettransactions}

Get transactions in a timestamp range

    POST http://{{IP}}:{{PORT}}/v0/ledgers/test/transactions/query

**start\_timestamp** and **end\_timestamp** follow the same requirementsand rules as in [???](#Query.GetBlocks).

##### Sample request

``` {.json}
{
  "start_timestamp": 1611038000,
  "end_timestamp": 1611039000
}
```

##### Return the sample


``` {.json}
{
  "transactions": [
    {
      "blockHash": "",
      "blockTimestamp": "0",
      "index": 0,
      "hash": "VQBeA5Ee0Y5hqEileoQuYMHbOSE=",
      "type": "RECORD",
      "from": "8A3K/vANyv7wDcr+8A3K/vANyv4=",
      "nonce": "0",
      "to": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
      "data": "lQItWZKS5hlUn6V/DMKKwvZXxvM="
    }
  ],
  "startTimestamp": "1611038043",
  "endTimestamp": "1611038043"
}
```

#### Query.CountTransactions{#_query_counttransactions}
 
Count all transactions in a ledger, or transactions in a timestamp range

    POST http://{{IP}}:{{PORT}}/v0/ledgers/test/transactions/count

**start\_timestamp** and **end\_timestamp** follow the same requirementsand rules as in [???](#Query.CountBlocks).

##### Sample request


``` {.json}
{}
```

##### Return the sample


``` {.json}
{
  "count": "4",
  "startTimestamp": "0",
  "endTimestamp": "1611039957"
}
```

##### Request Example 2


``` {.json}
{
  "start_timestamp": 1611038000,
  "end_timestamp": 1611039000
}
```

##### Return to Example 2


``` {.json}
{
  "count": "1",
  "startTimestamp": "1611038000",
  "endTimestamp": "1611039000"
}
```


- - -

## Contract node WebSocket interface

### User Management

#### Access to the Session

Before login, obtain the session for signing.

##### parameter

|field|value|
| ------ | ------------ |
|action|getSessionID|

##### Sample request


```
var req = {};
req.action = "getSessionID";
wssocket.send(JSON.stringify(req));
```


##### Returns the result


```json
{
	"action": "onSessionID",
	"session": "9782323_session"
}
```

#### The user login

The user performs public-private key authentication

##### parameter

|field| 值    |
| ------ | ----- |
|action| login |

##### Sample request


```
var loginParam = {};
loginParam.pubKey = global.sm2Key.publicKey;
loginParam.signature = sm2.doSignature(global.session,
			global.sm2Key.privateKey);
loginParam.action = "login";
wssocket.send(JSON.stringify(loginParam));
```

##### Returns the result


```json
{
	"action": "onLogin",
	"data": "NodeManager,ContractProvider"
}
```

#### Apply for role

In the node administrator interface, you can apply for the names contract administrator, ContractUser, ContractProvider.

##### parameter

| 字段   |value|
| ------ | ------------- |
| action |applyNodeRole|
|role|Applying for a Role Name|

##### Sample request


```
var param = {};
param.action = "applyNodeRole";
param.role = "ContractUser";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


``` json
{
	"action": "onApplyRole",
	"data": "success"
}

{
    "action":"onApplyRole",
    "data":"already has!"
}
```

#### Authorization role

##### parameter

| 字段     |value|
| -------- | -------------------- |
| action   |authNodeRole|
| isAccept |Bool: indicates no authorization|
| pubKey   |Authorized user public key|


##### Sample request


```
var param = {};
param.action = "authNodeRole";
param.isAccept = true;
param.pubKey = "xxxxx";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"action": "onAuthNodeRole",
	"data": "success"
}
```

#### Deleting a User Role

##### parameter

| 字段   |value|
| ------ | ---------- |
| action |deleteRole|
| role |Deleting a Role Name|

##### Sample request


```
var deleteInfo = {};
deleteInfo.pubKey = global.authorizedUsers.[publicKey];
deleteInfo.action = "deleteRole";
deleteInfo.role="ContractUser";
wssocket.send(JSON.stringify(deleteInfo));
```

##### Returns the result


```json
{
	"action": "onDeleteRole",
	"data": "success"
}
```

#### View the list of authorized users

View authorized node administrators in the current network

##### parameter

| 字段   |value|
| ------ | --------------- |
| action |listAllAuthRole|

##### Sample request


```
var param = {};
param.action = "listAllAuthRole";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
    "status":false,
    "action":"onListAllAuthRole",
    "data":
    {
        "kv":[{"key":"04eafad549d0757cf67f360815e15e157c7428c9ea9fb933f31a5d45bfb6edd9809c5bf6a5f37d7b817207f19fb2d76b7dbdefe38084cd3282e37b9ac39959dfab",
              "value":"NodeManager,ContractProvider,ContractUser,ContractInstanceManager"}],
        "time":[{"key":"04eafad549d0757cf67f360815e15e157c7428c9ea9fb933f31a5d45bfb6edd9809c5bf6a5f37d7b817207f19fb2d76b7dbdefe38084cd3282e37b9ac39959dfab",
                "value":"1617178709933"}]
    }
}
```

#### View the list of applied users

##### parameter

| 字段   |value|
| ------ | -------------- |
| action |listUnAuthRole|

##### Sample request


```
var param = {};
param.action = "listUnAuthRole";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"action": "onListUnAuthRole",
	 "kv": [{
        "key": "049999ebd14ff3b96ebf7f7325e1da94a1c4c376573a1dc1cec2b4f7a3b09ed7b07252134e93b6ac2e1853268b82f4b541d34fb42b0182cd61043e99d3489e2cf7",
        "value": "ContractProvider,ContractUser"
    }],
    "time": [{
        "key": "049999ebd14ff3b96ebf7f7325e1da94a1c4c376573a1dc1cec2b4f7a3b09ed7b07252134e93b6ac2e1853268b82f4b541d34fb42b0182cd61043e99d3489e2cf7",
        "value": "1587398989914"
    }]
}
```


##### Parameter (delete)

| 字段   |value|
| ------ | ------------- |
| action |queryUserStat|

##### Sample request


```
var param = {};
param.action = "queryUserStat";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"action": "onQueryUserStat",
	"userListCount": 3,
	"applyListCount":0
}
```

### Contract code management class

#### Gets a list of public contract files

##### parameter

| 字段   |value|
| ------ | ------------ |
| action |listProjects|

##### Sample request


```
var request = {};
request.action = "listProjects";
wssocket.send(JSON.stringify(request));
```

##### Returns the result

```json
{
    "action":"onListProjects",
    "data":"[\"AnnotationSample\",\"AppDataAnalysis\",\"AppDataSource\",\"BiddingExample\",\"ContractExecutor\"]",
    "executeTime":0,
    "isPrivate":false
}

```


#### Gets a list of private contract files

##### parameter

| 字段   |value|
| ------ | -------------------- |
| action |listProjects|
| pubKey |The public key of the user|
|isPrivate|true|

##### Sample request


```javascript
var request = {};
request.action = "listProjects";
request.pubKey = "global.sm2.publicKey";
request.isPrivate=true;
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
    "action":"onListProjects",
    "data":"[\"CSVFromTemplate\",\"Empty22\",\"MySQLFromTemplate\",\"test\"]",
    "executeTime":0,
    "isPrivate":true
}
```


#### Get the contract instance

##### parameter

| 字段   |value|
| ------ | ------------------- |
| action |listContractProcess|

##### Sample request


```
var request = {};
request.action = "listContractProcess";
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
    "status":false,
    "action":"onListContractProcess",
    "data":"[{\"id\": \"1658407837\",\"name\": \"BDCoin\",\"port\": \"1617\"}]"
}
```


#### Start the contract

##### parameter

| 字段      |value|
| --------- | ------------- |
| action    |startContract|
| owner     |pubkey|
|requestID| 当前时间      |
|script| 脚本内容      |
| signature |The signature|

##### Sample request


```
request.action = "startContract";
request.owner = global.sm2Key.publicKey;
request.requestID = new Date().getTime() + "";
request.script = global.projectScript;
request.signature = sm2.doSignature("Algorithm|" + request.script + "|" + global.sm2Key.publicKey, global.sm2Key.privateKey);
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
    "data":"{\"needSeq\":false,\"seq\":0,\"status\":\"Success\",\"result\":\"\",\"isInsnLimit\":false,\"totalGas\":0,\"executionGas\":0,\"extraGas\":0,\"size\":0,\"eventRelated\":false}",
    "action":"onStartContract",
    "cid":"-506393888",
    "executeTime":2496,
    "responseID":"1617206735696"
}
```

#### Start the trusted cluster contract

##### parameter

| 字段      |value|
| --------- | ------------------------------------ |
| action    |startContractP2PTrustfully|
| owner     |pubkey|
| isPrivate |The current time|
|path |Path where the script resides|
| signature |The signature|
| peersID   |An array of peerids of nodes in the trusted execution cluster|
|           |                                      |

##### Sample request


```javascript
var request = {};
request.action = "startContractP2PTrustfully";
request.peersID = ["3r729hf2ehf982","sjdfiwoehfwoi34","wnfnwoeifnwenef"];
var project = "JsonTest";
request.path = "/" + project + "/mainfest.json";
request.isPrivate = false;
request.signature = sm2.doSignature("Trusted|" + request.path + "|"
+ global.sm2Key.publicKey, global.sm2Key.privateKey);  //合约的签名
request.resultcheck = $("#resultcheck")[0].value;
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
    "data":"{\"status\":\"Success\",\"result\":\"\"}",
    "action":"onStartContractP2PTrustfully",
    "cid":"-1543583350",
    "executeTime":1544
}
```

#### Distribution of contract items

##### parameter

| 字段          |value|
| ------------- | ------------------ |
|action |distributeContract|
|peersID| 集群中节点peer     |
| projectName   |The contract of|
|isPrivate| 是否在私有目录     |
| sponsorPeerID |The originators of the ID|
| signature     |The signature|

##### Sample request


```javascript
request.action = "distributeContract";
request.peersID = peersID;
request.projectName = global.projects[global.lastClickedProjectId];
request.isPrivate = $("#privateDir-tab").hasClass("active"); 
request.sponsorPeerID = global.peerID;
request.signature = sm2.doSignature("DistributeContract|" + request.projectName + "|" + global.sm2Key.publicKey, global.sm2Key.privateKey);  
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
	"action":"onDistributeContract",
	"progress":"100.00%"
}
```

#### Terminate the contract

##### parameter

| 字段      |value|
| --------- | ------------------- |
| action    |killContractProcess|
| id        |Contract id|
| requestID |Request ID|

##### Sample request


```
request.action = "killContractProcess";
request.id = contractid;
request.requestID = new Date().getTime() + "";
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
    "data": "ContractHandler: exit in 3 seconds!",
    "action": "onOutputStream"
}
```

#### Termination of all contracts

##### parameter

| 字段   |value|
| ------ | --------------- |
| action |killAllContract|

##### Sample request


```
request.action = "killAllContract";
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
   	"status":false,
   	"action":"onKillAllContract",
   	"data":"Kill:7241,7245,"
}
```



#### Static analysis contract

##### parameter

| 字段       |value|
| ---------- | -------------------- |
| action     |staticVerifyContract|
| owner      |User private key|
| isPartial  |Is it part of|
| contractid |contractid|
| script     |The script content|
| path       |Name of contract|


##### Sample request


```javascript
request.action = "staticVerifyContract";
request.owner = global.sm2Key.privateKey
request.isPartial = false;
request.contractid = contractid;
request.script = global.projectScript;
request.path = global.projectName;
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json

{
    "data":"{\"needSeq\":false,\"seq\":0,\"status\":\"Success\",\"result\":{\"hello\":\"Ret:\"},\"isInsnLimit\":false,\"totalGas\":0,\"executionGas\":0,\"extraGas\":0,\"size\":0,\"eventRelated\":false}",
    "action":"onStaticVerifyResult",
    "cid":"verify",
    "executeTime":83
}
```



#### Delete the contract

##### parameter

| 字段   |value|
| ------ | ---------- |
| action |deleteFile|
| file   |fileName|

##### Sample request


```javascript
request.action = "deleteFile";
request.file = fileName;
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
    "action":"onDeleteFile",
    "data":"success",
    "executeTime":0
}
```



#### Private contracts are uploaded to public directories

##### parameter

| 字段     |value|
| -------- | ------------ |
| action   |changePublic|
|pubkey| 用户公钥     |
| fileName |fileName|

##### Sample request


```javascript
request.action = "changePublic";
request.pubkey = pubkey;
request.fileName = fileName;
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
    "action":"onChangePublic",
    "data":"success",
    "executeTime":0
}
```



#### Upload the contract

##### parameter

| 字段     |value|
| -------- | ----------- |
| action   |UploadFile|
| isAppend | false       |
|fileName|fileName|
| path     | path    |
|isPrivate|true/false|
| content  |The fileContent (base64 encoding)|

##### Sample request


```
request.action = "uploadFile";
request.isAppend = false;
request.fileName = "test1.yjs";
request.path = "test1";
text="Y29udHJhY3QgdGVzdDF7CglleHBvcnQgZnVuY3Rpb24gaGVsbG8oYXJnKXsgCiAgICAgICAgcmV0dXJuICJ3b3JsZCI7ICAKICAgIH0gICAKfQ=="
request.content = text;
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
    "action":"onUploadFile",
    "data":"success",
    "executeTime":0
}
```

#### Compile the contract

##### parameter

| 字段       |value|
| ---------- | -------------------------- |
| action     |compile|
| path       |String indicates the name of the project to be compiled|
| privateTab |Bool, indicates whether the item is a private directory|

##### Sample request


```javascript
var req = {"action":"compile","path":"Hello","privateTab":true}
```

##### Returns the result


```json
{"result":"Hello_2020-08-17-09:09:40.ypk","action":"onCompile"}
```

#### Locking private directories

Lock the private directory editing function for a user

##### parameter

| 字段   |value|
| ------ | ---------------------- |
| action |lockEdit|
| pubKey |String Indicates the public key to be locked|

##### Sample request


```javascript
var req = {};
req.action = "lockEdit";
req.pubKey = "xxxxxx";
wssocket.send(JSON.stringify(req));
```

```json
{
    "action":"onLockEdit",
    "status":"success",
    "data":"04c4c855862b53f323e077ccfcc744ecc2c0a04645ed16d99ede8fd5866b38c0670a97ad22c6260d1a4672aba2a5fe229a2d4eba34627c054aab102620afa288c1"
}
```


#### Unlock a private directory

Unlock the private directory editing function for a user

##### parameter

| 字段   |value|
| ------ | ---------------------- |
| action |unLockEdit|
| pubKey |String Indicates the public key to be locked|

##### Sample request


```javascript
var req = {};
req.action = unlockEdit;
req.pubKey = "xxxxxx";
wssocket.send(JSON.stringify(req));
```

```json
{
    "action":"onUnlockEdit",
    "status":"success",
    "data":"04c4c855862b53f323e077ccfcc744ecc2c0a04645ed16d99ede8fd5866b38c0670a97ad22c6260d1a4672aba2a5fe229a2d4eba34627c054aab102620afa288c1"
}
```


### Contract instance management class

#### Querying the contract process

Sends a request to the server for all the contract processes that have been started on the server.

##### parameter

| 字段   |value|
| ------ | ------------------- |
| action |listContractProcess|

##### Sample request


```javascript
var request = {};
request.action = "listContractProcess";
wssocket.send(JSON.stringify(request));
```

##### Result


```json
{
	"status": false,
	"action": "onListContractProcess",
	"data": "[...]"
}
```



#### Call the contract

Send a request to the server to invoke a contract.

##### parameter

| 字段                 |value|
| -------------------- | --------------------------- |
| action               |executeContract|
| contractID           |Contract ID|
| withDynamicAnalysis |True /false Specifies whether to perform dynamic analysis. This parameter is optional|
|operation| 调用合约的方法名            |
|arg| 调用合约的parameter              |
| pubkey              |Caller public key, optional|
| signature           |Caller signature, optional|

`*` Indicates that the parameter is optional


```javascript
//sm2 可从sm2.js中加载获得。
signature = sm2.doSignature(contractID+"|"+operation+"|"+arg+"|"+pubkey,privateKey);
```

##### Sample request


```javascript
var request = {};
request.action = "executeContract";
request.contractID = "2073401446";
request.operation = "main";
request.arg = "hhhhh";
wssocket.send(JSON.stringify(request));
```

##### Result


```json
{
    "needSeq":false,
    "seq":0,
    "status":"Success",
    "result":"world",
    "isInsnLimit":false,
    "totalGas":0,
    "executionGas":0,
    "extraGas":0,
    "size":0,
    "eventRelated":false,
    "responseID":"1617211077264_223",
    "action":"onExecuteResult",
    "executeTime":"5"
}
```

#### Output history log (delete)

Send a request to the server for the TimeTravel log of the contract on the node server.

##### parameter

| 字段   |value|
| ------ | ------------------ |
| action |printTimeTravelLog|

##### Sample request


```javascript
var request = {};
request.action = "printTimeTravelLog";
wssocket.send(JSON.stringify(request));
```

##### Result


```json
{
	"status": false,
	"data": "[CMActions] dumpContract :…t/contractExamples/memoryDumps/LicenceManager\n"
}
```



#### Outputting node transition logs (delete)

Send a request to the server to get the state transition log of the node server.

##### parameter

| 字段   |value|
| ------ | ---------------- |
| action |printTransferLog|

##### Sample request


```javascript
var request = {};
request.action = "printTransferLog";
wssocket.send(JSON.stringify(request));
```

##### Result


```json
 {
	"status": false,
	"data": ""
}
```



#### Contract status migration

Send a request to the server to get the state transition log of the node server.

##### parameter

| 字段         |value|
| ------------ | ------------ |
| action       | loadMemory   |
|contractName| 合约名称     |
|memoryFile| 合约文件名称 |

##### Sample request


```javascript
var request = {};
request.action = "loadMemory";
request.contractName = "JsonContract";
request.memoryFile = "2020-03-17.20/42/55";
wssocket.send(JSON.stringify(request));
```

##### Result


```json
{
    "data":"success",
    "size":"0.00 B",
    "action":"onTransferTo",
    "time":"0.01s"
}
```



### Log Viewing Class

#### Querying Local Node Logs in the last N Days (Deleted)

##### parameter

| 字段   |value|
| ------ | ---------------- |
| action |listLocalNodeLog|
| date   |The current time|

##### Sample request


```
request.action = "listLocalNodeLog";
request.date = new Date().getTime() - 24 * 3600 * 1000 * n;
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
   "data":"[{\"action\":\"login\",\"pubKey\":\"null\",\"status\":\"accept\",\"date\":1583139323822}\",]"
}
```



#### Querying Local Contract Logs in the last N Days (Deleted)

##### parameter

| 字段   |value|
| ------ | -------------------- |
| action |listLocalContractLog|
| date   |The current time|

##### Sample request


```
request.action = "listLocalContractLog";
request.date = new Date().getTime() - 24 * 3600 * 1000 * n;
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
    "data":"[\"{\"action\":\"startContract\",\"pubKey\":\"04405d7ba358d9234939623ab51ea94ca685e6a1f36ed81fd9630ccba6473e632f163bb30faffd4c91f21e5bace20101d6d6e36c04ac67eea14cc24b4962b84f57\",\"contractID\":\"845581788\",\"contractName\":\"null\",\"date\":1583141525539}\"]"
}
```




### Node Configuration Class

#### Obtain node configuration information

##### parameter

| 字段   |value|
| ------ | -------------- |
| action |loadNodeConfig|

##### Sample request


```
var param = {};
param.action = "loadNodeConfig";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```  
{
	"status": true,
	"action": "onLoadNodeConfig",
	"data": {
		"nodeName": "04BF52213343C147E631B877BCEB17B794230EE551E85F58FA429C4BA03D690778CC384C6916C63DF36CB9E35C7E274FDB4E18491DFE3D611D347856D441CACC5AF9090B515F02AFC2DFBF56461EC83B5A4CD342466360D6CF82E6E40B637430AC4A329CCBC798DAF7D526AF9E3B3600E0BEA1BFAB8C160EF90128FAF67B19E45F37664F1E4B",
		"licence": "04AADCC7103CD02626D228AFFBEF53F8242ECA4DDD6F179D30B622440666715CFBB6FD1D3678A2B25812DEA9917073E79A65F7ADE517F784DC76288EFCEB37ECAA1025E6903540702F729DA1C2ECCD93F4E6FAFCE40DF443E7FD74387169D0C6D927C7BB12882D0471C8D3E6F31B0316A42FC38F6DD9978D4351B23B2AD63E2244909E98F51185D32CB99B4AE4E22D3AB4C04027BB",
		"expireTime": "Wed Aug 26 09:43:08 CST 2020",
		"nodes": "[\"node1\",\"node2\",\"node3\"]",
		"yjsPath": "/Users/xxx/docs/BDWareHttp/generatedlib/yjs.jar",
		"nodeCenter": "ws://127.0.0.1:1719/SCIDE/NodeCenter"
	}
}

{ 
    "status":true,
    "action":"onLoadNodeConfig",
    "data":{  
        "nodeName":"Node_180",
        "peerID":"",
        "masterAddress":"39.104.201.40:21031",
        "licence":"04AADCC7103C",
        "doipConfig":"{\\"LHSProxyAddress\\":\\"http://39.104.201.40:21042/\\",\\"ownerHandle\\":\\"86.5000.470/dou.TEST\\",\\"certPath\\":\\"keys/dou.TEST.keystore\\",\\"certPassword\\":\\"123456\\",\\"repoID\\":\\"86.5000.470/doip.vcg9Mu1gSq_bdw\\",\\"listeners\\":\\"[{\\\\\\"url\\\\\\":\\\\\\"tcp://39.104.201.40:21032\\\\\\",\\\\\\"protocolVersion\\\\\\":\\\\\\"2.1\\\\\\",\\\\\\"messageFormat\\\\\\":\\\\\\"packet\\\\\\"}]\\",\\"serviceDescription\\":\\"test local Contract Repository\\",\\"serviceName\\":\\"ContractEngine021\\"}",
        "clusterConnected":"false",
        "nodePubKey":"0492d974b8a5b473d0ed2c81800917f76e2a1ec3666067888c85fe6922a672223f2083f95402ae13a744df58deabbe7206c4a317dd14296b0d3941a26ca4e34dc5",
        "ipPort":"",
        "bdledger":"39.108.56.240:18091,39.108.56.12:1809139.104.70.160:18091 47.98.247.70:18091 47.98.248.208:18091 39.104.77.165:18091 47.98.249.131:18091",
        "yjsPath":"/data/bdwaas/bdcontract/yjs.jar",
        "nodeCenter":"ws://39.104.201.21040/SCIDE/NodeCenter"
    }
}
```


#### Modifying Node Configuration

##### parameter

| 字段   |value|
| ------ | -------------- |
| action |updateConfig|
| key    |The configuration item to change|
| val    |The target value to change|

Options for key include:

| key的示       |Val sample| 说明                            |
| ------------- | ----------------------------------- | ------------------------------- |
| yjsPath       |/User/xxx/cp/yjs.jar| 合约进程启动所需的jar           |
| dataChain     | 192.168.1.8:18090,182.173.2.3:18091 | 账本节点的ip与端口              |
| nodeCenter    |ws://127.0.0.1:18002| CenterPortal所在的ip/端口       |
| nodeName      |Node_180| 字符串类型                      |
| masterAddress | 192.168.3.2:18001                   | 该NodePortal节点的ip和的TCP端口 |

The TCP port of the NodePortal is the HTTP/WS port number +1 of the Node.


#### Modifying a Node Name

##### parameter

| 字段   |value|
| ------ | -------------- |
| action |changeNodeName|
| data   |New node name|

##### Sample request


```
var param = {};
param.action = "changeNodeName";
param.data = "NewNodeName";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"status": true,
	"action": "onChangeNodeName",
	"data": true
}
```



#### Example Change the YJS path of a node

##### parameter

| 字段   |value|
| ------ | --------------------- |
| action |changeYJSPath|
| data   |Yjs.jar path of the node server|

##### Sample request


```
var param = {};
param.action = "changeYJSPath";
param.data = "/Users/xxx/docs/BDWareHttp/generatedlib/yjs.jar";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"status": true,
	"action": "onChangeYJSPath",
	"data": true
}
```



#### Modify NodeCenter

##### parameter

| 字段   |value|
| ------ | ----------------------------------------- |
| action |changeNodeCenter|
| data   |NodeCenterWebSocket path to which the node server is to connect|

##### Sample request


```
var param = {};
param.action = "changeNodeCenter";
param.data = "ws://127.0.0.1:1719/SCIDE/NodeCenter";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"status": true,
	"action": "onChangeNodeCenter",
	"data": true
}
```



#### Example Modify an account node

##### parameter

| 字段   |value|
| ------ | --------------------------- |
| action |changeBDledger|
| data   |The IP address of the node is port, separated by commas (,)|

##### Sample request


```
var param = {};
param.action = "changeBDledger";
param.data = "39.108.56.240:18091,39.108.56.12:18091";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"status": true,
	"action": "onChangeBDledger",
	"data": true
}
```



#### Uploading the Node License

##### parameter

| 字段   |value|
| ------ | ----------------------- |
| action |uploadLicence|
| data   |The content of the license on the node server|

##### Sample request


```
var param = {};
param.action = "uploadLicence";
param.data = "04AADCC7103C";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"status": true,
	"action": "onUploadLicence",
	"data": true
}
```



#### Obtaining Node ids

##### parameter

| 字段   |value|
| ------ | --------- |
| action |getNodeID|

##### Sample request


```
var param = {};
param.action = "getNodeID";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"status": true,
	"action": "onGetNodeID",
	"data": "0431…d3a92e1184bbc5817ebda5c2ad498e4ff1d240009b4f06d"
}
```



#### Gets the trusted execution cluster where the node resides

##### parameter

| 字段       |value|
| ---------- | ------------------------------------------------ |
| action     |getNodeTrustUnits|
| data       |The node ID|
| msgHandler |MsgHandler for the callback function that receives a reply|
| ws         |WebSocket address of the NodeCenter to which the node belongs|

##### Sample request


```
centerportalws = createWssocket("ws://127.0.0.1:1718/NodeCenterWS",function() {
var param = {};
param.action = "getNodeTrustUnits";
param.data = "0431e311bd70840fe69965e2cabea97fafe99f2133953c01abb9bd7cb62af42f8283f474d203051e920d3a92e1184bbc5817ebda5c2ad498e4ff1d240009b4f06d";
centerportalws.send(JSON.stringify(param));
}, msgHandler);
```

##### Returns the result


```json
{
	"data": [{
		"key": "0475c7b061...65e55_4063665700873624164",
		"value": "[\"04541429c11b094…40009b4f06d\"]"
	}],
	"action": "onGetNodeTrustUnits"
}
```

### Template generation class

####  Gets a list of contract templates

##### parameter

| 字段   |value|
| ------ | --------------- |
| action |getTemplateList|

##### Sample request


``` javascript
req={};
req.action = "getTemplateList";
wssocket.send(JSON.stringify(req));
```

##### Returns the result


``` json
{
    "data": [
        {
            "formDesc": {
                "dbPWD": {
                    "label": "密码",
                    "type": "input"
                },
                "contractName": {
                    "label": "合约名称",
                    "type": "input"
                },
                "accessPolicy": {
                    "label": "访问控制策略",
                    "type": "input",
                    "option": [
                        {
                            "text": "无访问控制",
                            "value": "NAC"
                        },
                        {
                            "text": "直接访问控制",
                            "value": "DAC"
                        },
                        {
                            "text": "基于角色的访问控制",
                            "value": "RBAC"
                        }
                    ]
                },
                "dbUserName": {
                    "label": "用户名",
                    "type": "input"
                },
                "fieldList": {
                    "label": "字段名",
                    "type": "tag"
                },
                "dbUrl": {
                    "label": "数据库链接",
                    "type": "input"
                },
                "tableName": {
                    "label": "表名",
                    "type": "input"
                }
            },
            "apiName": "generateMySQLProject"
        },
        {
            "formDesc": {
                "contractName": {
                    "label": "合约名称",
                    "type": "input"
                },
                "accessPolicy": {
                    "label": "访问控制策略",
                    "type": "input",
                    "option": [
                        {
                            "text": "无访问控制",
                            "value": "NAC"
                        },
                        {
                            "text": "直接访问控制",
                            "value": "DAC"
                        },
                        {
                            "text": "基于角色的访问控制",
                            "value": "RBAC"
                        }
                    ]
                }
            },
            "apiName": "generateEmptyProject"
        }
    ],
    "action": "onTemplateList"
}
```

#### Blank Contract Template

##### parameter

| 字段         |value|
| ------------ | ----------------------------- |
| action       |generateEmptyProject|
| contractName |The name of the contract is a string|
| isPrivate    |Boolean type, whether it is a private project|
| accessPolicy |If the value is “DAC”, direct access control is implemented|

##### Sample request


```javascript
var req = {};
req.contractName = "Empty22";
req.action = "generateEmptyProject";
req.accessPolicy = "DAC";
//wssocket为建立好的连接
wssocket.send(JSON.stringify(req));
```

##### Returns the result

```json
{
    "action":"onListProjects",
    "data":"[\"AnnotationSample\",\"AppDataAnalysis\",\"AppDataSource\"]",
    "executeTime":0,
    "isPrivate":false
}
```

#### MySQL Access Contract

##### parameter

| 字段          |value|
| ------------- | ------------------------------------------------------ |
| action        |generateMySQLProject|
| contractName  |The name of the contract is a string|
| isPrivate     |Boolean type, whether it is a private project|
| dbUrl         |The string is the URI of the database|
| dbUserName    |The value is a string of characters and the user name of the database|
| dbPWD         |The value is a string of characters and the database password|
| accessPolicy  |If it is “DAC”, direct access control is implemented; if it is “NAC”, no access control is implemented|
| tableName     |A string, the name of a database table|
| fieldList     |A list of strings, a list of database fields|
| defaultAccept |Boolean value indicating whether the application is granted by default|

##### Sample request


```javascript
var req = {};
req.contractName = "MySQLFromTemplate";
req.action = "generateMySQLProject";
req.pubKey = global.sm2Key.publicKey;
req.isPrivate = true;
req.tableName = "data";
req.dbUrl = "jdbc:mysql://xxx:xxx/xxx";
req.dbUserName = "loushuai";
req.dbPWD = "loushuai";
req.fieldList = [{"name":"名字","code":"*"}];
req.basicInfo={"type":"所属分类","name":"资源名称"};
req.accessPolicy = "DAC";
req.defaultAccept = true;
//global.wssocket为建立好的连接
global.wssocket.send(JSON.stringify(req));
```

##### Returns the result

```json
{
    "action":"onListProjects",
    "data":"[\"CSVFromTemplate\",\"Empty22\",\"Hello\",\"MySQLFromTemplate\",\"test\"]",
    "executeTime":0,
    "isPrivate":true
}
```
#### CSV Access Contract

##### parameter

| 字段              |value|
| ----------------- | ------------------------------------------------------ |
| action            |generateCSVProject|
| contractName      |The name of the contract is a string|
| base64EncodedData |The value is a string of characters in a Base64-encoded CSV file|
| isPrivate         |Optional fields, Boolean type, private item or not|
| accessPolicy      |If it is “DAC”, direct access control is implemented; if it is “NAC”, no access control is implemented|
| defaultAccept     |An optional field, a Boolean value that indicates whether the application is granted by default|

##### Sample request


```javascript
var req = {};
req.contractName = "CSVFromTemplate";
req.action = "generateCSVProject";
req.pubKey = global.sm2Key.publicKey;
req.isPrivate = true;
req.tableName = "data";
req.accessPolicy = "DAC";
req.defaultAccept = true;
req.base64EncodedData = "bmFtZSwgc2NvcmUsCmphY2ssIDkwLApsdWN5LCA5MQo=";
//global.wssocket为建立好的连接
global.wssocket.send(JSON.stringify(req));
```
##### Returns the result

```json
{
    "action":"onListProjects",
    "data":"[\"CSVFromTemplate\",\"Empty22\",\"Hello\",\"MySQLFromTemplate\",\"test\"]",
    "executeTime":0,
    "isPrivate":true
}
```

- - -

## Routing node WebSocket interface

### User Management

#### Access to the Session

Before login, obtain the session for signing.

##### parameter

| 字段   |value|
| ------ | ------------ |
| action |getSessionID|

##### Sample request


```
var req = {};
req.action = "getSessionID";
wssocket.send(JSON.stringify(req));
```


##### Returns the result


```json
{
	"action": "onSessionID",
	"session": "9782323_session"
}
```


#### The user login

To authenticate the public key, the user needs to call “getSessionID” to obtain the sessionID for signature.

##### 参数

| 字段   | 值    |
| ------ | ----- |
| action | login |

##### Sample request


```
var loginParam = {};
loginParam.pubKey = global.sm2Key.publicKey;
loginParam.signature = sm2.doSignature(global.session,
			global.sm2Key.privateKey);
loginParam.action = "login";
wssocket.send(JSON.stringify(loginParam));
```

##### Result


```json
{
	"action": "onLogin",
	"data": "CenterManager"
}
```



#### User gets the current role (Delete)

A user obtains a role based on the public key used during login. If it is the first login, the public key used during login is called the access administrator by default

##### parameter

| 字段   |value|
| ------ | ------- |
| action |getRole|

##### Sample request


```
var param = {};
param.action = "getRole";
wssocket.send(JSON.stringify(param));
```

##### Result


```json
{
	"action": "onGetRole",
	"data": "CenterManager"
}
```

#### Apply for role

On the Access administrator page, you can apply for a node administrator for a node in the network

##### parameter

| 字段   |value|
| ------ | --------- |
| action |applyRole|
|role|Specifies the name of the applied role|

##### Sample request


```
var param = {};
param.action = "applyRole";
param.role="
wssocket.send(JSON.stringify(param));
```

##### Result


```json
{
	"action": "onApplyRole",
	"data": "failed"
}
```


#### Add a node

##### parameter

| 字段       |value|
| ---------- | ---------------- |
| action     |addNode|
|nodePubKey| 要添加的节点公钥 |

#### Sample request


```
var req = {};
//某节点的publicKey可通过连接该节点，并通过"获取节点配置信息"接口获取
req.nodePubKey = publicKey;
req.action = "addNode";
wssocket.send(JSON.stringify(req));
```


#### Deleting a User Role

##### parameter

| 字段   |value|
| ------ | -------------- |
| action |delete|
| pubKey |The public key of the corresponding user|

##### Sample request


```
var deleteInfo = {};
deleteInfo.pubKey = user.publicKey;
deleteInfo.action = "delete";
wssocket.send(JSON.stringify(deleteInfo));
```

##### Result


```json
{
	"action": "onDelete",
	"data": "success"
}
```

#### View the list of authorized users

View authorized node administrators in the current network

##### parameter

| 字段   |value|
| ------ | ------------ |
| action |listAllUsers|

##### Sample request


```
var param = {};
param.action = "onListAllUsers";
wssocket.send(JSON.stringify(param));
```

##### Result


```json
{
	"action": "onListAllUsers",
	 "kv": {
        "key": "049999ebd14ff3b96ebf7f7325e1da94a1c4c376573a1dc1cec2b4f7a3b09ed7b07252134e93b6ac2e1853268b82f4b541d34fb42b0182cd61043e99d3489e2cf7",
        "value": " NodeManager"
    },
    "time": {
        "key": "049999ebd14ff3b96ebf7f7325e1da94a1c4c376573a1dc1cec2b4f7a3b09ed7b07252134e93b6ac2e1853268b82f4b541d34fb42b0182cd61043e99d3489e2cf7",
        "value": 1587398989914
    }
}
```

#### View the list of applied users

##### parameter

| 字段   |value|
| ------ | ------------- |
| action |listApplyList|

##### Sample request


```
var param = {};
param.action = "onListApplyList";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"action": "onListApplyList",
	 "kv": {
        "key": "04b00f32eab70c78d1b43738f190d326d36c021af2124acefe6d057016b11ea31c750bb473e565c9d89e4993a44f4d30adf447d3026a21ff4b3b64cef523074ef7",
        "value": " NodeManager"
    },
    "time": {
        "key": "04b00f32eab70c78d1b43738f190d326d36c021af2124acefe6d057016b11ea31c750bb473e565c9d89e4993a44f4d30adf447d3026a21ff4b3b64cef523074ef7",
        "value": 1587398989914
    }
}
```

#### View the distribution of user types

##### parameter

| 字段   |value|
| ------ | ------------- |
| action |queryUserStat|

##### Sample request


```
var param = {};
param.action = "onQueryUserStat";
wssocket.send(JSON.stringify(param));
```

##### Result


```json
{
	"action": "onQueryUserStat",
	"userListCount": 3,
	"applyListCount":0
}
```

### Node Management

#### Viewing the Node List

View the node list that the user has the permission to view (only available to access administrators and contract managers)

##### parameter

| 字段   |value|
| ------ | --------- |
| action |listNodes|

##### Sample request


```
var param = {};
param.action = "listNodes";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"offline": [{
		"key": "0431e31...40009b4f06d",
		"value": "0431e311bd708...b4f06d"
	}],
	"action": "onListNodes",
	"online": [{
		"contracts": [],
		"pubKey": "0431e311...09b4f06d",
		"nodeName": "NewNodeName",
		"udpID": "528822126",
		"cimanager": ""
	}]
}
```


#### View the list of trusted execution clusters

View the node list that the user has permission to view (available only to the center administrator and contract manager)

##### parameter

| 字段   |value|
| ------ | -------------- |
| action |listTrustUnits|

##### Sample request


```
var param = {};
param.action = "listTrustUnits";
wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"data": [{
		"key": "0470b2f27f4f6…1cb855f1ecec11",
		"value": "[...]"
	}],
	"action": "onListTrustUnits"
}
```


#### Establish a trusted execution cluster

##### parameter

| 字段   |value|
| ------ | ---------------------- |
| action |createTrustUnit|
| data   |Json array of node public keys|
| Msg    |The name of the cluster|

##### Sample request


```
var param = {};
param.action = "createTrustUnit";
param.data = "[\"382r0934309t...\",\"345343rr3f34...\"]";
param.msg = "newUnit1";
global.wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"action": "onCreateTrustUnit",
	"status": "Success"
}
```


#### Delete a trusted execution cluster

##### parameter

| 字段   |value|
| ------ | --------------- |
| action |deleteTrustUnit|
| data   |Trusted execution cluster ID|

##### Sample request


```
var param = {};
param.action = "deleteTrustUnit";
param.data = "0475d34rf3434..._1583410158761";
global.wssocket.send(JSON.stringify(param));
```

##### Returns the result


```json
{
	"action": "onDeleteTrustUnit",
	"status": "Success"
}
```



### Log Viewing Class

#### View the statistics of network management operations

##### parameter

| 字段   |value|
| ------ | -------------- |
| action |queryActionLog|
| date   |The current time|

##### Sample request


```
request.action = "onQueryActionLog";
request.date = new Date().getTime() - 24 * 3600 * 1000 * n;
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{	"action":"onQueryActionLog",
     "data":"[{\"action\":\"login\",\"pubKey\":\"null\",\"status\":\"accept\",\"date\":1583139323822}\",]"
}
```



#### View local contract logs in the last N days

##### parameter

| 字段   |value|
| ------ | -------------------- |
| action |listLocalContractLog|
| date   |The current time|

##### Sample request


```
request.action = "listLocalContractLog";
request.date = new Date().getTime() - 24 * 3600 * 1000 * n;
wssocket.send(JSON.stringify(request));
```

##### Returns the result


```json
{
    "data":"[\"{\"action\":\"startContract\",\"pubKey\":\"04405d7b...\",\"contractID\":\"845581788\",\"contractName\":\"null\",\"date\":1583141525539}\"]"
}
```


- - -

## Bash interface

Has been abandoned. BDWareConfigTool can be used instead. Send Socket instructions through the command line, execute the call `ContractController` class method, complete the following functions(need to run the `ContractManager` instance on the local `1615` port)

![Schematic diagram of Bash interface functions](./_static/imgs/bash-api.png)

### instruction


```bash
java -jar yjs.jar function_name arguments

```

`function_name` is the name of the called method;

`arguments` is the method parameter.

### Start the contract

#### parameter

`function_name` is `startContract`;

`arguments` to start the contract parameters, including the type of contract `type`, the contract ID `id`, contract script `script`.

#### Order sample


```bash
java -jar yjs.jar startContract "{\"type\":\"Algorigthm\",\"id\":\"656565\",\"script\":\"contract c{function main(arg){return arg/1.0+1;}}\"}"
```

### Call the contract

#### parameter

`function_name` is `executeContract`;

`arguments` need to invoke the contract parameters, including the call parameters `arg`, the contract ID `contractID`.

#### Order sample


```bash
java -jar yjs.jar executeContract "{\"arg\":\"http://www.baidu.com\",\"contractID\":\"656564\"}"
```

### To stop the contract

#### parameter

`function_name` is `stopContract`;

`arguments` is the parameter required to invoke the contract, that is, the contract ID `contractID`.

#### Order sample


```bash
java -jar yjs.jar stopContract "{\"arg\":\"http://www.baidu.com\",\"contractID\":\"656564\"}"
```

### Termination of all contracts

#### parameter

`function_name` indicates that `stopAllContracts`.

#### Order sample


```bash
java -jar yjs.jar stopAllContracts 
```

### Query all contracts

#### parameter

`function_name` is `listContracts`.

#### Order sample


```bash
java -jar yjs.jar listContracts 
```
 