feat: support requestID auto append in agent websocket

This commit is contained in:
CaiHQ 2021-11-01 18:52:02 +08:00
parent e11d151b55
commit 6a35a67631

View File

@ -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);
extractEventsFromContractResult(ocb, JsonUtil.parseString(result), client, request, start);
}
if (finalRet.length() == result.length()) {
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<REvent> 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);
}