Skip to content

Instantly share code, notes, and snippets.

@luren5
Last active August 25, 2017 11:25
Show Gist options
  • Save luren5/4870343f4103311db0fe11682af48898 to your computer and use it in GitHub Desktop.
Save luren5/4870343f4103311db0fe11682af48898 to your computer and use it in GitHub Desktop.
接口文档

列表内容说明: 列表内容是目前为止,域链浏览器、钱包客户端在应用层(基于以太坊链)开发过程中总结的接口需求,需要 L0 帮忙确认以下接口需求哪些可以提供,哪些不能提供,如果不能提供,是否可以有相应的解决办法(eg: 接口组合使用),以便在详细接口提供之前我们可以并行的进行结构调整。

根据 地址 获取交易列表 不支持(自动维护)

获取发布但未打包交易列表: 以太坊中的 pending 状态交易 此接口通过 websocket 实时推送,无需输入有新的交易即推送,消息格式如下

{
	ID: “msg ID”,
	Type: MsgNewTx,
	Content: txHash,
	Time: 消息时间戳,
}

新区块产生通知,同上实时推送,消息格式如下

{
	ID: “msg ID”,
	Type: MsgNewTx,
	Content: blockHash,
	Time: 消息时间戳,
}

账户余额(或未使用输出)的变更通知 不支持(自动维护)

交易详情接口: GetTransaction() // Func: GetTransaction 输入:

{
“id” :  2, 
“method”: “BlockChain.GetRawTransaction,
“params”: [{ “TxHash”:  “hash_value”}],
}

输出:

 {
“id”: 2,
“result”: {
“TxHash”: “dfahufdha892347312470873471hsdjklfhawdjfhadslfh”,
“VIn”:  [{
“PkScript”: “5678834472752”,
“Value”: 2,
“Version”:  1,
},],
“Vout”:  [{
“Hash”: “3740q75edfhasdfnadfafvnadspija”,
“Index”: 2,
“Sign”: “fdjaf8adfjadfjapfud89fu341rasdfa”,
},],
“Version”:  1,
“LockTime”: 0,
“Time”: 86754474,
“BlockTime”: 86754474,
“BlockHash”: “adofyhapfghadpoghaipfure89123dfjafia89p8f”,
“Confirmations”: 19,
}
“error”: null
}

交易发送: 通过以太坊的设计,可以实现用户在本地(client), 使用自己的私钥进行交易数据的签名, 然后调用交易发送方法(Server)传递签名结果即可发送交易。 // SendTransaction() 输入:

{
“id” :  2, 
“method”: “BlockChain.SendTransaction,
“params”: [{ “TxHex”:  “TxHex_value”}],
}

输出:

 {
“id”:  2,
“result”: “{
“Result”: true,
}”,
“error”: null,
}

//获取区块详情 GetBlockByHash() 输入:

{
“id” :  2, 
“method”: “BlockChain.GetBlock,
“params”: [{ “BlockHash”:  “BlockHash_value”}],
}

输出:

 {
“id” : 2,
“result”: {
BlockHash: “fadsfjadsf8eqrjef8asdfuadfasdfadsfa8”,
“Version”: 1,
“MerkleRoot”: “fjasdfj8qfarpfu8arwsefq8”,
“PreviousHash”: “dfya97fjas89fuyq08herfgper”,
“Nonce”: 43701,
“Time”: 438574275,
“Confirmations”: 34,
“Height”: 3454,
“Size”: 4313,
“Difficulty”: 0.33,
“NextHash”: “345702308567dfjasdghadfuiosfgharfdf”,
}
}

//以高度获取区块详情 GetBlockByHeight() 输入:

{
“id” :  2, 
“method”: “BlockChain.GetBlock,
“params”: [{ “BlockHeight”:  “block_height”}],
}

输出:

{
同上
}

//获取下一个区块的哈希通过 // GetNextBlockHash() 输入:

{
“id” :  2, 
“method”: “BlockChain.GetNextBlockHash,
“params”: [{ “BlockHash”:  “BlockHash_value”}],    //当前区块的哈希值
}

输出:

 {
“id” : 2,
“result”: {
“NextBlockHash”: “jsdfyw04yr7812h8fjedf8uyq24038ryhseifh”,
}
“error”: null
}

//获取当前最好区块信息 //GetBestBlockInfo() 输入:

{
“id” :  2, 
“method”: “BlockChain.GetBestBlockInfo,
“params”: [“”],    
}

输出:

 {
“id” : 2,
“result”: {
“BlockHash”: “jsdfyw04yr7812h8fjedf8uyq24038ryhseifh”,
“BlockHeight”: 456,
}
“error”: null
}

其他RPC接口:

GetLocalNodeInfo()
Get

==钱包相关json rpc==

  • 创建账户 输入
{
     "id": id,
      "method": "Account.Create",
      "params": [{"Passphrase": "123456"}]
}

输出

{
     "id": id,
      "result": "new address",
      "error": "null"
}
  • 修改账户密码 输入
{
     "id": id,
      "method": "Account.ChangePass",
      "params": [{"Address":  "address",  "Passphrase": "123456"}]
}

输出

{
  "id": id,
  "result": "",
  "error": null
}

根据error信息判断是否修改成功

  • 创建交易
待定
  • 签名交易 此接口只用于交易发起账户的私钥存在于钱包中的情况 输入
{
    id: id,
    method: "Account.Sign"
    params: [{"Addr": "address", "Pass": "123456", "OriginTx": "origin data"}]
}

输出

{
    "id": 1,
    "result": "signed tx data",
    "error": null
}
  • 新增监听地址 (钱包只管理和存储指定的地址相关的数据) 输入
{
    id: id,
    method: "Account.Register",
    params: ["addr1", "addr2", …]
}

输出

{
    "id": 1,
    "result": "",
    "error": null
}

根据error判断是否注册成功

  • 获取指定地址相关交易 输入
{
    id: id,
    method: "Transaction.GetByAddr",
    params: ["addr"]
}

输出

{
    "id": 1,
    "result": ["tx1", "tx2", "tx3"],
    "error": null
}
  • 获取指定地址相关的可用UTXO 输入
{
    id: id,
    method: "UTXO.GetByAddr",
    params: ["addr"]
}

输出

{
    "id": 1,
    "result": ["utxo1", "utxo2", "utxo3"],
    "error": null
}
  • 获取指定地址的余额 输入
{
    id: id,
    method: "Account.GetBalance",
    params: ["addr"]
}

输出

{
    "id": 1,
    "result": ["balance"],
    "error": null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment