diff --git a/bdledger/api/common.proto b/bdledger/api/common.proto index 80ca0f7..3ad65e0 100644 --- a/bdledger/api/common.proto +++ b/bdledger/api/common.proto @@ -1,15 +1,13 @@ syntax = "proto3"; -package bdledger.api.common; +package bdledger.api; -option go_package = "bdware.org/bdledger/sdk/api/grpc/common"; +option go_package = "bdware.org/bdledger/pkg/api/grpc/proto"; option java_package = "bdledger.api.grpc.common"; option java_outer_classname = "CommonProto"; option java_multiple_files = true; -message ClientVersionResponse { - string version = 1; // 节点客户端版本 -} + /* 事务类型 */ enum TransactionType { @@ -24,7 +22,7 @@ message Transaction { bytes block_hash = 1; // 事务所在的区块的哈希,当事务处于待确认状态时为`null` uint32 index = 2; // 事务在区块中的位置 index,当事务处于待确认状态时为`null` bytes hash = 3; // 事务的哈希 - common.TransactionType type = 4; // 事务类型 + TransactionType type = 4; // 事务类型 bytes from = 5; // 发送账户地址 uint64 nonce = 6; // 这条事务之前发送者所发送的事务数量 bytes to = 7; // 接收账户地址,或者调用的合约地址,或者`null`如为合约创建 diff --git a/bdledger/api/error_details.proto b/bdledger/api/error_details.proto index 59d6db2..9423514 100644 --- a/bdledger/api/error_details.proto +++ b/bdledger/api/error_details.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package bdledger.api.common; +package bdledger.api; -option go_package = "bdware.org/bdledger/sdk/api/grpc/errdetails"; +option go_package = "bdware.org/bdledger/pkg/api/grpc/proto"; option java_package = "bdledger.api.grpc.common"; option java_outer_classname = "ErrorDetailsProto"; option java_multiple_files = true; diff --git a/bdledger/api/ledger.proto b/bdledger/api/ledger.proto new file mode 100644 index 0000000..8ad9819 --- /dev/null +++ b/bdledger/api/ledger.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package bdledger.api; + +import "google/protobuf/empty.proto"; +import "bdledger/api/common.proto"; + +option go_package = "bdware.org/bdledger/pkg/api/grpc/proto"; +option java_package = "bdledger.api.grpc.ledger"; +option java_outer_classname = "LedgerProto"; +option java_multiple_files = true; + +service TransactionLedger { + rpc CreateLedger (CreateLedgerRequest) returns (CreateLedgerResponse); + rpc GetLedgers (google.protobuf.Empty) returns (GetLedgersResponse); + rpc SendTransaction (SendTransactionRequest) returns (SendTransactionResponse); +} + +message CreateLedgerRequest { + string name = 1; +} +message CreateLedgerResponse { + bool ok = 1; +} + +message GetLedgersResponse { + repeated string ledgers = 1; +} + +message SendTransactionRequest { + string ledger = 1; + message Transaction { + TransactionType type = 1; + bytes from = 2; + bytes to = 3; + bytes data = 4; + } + Transaction transaction = 2; +} +message SendTransactionResponse { + bytes hash = 1; +} diff --git a/bdledger/api/node.proto b/bdledger/api/node.proto new file mode 100644 index 0000000..4d177a7 --- /dev/null +++ b/bdledger/api/node.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package bdledger.api; + +import "google/protobuf/empty.proto"; + +option go_package = "bdware.org/bdledger/pkg/api/grpc/proto"; +option java_package = "bdledger.api.grpc.node"; +option java_outer_classname = "NodeProto"; +option java_multiple_files = true; + +service Node { + rpc ClientVersion (google.protobuf.Empty) returns (ClientVersionResponse); +} + +message ClientVersionResponse { + string version = 1; // 节点客户端版本 + } \ No newline at end of file diff --git a/bdledger/api/query_service.proto b/bdledger/api/query.proto similarity index 83% rename from bdledger/api/query_service.proto rename to bdledger/api/query.proto index e406089..9111963 100644 --- a/bdledger/api/query_service.proto +++ b/bdledger/api/query.proto @@ -1,12 +1,12 @@ syntax = "proto3"; -package bdledger.api.queryservice; +package bdledger.api; import "bdledger/api/common.proto"; -option go_package = "bdware.org/bdledger/sdk/api/grpc/queryservice"; -option java_package = "bdledger.api.grpc.queryservice"; -option java_outer_classname = "QueryServiceProto"; +option go_package = "bdware.org/bdledger/pkg/api/grpc/proto"; +option java_package = "bdledger.api.grpc.query"; +option java_outer_classname = "QueryProto"; option java_multiple_files = true; service Query { @@ -39,7 +39,7 @@ message BlocksRequest { int64 end_timestamp = 4; } message GetBlocksResponse { - repeated common.Block blocks= 1; + repeated Block blocks= 1; int64 start_timestamp = 2; int64 end_timestamp = 3; } @@ -54,7 +54,7 @@ message TransactionsRequest { int64 end_timestamp = 4; } message GetTransactionsResponse { - repeated common.Transaction Transactions = 1; + repeated Transaction transactions = 1; int64 start_timestamp = 2; int64 end_timestamp = 3; } @@ -68,7 +68,7 @@ message GetBlockByHashRequest { bool full_transaction = 3; } message GetBlockByHashResponse { - common.Block block = 1; + Block block = 1; } message GetTransactionByHashRequest { @@ -76,7 +76,7 @@ message GetTransactionByHashRequest { bytes hash = 2; } message GetTransactionByHashResponse { - common.Transaction transaction = 1; + Transaction transaction = 1; } message GetTransactionByBlockHashAndIndexRequest { @@ -85,5 +85,5 @@ message GetTransactionByBlockHashAndIndexRequest { uint32 index = 3; } message GetTransactionByBlockHashAndIndexResponse { - common.Transaction transaction = 1; + Transaction transaction = 1; } diff --git a/bdledger/api/tx_ledger.proto b/bdledger/api/tx_ledger.proto deleted file mode 100644 index ab11ac9..0000000 --- a/bdledger/api/tx_ledger.proto +++ /dev/null @@ -1,62 +0,0 @@ -syntax = "proto3"; - -package bdledger.api.txledger; - -import "google/protobuf/empty.proto"; -import "bdledger/api/common.proto"; - -option go_package = "bdware.org/bdledger/sdk/api/grpc/txledger"; -option java_package = "bdledger.api.grpc.txledger"; -option java_outer_classname = "TransactionLedgerProto"; -option java_multiple_files = true; - -service TransactionLedger { - rpc ClientVersion (google.protobuf.Empty) returns (common.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 CreateLedgerRequest { - string name = 1; -} -message CreateLedgerResponse { - bool ok = 1; -} - -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 common.Block blocks = 1; -} - -message SendTransactionRequest { - string ledger = 1; - message Transaction { - common.TransactionType type = 1; - bytes from = 2; - bytes to = 3; - bytes data = 4; - } - Transaction transaction = 2; -} -message SendTransactionResponse { - bytes hash = 1; -} diff --git a/docs.md b/docs.md index 58592cd..581ab7f 100644 --- a/docs.md +++ b/docs.md @@ -8,7 +8,7 @@ message ClientVersionResponse { } ``` -### common.TransactionType 事务类型 +### TransactionType 事务类型 ``` enum TransactionType { @@ -30,7 +30,7 @@ message Transaction { bytes block_hash = 2; // 事务所在的区块的哈希,当事务处于待确认状态时为`null` uint32 index = 3; // 事务在区块中的位置index,当事务处于待确认状态时为`null` bytes hash = 4; // 事务的哈希 - common.TransactionType type = 5; // 事务类型 + TransactionType type = 5; // 事务类型 bytes from = 6; // 发送账户地址 uint64 nonce = 7; // 这条事务之前发送者所发送的事务数量 bytes to = 8; // 接收账户地址,或者调用的合约地址,或者`null`如为合约创建 @@ -186,7 +186,7 @@ message GetLedgersResponse { message SendTransactionRequest { string ledger = 1; message Transaction { - common.TransactionType type = 1; + TransactionType type = 1; bytes from = 2; bytes to = 3; bytes data = 4; diff --git a/gen-go.bat b/gen-go.bat index e9314cf..ef0fa5c 100644 --- a/gen-go.bat +++ b/gen-go.bat @@ -11,7 +11,8 @@ where /q %gen% || echo missing %gen% && exit /B if not exist %dir% mkdir %dir% %exe% -I . --go_out=plugins=grpc:%dir% bdledger/api/common.proto %exe% -I . --go_out=plugins=grpc:%dir% bdledger/api/error_details.proto -%exe% -I . --go_out=plugins=grpc:%dir% bdledger/api/tx_ledger.proto -%exe% -I . --go_out=plugins=grpc:%dir% bdledger/api/query_service.proto +%exe% -I . --go_out=plugins=grpc:%dir% bdledger/api/ledger.proto +%exe% -I . --go_out=plugins=grpc:%dir% bdledger/api/query.proto +%exe% -I . --go_out=plugins=grpc:%dir% bdledger/api/node.proto echo all done diff --git a/gen-go.sh b/gen-go.sh index 1ecec3b..617ffc7 100644 --- a/gen-go.sh +++ b/gen-go.sh @@ -2,5 +2,6 @@ mkdir -p gen/go protoc -I . --go_out=plugins=grpc:gen/go bdledger/api/common.proto protoc -I . --go_out=plugins=grpc:gen/go bdledger/api/error_details.proto -protoc -I . --go_out=plugins=grpc:gen/go bdledger/api/tx_ledger.proto -protoc -I . --go_out=plugins=grpc:gen/go bdledger/api/query_service.proto +protoc -I . --go_out=plugins=grpc:gen/go bdledger/api/ledger.proto +protoc -I . --go_out=plugins=grpc:gen/go bdledger/api/query.proto +protoc -I . --go_out=plugins=grpc:gen/go bdledger/api/node.proto diff --git a/gen-web.bat b/gen-web.bat index 6a7d7f3..4329193 100644 --- a/gen-web.bat +++ b/gen-web.bat @@ -9,7 +9,8 @@ where /q %gen% || echo missing %gen% && exit /B if not exist %dir% mkdir %dir% %exe% -I . --js_out=import_style=commonjs:%dir% --grpc-web_out=import_style=commonjs,mode=grpcwebtext:%dir% bdledger/api/common.proto %exe% -I . --js_out=import_style=commonjs:%dir% --grpc-web_out=import_style=commonjs,mode=grpcwebtext:%dir% bdledger/api/error_details.proto -%exe% -I . --js_out=import_style=commonjs:%dir% --grpc-web_out=import_style=commonjs,mode=grpcwebtext:%dir% bdledger/api/tx_ledger.proto -%exe% -I . --js_out=import_style=commonjs:%dir% --grpc-web_out=import_style=commonjs,mode=grpcwebtext:%dir% bdledger/api/query_service.proto +%exe% -I . --js_out=import_style=commonjs:%dir% --grpc-web_out=import_style=commonjs,mode=grpcwebtext:%dir% bdledger/api/ledger.proto +%exe% -I . --js_out=import_style=commonjs:%dir% --grpc-web_out=import_style=commonjs,mode=grpcwebtext:%dir% bdledger/api/query.proto +%exe% -I . --js_out=import_style=commonjs:%dir% --grpc-web_out=import_style=commonjs,mode=grpcwebtext:%dir% bdledger/api/node.proto echo all done diff --git a/gen-web.sh b/gen-web.sh index 341c76a..0a07ce3 100644 --- a/gen-web.sh +++ b/gen-web.sh @@ -3,5 +3,6 @@ dir=gen/web mkdir -p $dir protoc -I . --js_out=import_style=commonjs:$dir --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$dir bdledger/api/common.proto protoc -I . --js_out=import_style=commonjs:$dir --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$dir bdledger/api/error_details.proto -protoc -I . --js_out=import_style=commonjs:$dir --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$dir bdledger/api/tx_ledger.proto -protoc -I . --js_out=import_style=commonjs:$dir --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$dir bdledger/api/query_service.proto +protoc -I . --js_out=import_style=commonjs:$dir --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$dir bdledger/api/ledger.proto +protoc -I . --js_out=import_style=commonjs:$dir --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$dir bdledger/api/query.proto +protoc -I . --js_out=import_style=commonjs:$dir --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$dir bdledger/api/node.proto diff --git a/test.md b/test.md index 61aeb22..b27d73f 100644 --- a/test.md +++ b/test.md @@ -10,7 +10,7 @@ message ClientVersionResponse { } ``` -### common.TransactionType +### TransactionType ```proto enum TransactionType { @@ -29,7 +29,7 @@ message Transaction { bytes block_hash = 1; // 事务所在的区块的哈希,当事务处于待确认状态时为`null` uint32 index = 2; // 事务在区块中的位置 index,当事务处于待确认状态时为`null` bytes hash = 3; // 事务的哈希 - common.TransactionType type = 4; // 事务类型 + TransactionType type = 4; // 事务类型 bytes from = 5; // 发送账户地址 uint64 nonce = 6; // 这条事务之前发送者所发送的事务数量 bytes to = 7; // 接收账户地址,或者调用的合约地址,或者`null`如为合约创建 @@ -48,7 +48,7 @@ message Transaction { bytes block_hash = 2; // 事务所在的区块的哈希,当事务处于待确认状态时为`null` uint32 index = 3; // 事务在区块中的位置index,当事务处于待确认状态时为`null` bytes hash = 4; // 事务的哈希 - common.TransactionType type = 5; // 事务类型 + TransactionType type = 5; // 事务类型 bytes from = 6; // 发送账户地址 uint64 nonce = 7; // 这条事务之前发送者所发送的事务数量 bytes to = 8; // 接收账户地址,或者调用的合约地址,或者`null`如为合约创建 @@ -339,7 +339,7 @@ blocks: - block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 0 hash: 0x0404040404040404040404040404040404040404 (in bytes) - type: common.TransactionType.RECORD + type: TransactionType.RECORD from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2018 to: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) @@ -350,7 +350,7 @@ blocks: - block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 1 hash: 0x1313131313131313131313131313131313131313 (in bytes) - type: common.TransactionType.MESSAGE + type: TransactionType.MESSAGE from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2019 to: 0xfeedbabefeedbabefeedbabefeedbabefeedbabe (in bytes) @@ -556,7 +556,7 @@ blocks: message SendTransactionRequest { string ledger = 1; message Transaction { - common.TransactionType type = 1; + TransactionType type = 1; bytes from = 2; bytes to = 3; bytes data = 4; @@ -582,7 +582,7 @@ message SendTransactionResponse { ```yaml ledger: 'test' transaction: - type: common.TransactionType.MESSAGE + type: TransactionType.MESSAGE from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) to: 0xfeedbabefeedbabefeedbabefeedbabefeedbabe (in bytes) data: 0xdeadbeef (in bytes) @@ -601,7 +601,7 @@ hash: 0xd15ea5edd15ea5edd15ea5edd15ea5edd15ea5edd15ea5edd15ea5edd15ea5ed (in byt ```yaml ledger: 'test' transaction: - type: common.TransactionType.MESSAGE + type: TransactionType.MESSAGE from: null (in bytes) to: 0x50bada55 (in bytes) data: null (in bytes) @@ -764,7 +764,7 @@ transactions: block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 0 hash: 0x0404040404040404040404040404040404040404 (in bytes) - type: common.TransactionType.RECORD + type: TransactionType.RECORD from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2018 to: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) @@ -776,7 +776,7 @@ transactions: block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 1 hash: 0x1313131313131313131313131313131313131313 (in bytes) - type: common.TransactionType.MESSAGE + type: TransactionType.MESSAGE from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2019 to: 0xfeedbabefeedbabefeedbabefeedbabefeedbabe (in bytes) @@ -914,7 +914,7 @@ block_number: 2018 block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 0 hash: 0x0404040404040404040404040404040404040404 (in bytes) -type: common.TransactionType.RECORD +type: TransactionType.RECORD from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2018 to: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) @@ -963,7 +963,7 @@ block_number: 2018 block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 0 hash: 0x0404040404040404040404040404040404040404 (in bytes) -type: common.TransactionType.RECORD +type: TransactionType.RECORD from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2018 to: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) @@ -1012,7 +1012,7 @@ block_number: 2018 block_hash: 0xdeadc0dedeadc0dedeadc0dedeadc0dedeadc0de (in bytes) index: 0 hash: 0x0404040404040404040404040404040404040404 (in bytes) -type: common.TransactionType.RECORD +type: TransactionType.RECORD from: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes) nonce: 2018 to: 0xf00dcafef00dcafef00dcafef00dcafef00dcafe (in bytes)