OSDN Git Service

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