Store
简述
存证功能是将 数据信息 通过交易的方式存储到区块链上。
账户信息
账户地址为: 0xffffffffffffffffffffffffffffffffff010000
注: CITA 系统会将所有发送至该账户地址的交易默认为 存证 交易。
操作示例
首先需要启动一条链
通过以下命令初始化一条链,生成配置文件:
$ bin/cita create \
--super_admin "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523" \
--nodes "127.0.0.1:4000,127.0.0.1:4001,127.0.0.1:4002,127.0.0.1:4003"
启动链接下来的步骤见启动 CITA部分。
为了简化操作,以下将用 cita-cli 命令行模式进行演示。 所涉及的 JSON-RPC 接口,将在过程中做简要的说明,详细使用方式请参考 JSON-RPC 说明 。
发送数据存证交易
使用默认私钥进行演示
- 发送交易
store data --content 0x3474524832041587483261437874876510837787487658976141347658716817365465984753489650 --private-key 0x5f0258a4778057a8a7d97809bd209055b2fbafa654ce7d31ec7191066b9225e6
输出:
{
"id": 4,
"jsonrpc": "2.0",
"result": {
"hash": "0xfeda91e7cd688d01838db6114126fa7e99d41dc96b009a3014e368d727628b1b",
"status": "OK"
}
}
- 获取交易回执
rpc getTransactionReceipt --hash 0xfeda91e7cd688d01838db6114126fa7e99d41dc96b009a3014e368d727628b1b
输出:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockHash": "0xa2f815cd85d1c8957ee1864a5c2a16ceab65de9c20cdc39a2b092a357f9e6fd3",
"blockNumber": "0x54f",
"contractAddress": null,
"cumulativeQuotaUsed": "0x7210",
"errorMessage": null,
"logs": [
],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"quotaUsed": "0x7210",
"root": null,
"transactionHash": "0xfeda91e7cd688d01838db6114126fa7e99d41dc96b009a3014e368d727628b1b",
"transactionIndex": "0x0"
}
}
说明
- 以上操作将数据
0x3474524832041587483261437874876510837787487658976141347658716817365465984753489650
以交易形式存储到了 区块链上; - 所存储的数据为 16 进制数据,应用层的数据需要用户自行转换与解析;
- 其中使用的 JSON-RPC 为
sendRawTransaction
; - 获取交易回执时,请使用实际交易 hash 获取。
- 以上操作将数据
查询存证内容
存证数据实际上是以 交易 形式存储在区块链中;所以,查看存证内容实际上就是根据交易 hash 查看交易内容。
- 查看交易内容
rpc getTransaction --hash 0xfeda91e7cd688d01838db6114126fa7e99d41dc96b009a3014e368d727628b1b
输出:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockHash": "0xa2f815cd85d1c8957ee1864a5c2a16ceab65de9c20cdc39a2b092a357f9e6fd3",
"blockNumber": "0x54f",
"content": "0x0ab101122064356565386436313239333634343735396462336265663561323132373366381880ade20420a50b2a2934745248320415874832614378748765108377874876589761413476587168173654659847534896503220000000000000000000000000000000000000000000000000000000000000000040014a14ffffffffffffffffffffffffffffffffff0100005220000000000000000000000000000000000000000000000000000000000000000112415c2b3ee0c4d42e34f64b315273ca043d2b4dd2067317dabb6c5c4c1423032408516e73bf1fcdcfb2a570f3d40f6a1a91c6eaa8cb2745f4b6c2acbc3937dc08e701",
"from": "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523",
"hash": "0xfeda91e7cd688d01838db6114126fa7e99d41dc96b009a3014e368d727628b1b",
"index": "0x0"
}
}
交易中的 content
域是存证的数据,由于交易数据是签名后数据,需要进行相应的解析,才能看到所存储的原始数据。
- 解析 content 数据
tx decode-unverifiedTransaction --content 0x0ab101122064356565386436313239333634343735396462336265663561323132373366381880ade20420a50b2a2934745248320415874832614378748765108377874876589761413476587168173654659847534896503220000000000000000000000000000000000000000000000000000000000000000040014a14ffffffffffffffffffffffffffffffffff0100005220000000000000000000000000000000000000000000000000000000000000000112415c2b3ee0c4d42e34f64b315273ca043d2b4dd2067317dabb6c5c4c1423032408516e73bf1fcdcfb2a570f3d40f6a1a91c6eaa8cb2745f4b6c2acbc3937dc08e701
输出:
{
"crypto": 0,
"signature": "0x5c2b3ee0c4d42e34f64b315273ca043d2b4dd2067317dabb6c5c4c1423032408516e73bf1fcdcfb2a570f3d40f6a1a91c6eaa8cb2745f4b6c2acbc3937dc08e701",
"transaction": {
"chain_id": 0,
"chain_id_v1": "0x0000000000000000000000000000000000000000000000000000000000000001",
"data": "0x3474524832041587483261437874876510837787487658976141347658716817365465984753489650",
"encrypted_hash": "0x35630be9e9062c0cba0d59b9c9faa05389bceb1b0015db75c3852799d5b97b30",
"nonce": "d5ee8d61293644759db3bef5a21273f8",
"pub_key": "0xd2bdee2f7bbf540e1bef0a081f317bc8d99eb0777e6fd9e30cc1ddc220a17a0c2a18d56b4c1727149a2571a4ad25f1ff58f631c6a4ab3cd518d2fd695313acc2",
"quota": 10000000,
"sender": "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523",
"to": "",
"to_v1": "0xffffffffffffffffffffffffffffffffff010000",
"valid_until_block": 1445,
"value": "0x0000000000000000000000000000000000000000000000000000000000000000",
"version": 1
}
}
其中,解析后的 data
域正是上文存证的原始数据。