diff --git a/bdchain/api/ac_chain.proto b/bdchain/api/ac_chain.proto index 6145943..4f946e6 100644 --- a/bdchain/api/ac_chain.proto +++ b/bdchain/api/ac_chain.proto @@ -39,7 +39,7 @@ message Block { uint64 number = 1; // 区块号,当区块处于待确认状态时为`null` bytes hash = 2; // 区块的哈希,当区块处于待确认状态时为`null` bytes parent_hash = 3; // 父区块的哈希 - bytes witness = 4; // 见证者账户地址 + repeated bytes witnesses = 4; // 见证者账户地址的数组 uint64 timestamp = 5; // 区块产生时的UNIX时间戳 uint64 size = 6; // 区块大小的字节数 bytes transactions_root = 7; // 区块的事务树根 diff --git a/bdchain/api/tx_ledger.proto b/bdchain/api/tx_ledger.proto index 6c98478..10b6b55 100644 --- a/bdchain/api/tx_ledger.proto +++ b/bdchain/api/tx_ledger.proto @@ -14,9 +14,37 @@ service TransactionLedger { rpc ClientVersion (google.protobuf.Empty) returns (ClientVersionResponse); rpc CreateLedger (CreateLedgerRequest) returns (CreateLedgerResponse); rpc GetLedgers (google.protobuf.Empty) returns (GetLedgersResponse); + rpc BlockCount (BlockCountRequest) returns (BlockCountResponse); + rpc GetBlocks (GetBlocksRequest) returns (GetBlocksResponse); rpc SendTransaction (SendTransactionRequest) returns (SendTransactionResponse); } +message Transaction { + bytes block_hash = 1; // 事务所在的区块的哈希,当事务处于待确认状态时为`null` + uint32 index = 2; // 事务在区块中的位置index,当事务处于待确认状态时为`null` + bytes hash = 3; // 事务的哈希 + TransactionType type = 4; // 事务类型 + bytes from = 5; // 发送账户地址 + uint64 nonce = 6; // 这条事务之前发送者所发送的事务数量 + bytes to = 7; // 接收账户地址,或者调用的合约地址,或者`null`如为合约创建 + bytes data = 8; // 数据或合约代码 + bytes v = 9; // ECDSA recovery id + bytes r = 10; // ECDSA signature r + bytes s = 11; // ECDSA signature s +} + +message Block { + uint64 index = 1; // 事务链本地区块索引,当区块处于待确认状态时为`null` + bytes hash = 2; // 区块的哈希,当区块处于待确认状态时为`null` + repeated bytes parent_hashes = 3; // 父区块的哈希 + bytes witness = 4; // 见证者账户地址 + uint64 timestamp = 5; // 区块产生时的UNIX时间戳 + uint64 size = 6; // 区块大小的字节数 + bytes transactions_root = 7; // 区块的事务树根 + repeated Transaction transactions = 8; // 事务对象的数组,或为空 + repeated bytes transaction_hashes = 9; // 32字节的交易哈希的数组,或为空 +} + message CreateLedgerRequest { string name = 1; } @@ -28,6 +56,23 @@ message GetLedgersResponse { repeated string ledgers = 1; } +message BlockCountRequest { + string ledger = 1; +} +message BlockCountResponse { + uint64 block_count = 1; +} + +message GetBlocksRequest { + string ledger = 1; + uint64 from_index = 2; + uint32 count = 3; // Optional, default to 10, max value is 10 + bool full_transaction = 4; +} +message GetBlocksResponse { + repeated Block blocks = 1; +} + message SendTransactionRequest { string ledger = 1; message Transaction { diff --git a/test.md b/test.md index 7f4c446..66a81e5 100644 --- a/test.md +++ b/test.md @@ -20,7 +20,25 @@ enum TransactionType { } ``` -### Transaction +### Transaction (in Transaction ledger) + +```proto +message Transaction { + bytes block_hash = 1; // 事务所在的区块的哈希,当事务处于待确认状态时为`null` + uint32 index = 2; // 事务在区块中的位置index,当事务处于待确认状态时为`null` + bytes hash = 3; // 事务的哈希 + TransactionType type = 4; // 事务类型 + bytes from = 5; // 发送账户地址 + uint64 nonce = 6; // 这条事务之前发送者所发送的事务数量 + bytes to = 7; // 接收账户地址,或者调用的合约地址,或者`null`如为合约创建 + bytes data = 8; // 数据或合约代码 + bytes v = 9; // ECDSA recovery id + bytes r = 10; // ECDSA signature r + bytes s = 11; // ECDSA signature s +} +``` + +### Transaction (in Accounting chain) ```proto message Transaction { @@ -39,14 +57,30 @@ message Transaction { } ``` -### Block +### Block (in Transaction ledger) + +```proto +message Block { + uint64 index = 1; // 事务链本地区块索引,当区块处于待确认状态时为`null` + bytes hash = 2; // 区块的哈希,当区块处于待确认状态时为`null` + repeated bytes parent_hashes = 3; // 父区块的哈希 + bytes witness = 4; // 见证者账户地址 + uint64 timestamp = 5; // 区块产生时的UNIX时间戳 + uint64 size = 6; // 区块大小的字节数 + bytes transactions_root = 7; // 区块的事务树根 + repeated Transaction transactions = 8; // 事务对象的数组,或为空 + repeated bytes transaction_hashes = 9; // 32字节的交易哈希的数组,或为空 +} +``` + +### Block (in Accounting chain) ```proto message Block { uint64 number = 1; // 区块号,当区块处于待确认状态时为`null` bytes hash = 2; // 区块的哈希,当区块处于待确认状态时为`null` bytes parent_hash = 3; // 父区块的哈希 - bytes witness = 4; // 见证者账户地址 + repeated bytes witnesses = 4; // 见证者账户地址的数组 uint64 timestamp = 5; // 区块产生时的UNIX时间戳 uint64 size = 6; // 区块大小的字节数 bytes transactions_root = 7; // 区块的事务树根 @@ -178,6 +212,287 @@ ledgers: --- +### BlockCount + +#### Request + +```proto +message BlockCountRequest { + string ledger = 1; +} +``` + +#### Response + +```proto +message BlockCountResponse { + uint64 block_count = 1; +} +``` + +#### Test cases + +##### 1 + +**Request** +```yaml +ledger: 'test' +``` + +**Response** +```yaml +block_count: 2018 +``` + +##### 2 + +**Request** + +Client: +```yaml +ledger: null +``` +On the wire: +```yaml +ledger: '' (defualt value) +``` + +**Error** +```yaml +code: Code.InvalidArgument +message: 'ledger must not be empty' +details: +``` + +--- + +### GetBlocks + +#### Request + +```proto +message GetBlocksRequest { + string ledger = 1; + uint64 from_index = 2; + uint32 count = 3; // Optional, default to 10, max value is 10 + bool full_transaction = 4; +} +``` + +#### Response + +```proto +message GetBlocksResponse { + repeated Block blocks = 1; +} +``` + +#### Test cases + +##### 1 + +**Request** +```yaml +ledger: 'test' +from_index: 2018 +count: 1 +full_transactions: true +``` + +**Response** +```yaml +blocks: + - index: 2018 + hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + - block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) + index: 0 + hash: 0x0404040404040404040404040404040404040404 (in bytes) + type: TransactionType.RECORD + from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) + nonce: 2018 + to: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) + data: 0xdeadbeef (in bytes) + v: 0x25 (in bytes) + r: 0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea (in bytes) + s: 0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c (in bytes) + - block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) + index: 1 + hash: 0x1313131313131313131313131313131313131313 (in bytes) + type: TransactionType.MESSAGE + from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) + nonce: 2019 + to: 0xfeedbabefeedbabefeedbabefeedbabefeedbabe (in bytes) + data: (empty bytes, default value) + v: 0x25 (in bytes) + r: 0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea (in bytes) + s: 0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c (in bytes) + transaction_hashes: +``` + +##### 2 + +**Request** +```yaml +ledger: 'test' +from_index: 2018 +``` + +**Response** +```yaml +blocks: + - index: 2018 + hash: 0x0101010101010101010101010101010101010101 (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + transaction_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - index: 2019 + hash: 0x0202020202020202020202020202020202020202 (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + transaction_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - index: 2020 + hash: 0x0303030303030303030303030303030303030303 (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + transaction_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - index: 2021 + hash: 0x0404040404040404040404040404040404040404 (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + transaction_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - index: 2022 + hash: 0x0505050505050505050505050505050505050505 (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + transaction_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - index: 2023 + hash: 0x0606060606060606060606060606060606060606 (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + transaction_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - index: 2024 + hash: 0x0707070707070707070707070707070707070707 (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + transaction_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - index: 2025 + hash: 0x0808080808080808080808080808080808080808 (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + transaction_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - index: 2026 + hash: 0x0909090909090909090909090909090909090909 (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + transaction_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - index: 2027 + hash: 0x1010101010101010101010101010101010101010101010101010101010101010 (in bytes) + parent_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) + witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) + timestamp: 2018050400000 + size: 20180504 + transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) + transactions: + transaction_hashes: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) +``` + +--- + ### SendTransaction #### Request @@ -366,17 +681,20 @@ full_transaction: true **Response** ```yaml number: 2018 -hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) -parent_hash: 0xbabefacebabefacebabefacebabefacebabefacebabefacebabefacebabeface (in bytes) -witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) +hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) +parent_hash: 0xbabefacebabefacebabefacebabefacebabeface (in bytes) +witnesses: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) timestamp: 2018050400000 size: 20180504 -transactions_root: 0x50bada5550bada5550bada5550bada5550bada5550bada5550bada5550bada55 (in bytes) +transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) transactions: - block_number: 2018 - block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) + block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 0 - hash: 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes) + hash: 0x0404040404040404040404040404040404040404 (in bytes) type: TransactionType.RECORD from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2018 @@ -386,9 +704,9 @@ transactions: r: 0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea (in bytes) s: 0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c (in bytes) - block_number: 2018 - block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) + block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 1 - hash: 0x1313131313131313131313131313131313131313131313131313131313131313 (in bytes) + hash: 0x1313131313131313131313131313131313131313 (in bytes) type: TransactionType.MESSAGE from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2019 @@ -420,16 +738,19 @@ full_transaction: false (defualt value) **Response** ```yaml number: 2018 -hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) -parent_hash: 0xbabefacebabefacebabefacebabefacebabefacebabefacebabefacebabeface (in bytes) -witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) +hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) +parent_hash: 0xbabefacebabefacebabefacebabefacebabeface (in bytes) +witnesses: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) timestamp: 2018050400000 size: 20180504 -transactions_root: 0x50bada5550bada5550bada5550bada5550bada5550bada5550bada5550bada55 (in bytes) +transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) transactions: transaction_hashes: - - 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes) - - 0x1313131313131313131313131313131313131313131313131313131313131313 (in bytes) + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) ``` --- @@ -459,23 +780,26 @@ Block **Request** ```yaml ledger: 'test' -hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) +hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) full_transaction: false ``` **Response** ```yaml number: 2018 -hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) -parent_hash: 0xbabefacebabefacebabefacebabefacebabefacebabefacebabefacebabeface (in bytes) -witness: 0x1fee1bad1fee1bad1fee1bad1fee1bad1fee1bad (in bytes) +hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) +parent_hash: 0xbabefacebabefacebabefacebabefacebabeface (in bytes) +witnesses: + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) + - 0x5252525252525252525252525252525252525252 (in bytes) timestamp: 2018050400000 size: 20180504 -transactions_root: 0x50bada5550bada5550bada5550bada5550bada5550bada5550bada5550bada55 (in bytes) +transactions_root: 0x50bada5550bada5550bada5550bada5550bada55 (in bytes) transactions: transaction_hashes: - - 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes) - - 0x1313131313131313131313131313131313131313131313131313131313131313 (in bytes) + - 0x0404040404040404040404040404040404040404 (in bytes) + - 0x1313131313131313131313131313131313131313 (in bytes) ``` --- @@ -504,15 +828,15 @@ Transaction **Request** ```yaml ledger: 'test' -hash: 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes) +hash: 0x0404040404040404040404040404040404040404 (in bytes) ``` **Response** ```yaml block_number: 2018 -block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) +block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 0 -hash: 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes) +hash: 0x0404040404040404040404040404040404040404 (in bytes) type: TransactionType.RECORD from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2018 @@ -557,9 +881,9 @@ index: 0 **Response** ```yaml block_number: 2018 -block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) +block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 0 -hash: 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes) +hash: 0x0404040404040404040404040404040404040404 (in bytes) type: TransactionType.RECORD from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2018 @@ -597,16 +921,16 @@ Transaction **Request** ```yaml ledger: 'test' -block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) +block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 0 ``` **Response** ```yaml block_number: 2018 -block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) +block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 0 -hash: 0x0404040404040404040404040404040404040404040404040404040404040404 (in bytes) +hash: 0x0404040404040404040404040404040404040404 (in bytes) type: TransactionType.RECORD from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2018