Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP API 接口 #1

Open
clarenous opened this issue Mar 5, 2019 · 5 comments
Open

HTTP API 接口 #1

clarenous opened this issue Mar 5, 2019 · 5 comments

Comments

@clarenous
Copy link
Owner

clarenous commented Mar 5, 2019

区块数据 (blocks)

关于 path 中的 id 字段,表示块哈希时应拼接为 "hash-1a4def82...",表示块高度时应拼接为 "height-123"

GET /v1/blocks/best

获取区块链的当前最新块。

request

null

response

{
    "hash" : "af1234d...",
    "height" : "12345"
}

GET /v1/blocks/{id}

按块哈希或块高度获取区块的主要信息。

request

"id" : 可为 Hex 型的块哈希,也可为十进制的块高度。

response

{
    "hash" : "af1234d...",
    "chain_id" : "ec1235a...",
    "version" : "1",
    "height" : "123",
    "timestamp" : "21344445",
    "previous" : "af1234d...",
    "transaction_root" : "afa2ecd...",
    "witness_root" : "af12c4d...",
    "proof" : {
        "target" : "123455",
        "nonce" : "12345"
    },
    "transactions" : [
        "af123e...",
        "cd123e..."
    ],
    "evidences" : [
        "ec123e...",
        "ec124e..."
    ]
}

GET /v1/blocks/{id}/header

按块哈希或块高度获取区块的区块头。

request

"id" : 可为 Hex 型的块哈希,也可为十进制的块高度。

response

{
    "hash" : "af1234d...",
    "chain_id" : "ec1235a...",
    "version" : "1",
    "height" : "123",
    "timestamp" : "21344445",
    "previous" : "af1234d...",
    "transaction_root" : "afa2ecd...",
    "witness_root" : "af12c4d...",
    "proof" : {
        "target" : "123455",
        "nonce" : "12345"
    }
}

GET /v1/blocks/{id}/verbose/{verbose}

按块哈希或块高度获取区块的详细信息,详细等级由 verbose 确定。

request

"id" : 可为 Hex 型的块哈希,也可为十进制的块高度,
"verbose" : 十进制的数字

response

当 verbose == 0 时,返回值如下:

{
    "hash" : "af1234d...",
    "chain_id" : "ec1235a...",
    "version" : "1",
    "height" : "123",
    "timestamp" : "21344445",
    "previous" : "af1234d...",
    "transaction_root" : "afa2ecd...",
    "witness_root" : "af12c4d...",
    "proof" : {
        "target" : "123455",
        "nonce" : "12345"
    },
    "transactions" : [
        {
            "txid" : "ec123e...",
            "evidences" : [
                "ec123e...",
                "ec124e..."
            ]
        }
    ],

}

当 verbose == 1 时,返回值如下:

{
    "hash" : "af1234d...",
    "chain_id" : "ec1235a...",
    "version" : "1",
    "height" : "123",
    "timestamp" : "21344445",
    "previous" : "af1234d...",
    "transaction_root" : "afa2ecd...",
    "witness_root" : "af12c4d...",
    "proof" : {
        "target" : "123455",
        "nonce" : "12345"
    },
    "transactions" : [
        {
            "txid" : "af1234d...",
            "version" : "1",
            "inputs" : [
                {
                    "value_source" : {
                        "txid" : "string",
                        "index" : "2"
                    },
                    "redeem_script" : "string",
                    "unlock_script" : "string",
                    "sequence" : "string",
                }
            ],
            "outputs" : [
                {
                    "value" : "123",
                    "script_hash" : "string"
                }
            ],
            "evidences" : [
                {
                    "evid" : "af1234d...",
                    "digest" : "hex_string",
                    "source" : "hex_string",
                    "valid_script" : "hex_string"
                }
            ],
            "lock_time" : "12345"
        }
    ]
}
@clarenous
Copy link
Owner Author

clarenous commented Mar 31, 2019

交易数据 (transactions)

GET /v1/transactions/{txid}

按照 txid 获取交易的详细信息。

request

"txid" : 即交易的哈希值

response

{
    "txid" : "af1234d...",
    "version" : "1",
    "inputs" : [
        {
            "value_source" : {
                "txid" : "string",
                "index" : "2"
            },
            "redeem_script" : "string",
            "unlock_script" : "string",
            "sequence" : "string",
        }
    ],
    "outputs" : [
        {
            "value" : "123",
            "script_hash" : "string"
        }
    ],
    "evidences" : [
        {
            "evid" : "af1234d...",
            "digest" : "hex_string",
            "source" : "hex_string",
            "valid_script" : "hex_string"
        }
    ],
    "lock_time" : "12345"
}

@clarenous
Copy link
Owner Author

clarenous commented Mar 31, 2019

凭证数据 (evidences)

GET /v1/evidences/{evid}

按照 evid 获取凭证的详细信息。

request

"evid" : 即凭证的唯一 ID

response

{
    "evid" : "af1234d...",
    "digest" : "hex_string",
    "source" : "hex_string",
    "valid_script" : "hex_string"
}

@clarenous
Copy link
Owner Author

clarenous commented Mar 31, 2019

@Qearlyy 目前根据你的设计,重点关注以下几个接口即可:

GET /v1/blocks/best
GET /v1/blocks/{id}
GET /v1/blocks/{id}/verbose/{verbose}
GET /v1/transactions/{txid}
GET /v1/evidences/{evid}

@clarenous
Copy link
Owner Author

clarenous commented Apr 30, 2019

钱包数据 (wallet)

GET /v1/wallet/status

获取钱包的基础信息。

request

response

{
    "tx_count" : 123,
    "evid_count" : 123,
    "balance" : "float64_in_string"
}

GET /v1/wallet/addresses

获取钱包内的所有地址和地址对应的余额。

request

response

{
    "addresses" : [
      {
         "address" : "address_in_string",
         "balance" : "balance_in_float64"
      }
   ] 
}

GET /v1/wallet/balance

获取钱包内的总余额。

request

response

{
    "balance" : "float64_in_string"
}

GET /v1/wallet/transactions

获取钱包内地址相关的所有交易 ID。

request

response

{
    "transactions" : [
        "txid_in_string",
        "txid_in_string"
    ]
}

GET /v1/wallet/evidences

获取钱包内地址相关的所有存证 ID。

request

response

{
    "evidences" : [
        "evid_in_string",
        "evid_in_string"
    ]
}

POST /v1/wallet/addresses

在钱包中创建新的交易地址。

request

{
    "password" : "string"
}

response

{
    "address" : "string",
    "success" : true,
    "error" : "string",
}

POST /v1/wallet/transactions/creating

创建交易。

request

{
    "to_address" : "address",
    "value" : "float64_in_string",
    "file" : "file_path",
    "digest_mode" : "string"
}

response

{
    "hex" : "hex_string",
    "success" : true,
    "error" : "string"
}

POST /v1/wallet/transactions/sending

签名并发送交易。

request

{
    "hex" : "hex_string",
    "password" : "string"
}

response

{
    "txid" : "txid_in_string",
    "success" : true,
    "error" : "string"
}

@clarenous
Copy link
Owner Author

clarenous commented Apr 30, 2019

客户端数据 (client)

GET /v1/client/status

获取客户端状态。

request

response

{
    "local_block_height" : "uint64_in_string",
    "known_block_height" : "uint64_in_string",
    "mining" : true,
    "peer_listening" : true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant