diff --git a/src/main/java/org/tron/walletcli/Client.java b/src/main/java/org/tron/walletcli/Client.java index f9b6bb190..f84d5c731 100755 --- a/src/main/java/org/tron/walletcli/Client.java +++ b/src/main/java/org/tron/walletcli/Client.java @@ -111,6 +111,7 @@ public class Client { "GetBalance", "GetBlock", "GetBlockById", + "GetBlockByIdOrNum", "GetBlockByLatestNum", "GetBlockByLimitNext", "GetBrokerage", @@ -240,6 +241,7 @@ public class Client { "GetBalance", "GetBlock", "GetBlockById", + "GetBlockByIdOrNum", "GetBlockByLatestNum", "GetBlockByLimitNext", "GetBrokerage", @@ -4357,6 +4359,10 @@ private void run() { getMarketOrderById(parameters); break; } + case "getblockbyidornum": { + getBlockByIdOrNum(parameters); + break; + } case "exit": case "quit": { System.out.println("Exit !!!"); @@ -4403,6 +4409,47 @@ private void getChainParameters() { } } + private void getBlockByIdOrNum(String[] parameters) { + String idOrNum = null; + boolean detail = false; + if (parameters == null || parameters.length == 0) { + // query current header + System.out.println("Get current header !!!"); + } else { + if (parameters.length == 1) { + String param = parameters[0]; + if ("help".equalsIgnoreCase(param)) { + // print help + System.out.println("1.get current header using the following command:"); + System.out.println("getBlockByIdOrNum"); + System.out.println("2. get current block command:"); + System.out.println("getBlockByIdOrNum true"); + System.out.println("3. get header by id or number with the following syntax:"); + System.out.println("getBlockByIdOrNum idOrNum"); + System.out.println("4. get block by id or number with the following syntax:"); + System.out.println("getBlockByIdOrNum idOrNum true"); + return; + } + if ("true".equalsIgnoreCase(param)) { + // query current block + detail = true; + } else { + // query header by id or num + idOrNum = parameters[0]; + } + } else { + idOrNum = parameters[0]; + detail = Boolean.parseBoolean(parameters[1]); + } + } + BlockExtention blockExtention = walletApiWrapper.getBlock(idOrNum, detail); + if (blockExtention == null) { + System.out.println("No header for idOrNum : " + idOrNum); + return; + } + System.out.println(Utils.printBlockExtention(blockExtention)); + } + public static void main(String[] args) { Client cli = new Client(); JCommander.newBuilder() diff --git a/src/main/java/org/tron/walletcli/WalletApiWrapper.java b/src/main/java/org/tron/walletcli/WalletApiWrapper.java index d359a754d..5778eceaa 100644 --- a/src/main/java/org/tron/walletcli/WalletApiWrapper.java +++ b/src/main/java/org/tron/walletcli/WalletApiWrapper.java @@ -1852,4 +1852,8 @@ public Optional getMarketOrderById(byte[] order) { return WalletApi.getMarketOrderById(order); } + public BlockExtention getBlock(String idOrNum, boolean detail) { + return WalletApi.getBlock(idOrNum, detail); + } + } diff --git a/src/main/java/org/tron/walletserver/GrpcClient.java b/src/main/java/org/tron/walletserver/GrpcClient.java index 361b94c82..2ea3ea9c0 100644 --- a/src/main/java/org/tron/walletserver/GrpcClient.java +++ b/src/main/java/org/tron/walletserver/GrpcClient.java @@ -1083,4 +1083,23 @@ public Optional getMarketOrderById(byte[] order) { return Optional.ofNullable(orderPair); } + public BlockExtention getBlock(String idOrNum, boolean detail) { + BlockExtention block; + + BlockReq.Builder builder = BlockReq.newBuilder(); + if (idOrNum != null && !idOrNum.isEmpty()) { + builder.setIdOrNum(idOrNum); + } + builder.setDetail(detail); + if (blockingStubSolidity != null) { + block = blockingStubSolidity.getBlock(builder.build()); + } else { + block = blockingStubFull.getBlock(builder.build()); + } + if (block == BlockExtention.getDefaultInstance()) { + block = null; // set to null + } + return block; + } + } diff --git a/src/main/java/org/tron/walletserver/WalletApi.java b/src/main/java/org/tron/walletserver/WalletApi.java index 201d6c090..a000cace5 100644 --- a/src/main/java/org/tron/walletserver/WalletApi.java +++ b/src/main/java/org/tron/walletserver/WalletApi.java @@ -2806,4 +2806,8 @@ public static Optional getMarketOrderById(byte[] order) { return rpcCli.getMarketOrderById(order); } + public static BlockExtention getBlock(String idOrNum, boolean detail) { + return rpcCli.getBlock(idOrNum, detail); + } + } diff --git a/src/main/protos/api/api.proto b/src/main/protos/api/api.proto index f9dcc0f32..6cfa57986 100644 --- a/src/main/protos/api/api.proto +++ b/src/main/protos/api/api.proto @@ -778,6 +778,8 @@ service Wallet { rpc GetMarketPairList (EmptyMessage) returns (MarketOrderPairList) { } // end for market + rpc GetBlock (BlockReq) returns (BlockExtention) { + } }; service WalletSolidity { @@ -960,6 +962,8 @@ service WalletSolidity { rpc GetMarketPairList (EmptyMessage) returns (MarketOrderPairList) { } + rpc GetBlock (BlockReq) returns (BlockExtention) { + } }; service WalletExtension { @@ -1094,6 +1098,10 @@ message TimeMessage { int64 beginInMilliseconds = 1; int64 endInMilliseconds = 2; } +message BlockReq { + string id_or_num = 1; + bool detail = 2; +} message BlockLimit { int64 startNum = 1; int64 endNum = 2; diff --git a/src/main/protos/install-googleapis.sh b/src/main/protos/install-googleapis.sh index 0d44f6108..e1c1df801 100755 --- a/src/main/protos/install-googleapis.sh +++ b/src/main/protos/install-googleapis.sh @@ -5,7 +5,7 @@ go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger go get -u github.com/golang/protobuf/protoc-gen-go -wget http://central.maven.org/maven2/com/google/api/grpc/googleapis-common-protos/0.0.3/googleapis-common-protos-0.0.3.jar +wget https://repo1.maven.org/maven2/com/google/api/grpc/googleapis-common-protos/0.0.3/googleapis-common-protos-0.0.3.jar jar xvf googleapis-common-protos-0.0.3.jar cp -r google/ $HOME/protobuf/include/ ls -l