OSDN Git Service

update fedProg (#330)
[bytom/vapor.git] / docs / federation / README-en.md
1 # Federation
2
3 To run a federation node, you will need to:
4
5 1. init a MySQL database with this [schema](./federation.sql);
6 2. run a `bytomd` node;
7 3. run a `vapord` node and import the federation private key;
8 4. and last but not least, run a `fedd` node with a `fed_cfg.json` and it will listen at 9886 port.
9
10 A `fed_cfg.json` would look like this:
11
12 ```json
13 {
14     "api" : {
15         "is_release_mode": false
16     },
17     "mysql" : {
18         "connection" : {
19             "host": "127.0.0.1",
20             "port": 3306,
21             "username": "root",
22             "password": "",
23             "database": "federation"
24         },
25         "log_mode" : true
26     },
27     "network" : "testnet",
28     "federation_prog" : "0020f86826d640810eb08a2bfb706e0092273e05e9a7d3d71f9d53f4f6cc2e3d6c6a",
29     "mainchain" : {
30         "name" : "btm",
31         "confirmations" : 10,
32         "upstream" : "http://127.0.0.1:9888",
33         "sync_seconds" : 150
34     },
35     "sidechain" : {
36         "name" : "vapor",
37         "confirmations" : 100,
38         "upstream" : "http://127.0.0.1:9889",
39         "sync_seconds" : 5
40     }
41 }
42 ```
43 ## API
44 A federation node can function as an api server for querying cross-chain transactions.
45
46 The default JSON-RPC endpoint is: [http://host:port/api/v1/federation/](http://host:port/api/v1/federation/)
47
48 The response contains some meta data of:
49
50 + success/error status, which can be told from `code` and `msg`;
51 + pagination info, which can be told from `start`, `limit` and `_links` (`_links` is used to look up the preceding and the succeeding items);
52
53 and looks like:
54 ```
55 {
56   "code":200,
57   "msg":"",
58   "result":{
59     "_links":{
60     },
61     "data":...,
62     "limit":10,
63     "start":0
64   }
65 }
66 ```
67
68 If a request succeed, `data` field contains the detailed result as an object or as an array of objects.
69
70 ### Pagination
71
72 Append `?start=<integer>&limit=<integer>` to the url in order to use pagination.
73
74 ### Methods
75
76 #### `/list-crosschain-txs`
77
78 To list cross-chain transactions and filter the transactions.
79
80 ##### Parameters
81
82 Optional:
83
84 - `Object` - *filter*, transactions filter.
85     + Optional
86         * `String` - *status*, transactions status, which can be `pending` or `completed`.
87         * `String` - *source_chain_name*, transactions source chain, which can be `bytom` or `vapor`.
88         * `String` - *address*, filter cross-chain requests by address. The address can be either a mainchain or a sidechain one. Note that other requests in such a transaction will also be filtered. 
89         * `String` - *source_tx_hash*, souce transaction hash string.
90         * `String` - *dest_tx_hash*, destination transaction hash string.
91 - `Object` - *sort*, transactions sorter.
92     + Optional
93         * `String` - *order*, transactions order sorter, which can be `asc` or `desc`.
94
95
96 ##### Returns
97
98
99 `Object`:
100
101 - `String` - *source_chain_name*, source chain name of the cross-chain transaction.
102 - `Integer` - *source_block_height*, block height of the cross-chain transaction on the source chain.
103 - `Integer` - *source_block_timestamp*, block timestamp of the cross-chain transaction on the source chain.
104 - `String` - *source_block_hash*, block hash of the cross-chain transaction on the source chain.
105 - `Integer` - *source_tx_index*, transaction index in the source block.
106 - `String` - *source_tx_hash*, source transaction hash.
107 - `Integer` - *dest_block_height*, block height of the cross-chain transaction on the destination chain, `0` if `status` is `pending`.
108 - `Integer` - *dest_block_timestamp*, block timestamp of the cross-chain transaction on the destination chain, `0` if `status` is `pending`.
109 - `String` - *dest_block_hash*, block hash of the cross-chain transaction on the destination chain, empty string if `status` is `pending`.
110 - `Integer` - *dest_tx_index*, transaction index in the destination block, `0` if `status` is `pending`.
111 - `String` - *dest_tx_hash*, destination transaction hash, empty string if `status` is `pending`.
112 - `String` - *status*, cross-chain transaction status, can be `pending` or `completed`.
113 - `Array of objects` - *crosschain_requests*, asset transfer details per request included in the cross-chain transaction.
114     + `Integer` - *amount*, asset transfer amount.
115     + `String` - *from_address*, source address.
116     + `String` - *to_address*, destination address.
117     + `Object` - *asset*, asset detail.
118         * `String` - *asset_id*, asset id string.
119
120 ##### Example
121
122 ```js
123 // Request
124 curl -X POST 127.0.0.1:9886/api/v1/federation/list-crosschain-txs -d '{}'
125
126 // Result
127 {
128   "code":200,
129   "msg":"",
130   "result":{
131     "_links":{
132
133     },
134     "data":[
135       {
136         "source_chain_name":"bytom",
137         "source_block_height":174,
138         "source_block_timestamp":1561457348,
139         "source_block_hash":"569a3a5a43910ea634a947fd092bb3085359db451235ae59c20daab4e4b0d274",
140         "source_tx_index":1,
141         "source_tx_hash":"584d1dcc4dfe741bb3ae5b193896b08db469169e6fd76098eac132af628a3183",
142         "dest_block_height":0,
143         "dest_block_timestamp":0,
144         "dest_block_hash":"",
145         "dest_tx_index":0,
146         "dest_tx_hash":"",
147         "status":"pending",
148         "crosschain_requests":[
149           {
150             "amount":1000000,
151             "from_address":"bm1qf872k7nr8pwjt4afx60m2wwz5hwj2tu4jaxm9g",
152             "to_address":"vp1qf872k7nr8pwjt4afx60m2wwz5hwj2tu4eukxq7",
153             "asset":{
154               "asset_id":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
155             }
156           }
157         ]
158       }
159     ],
160     "limit":10,
161     "start":0
162   }
163 }
164 ```