github.com/annchain/OG@v0.0.9/rpc/doc.md (about)

     1  # **RPC API Document** 
     2  
     3  ## **Get Status**
     4  Get the status of the chain.
     5  
     6  **URL**:
     7  ```
     8  /status
     9  ```
    10  
    11  **Method**: GET
    12  
    13  **请求参数**:  
    14  无
    15  
    16  **请求示例**:
    17  > /status
    18  
    19  **返回示例**:
    20  ```json
    21  {
    22      "data":{
    23          "node_info":{
    24              "id":"99fa33...",
    25              "short_id":"99fa3376342834b0",
    26              "name":"og",
    27              "onode":"onode://99fa3376342...2b8d6@0.0.0.0:8001",
    28              "ip":"0.0.0.0",
    29              "ports":{"discovery":8001,"listener":8001},
    30              "listenAddr":"[::]:8001",
    31              "protocols":{
    32                  "og":{
    33                      "network":1,
    34                      "difficulty":null,
    35                      "genesis":"0x1dfb...d3736e",
    36                      "head":"0x38ed1158...e7e2"
    37                  }
    38              }
    39          },
    40          "peers_info":[]
    41      },
    42      "message":""
    43  }
    44  ```
    45  ---
    46  
    47  ## **Get Net Information**
    48  Get information of the network. 
    49  
    50  **URL**:
    51  ```
    52  /net_info
    53  ```
    54  
    55  **Method**: GET
    56  
    57  **请求参数**:  
    58  无
    59  
    60  **请求示例**:
    61  > /net_info
    62  
    63  **返回示例**:
    64  ```json
    65  {
    66      "data":{
    67          "id":"99fa3...4f2b8d6",
    68          "short_id":"99fa3376342834b0",
    69          "name":"og",
    70          "onode":"enode://99fa337634...2b8d6@0.0.0.0:8001",
    71          "ip":"0.0.0.0",
    72          "ports":{"discovery":8001,"listener":8001},
    73          "listenAddr":"[::]:8001",
    74          "protocols":{
    75              "og":{
    76                  "network":1,
    77                  "difficulty":null,
    78                  "genesis":"0x1dfb...36e",
    79                  "head":"0x3e...15"
    80              }
    81          }
    82      },
    83      "message":""
    84  }
    85  ```
    86  ---
    87  
    88  ## **Get Peers Information**
    89  Get information of the peers. 
    90  
    91  **URL**:
    92  ```
    93  /peers_info
    94  ```
    95  
    96  **Method**: GET
    97  
    98  **请求参数**:  
    99  无
   100  
   101  **请求示例**:
   102  > /peers_info
   103  
   104  **返回示例**:
   105  ```json
   106  {
   107      "data":[],
   108      "message":""
   109  }
   110  ```
   111  ---
   112  
   113  ## **node monitor**
   114  Get Node Status , neighbor status , sync status ,and tps information ,used for testing
   115  
   116  **URL**:
   117  ```
   118  /monitor
   119  ```
   120  **Method**: GET
   121  
   122  **请求参数**:  
   123  无
   124  
   125  **请求示例**:
   126  > /monitor
   127  **返回示例**:
   128  ```json
   129  {
   130  	"data": {
   131  		"port": "11301",
   132  		"short_id": "5140035b59e10b55",
   133  		"peers": [
   134  			{
   135  				"addr": "127.0.0.1:11331",
   136  				"short_id": "7fafa309e4c0d55c",
   137  				"link": true
   138  			},
   139  			{
   140  				"addr": "127.0.0.1:11311",
   141  				"short_id": "59562991b0166817",
   142  				"link": false
   143  			},
   144  			{
   145  				"addr": "127.0.0.1:11321",
   146  				"short_id": "c418f71a4cbd8989",
   147  				"link": true
   148  			}
   149  		],
   150  		"seq_id": 650,
   151  		"tps": {
   152  			"num": 0,
   153  			"tx_num": 0,
   154  			"duration": 12.278686557
   155  		},
   156  		"status": {
   157  			"id": "5140035b59e10b55",
   158  			"syncMode": "SyncStatusIncremental",
   159  			"catchupSyncerStatus": "CSSStopped",
   160  			"catchupSyncerEnabled": true,
   161  			"incrementalSyncerEnabled": true,
   162  			"height": 650,
   163  			"latestHeight": 650,
   164  			"bestPeer": "59562991b0166817",
   165  			"error": "",
   166  			"txid": 0
   167  		}
   168  	},
   169  	"message": ""
   170  }
   171  ```
   172  ---
   173  
   174  
   175  ## **consensus status**
   176  Get Node consensus status
   177  
   178  **URL**:
   179  ```
   180  /consensus
   181  ```
   182  **Method**: GET
   183  
   184  **请求参数**:  
   185  无
   186  
   187  **请求示例**:
   188  > /consensus
   189  **返回示例**:
   190  ```json
   191  {
   192  data: {
   193  dkg: {
   194  term_id: 1,
   195  id: 0,
   196  part_pubs: [
   197  { },
   198  { },
   199  { },
   200  { }
   201  ],
   202  candidate_public_key: [
   203  "LtgUTq4we+nS6PdRxU0IydGhRH1QWTaNI3jGl+DsqOhJW5Z4ajZ4/N3QNdS3Vn+9Sh8NJ5DukYLUNomeilPOzURw+oILObS98dCHacmgwcTErZ4oCyGQFE2W0zJKBxnOjhU31h2ktiejkrsyHhP2DgVry9Fuh1vtyoghQxh69Gk="
   204  ],
   205  address_index: {
   206  0x2dfdf4039dccec33e2d8665402d4a8b630f4af5c: 1,
   207  0x49e52b4ed3b826283722eca606ddb05a435cd8fd: 0,
   208  0x9c2c02d8bbf82b95b4abcf6e9242a2fe218c1df9: 2,
   209  0xf369c9cf16ec32471bac2e25a5bf393ca589c03a: 3
   210  }
   211  },
   212  bft: {
   213  bft_partner: {
   214  address: "0x49e52b4ed3b826283722eca606ddb05a435cd8fd",
   215  public_key: "BMpJJKyicaB6xXEQ9eTvrOf8rLKC60RIcQF6dE23T0i8AKfeFCYU1TauItSzt1fySBWSd5fq5q7KVSYK3WtaJPk="
   216  },
   217  dkg_term_id: 1,
   218  sequencer_time: 3000000000,
   219  partners: [
   220  {
   221  address: "0x49e52b4ed3b826283722eca606ddb05a435cd8fd",
   222  public_key: "BMpJJKyicaB6xXEQ9eTvrOf8rLKC60RIcQF6dE23T0i8AKfeFCYU1TauItSzt1fySBWSd5fq5q7KVSYK3WtaJPk="
   223  },
   224  {
   225  address: "0x2dfdf4039dccec33e2d8665402d4a8b630f4af5c",
   226  public_key: "BEjOkJFkGpvgRnFWCjNjuBD9kOXSOHZht+ovV61EH2/FWv8G5e6P/eE5liFB/Jo62P4KDiMKNv7hI6MBWTRMbk8="
   227  },
   228  {
   229  address: "0x9c2c02d8bbf82b95b4abcf6e9242a2fe218c1df9",
   230  public_key: "BAYJ7t/joFHtgVxiVYEwdPQbNav+NrM7qH06I/MAUxTv6VRnyBdbtyeBCr6VU1CaIrDY97HSuddS1QM2liQkH3k="
   231  },
   232  {
   233  address: "0xf369c9cf16ec32471bac2e25a5bf393ca589c03a",
   234  public_key: "BGXA1DvmRPfYO00p5XhGOKvoAodJD2oamMvhxfKkblmiUfHqgAQ0xcWWbZ0r7IG42Vp2VWTTzNetlTsP3sdGeQg="
   235  }
   236  ]
   237  }
   238  },
   239  message: ""
   240  }
   241  ```
   242  
   243  ## **Query Transaction**
   244  Get transaction from og node. 
   245  
   246  **URL**: 
   247  ```
   248  /transaction
   249  ```
   250  
   251  **Method**: GET
   252  
   253  **请求参数**:  
   254  
   255  | 参数 | 数据类型 | 是否必填 | 备注
   256  | --- | --- | --- | ---
   257  | hash | string | 是 | 必须是可以转成byte数组的 hex string
   258  
   259  **请求示例**:
   260  > /transaction?hash=69a1379feffe1049e0b45d5dcb131034f79e94cd2ce5085cececb9c4ccdc2be0
   261  
   262  **返回示例**:
   263  ```json
   264  {
   265      "data":{
   266          "Type":0,
   267          "Hash":"0x22359bb1c...8c56",
   268          "ParentsHash":["0xce63a703e0a...b9990509"],
   269          "AccountNonce":10,
   270          "Height":1,
   271          "PublicKey":"BKVH401d4...eGR+I=",
   272          "Signature":"HzgliZb...YpzdgE=",
   273          "MineNonce":1,
   274          "From":"0x96f4ac2f3215b80ea3a6466ebc1f268f6f1d5406",
   275          "To":"0xa70c8a9485441f6fa2141d550c26d793107d3dea",
   276          "Value":"0",
   277          "Data":null
   278      },
   279      "message":""
   280  }
   281  ```
   282  ---
   283  
   284  ## **Check Confirm**
   285  Check if a transaction is been confirmed. 
   286  
   287  **URL**: 
   288  ```
   289  /confirm
   290  ```
   291  
   292  **Method**: GET
   293  
   294  **请求参数**:  
   295  
   296  | 参数 | 数据类型 | 是否必填 | 备注
   297  | --- | --- | --- | ---
   298  | hash | string | 是 | tx的哈希,必须是可以转成byte数组的 hex string
   299  
   300  **请求示例**:
   301  > /confirm?hash=69a1379feffe1049e0b45d5dcb131034f79e94cd2ce5085cececb9c4ccdc2be0
   302  
   303  **返回示例**:
   304  ```json
   305  {
   306      "data":true,
   307      "message":""
   308  }
   309  ```
   310  ---
   311  
   312  ## **Transactions**
   313  Check if a transaction is been confirmed. 
   314  
   315  **URL**: 
   316  ```
   317  /transactions
   318  ```
   319  
   320  **Method**: GET
   321  
   322  **请求参数**:  
   323  
   324  | 参数 | 数据类型 | 是否必填 | 备注
   325  | --- | --- | --- | ---
   326  | seq_id | int string | 否 | 和 address 两个选一个必填,如果address有值优先获取地址相关的所有交易。
   327  | address | string | 否 | 和 seq_id 两个选一个必填,必须是 hex string.
   328  
   329  **请求示例**:
   330  > /transactions?seq_id=123
   331  
   332  > /transactions?address=96f4ac2f3215b80ea3a6466ebc1f268f6f1d5406
   333  
   334  **返回示例**:
   335  ```json
   336  {
   337  	"data":{
   338  		"total":12,
   339  		"txs":[
   340  			{...},
   341  			{...},
   342  			{...},
   343  			{...},
   344  			{...},
   345  			{...},
   346  			{...},
   347  			{...},
   348  			{...},
   349  			{...},
   350  			{...},
   351  			{...}
   352  		]},
   353  	"message":""
   354  }
   355  ```
   356  ---
   357  
   358  ## **Genesis**
   359  Check genesis sequencer from OG. 
   360  
   361  **URL**: 
   362  ```
   363  /genesis
   364  ```
   365  
   366  **Method**: GET
   367  
   368  **请求参数**:
   369  无
   370  
   371  **请求示例**:
   372  > /genesis
   373  
   374  **返回示例**:
   375  ```json
   376  {
   377      "data":{
   378          "Type":1,
   379          "Hash":"0x1dfb6fea83e3d62af98d72255527a677dbaf3ba4f98c80ae0ea9e3db97d3736e",
   380          "ParentsHash":null,
   381          "AccountNonce":0,
   382          "Height":0,
   383          "PublicKey":"s+G4MG4bqxXtUaTCSwhlUGd7qZzWKDWWUxajZBno9ZzmojKJIYLadAGjKQZuj+KvYHKHE55jfTFL8NYcudHH7g==",
   384          "Signature":"MEQCIBIwK9fJUfy/7yZG2Zb6QnCaPMNd/K9ID6Tw+HgmRVhdAiBCTXEC2on0R7KMU6rjiKzwulcAjIBI9eNNwRdlscq39g==",
   385          "MineNonce":0,
   386          "Id":0,
   387          "Issuer":"0x0000000000000000000000000000000000000000",
   388          "ContractHashOrder":[]
   389      },
   390      "message":""
   391  }
   392  ```
   393  ---
   394  
   395  ## **Sequencer**
   396  Check sequencer from OG. 
   397  
   398  **URL**: 
   399  ```
   400  /sequencer
   401  ```
   402  
   403  **Method**: GET
   404  
   405  **请求参数**:  
   406  
   407  | 参数 | 数据类型 | 是否必填 | 备注
   408  | --- | --- | --- | ---
   409  | hash | string | 否 | 必须是hex string,和seq_id字段二选一,都存在的话优先 seq_id,两字段都不存在则返回最新的sequencer
   410  | seq_id | int | 否 | 和 hash 字段二选一,两字段都不存在则返回最新的sequencer
   411  
   412  **请求示例**:
   413  > /sequencer?hash=69a1379feffe1049e0b45d5dcb131034f79e94cd2ce5085cececb9c4ccdc2be0
   414  
   415  > /sequencer?seq_id=123
   416  
   417  **返回示例**:
   418  ```json
   419  {
   420      "data":{
   421          "Type":1,
   422          "Hash":"0x5bcb676788cd6...6cf5",
   423          "ParentsHash":[
   424              "0xfb9aa6509b5...61b8c233b4d",
   425              "0x363e56d1a0f...fdaef3b1e46"
   426          ],
   427          "AccountNonce":225,
   428          "Height":12,
   429          "PublicKey":"BIDG6ARHwZ...0gHt8RtnRHzrI=","Signature":"AcRW9jpW...o9dQE=",
   430          "MineNonce":1,
   431          "Id":12,
   432          "Issuer":"0x7349f7a6f622378d5fb0e2c16b9d4a3e5237c187",
   433          "ContractHashOrder":null
   434      },
   435      "message":""
   436  }
   437  ```
   438  ---
   439  
   440  ## **New Transaction**
   441  Send new transaction to OG. 
   442  
   443  **URL**: 
   444  ```
   445  /new_transaction
   446  ```
   447  
   448  **Method**: GET / POST
   449  
   450  **请求参数**:  
   451  
   452  | 参数 | 数据类型 | 是否必填 | 备注
   453  | --- | --- | --- | ---
   454  | nonce | int string | 是 |
   455  | from | hex string | 是 |
   456  | to | hex string | 否 | 创建合约时可以置空
   457  | value | int string | 是 | 不转账时填0
   458  | crypto_type | string | 是 | secp256k1 或者 ed25519
   459  | signature | hex string | 是 |
   460  | pubkey | hex string | 是 |
   461  | data | hex string | 否 | 
   462  
   463  **请求示例**:
   464  ```json
   465  {
   466      "nonce": "0",
   467      "from": "0x889e0b36dc6f2c06eb68d9c5f53434e4c42c8d19",
   468      "to": "0x473c176c84213626588c4d2d7724b9524aaf6f3d",
   469      "value": "0",
   470      "crypto_type": "secp256k1", 
   471      "signature": "0x421001d20e2dbbd13...",
   472      "pubkey": "0x04249f001e59783eb10f1...",
   473      "data": "0x5682aec..."
   474  }
   475  ```
   476  
   477  **返回示例**:
   478  ```json
   479  {
   480      "data":"0xb4d525888e28119419f8ad1ccb837d899c17c1680f3bb4cb184471313439f570",
   481      "message":""
   482  }
   483  ```
   484  ---
   485  
   486  ## **New Account**
   487  Generage a random key pair. 
   488  
   489  **URL**: 
   490  ```
   491  /new_account
   492  ```
   493  
   494  **Method**: POST
   495  
   496  **请求参数**:  
   497  
   498  | 参数 | 数据类型 | 是否必填 | 备注
   499  | --- | --- | --- | ---
   500  | algorithm | string | 是 | 签名类型(ed25519, secp256k1)
   501  
   502  **请求示例**:
   503  ```json
   504  {
   505      "algorithm": "secp256k1",
   506  }
   507  ```
   508  
   509  **返回示例**:
   510  ```json
   511  {
   512  
   513  }
   514  ```
   515  ---
   516  
   517  ## **Auto Tx**
   518  TODO 
   519  
   520  **URL**: 
   521  ```
   522  /auto_tx
   523  ```
   524  
   525  **Method**: GET
   526  
   527  ---
   528  
   529  ## **Query Nonce**
   530  Get latest nonce of a specific address. 
   531  
   532  **URL**: 
   533  ```
   534  /query_nonce
   535  ```
   536  
   537  **Method**: GET
   538  
   539  **请求参数**:  
   540  
   541  | 参数 | 数据类型 | 是否必填 | 备注
   542  | --- | --- | --- | ---
   543  | address | hex string | 是 | 
   544  
   545  **请求示例**:
   546  > /query_nonce?address=96f4ac2f3215b80ea3a6466ebc1f268f6f1d5406
   547  
   548  **返回示例**:
   549  ```json
   550  {
   551      "data":144,
   552      "message":""
   553  }
   554  ```
   555  ---
   556  
   557  ## **Query Balance**
   558  Get current balance of a specific address. 
   559  
   560  **URL**: 
   561  ```
   562  /query_balance
   563  ```
   564  
   565  **Method**: GET
   566  
   567  **请求参数**:  
   568  
   569  | 参数 | 数据类型 | 是否必填 | 备注
   570  | --- | --- | --- | ---
   571  | address | hex string | 是 | 
   572  
   573  **请求示例**:
   574  > /query_balance?address=96f4ac2f3215b80ea3a6466ebc1f268f6f1d5406
   575  
   576  **返回示例**:
   577  ```json
   578  {
   579      "data":{
   580          "balance":"8888888",
   581          "address":"0x96f4ac2f3215b80ea3a6466ebc1f268f6f1d5406"
   582      },
   583      "message":""
   584  }
   585  ```
   586  ---
   587  
   588  ## **Query Receipt**
   589  Get receipt of a transaction. 
   590  
   591  **URL**: 
   592  ```
   593  /query_receipt
   594  ```
   595  
   596  **Method**: GET
   597  
   598  **请求参数**:  
   599  
   600  | 参数 | 数据类型 | 是否必填 | 备注
   601  | --- | --- | --- | ---
   602  | hash | hex string | 是 | 
   603  
   604  **请求示例**:
   605  > /query_receipt?hash=0x0a0e69f4bd4c027e8ec0d6ab20eda7c8558c9a5ea690aa25b5e1cd72c67f444a
   606  
   607  **返回示例**:
   608  ```json
   609  {
   610      "data":{
   611          "tx_hash":"0x0a0e69...67f444a",
   612          "status":1,
   613          "result":"",
   614          "contract_address":"0x0000...0000000"
   615      },
   616      "message":""
   617  }
   618  ```
   619  ---
   620  
   621  ## **Query Contract**
   622  Query data from a contract.
   623  
   624  **URL**:
   625  ```
   626  /query_contract
   627  ```
   628  
   629  **Method**: POST
   630  
   631  **请求参数**:  
   632  
   633  | 参数 | 数据类型 | 是否必填 | 备注
   634  | --- | --- | --- | ---
   635  | address | hex string | 是 | 
   636  | data | hex string | 是 | 
   637  
   638  **请求示例**:
   639  ```json
   640  {
   641      "address": "0x0123456789000000000000000000000000000000",
   642      "data": "0x5682aec..."
   643  }
   644  ```
   645  
   646  **返回示例**:
   647  ```json
   648  {
   649      "data": "0x000000000000000000000000000000000000000000000000000000000000000a",
   650      "message":""
   651  }
   652  ```
   653