Skip to content

crossChain Bridge API

cross-chain edited this page May 23, 2020 · 4 revisions

crossChain-Bridge API

JSON RPC API Reference

RESTful API Reference

JSON RPC API Reference

JSON PRC API 通用调用格式:

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"方法名","params":参数,"id":1}' SERVER_URL

其中,SERVER_URL格式为http://host:port/rpc

成功返回的通用格式:

{"jsonrpc":"2.0","result":返回值,"id":1}

错误返回的通用格式:

{"jsonrpc":"2.0","error":{"code":错误码,"message":"错误信息","data":附加备注},"id":1}

以下为了简洁对每个 API 说明只列出参数返回值两项

swap.Swapin
swap.Swapout
swap.RecallSwapin
swap.GetServerInfo
swap.GetSwapStatistics
swap.GetSwapin
swap.GetSwapout
swap.GetSwapinHistory
swap.GetSwapoutHistory
swap.BuildSwapoutTx

swap.Swapin

申请换进置换

参数:
["充值交易哈希"]
返回值:
成功返回`Success`,失败返回错误。

swap.Swapout

申请换出置换

参数:
["销毁交易哈希"]
返回值:
成功返回`Success`,失败返回错误。

swap.RecallSwapin

申请撤消换进置换(只有在往共管账户中充值的交易中忘记填写交易备注或者备注格式错误时才能撤消)

参数:
["充值交易哈希"]
返回值:
成功返回`Success`,失败返回错误。

swap.GetServerInfo

查询服务信息

参数:
[] (空)
返回值:
成功返回服务信息,失败返回错误。

swap.GetSwapStatistics

查询统计信息

参数:
[] (空)
返回值:
成功返回统计信息,失败返回错误。

swap.GetSwapin

查询换进置换

参数:
["充值交易哈希"]
返回值:
成功返回换进置换信息,失败返回错误。

swap.GetSwapout

查询换出置换

参数:
["销毁交易哈希"]
返回值:
成功返回换出置换信息,失败返回错误。

swap.GetSwapinHistory

查询换进置换历史,支持分页,从 offset (默认0) 开始选取前 limit (默认20) 项

参数:
[{"address":"账户地址", "offset":offset, "limit":limit}]
返回值:
成功返回换进置换历史,失败返回错误。

swap.GetSwapoutHistory

查询换出置换历史,支持分页,从 offset (默认0) 开始选取前 limit (默认20) 项

参数:
[{"address":"账户地址", "offset":offset, "limit":limit}]
返回值:
成功返回换出置换历史,失败返回错误。

swap.BuildSwapoutTx

构建换出置换未签名交易

参数:
[{"from":"账户地址","value":"数额","bind":"绑定地址","gas":"燃油上限", "gasPrice":"燃油费","nonce":"账户nonce"}]

bind 为源链上的接收地址(例如比特币p2pkh地址)
value, gas, gasPrice, nonce 取值均为十六进制数字符串
from, value, bind 为必填参数
返回值:
成功返回求签名交易对象,失败返回错误。
示例:
curl -X POST -H "Content-Type":application/json --data '{"jsonrpc":"2.0","method":"swap.BuildSwapoutTx","params":
[{"from":"0x46CBe22b687d4B72c8913e4784DFE5B20FdC2B0E","value":"0x100","bind":"mmiApsjjnceZ7Cx1UMj344JRU3R8A2SYy6",
"gas":"0x15f90", "gasPrice":"0x3b9aca00","nonce":"0x10"}],"id":1}' http://localhost:11556/rpc

{
  "jsonrpc": "2.0",
  "result": {
    "nonce": "0x10",
    "gasPrice": "0x3b9aca00",
    "gas": "0x15f90",
    "to": "0x36793680e55bff3795c0dbad6eb0510a2d06ff42",
    "value": "0x0",
    "input": "0xad54056d0000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000226d6d694170736a6a6e63655a37437831554d6a3334344a5255335238413253597936000000000000000000000000000000000000000000000000000000000000",
    "v": "0x0",
    "r": "0x0",
    "s": "0x0",
    "hash": "0xb894913875744cf6b1d9d7ac9dbe0e5d62831a9a6752aad1a2db6f1369c5a8f6"
  },
  "id": 1
}

RESTful API Reference

GEt /serverinfo

查询服务信息

GET /statistics

查询统计信息

GET /swapin/{txid}

查询换进置换,txid 为充值交易哈希

GET /swapout/{txid}

查询换出置换,txid 为销毁交易哈希

GET /swapin/history/{address}?offset=0&limit=20

查询换进置换历史,支持分页,addess 为账户地址

GET /swapout/history/{address}?offset=0&limit=20

查询换出置换历史,支持分页,addess 为账户地址

POST /swapin/post/{txid}

申请换进置换,txid 为充值交易哈希

POST /swapout/post/{txid}

申请换出置换,txid 为销毁交易哈希

POST /swapin/recall/{txid}

申请撤消换进置换,txid 为充值交易哈希(只有在往共管账户中充值的交易中忘记填写交易备注或者备注格式错误时才能撤消)