mirror of
https://gitee.com/BDWare/ypk-deploy-tool
synced 2025-01-09 17:34:02 +00:00
build: config spotless plugin and reformat code
This commit is contained in:
parent
698c8cf569
commit
23f367f398
@ -4,6 +4,9 @@ plugins {
|
||||
id 'maven-publish'
|
||||
id 'signing'
|
||||
}
|
||||
|
||||
apply from: '../spotless.gradle'
|
||||
|
||||
group "org.bdware.bdcontract"
|
||||
version "0.7.4"
|
||||
sourceCompatibility = 1.8
|
||||
|
@ -12,4 +12,4 @@ public class BDRepoConfig {
|
||||
public int shardingID;
|
||||
public int doipStartPort;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,22 +21,26 @@ public class BDRepoTool {
|
||||
EndpointConfig endpointConfig = storage.loadAsEndpointConfig();
|
||||
AuditIrpClient irpClient = new AuditIrpClient(endpointConfig);
|
||||
BDRepoConfig bdosConfig = new Gson().fromJson(storage.load(), BDRepoConfig.class);
|
||||
BDRepoClient client = new BDRepoClient(bdosConfig.bdRepoId, irpClient, SM2KeyPair.fromJson(bdosConfig.accessKeyPair.toString()));
|
||||
BDRepoClient client = new BDRepoClient(bdosConfig.bdRepoId, irpClient,
|
||||
SM2KeyPair.fromJson(bdosConfig.accessKeyPair.toString()));
|
||||
AtomicInteger result = new AtomicInteger(0);
|
||||
if (bcoId == null)
|
||||
bcoId = bdosConfig.bcoId;
|
||||
LOGGER.info("deploy: " + bcoId + " @" + bdosConfig.bdRepoId);
|
||||
client.createBDO(bcoId, bdosConfig.shardingID, bdosConfig.createParam, bdosConfig.doipStartPort, SM2KeyPair.fromJson(bdosConfig.deployKeyPair.toString()),
|
||||
client.createBDO(bcoId, bdosConfig.shardingID, bdosConfig.createParam,
|
||||
bdosConfig.doipStartPort, SM2KeyPair.fromJson(bdosConfig.deployKeyPair.toString()),
|
||||
new BDRepoClient.StartBDOResultCallback() {
|
||||
@Override
|
||||
public void onResult(BDRepoClient.StartBDOResult ret) {
|
||||
LOGGER.info("[BDRepoTool] " + new Gson().toJson(ret));
|
||||
LOGGER.info("[BDRepoTool] " + new Gson().toJson(ret.originalMessage.header));
|
||||
LOGGER.info("[BDRepoTool] doipMsg:" + ret.originalMessage.body.getDataAsJsonString());
|
||||
LOGGER.info(
|
||||
"[BDRepoTool] " + new Gson().toJson(ret.originalMessage.header));
|
||||
LOGGER.info("[BDRepoTool] doipMsg:"
|
||||
+ ret.originalMessage.body.getDataAsJsonString());
|
||||
result.incrementAndGet();
|
||||
}
|
||||
});
|
||||
for (; result.get() == 0; ) {
|
||||
for (; result.get() == 0;) {
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
@ -54,10 +58,12 @@ public class BDRepoTool {
|
||||
EndpointConfig endpointConfig = storage.loadAsEndpointConfig();
|
||||
AuditIrpClient irpClient = new AuditIrpClient(endpointConfig);
|
||||
BDRepoConfig bdosConfig = new Gson().fromJson(storage.load(), BDRepoConfig.class);
|
||||
BDRepoClient client = new BDRepoClient(bdosConfig.bdRepoId, irpClient, SM2KeyPair.fromJson(bdosConfig.accessKeyPair.toString()));
|
||||
BDRepoClient client = new BDRepoClient(bdosConfig.bdRepoId, irpClient,
|
||||
SM2KeyPair.fromJson(bdosConfig.accessKeyPair.toString()));
|
||||
AtomicInteger result = new AtomicInteger(0);
|
||||
if (bdoId == null)
|
||||
bdoId = bdosConfig.bdRepoId + "/" + bdosConfig.deployKeyPair.get("publicKey").getAsString().hashCode();
|
||||
bdoId = bdosConfig.bdRepoId + "/"
|
||||
+ bdosConfig.deployKeyPair.get("publicKey").getAsString().hashCode();
|
||||
LOGGER.info("kill:" + bdoId);
|
||||
client.deleteBDO(bdoId, new DoipMessageCallback() {
|
||||
@Override
|
||||
@ -67,7 +73,7 @@ public class BDRepoTool {
|
||||
result.incrementAndGet();
|
||||
}
|
||||
});
|
||||
for (; result.get() == 0; ) {
|
||||
for (; result.get() == 0;) {
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
|
@ -3,4 +3,4 @@ package org.bdware.ypkdeploy;
|
||||
public class CodeRepoConfig {
|
||||
public String codeRepoId;
|
||||
public String ypkPath;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,8 @@ public class CodeRepoTool {
|
||||
System.out.println("[CodeRepoTool] error: missing codeRepoId");
|
||||
return;
|
||||
}
|
||||
CodeRepoClient client = new CodeRepoClient(bdosConfig.codeRepoId, irpClient, SM2KeyPair.fromJson(arg.toString()));
|
||||
CodeRepoClient client = new CodeRepoClient(bdosConfig.codeRepoId, irpClient,
|
||||
SM2KeyPair.fromJson(arg.toString()));
|
||||
if (ypkPath == null)
|
||||
ypkPath = bdosConfig.ypkPath;
|
||||
if (ypkPath == null) {
|
||||
@ -39,7 +40,8 @@ public class CodeRepoTool {
|
||||
|
||||
@Override
|
||||
public void onProgress(String doId, int currentChunk, int totalChunk) {
|
||||
System.out.println("[CodeRepoTool] " + doId + " progress: " + currentChunk + "/" + totalChunk);
|
||||
System.out.println(
|
||||
"[CodeRepoTool] " + doId + " progress: " + currentChunk + "/" + totalChunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,7 +57,7 @@ public class CodeRepoTool {
|
||||
result.incrementAndGet();
|
||||
}
|
||||
});
|
||||
for (; result.get() == 0; ) {
|
||||
for (; result.get() == 0;) {
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,12 @@ public class DeployConfGenerator {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void generateDeployConf(String dir, String template, String commonvar, String fileName) {
|
||||
public static void generateDeployConf(String dir, String template, String commonvar,
|
||||
String fileName) {
|
||||
String templateStr = getFileContent(dir + template);
|
||||
try {
|
||||
JsonObject commVar = JsonParser.parseReader(new FileReader(new File(dir, commonvar))).getAsJsonObject();
|
||||
JsonObject commVar = JsonParser.parseReader(new FileReader(new File(dir, commonvar)))
|
||||
.getAsJsonObject();
|
||||
String content = templateStr;
|
||||
File output = new File(dir, fileName);
|
||||
if (!output.getParentFile().exists())
|
||||
@ -44,11 +46,14 @@ public class DeployConfGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
public static void batchGenerateDeployConf(String dir, String template, String commonvar, String filesStr) {
|
||||
public static void batchGenerateDeployConf(String dir, String template, String commonvar,
|
||||
String filesStr) {
|
||||
String templateStr = getFileContent(new File(dir, template).getAbsolutePath());
|
||||
try {
|
||||
JsonObject commVar = JsonParser.parseReader(new FileReader(new File(dir, commonvar))).getAsJsonObject();
|
||||
JsonArray files = JsonParser.parseReader(new FileReader(new File(dir, filesStr))).getAsJsonArray();
|
||||
JsonObject commVar = JsonParser.parseReader(new FileReader(new File(dir, commonvar)))
|
||||
.getAsJsonObject();
|
||||
JsonArray files = JsonParser.parseReader(new FileReader(new File(dir, filesStr)))
|
||||
.getAsJsonArray();
|
||||
for (JsonElement je : files) {
|
||||
JsonObject file = je.getAsJsonObject();
|
||||
File output = new File(dir, file.get("fileName").getAsString());
|
||||
@ -57,11 +62,13 @@ public class DeployConfGenerator {
|
||||
FileOutputStream fout = new FileOutputStream(output);
|
||||
String content = templateStr;
|
||||
for (String key : file.keySet()) {
|
||||
if (!key.startsWith("_")) continue;
|
||||
if (!key.startsWith("_"))
|
||||
continue;
|
||||
content = content.replaceAll(key, file.get(key).getAsString());
|
||||
}
|
||||
for (String key : commVar.keySet()) {
|
||||
if (file.has(key)) continue;
|
||||
if (file.has(key))
|
||||
continue;
|
||||
content = content.replaceAll(key, commVar.get(key).getAsString());
|
||||
}
|
||||
fout.write(content.getBytes(StandardCharsets.UTF_8));
|
||||
|
@ -25,19 +25,23 @@ public class Entry {
|
||||
}
|
||||
|
||||
private static void deployYpk(List<String> deployTasks) {
|
||||
if (deployTasks == null) return;
|
||||
if (deployTasks == null)
|
||||
return;
|
||||
for (String deployTask : deployTasks) {
|
||||
HTTPTool.deploy(deployTask);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateJson(List<GenerateTask> generateTaskList) {
|
||||
if (generateTaskList == null) return;
|
||||
if (generateTaskList == null)
|
||||
return;
|
||||
for (GenerateTask task : generateTaskList) {
|
||||
if (task.isBatch) {
|
||||
DeployConfGenerator.batchGenerateDeployConf(task.dir, task.template, task.commvar, task.files);
|
||||
DeployConfGenerator.batchGenerateDeployConf(task.dir, task.template, task.commvar,
|
||||
task.files);
|
||||
} else
|
||||
DeployConfGenerator.generateDeployConf(task.dir, task.template, task.commvar, task.files);
|
||||
DeployConfGenerator.generateDeployConf(task.dir, task.template, task.commvar,
|
||||
task.files);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class HTTPTool {
|
||||
static class DeployConfig {
|
||||
public boolean asDebug;
|
||||
String agentAddress;
|
||||
//common config
|
||||
// common config
|
||||
JsonElement createParam;
|
||||
String killBeforeStart;
|
||||
String privateKey;
|
||||
@ -74,23 +74,24 @@ public class HTTPTool {
|
||||
|
||||
private static void restart(DeployConfig config) {
|
||||
SM2KeyPair keyPair = SM2KeyPair.fromJson(new Gson().toJson(config));
|
||||
SmartContractClientExt ext = new SmartContractClientExt(String.format("ws://%s/SCIDE/SCExecutor", config.agentAddress), keyPair);
|
||||
SmartContractClientExt ext = new SmartContractClientExt(
|
||||
String.format("ws://%s/SCIDE/SCExecutor", config.agentAddress), keyPair);
|
||||
ext.waitForConnect();
|
||||
ext.login();
|
||||
for (; !ext.isLoggedIn; )
|
||||
for (; !ext.isLoggedIn;)
|
||||
Thread.yield();
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
try {
|
||||
if (config.killBeforeStart != null) ext.kill(config.killBeforeStart, new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(JsonObject r) {
|
||||
System.out.println(TAG + r);
|
||||
counter.incrementAndGet();
|
||||
}
|
||||
});
|
||||
for (; counter.get() == 0; )
|
||||
Thread.yield();
|
||||
;
|
||||
if (config.killBeforeStart != null)
|
||||
ext.kill(config.killBeforeStart, new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(JsonObject r) {
|
||||
System.out.println(TAG + r);
|
||||
counter.incrementAndGet();
|
||||
}
|
||||
});
|
||||
for (; counter.get() == 0;)
|
||||
Thread.yield();;
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -101,15 +102,17 @@ public class HTTPTool {
|
||||
ext.listProjects(true, new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(JsonObject r) {
|
||||
JsonArray array = JsonParser.parseString(r.get("data").getAsString()).getAsJsonArray();
|
||||
JsonArray array =
|
||||
JsonParser.parseString(r.get("data").getAsString()).getAsJsonArray();
|
||||
for (JsonElement je : array) {
|
||||
String fileName = je.getAsString();
|
||||
if (fileName.startsWith(contractName)) fileNames.add(fileName);
|
||||
if (fileName.startsWith(contractName))
|
||||
fileNames.add(fileName);
|
||||
}
|
||||
counter.incrementAndGet();
|
||||
}
|
||||
});
|
||||
for (; counter.get() == 1; )
|
||||
for (; counter.get() == 1;)
|
||||
Thread.yield();
|
||||
Collections.sort(fileNames, new Comparator<String>() {
|
||||
@Override
|
||||
@ -120,24 +123,26 @@ public class HTTPTool {
|
||||
|
||||
System.out.println(TAG + "startContract:" + fileNames.get(0));
|
||||
if (config.asDebug) {
|
||||
ext.startContractAsDebug(fileNames.get(0), config.createParam,config.remoteDebugPort, new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(JsonObject r) {
|
||||
System.out.println(TAG + r);
|
||||
counter.incrementAndGet();
|
||||
}
|
||||
});
|
||||
ext.startContractAsDebug(fileNames.get(0), config.createParam, config.remoteDebugPort,
|
||||
new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(JsonObject r) {
|
||||
System.out.println(TAG + r);
|
||||
counter.incrementAndGet();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ext.startContract(fileNames.get(0), config.createParam,config.remoteDebugPort, new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(JsonObject r) {
|
||||
System.out.println(TAG + r);
|
||||
counter.incrementAndGet();
|
||||
}
|
||||
});
|
||||
ext.startContract(fileNames.get(0), config.createParam, config.remoteDebugPort,
|
||||
new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(JsonObject r) {
|
||||
System.out.println(TAG + r);
|
||||
counter.incrementAndGet();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (; counter.get() == 2; )
|
||||
for (; counter.get() == 2;)
|
||||
Thread.yield();
|
||||
}
|
||||
|
||||
@ -145,7 +150,8 @@ public class HTTPTool {
|
||||
String sub = dirName.substring(contractName.length());
|
||||
if (sub.startsWith("_")) {
|
||||
return Integer.valueOf(sub.substring(1));
|
||||
} else return -1;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void deployUseHttp(DeployConfig config) {
|
||||
@ -154,9 +160,13 @@ public class HTTPTool {
|
||||
String argWithoutSig = "path=%s&fileName=%s&isPrivate=true&order=%d&count=%d&pubKey=%s";
|
||||
SM2KeyPair keyPair;
|
||||
try {
|
||||
keyPair = SM2KeyPair.fromJson(String.format("{\"publicKey\":\"%s\",\"privateKey\":\"%s\"}", config.publicKey, config.privateKey));
|
||||
keyPair = SM2KeyPair
|
||||
.fromJson(String.format("{\"publicKey\":\"%s\",\"privateKey\":\"%s\"}",
|
||||
config.publicKey, config.privateKey));
|
||||
} catch (Exception e) {
|
||||
System.out.println("[HttpTool] parse key error:\n" + String.format("{\"publicKey\":\"%s\",\"privateKey\":\"%s\"}", config.publicKey, config.privateKey));
|
||||
System.out.println("[HttpTool] parse key error:\n"
|
||||
+ String.format("{\"publicKey\":\"%s\",\"privateKey\":\"%s\"}",
|
||||
config.publicKey, config.privateKey));
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
@ -169,17 +179,21 @@ public class HTTPTool {
|
||||
FileInputStream fin = new FileInputStream(file);
|
||||
for (int len = 0; (len = fin.read(buff)) > 0; order++) {
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
String arg = String.format(argWithoutSig, "./", file.getName(), order, count, pubKey);
|
||||
String sign = ByteUtils.toHexString(SM2Util.sign(keyPair.getPrivateKeyParameter(), arg.getBytes(StandardCharsets.UTF_8)));
|
||||
String arg =
|
||||
String.format(argWithoutSig, "./", file.getName(), order, count, pubKey);
|
||||
String sign = ByteUtils.toHexString(SM2Util.sign(keyPair.getPrivateKeyParameter(),
|
||||
arg.getBytes(StandardCharsets.UTF_8)));
|
||||
String urlStr = String.format(url, config.agentAddress, arg, sign);
|
||||
HttpPost httpPost = new HttpPost(urlStr);
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
if (len == trunc)
|
||||
builder.addBinaryBody("file", buff, ContentType.APPLICATION_OCTET_STREAM, file.getName());
|
||||
builder.addBinaryBody("file", buff, ContentType.APPLICATION_OCTET_STREAM,
|
||||
file.getName());
|
||||
else {
|
||||
byte[] bu = new byte[len];
|
||||
System.arraycopy(buff, 0, bu, 0, len);
|
||||
builder.addBinaryBody("file", bu, ContentType.APPLICATION_OCTET_STREAM, file.getName());
|
||||
builder.addBinaryBody("file", bu, ContentType.APPLICATION_OCTET_STREAM,
|
||||
file.getName());
|
||||
|
||||
}
|
||||
HttpEntity multipart = builder.build();
|
||||
|
@ -42,7 +42,7 @@ public class RouterSetter {
|
||||
count.incrementAndGet();
|
||||
}
|
||||
});
|
||||
for (; count.get() < entry.tasks.size(); ) {
|
||||
for (; count.get() < entry.tasks.size();) {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
@ -55,8 +55,8 @@ public class RouterSetter {
|
||||
|
||||
private static void executeTask(SetUpperTask task) throws Exception {
|
||||
SM2KeyPair keyPair = SM2KeyPair.fromJson(new Gson().toJson(task));
|
||||
SmartContractClientExt ext = new SmartContractClientExt(String.format("ws://%s/SCIDE/SCExecutor", task.ipAndPort),
|
||||
keyPair);
|
||||
SmartContractClientExt ext = new SmartContractClientExt(
|
||||
String.format("ws://%s/SCIDE/SCExecutor", task.ipAndPort), keyPair);
|
||||
System.out.println("[RouterSetter] try connect " + task.nodeName + " " + task.ipAndPort);
|
||||
|
||||
ext.waitForConnect();
|
||||
@ -99,10 +99,8 @@ public class RouterSetter {
|
||||
cr.setAction("setSignature");
|
||||
cr.setContractID("Router");
|
||||
String toSign = task.nodeName + "|" + task.publicKey;
|
||||
String signature =
|
||||
ByteUtils.toHexString(
|
||||
SM2Util.sign(
|
||||
keyPair.getPrivateKeyParameter(), toSign.getBytes()));
|
||||
String signature = ByteUtils
|
||||
.toHexString(SM2Util.sign(keyPair.getPrivateKeyParameter(), toSign.getBytes()));
|
||||
cr.setArg(String.format("{\"signature\":\"%s\"}", signature));
|
||||
cr.doSignature(keyPair);
|
||||
result = ext.executeContractSync(cr);
|
||||
|
@ -37,7 +37,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
startContract(project, createParam, 0, null);
|
||||
}
|
||||
|
||||
public void startContractByYpk(String path, boolean isPrivate, JsonElement createParam, ResultCallback rc) {
|
||||
public void startContractByYpk(String path, boolean isPrivate, JsonElement createParam,
|
||||
ResultCallback rc) {
|
||||
String reqID = System.currentTimeMillis() + "";
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
ret.put("action", "startContractByYPK");
|
||||
@ -50,10 +51,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
String.format("Sole|%s|%s", ret.get("path"), getKeyPair().getPublicKeyStr());
|
||||
String sig;
|
||||
try {
|
||||
sig =
|
||||
ByteUtils.toHexString(
|
||||
SM2Util.sign(
|
||||
getKeyPair().getPrivateKeyParameter(), content.getBytes()));
|
||||
sig = ByteUtils.toHexString(
|
||||
SM2Util.sign(getKeyPair().getPrivateKeyParameter(), content.getBytes()));
|
||||
ret.put("signature", sig);
|
||||
} catch (CryptoException e) {
|
||||
e.printStackTrace();
|
||||
@ -77,10 +76,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
String.format("Sole|%s|%s", ret.get("path"), getKeyPair().getPublicKeyStr());
|
||||
String sig;
|
||||
try {
|
||||
sig =
|
||||
ByteUtils.toHexString(
|
||||
SM2Util.sign(
|
||||
getKeyPair().getPrivateKeyParameter(), content.getBytes()));
|
||||
sig = ByteUtils.toHexString(
|
||||
SM2Util.sign(getKeyPair().getPrivateKeyParameter(), content.getBytes()));
|
||||
ret.put("signature", sig);
|
||||
} catch (CryptoException e) {
|
||||
e.printStackTrace();
|
||||
@ -93,7 +90,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
this.sendMsg(new Gson().toJson(ret));
|
||||
}
|
||||
|
||||
public void startContractAsDebug(String project, JsonElement createParam, int remoteDebugPort, ResultCallback rc) {
|
||||
public void startContractAsDebug(String project, JsonElement createParam, int remoteDebugPort,
|
||||
ResultCallback rc) {
|
||||
String reqID = System.currentTimeMillis() + "";
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
ret.put("action", "startContractAsDebug");
|
||||
@ -108,10 +106,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
String.format("Sole|%s|%s", ret.get("path"), getKeyPair().getPublicKeyStr());
|
||||
String sig;
|
||||
try {
|
||||
sig =
|
||||
ByteUtils.toHexString(
|
||||
SM2Util.sign(
|
||||
getKeyPair().getPrivateKeyParameter(), content.getBytes()));
|
||||
sig = ByteUtils.toHexString(
|
||||
SM2Util.sign(getKeyPair().getPrivateKeyParameter(), content.getBytes()));
|
||||
ret.put("signature", sig);
|
||||
} catch (CryptoException e) {
|
||||
e.printStackTrace();
|
||||
@ -124,7 +120,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
this.sendMsg(new Gson().toJson(ret));
|
||||
}
|
||||
|
||||
public void startContract(String project, JsonElement createParam, int remoteDebugPort, ResultCallback rc) {
|
||||
public void startContract(String project, JsonElement createParam, int remoteDebugPort,
|
||||
ResultCallback rc) {
|
||||
String reqID = System.currentTimeMillis() + "";
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
ret.put("action", "startContract");
|
||||
@ -139,10 +136,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
String.format("Sole|%s|%s", ret.get("path"), getKeyPair().getPublicKeyStr());
|
||||
String sig;
|
||||
try {
|
||||
sig =
|
||||
ByteUtils.toHexString(
|
||||
SM2Util.sign(
|
||||
getKeyPair().getPrivateKeyParameter(), content.getBytes()));
|
||||
sig = ByteUtils.toHexString(
|
||||
SM2Util.sign(getKeyPair().getPrivateKeyParameter(), content.getBytes()));
|
||||
ret.put("signature", sig);
|
||||
} catch (CryptoException e) {
|
||||
e.printStackTrace();
|
||||
@ -157,11 +152,12 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
|
||||
@Override
|
||||
public void onLogin(JsonObject obj) {
|
||||
// LOGGER.info(obj.toString());
|
||||
// LOGGER.info(obj.toString());
|
||||
isLoggedIn = true;
|
||||
}
|
||||
|
||||
public void startMultiContractByScript(String script, String peersID, JsonElement createParam, ResultCallback rc) {
|
||||
public void startMultiContractByScript(String script, String peersID, JsonElement createParam,
|
||||
ResultCallback rc) {
|
||||
String reqID = System.currentTimeMillis() + "" + secureRandom.nextInt();
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
ret.put("action", "startContractMultiPoint");
|
||||
@ -172,7 +168,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
ret.put("requestID", reqID);
|
||||
ret.put("createParam", createParam);
|
||||
// "Algorithm|" + request.script + "|" + global.sm2Key.publicKey
|
||||
ret.put("signature", doSignature(getKeyPair().getPrivateKeyParameter(), "Sole|" + script + "|" + ret.get("owner")));
|
||||
ret.put("signature", doSignature(getKeyPair().getPrivateKeyParameter(),
|
||||
"Sole|" + script + "|" + ret.get("owner")));
|
||||
if (rc != null) {
|
||||
cbs.put(reqID, rc);
|
||||
}
|
||||
@ -183,10 +180,7 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
|
||||
public String doSignature(ECPrivateKeyParameters privateKey, String content) {
|
||||
try {
|
||||
return
|
||||
ByteUtils.toHexString(
|
||||
SM2Util.sign(
|
||||
privateKey, content.getBytes()));
|
||||
return ByteUtils.toHexString(SM2Util.sign(privateKey, content.getBytes()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -208,13 +202,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
|
||||
}
|
||||
|
||||
public void startMultiContract(
|
||||
boolean isPrivate,
|
||||
String ypkName,
|
||||
String peersID,
|
||||
int contractExecType,
|
||||
JsonElement createParam,
|
||||
ResultCallback rc) {
|
||||
public void startMultiContract(boolean isPrivate, String ypkName, String peersID,
|
||||
int contractExecType, JsonElement createParam, ResultCallback rc) {
|
||||
String reqID = System.currentTimeMillis() + "" + secureRandom.nextInt();
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
ret.put("action", "startContractMultiPoint");
|
||||
@ -242,9 +231,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
ret.put("owner", getKeyPair().getPublicKeyStr());
|
||||
ret.put("requestID", reqID);
|
||||
// "Algorithm|" + request.script + "|" + global.sm2Key.publicKey
|
||||
ret.put(
|
||||
"signature",
|
||||
doSignature(getKeyPair().getPrivateKeyParameter(), "Algorithm|" + script + "|" + ret.get("owner")));
|
||||
ret.put("signature", doSignature(getKeyPair().getPrivateKeyParameter(),
|
||||
"Algorithm|" + script + "|" + ret.get("owner")));
|
||||
if (rc != null) {
|
||||
cbs.put(reqID, rc);
|
||||
}
|
||||
@ -272,8 +260,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
this.sendMsg(new Gson().toJson(ret));
|
||||
}
|
||||
|
||||
// public void onExecuteResult(JsonObject obj) {
|
||||
// }
|
||||
// public void onExecuteResult(JsonObject obj) {
|
||||
// }
|
||||
|
||||
public void genBDCoin(String name) {
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
@ -295,7 +283,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
public void onStartContractTrustfullyResult(JsonObject jo) {
|
||||
String responseID = jo.get("responseID").getAsString();
|
||||
ResultCallback cb = cbs.get(responseID);
|
||||
if (cb != null) cb.onResult(jo);
|
||||
if (cb != null)
|
||||
cb.onResult(jo);
|
||||
}
|
||||
|
||||
@Action
|
||||
@ -317,7 +306,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
public void onListProjects(JsonObject jo) {
|
||||
String responseID = jo.get("responseID").getAsString();
|
||||
ResultCallback cb = cbs.get(responseID);
|
||||
if (cb != null) cb.onResult(jo);
|
||||
if (cb != null)
|
||||
cb.onResult(jo);
|
||||
}
|
||||
|
||||
|
||||
@ -329,7 +319,8 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
}
|
||||
String responseID = jo.get("responseID").getAsString();
|
||||
ResultCallback cb = cbs.get(responseID);
|
||||
if (cb != null) cb.onResult(jo);
|
||||
if (cb != null)
|
||||
cb.onResult(jo);
|
||||
}
|
||||
|
||||
public void requestNodeInfo() {
|
||||
@ -344,7 +335,7 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
|
||||
public void loginSync() {
|
||||
login();
|
||||
for (; !isLoggedIn; )
|
||||
for (; !isLoggedIn;)
|
||||
Thread.yield();
|
||||
}
|
||||
|
||||
@ -363,4 +354,4 @@ public class SmartContractClientExt extends SmartContractClient {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,32 +5,34 @@ import org.junit.Test;
|
||||
public class EntryTest {
|
||||
@Test
|
||||
public void generateAllConf() {
|
||||
Entry.main(new String[]{"./testinput/generateAllConf.json"});
|
||||
Entry.main(new String[] {"./testinput/generateAllConf.json"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deployrouter() {
|
||||
Entry.main(new String[]{"./testinput/deployrouter.json"});
|
||||
Entry.main(new String[] {"./testinput/deployrouter.json"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deployap() {
|
||||
Entry.main(new String[]{"./testinput/deployrouter.json"});
|
||||
Entry.main(new String[] {"./testinput/deployrouter.json"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deploycp() {
|
||||
Entry.main(new String[]{"./testinput/deployrouter.json"});
|
||||
Entry.main(new String[] {"./testinput/deployrouter.json"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deployBDTest() {
|
||||
HTTPTool.deploy("./testinput/deploy/router/GlobalRouter-023.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deployShanxiProxy() {
|
||||
HTTPTool.deploy("./testinput/debugconf-shanxiproxy.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deployRemoteDebug() {
|
||||
HTTPTool.deploy("./testinput/debugconf-remotedebug.json");
|
||||
|
@ -21,12 +21,15 @@ public class HttpUploadTest {
|
||||
@Test
|
||||
public void run() {
|
||||
String url = "http://%s/Upload?%s&sign=%s";
|
||||
File file = new File("/Users/huaqiancai/BDWare/bdcontract-bundle/agent-backend/BDWareProjectDir/publicCompiled/DoipDist-0.3.3.ypk");
|
||||
String argWithoutSig = "path=%s&fileName=%s&isPrivate=true&contractID=%s&order=%d&count=%d&pubKey=%s";
|
||||
File file = new File(
|
||||
"/Users/huaqiancai/BDWare/bdcontract-bundle/agent-backend/BDWareProjectDir/publicCompiled/DoipDist-0.3.3.ypk");
|
||||
String argWithoutSig =
|
||||
"path=%s&fileName=%s&isPrivate=true&contractID=%s&order=%d&count=%d&pubKey=%s";
|
||||
|
||||
SM2KeyPair keyPair;
|
||||
try {
|
||||
keyPair = SM2KeyPair.fromJson("{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}");
|
||||
keyPair = SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
@ -40,18 +43,22 @@ public class HttpUploadTest {
|
||||
FileInputStream fin = new FileInputStream(file);
|
||||
for (int len = 0; (len = fin.read(buff)) > 0; order++) {
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
String arg = String.format(argWithoutSig, "/ypks", file.getName(), "CodeRepo", order, count, pubKey);
|
||||
String sign = ByteUtils.toHexString(SM2Util.sign(keyPair.getPrivateKeyParameter(), arg.getBytes(StandardCharsets.UTF_8)));
|
||||
String arg = String.format(argWithoutSig, "/ypks", file.getName(), "CodeRepo",
|
||||
order, count, pubKey);
|
||||
String sign = ByteUtils.toHexString(SM2Util.sign(keyPair.getPrivateKeyParameter(),
|
||||
arg.getBytes(StandardCharsets.UTF_8)));
|
||||
String urlStr = String.format(url, "127.0.0.1:18000", arg, sign);
|
||||
System.out.println("urlStr:" + urlStr);
|
||||
HttpPost httpPost = new HttpPost(urlStr);
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
if (len == trunc)
|
||||
builder.addBinaryBody("file", buff, ContentType.APPLICATION_OCTET_STREAM, file.getName());
|
||||
builder.addBinaryBody("file", buff, ContentType.APPLICATION_OCTET_STREAM,
|
||||
file.getName());
|
||||
else {
|
||||
byte[] bu = new byte[len];
|
||||
System.arraycopy(buff, 0, bu, 0, len);
|
||||
builder.addBinaryBody("file", bu, ContentType.APPLICATION_OCTET_STREAM, file.getName());
|
||||
builder.addBinaryBody("file", bu, ContentType.APPLICATION_OCTET_STREAM,
|
||||
file.getName());
|
||||
|
||||
}
|
||||
HttpEntity multipart = builder.build();
|
||||
|
Loading…
Reference in New Issue
Block a user