Skip to content

Commit cd701ad

Browse files
authored
Merge pull request #507 from tronprotocol/release_4.5.2
merge release 4.5.2 to master
2 parents 851ff73 + 8527d2e commit cd701ad

File tree

6 files changed

+83
-1
lines changed

6 files changed

+83
-1
lines changed

src/main/java/org/tron/walletcli/Client.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public class Client {
111111
"GetBalance",
112112
"GetBlock",
113113
"GetBlockById",
114+
"GetBlockByIdOrNum",
114115
"GetBlockByLatestNum",
115116
"GetBlockByLimitNext",
116117
"GetBrokerage",
@@ -240,6 +241,7 @@ public class Client {
240241
"GetBalance",
241242
"GetBlock",
242243
"GetBlockById",
244+
"GetBlockByIdOrNum",
243245
"GetBlockByLatestNum",
244246
"GetBlockByLimitNext",
245247
"GetBrokerage",
@@ -4357,6 +4359,10 @@ private void run() {
43574359
getMarketOrderById(parameters);
43584360
break;
43594361
}
4362+
case "getblockbyidornum": {
4363+
getBlockByIdOrNum(parameters);
4364+
break;
4365+
}
43604366
case "exit":
43614367
case "quit": {
43624368
System.out.println("Exit !!!");
@@ -4403,6 +4409,47 @@ private void getChainParameters() {
44034409
}
44044410
}
44054411

4412+
private void getBlockByIdOrNum(String[] parameters) {
4413+
String idOrNum = null;
4414+
boolean detail = false;
4415+
if (parameters == null || parameters.length == 0) {
4416+
// query current header
4417+
System.out.println("Get current header !!!");
4418+
} else {
4419+
if (parameters.length == 1) {
4420+
String param = parameters[0];
4421+
if ("help".equalsIgnoreCase(param)) {
4422+
// print help
4423+
System.out.println("1.get current header using the following command:");
4424+
System.out.println("getBlockByIdOrNum");
4425+
System.out.println("2. get current block command:");
4426+
System.out.println("getBlockByIdOrNum true");
4427+
System.out.println("3. get header by id or number with the following syntax:");
4428+
System.out.println("getBlockByIdOrNum idOrNum");
4429+
System.out.println("4. get block by id or number with the following syntax:");
4430+
System.out.println("getBlockByIdOrNum idOrNum true");
4431+
return;
4432+
}
4433+
if ("true".equalsIgnoreCase(param)) {
4434+
// query current block
4435+
detail = true;
4436+
} else {
4437+
// query header by id or num
4438+
idOrNum = parameters[0];
4439+
}
4440+
} else {
4441+
idOrNum = parameters[0];
4442+
detail = Boolean.parseBoolean(parameters[1]);
4443+
}
4444+
}
4445+
BlockExtention blockExtention = walletApiWrapper.getBlock(idOrNum, detail);
4446+
if (blockExtention == null) {
4447+
System.out.println("No header for idOrNum : " + idOrNum);
4448+
return;
4449+
}
4450+
System.out.println(Utils.printBlockExtention(blockExtention));
4451+
}
4452+
44064453
public static void main(String[] args) {
44074454
Client cli = new Client();
44084455
JCommander.newBuilder()

src/main/java/org/tron/walletcli/WalletApiWrapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,4 +1852,8 @@ public Optional<MarketOrder> getMarketOrderById(byte[] order) {
18521852
return WalletApi.getMarketOrderById(order);
18531853
}
18541854

1855+
public BlockExtention getBlock(String idOrNum, boolean detail) {
1856+
return WalletApi.getBlock(idOrNum, detail);
1857+
}
1858+
18551859
}

src/main/java/org/tron/walletserver/GrpcClient.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,4 +1083,23 @@ public Optional<MarketOrder> getMarketOrderById(byte[] order) {
10831083
return Optional.ofNullable(orderPair);
10841084
}
10851085

1086+
public BlockExtention getBlock(String idOrNum, boolean detail) {
1087+
BlockExtention block;
1088+
1089+
BlockReq.Builder builder = BlockReq.newBuilder();
1090+
if (idOrNum != null && !idOrNum.isEmpty()) {
1091+
builder.setIdOrNum(idOrNum);
1092+
}
1093+
builder.setDetail(detail);
1094+
if (blockingStubSolidity != null) {
1095+
block = blockingStubSolidity.getBlock(builder.build());
1096+
} else {
1097+
block = blockingStubFull.getBlock(builder.build());
1098+
}
1099+
if (block == BlockExtention.getDefaultInstance()) {
1100+
block = null; // set to null
1101+
}
1102+
return block;
1103+
}
1104+
10861105
}

src/main/java/org/tron/walletserver/WalletApi.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,4 +2806,8 @@ public static Optional<MarketOrder> getMarketOrderById(byte[] order) {
28062806
return rpcCli.getMarketOrderById(order);
28072807
}
28082808

2809+
public static BlockExtention getBlock(String idOrNum, boolean detail) {
2810+
return rpcCli.getBlock(idOrNum, detail);
2811+
}
2812+
28092813
}

src/main/protos/api/api.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ service Wallet {
778778
rpc GetMarketPairList (EmptyMessage) returns (MarketOrderPairList) {
779779
}
780780
// end for market
781+
rpc GetBlock (BlockReq) returns (BlockExtention) {
782+
}
781783
};
782784

783785
service WalletSolidity {
@@ -960,6 +962,8 @@ service WalletSolidity {
960962

961963
rpc GetMarketPairList (EmptyMessage) returns (MarketOrderPairList) {
962964
}
965+
rpc GetBlock (BlockReq) returns (BlockExtention) {
966+
}
963967
};
964968

965969
service WalletExtension {
@@ -1094,6 +1098,10 @@ message TimeMessage {
10941098
int64 beginInMilliseconds = 1;
10951099
int64 endInMilliseconds = 2;
10961100
}
1101+
message BlockReq {
1102+
string id_or_num = 1;
1103+
bool detail = 2;
1104+
}
10971105
message BlockLimit {
10981106
int64 startNum = 1;
10991107
int64 endNum = 2;

src/main/protos/install-googleapis.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
55
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
66
go get -u github.com/golang/protobuf/protoc-gen-go
77

8-
wget http://central.maven.org/maven2/com/google/api/grpc/googleapis-common-protos/0.0.3/googleapis-common-protos-0.0.3.jar
8+
wget https://repo1.maven.org/maven2/com/google/api/grpc/googleapis-common-protos/0.0.3/googleapis-common-protos-0.0.3.jar
99
jar xvf googleapis-common-protos-0.0.3.jar
1010
cp -r google/ $HOME/protobuf/include/
1111
ls -l

0 commit comments

Comments
 (0)