add hash query

Summary:
add TransactionCount/GetTransactions
增加关于 transaction/block 相关的查询接口

Test Plan: none

Reviewers: nex, wuyi

Reviewed By: nex

Differential Revision: https://phabricator.internetapi.cn/D25
This commit is contained in:
huyingcong 2019-11-25 21:23:49 +08:00
parent 3dc5c90025
commit de035bd3bc
8 changed files with 120 additions and 115 deletions

View File

@ -1,84 +0,0 @@
syntax = "proto3";
package bdledger.api.acchain;
import "google/protobuf/empty.proto";
import "bdledger/api/common.proto";
option go_package = "bdware.org/bdledger/sdk/api/grpc/acchain";
option java_package = "bdledger.api.grpc.acchain";
option java_outer_classname = "AccountingChainProto";
option java_multiple_files = true;
service AccountingChain {
rpc ClientVersion (google.protobuf.Empty) returns (common.ClientVersionResponse);
rpc BlockNumber (BlockNumberRequest) returns (BlockNumberResponse);
rpc GetBlockByNumber (GetBlockByNumberRequest) returns (Block);
rpc GetBlockByHash (GetBlockByHashRequest) returns (Block);
rpc GetTransactionByHash (GetTransactionByHashRequest) returns (Transaction);
rpc GetTransactionByBlockNumberAndIndex (GetTransactionByBlockNumberAndIndexRequest) returns (Transaction);
rpc GetTransactionByBlockHashAndIndex (GetTransactionByBlockHashAndIndexRequest) returns (Transaction);
}
message Transaction {
uint64 block_number = 1; // `null`
bytes block_hash = 2; // `null`
uint32 index = 3; // index`null`
bytes hash = 4; //
common.TransactionType type = 5; //
bytes from = 6; //
uint64 nonce = 7; //
bytes to = 8; // `null`
bytes data = 9; //
bytes v = 10; // ECDSA recovery id
bytes r = 11; // ECDSA signature r
bytes s = 12; // ECDSA signature s
}
message Block {
uint64 number = 1; // `null`
bytes hash = 2; // `null`
bytes parent_hash = 3; //
repeated bytes witnesses = 4; //
int64 timestamp = 5; // UNIX时间戳
uint64 size = 6; //
bytes transactions_root = 7; //
repeated Transaction transactions = 8; //
repeated bytes transaction_hashes = 9; // 20
}
message BlockNumberRequest {
string ledger = 1;
}
message BlockNumberResponse {
uint64 block_number = 1;
}
message GetBlockByNumberRequest {
string ledger = 1;
uint64 number = 2;
bool full_transaction = 3;
}
message GetBlockByHashRequest {
string ledger = 1;
bytes hash = 2;
bool full_transaction = 3;
}
message GetTransactionByHashRequest {
string ledger = 1;
bytes hash = 2;
}
message GetTransactionByBlockNumberAndIndexRequest {
string ledger = 1;
uint64 block_number = 2;
uint32 index = 3;
}
message GetTransactionByBlockHashAndIndexRequest {
string ledger = 1;
bytes block_hash = 2;
uint32 index = 3;
}

View File

@ -19,3 +19,29 @@ enum TransactionType {
CONTRACT_INVOCATION = 3; //
CONTRACT_STATUS = 4; //
}
message Transaction {
bytes block_hash = 1; // `null`
uint32 index = 2; // index`null`
bytes hash = 3; //
common.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; //
repeated bytes witnesses = 4; //
int64 timestamp = 5; // UNIX
uint64 size = 6; //
bytes transactions_root = 7; //
repeated Transaction transactions = 8; //
repeated bytes transaction_hashes = 9; // 20
}

View File

@ -0,0 +1,89 @@
syntax = "proto3";
package bdledger.api.txledger;
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 Query {
rpc GetBlocks (BlocksRequest) returns (GetBlocksResponse);
rpc CountBlocks (BlocksRequest) returns (CountBlocksResponse);
rpc GetTransactions(TransactionsRequest) returns (GetTransactionsResponse);
rpc CountTransactions(TransactionsRequest) returns (CountTransactionsResponse);
rpc GetBlockByHash (GetBlockByHashRequest) returns (GetBlockByHashResponse);
rpc GetTransactionByHash (GetTransactionByHashRequest) returns (GetTransactionByHashResponse);
rpc GetTransactionByBlockHashAndIndex (GetTransactionByBlockHashAndIndexRequest) returns (GetTransactionByBlockHashAndIndexResponse);
}
// repeated Transaction/BlockFilters are combined by "&&"(and) operator;
message TransactionFilter {
bytes hash = 1;
bytes from = 2;
bytes to = 3;
bytes timestamp = 4;
}
message BlockFilter {
bytes hash = 1;
int64 timestamp = 2;
}
message BlocksRequest {
string ledger = 1;
repeated BlockFilter filters = 2;
required int64 start_timestamp = 3;
int64 end_timestamp = 4;
}
message GetBlocksResponse {
repeated common.Block blocks= 1;
int64 start_timestamp = 2;
int64 end_timestamp = 3;
}
message CountBlocksResponse {
uint64 count = 1;
}
message TransactionsRequest {
string ledger = 1;
repeated TransactionFilter filters = 2;
required int64 start_timestamp = 3;
int64 end_timestamp = 4;
}
message GetTransactionsResponse {
repeated common.Transaction Transactions = 1;
int64 start_timestamp = 2;
int64 end_timestamp = 3;
}
message CountTransactionsResponse {
uint64 count = 1;
}
message GetBlockByHashRequest {
string ledger = 1;
bytes hash = 2;
bool full_transaction = 3;
}
message GetBlockByHashResponse {
common.Block block = 1;
}
message GetTransactionByHashRequest {
string ledger = 1;
bytes hash = 2;
}
message GetTransactionByHashResponse {
common.Transaction transaction = 1;
}
message GetTransactionByBlockHashAndIndexRequest {
string ledger = 1;
bytes block_hash = 2;
uint32 index = 3;
}
message GetTransactionByBlockHashAndIndexResponse {
common.Transaction transaction = 1;
}

View File

@ -19,32 +19,6 @@ service TransactionLedger {
rpc SendTransaction (SendTransactionRequest) returns (SendTransactionResponse);
}
message Transaction {
bytes block_hash = 1; // `null`
uint32 index = 2; // index`null`
bytes hash = 3; //
common.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; //
repeated bytes witnesses = 4; //
int64 timestamp = 5; // UNIX
uint64 size = 6; //
bytes transactions_root = 7; //
repeated Transaction transactions = 8; //
repeated bytes transaction_hashes = 9; // 20
}
message CreateLedgerRequest {
string name = 1;
}
@ -70,7 +44,7 @@ message GetBlocksRequest {
bool full_transaction = 4;
}
message GetBlocksResponse {
repeated Block blocks = 1;
repeated common.Block blocks = 1;
}
message SendTransactionRequest {

View File

@ -12,6 +12,6 @@ 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/ac_chain.proto
%exe% -I . --go_out=plugins=grpc:%dir% bdledger/api/query_service.proto
echo all done

View File

@ -3,4 +3,4 @@ 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/ac_chain.proto
protoc -I . --go_out=plugins=grpc:gen/go bdledger/api/query_service.proto

View File

@ -10,6 +10,6 @@ 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/ac_chain.proto
%exe% -I . --js_out=import_style=commonjs:%dir% --grpc-web_out=import_style=commonjs,mode=grpcwebtext:%dir% bdledger/api/query_service.proto
echo all done

View File

@ -4,4 +4,4 @@ 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/ac_chain.proto
protoc -I . --js_out=import_style=commonjs:$dir --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$dir bdledger/api/query_service.proto