From 6a35a67631b66116be1655d243c8b5bcb3fb4247 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Mon, 1 Nov 2021 18:52:02 +0800 Subject: [PATCH] feat: support requestID auto append in agent websocket --- .../java/org/bdware/sc/ContractManager.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/bdware/sc/ContractManager.java b/src/main/java/org/bdware/sc/ContractManager.java index 00f7ee0..7cc1481 100644 --- a/src/main/java/org/bdware/sc/ContractManager.java +++ b/src/main/java/org/bdware/sc/ContractManager.java @@ -1295,7 +1295,7 @@ public class ContractManager { if (client.contractMeta.sigRequired) { if (!request.verifySignature()) { cr = new ContractResult(Status.Error, new JsonPrimitive("sign verified failed")); - rcb.onResult(JsonUtil.toJson(cr)); + rcb.onResult(JsonUtil.parseObject(cr)); return; } } @@ -1307,19 +1307,20 @@ public class ContractManager { new ResultCallback() { @Override public void onResult(String result) { + //TODO???? client.traffic += result.length(); client.contractStatus = ContractStatus.Executed; - String finalRet = result; + JsonObject finalRet = JsonUtil.parseString(result); if (client.getContractCopies() == 1) { finalRet = extractEventsFromContractResult( - cb, result, client, request, start); + cb, finalRet, client, request, start); } rcb.onResult(finalRet); - if (finalRet.length() == result.length()) { + if (finalRet != null) { chainOpener.writeContractResultToLocalAndLedger( - finalRet, + finalRet.toString(), client, request, cb, @@ -1334,6 +1335,7 @@ public class ContractManager { totalCounter.inc(); } + }; // if (ignoreLog) { // rcb.onResult( @@ -1367,14 +1369,11 @@ public class ContractManager { client.traffic += result.length(); - String finalRet = result; if (client.getContractCopies() == 1) { - finalRet = extractEventsFromContractResult(ocb, result, client, request, start); - } - if (finalRet.length() == result.length()) { - chainOpener.writeContractResultToLocalAndLedger( - result, client, request, ocb, start, System.currentTimeMillis() - start); + extractEventsFromContractResult(ocb, JsonUtil.parseString(result), client, request, start); } + chainOpener.writeContractResultToLocalAndLedger( + result, client, request, ocb, start, System.currentTimeMillis() - start); contractCounter.inc(); return result; } @@ -1384,21 +1383,19 @@ public class ContractManager { * * @author Kaidong Wu */ - public String extractEventsFromContractResult( + public JsonObject extractEventsFromContractResult( OnHashCallback ocb, - String result, + JsonObject result, ContractClient client, ContractRequest request, long startTime) { - String ret = result; try { ContractResult cr = JsonUtil.fromJson(result, ContractResult.class); if (null != cr.events && !cr.events.isEmpty()) { List msgList = cr.events; cr.events = null; - ret = JsonUtil.toJson(cr); chainOpener.writeContractResultToLocalAndLedger( - ret, + result.toString(), client, request, (reqID, hashStr) -> { @@ -1431,7 +1428,7 @@ public class ContractManager { } } catch (Exception ignored) { } - return ret; + return result; } public int countEvents() { @@ -1550,9 +1547,10 @@ public class ContractManager { new JsonPrimitive( "Contract " + cr.getContractID() + " doesn't exists!!")); } - rcb.onResult(JsonUtil.toJson(result)); + rcb.onResult(JsonUtil.parseObject(result)); } + private ContractClient getByName(String contractName) { return statusRecorder.getContractClient(contractName); }