Skip to content

Commit 37c329e

Browse files
committed
add get contract info api
1 parent 38dd31d commit 37c329e

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.tron.protos.contract.SmartContractOuterClass.SmartContract;
5757
import org.tron.protos.Protocol.Transaction;
5858
import org.tron.protos.Protocol.TransactionInfo;
59+
import org.tron.protos.contract.SmartContractOuterClass.SmartContractDataWrapper;
5960
import org.tron.walletserver.WalletApi;
6061

6162

@@ -108,6 +109,7 @@ public class Client {
108109
"GetBrokerage",
109110
"GetChainParameters",
110111
"GetContract contractAddress",
112+
"GetContractInfo contractAddress",
111113
"GetDelegatedResource",
112114
"GetDelegatedResourceAccountIndex",
113115
"GetDiversifier",
@@ -237,6 +239,7 @@ public class Client {
237239
"GetBrokerage",
238240
"GetChainParameters",
239241
"GetContract",
242+
"GetContractInfo",
240243
"GetDelegatedResource",
241244
"GetDelegatedResourceAccountIndex",
242245
"GetDiversifier",
@@ -2237,6 +2240,28 @@ private void getContract(String[] parameters) {
22372240
}
22382241
}
22392242

2243+
private void getContractInfo(String[] parameters) {
2244+
if (parameters == null ||
2245+
parameters.length != 1) {
2246+
System.out.println("Using getContractInfo needs 1 parameter like: ");
2247+
System.out.println("GetContractInfo contractAddress");
2248+
return;
2249+
}
2250+
2251+
byte[] addressBytes = WalletApi.decodeFromBase58Check(parameters[0]);
2252+
if (addressBytes == null) {
2253+
System.out.println("GetContractInfo: invalid address !!!");
2254+
return;
2255+
}
2256+
2257+
SmartContractDataWrapper contractDeployContract = WalletApi.getContractInfo(addressBytes);
2258+
if (contractDeployContract != null) {
2259+
System.out.println(Utils.formatMessageString(contractDeployContract));
2260+
} else {
2261+
System.out.println("Query contract failed !!!");
2262+
}
2263+
}
2264+
22402265
private void generateAddress() {
22412266
AddressPrKeyPairMessage result = walletApiWrapper.generateAddress();
22422267
if (null != result) {
@@ -4078,6 +4103,10 @@ private void run() {
40784103
getContract(parameters);
40794104
break;
40804105
}
4106+
case "getcontractinfo": {
4107+
getContractInfo(parameters);
4108+
break;
4109+
}
40814110
case "generateaddress": {
40824111
generateAddress();
40834112
break;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.tron.protos.Protocol.Transaction;
6363
import org.tron.protos.Protocol.TransactionInfo;
6464
import org.tron.protos.Protocol.TransactionSign;
65+
import org.tron.protos.contract.SmartContractOuterClass.SmartContractDataWrapper;
6566
import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract;
6667
import org.tron.protos.contract.SmartContractOuterClass.UpdateEnergyLimitContract;
6768
import org.tron.protos.contract.SmartContractOuterClass.UpdateSettingContract;
@@ -838,6 +839,12 @@ public SmartContract getContract(byte[] address) {
838839
return blockingStubFull.getContract(bytesMessage);
839840
}
840841

842+
public SmartContractDataWrapper getContractInfo(byte[] address) {
843+
ByteString byteString = ByteString.copyFrom(address);
844+
BytesMessage bytesMessage = BytesMessage.newBuilder().setValue(byteString).build();
845+
return blockingStubFull.getContractInfo(bytesMessage);
846+
}
847+
841848
public TransactionExtention accountPermissionUpdate(
842849
AccountPermissionUpdateContract request) {
843850
return blockingStubFull.accountPermissionUpdate(request);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
import org.tron.protos.contract.ShieldContract.OutputPointInfo;
109109
import org.tron.protos.contract.ShieldContract.ShieldedTransferContract;
110110
import org.tron.protos.contract.ShieldContract.SpendDescription;
111+
import org.tron.protos.contract.SmartContractOuterClass.SmartContractDataWrapper;
111112
import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract;
112113
import org.tron.protos.contract.StorageContract.BuyStorageBytesContract;
113114
import org.tron.protos.contract.StorageContract.BuyStorageContract;
@@ -139,6 +140,7 @@
139140
import org.tron.protos.contract.WitnessContract.WitnessUpdateContract;
140141
import org.tron.protos.contract.MarketContract.MarketCancelOrderContract;
141142
import org.tron.protos.contract.MarketContract.MarketSellAssetContract;
143+
import org.tron.protos.contract.MarketContract.MarketSellAssetContract;
142144

143145
import java.io.File;
144146
import java.io.IOException;
@@ -2208,6 +2210,10 @@ public static SmartContract getContract(byte[] address) {
22082210
return rpcCli.getContract(address);
22092211
}
22102212

2213+
public static SmartContractDataWrapper getContractInfo(byte[] address) {
2214+
return rpcCli.getContractInfo(address);
2215+
}
2216+
22112217
public boolean accountPermissionUpdate(byte[] owner, String permissionJson)
22122218
throws CipherException, IOException, CancelException {
22132219
AccountPermissionUpdateContract contract =

src/main/protos/api/api.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ service Wallet {
411411
rpc GetContract (BytesMessage) returns (SmartContract) {
412412
}
413413

414+
rpc GetContractInfo (BytesMessage) returns (SmartContractDataWrapper) {
415+
}
416+
414417
rpc TriggerContract (TriggerSmartContract) returns (TransactionExtention) {
415418
}
416419

src/main/protos/core/contract/smart_contract.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ message UpdateEnergyLimitContract {
8787
bytes contract_address = 2;
8888
int64 origin_energy_limit = 3;
8989
}
90+
91+
message SmartContractDataWrapper {
92+
SmartContract smart_contract = 1;
93+
bytes runtimecode = 2;
94+
}

0 commit comments

Comments
 (0)