From c322a981a9ed9549a1786d9e5272fc6654710a5e Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Fri, 10 Jun 2022 11:39:52 +0800 Subject: [PATCH] add start as debug --- build.gradle | 2 +- .../java/org/bdware/ypkdeploy/HTTPTool.java | 26 ++++++++++++----- .../ypkdeploy/SmartContractClientExt.java | 28 +++++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 951c75e..9bf7282 100755 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'signing' } group "org.bdware.bdcontract" -version "0.5.2" +version "0.5.5" sourceCompatibility = 1.8 repositories { mavenCentral() diff --git a/src/main/java/org/bdware/ypkdeploy/HTTPTool.java b/src/main/java/org/bdware/ypkdeploy/HTTPTool.java index 24a6be9..954d26e 100644 --- a/src/main/java/org/bdware/ypkdeploy/HTTPTool.java +++ b/src/main/java/org/bdware/ypkdeploy/HTTPTool.java @@ -27,6 +27,7 @@ public class HTTPTool { final static String TAG = "[HTTPTool] "; static class DeployConfig { + public boolean asDebug; String agentAddress; //common config JsonElement createParam; @@ -118,13 +119,24 @@ public class HTTPTool { }); System.out.println(TAG + "startContract:" + fileNames.get(0)); - ext.startContract(fileNames.get(0), config.createParam, new ResultCallback() { - @Override - public void onResult(JsonObject r) { - System.out.println(TAG + r); - counter.incrementAndGet(); - } - }); + if (config.asDebug) { + ext.startContractAsDebug(fileNames.get(0), config.createParam, new ResultCallback() { + @Override + public void onResult(JsonObject r) { + System.out.println(TAG + r); + counter.incrementAndGet(); + } + }); + } else { + ext.startContract(fileNames.get(0), config.createParam, new ResultCallback() { + @Override + public void onResult(JsonObject r) { + System.out.println(TAG + r); + counter.incrementAndGet(); + } + }); + } + for (; counter.get() == 2; ) Thread.yield(); } diff --git a/src/main/java/org/bdware/ypkdeploy/SmartContractClientExt.java b/src/main/java/org/bdware/ypkdeploy/SmartContractClientExt.java index 4933dd0..13be930 100644 --- a/src/main/java/org/bdware/ypkdeploy/SmartContractClientExt.java +++ b/src/main/java/org/bdware/ypkdeploy/SmartContractClientExt.java @@ -92,6 +92,34 @@ public class SmartContractClientExt extends SmartContractClient { } this.sendMsg(new Gson().toJson(ret)); } + public void startContractAsDebug(String project, JsonElement createParam, ResultCallback rc) { + String reqID = System.currentTimeMillis() + ""; + Map ret = new HashMap<>(); + ret.put("action", "startContractAsDebug"); + ret.put("isPrivate", true); + ret.put("owner", getKeyPair().getPublicKeyStr()); + ret.put("requestID", reqID); + ret.put("path", "/" + project + "/manifest.json"); + ret.put("createParam", createParam); + String content = + String.format("Sole|%s|%s", ret.get("path"), getKeyPair().getPublicKeyStr()); + String sig; + try { + sig = + ByteUtils.toHexString( + SM2Util.sign( + getKeyPair().getPrivateKeyParameter(), content.getBytes())); + ret.put("signature", sig); + } catch (CryptoException e) { + e.printStackTrace(); + } + + ret.put("script", "empty"); + if (rc != null) { + cbs.put(reqID, rc); + } + this.sendMsg(new Gson().toJson(ret)); + } public void startContract(String project, JsonElement createParam, ResultCallback rc) { String reqID = System.currentTimeMillis() + "";