Skip to content

Commit

Permalink
Merge pull request #507 from tronprotocol/release_4.5.2
Browse files Browse the repository at this point in the history
merge release 4.5.2 to master
  • Loading branch information
waynercheung committed Aug 18, 2022
2 parents 851ff73 + 8527d2e commit cd701ad
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
47 changes: 47 additions & 0 deletions src/main/java/org/tron/walletcli/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class Client {
"GetBalance",
"GetBlock",
"GetBlockById",
"GetBlockByIdOrNum",
"GetBlockByLatestNum",
"GetBlockByLimitNext",
"GetBrokerage",
Expand Down Expand Up @@ -240,6 +241,7 @@ public class Client {
"GetBalance",
"GetBlock",
"GetBlockById",
"GetBlockByIdOrNum",
"GetBlockByLatestNum",
"GetBlockByLimitNext",
"GetBrokerage",
Expand Down Expand Up @@ -4357,6 +4359,10 @@ private void run() {
getMarketOrderById(parameters);
break;
}
case "getblockbyidornum": {
getBlockByIdOrNum(parameters);
break;
}
case "exit":
case "quit": {
System.out.println("Exit !!!");
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/tron/walletcli/WalletApiWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1852,4 +1852,8 @@ public Optional<MarketOrder> getMarketOrderById(byte[] order) {
return WalletApi.getMarketOrderById(order);
}

public BlockExtention getBlock(String idOrNum, boolean detail) {
return WalletApi.getBlock(idOrNum, detail);
}

}
19 changes: 19 additions & 0 deletions src/main/java/org/tron/walletserver/GrpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1083,4 +1083,23 @@ public Optional<MarketOrder> 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;
}

}
4 changes: 4 additions & 0 deletions src/main/java/org/tron/walletserver/WalletApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2806,4 +2806,8 @@ public static Optional<MarketOrder> getMarketOrderById(byte[] order) {
return rpcCli.getMarketOrderById(order);
}

public static BlockExtention getBlock(String idOrNum, boolean detail) {
return rpcCli.getBlock(idOrNum, detail);
}

}
8 changes: 8 additions & 0 deletions src/main/protos/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ service Wallet {
rpc GetMarketPairList (EmptyMessage) returns (MarketOrderPairList) {
}
// end for market
rpc GetBlock (BlockReq) returns (BlockExtention) {
}
};

service WalletSolidity {
Expand Down Expand Up @@ -960,6 +962,8 @@ service WalletSolidity {

rpc GetMarketPairList (EmptyMessage) returns (MarketOrderPairList) {
}
rpc GetBlock (BlockReq) returns (BlockExtention) {
}
};

service WalletExtension {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/protos/install-googleapis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd701ad

Please sign in to comment.