Skip to content

Commit cb02cdd

Browse files
Merge pull request #461 from dpneko/feature/set_multi_sign_address
feat: set multi sign address
2 parents 8d6169e + 67b9de8 commit cb02cdd

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

sun-sdk/src/main/java/org/tron/core/config/Configuration.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,24 @@ public static Config getByPath(final String configurationPath) {
6464
}
6565
return config;
6666
}
67+
68+
public static Config getByPathNoCache(final String configurationPath) {
69+
if (isBlank(configurationPath)) {
70+
throw new IllegalArgumentException("Configuration path is required!");
71+
}
72+
Config localConfig = null;
73+
File configFile = new File(System.getProperty("user.dir")+'/'+configurationPath);
74+
if(configFile.exists()){
75+
try {
76+
localConfig = ConfigFactory.parseReader(new InputStreamReader(new FileInputStream(configurationPath)));
77+
logger.info("use user defined config file in current dir");
78+
} catch (FileNotFoundException e) {
79+
logger.error("load user defined config file exception: " + e.getMessage());
80+
}
81+
}else {
82+
localConfig = ConfigFactory.load(configurationPath);
83+
logger.info("user defined config file doesn't exists, use default config file in jar");
84+
}
85+
return localConfig;
86+
}
6787
}

sun-sdk/src/main/java/org/tron/sunapi/Chain.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ public SunNetworkResponse<Integer> setPrivateKey(String priKey) {
105105
return ret.success(0);
106106
}
107107

108+
public SunNetworkResponse<Integer> setPrivateKey(String priKey, String address) {
109+
SunNetworkResponse<Integer> ret = new SunNetworkResponse<>();
110+
byte[] temp = ByteArray.fromHexString(priKey);
111+
byte[] tempAddress = AddressUtil.decodeFromBase58Check(address);
112+
113+
if (!Utils.priKeyValid(temp)) {
114+
ret.failed(ErrorCodeEnum.COMMON_PARAM_ERROR);
115+
}
116+
117+
this.serverApi.initPrivateKey(temp, tempAddress);
118+
119+
return ret.success(0);
120+
}
121+
108122
/**
109123
* @param request request of deploy contract
110124
* @return the response of deploy contract which contains the address of contract deployed

sun-sdk/src/main/java/org/tron/sunapi/SunNetwork.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,17 @@ public SunNetworkResponse<Integer> setPrivateKey(String priKey) {
5252

5353
return ret;
5454
}
55+
56+
public SunNetworkResponse<Integer> setPrivateKey(String priKey, String address) {
57+
SunNetworkResponse<Integer> ret;
58+
59+
ret = this.mainChainService.setPrivateKey(priKey, address);
60+
if (!ret.getCode().equals(ErrorCodeEnum.SUCCESS.getCode())) {
61+
return ret;
62+
}
63+
64+
ret = this.sideChainService.setPrivateKey(priKey, address);
65+
66+
return ret;
67+
}
5568
}

sun-sdk/src/main/java/org/tron/sunserver/ServerApi.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ public void initPrivateKey(byte[] priKey) {
167167
this.address = priEcKey.getAddress();
168168
}
169169

170+
public void initPrivateKey(byte[] priKey, byte[] address) {
171+
this.priEcKey = ECKey.fromPrivate(priKey);
172+
173+
this.address = address;
174+
}
175+
170176
public ServerApi(IServerConfig config, byte[] priKey, boolean isMainChain,
171177
IMultiTransactionSign multiTransactionSign) {
172178
this.isMainChain = isMainChain;

0 commit comments

Comments
 (0)