From 22e0127bd0d1ac8d041b26f2761c2208ab3e2054 Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Wed, 23 Mar 2022 18:29:24 +0800 Subject: [PATCH] feat(cm): implement two functions in ContractManager implement ContractManager.recoverUnitFromCheckPoint and ContractManager.getCheckPointFromUnit --- .../java/org/bdware/sc/ContractManager.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/bdware/sc/ContractManager.java b/src/main/java/org/bdware/sc/ContractManager.java index 592e06f..125fd96 100644 --- a/src/main/java/org/bdware/sc/ContractManager.java +++ b/src/main/java/org/bdware/sc/ContractManager.java @@ -1212,12 +1212,25 @@ public class ContractManager { } public void recoverUnitFromCheckPoint(String contractId, String checkPoint) { - // TODO + ContractClient client = getClient(contractId); + ContractRequest request = new ContractRequest(); + request.setContractID(contractId); + request.setAction("setGlobal"); + request.setArg(JsonUtil.parseObjectAsJsonObject(checkPoint)); + request.setPublicKey(client.contractMeta.getPubkey()); + request.doSignature(client.contractMeta.contract.key); + executeLocally(request, null); } public String getCheckPointFromUnit(String contractId) { - // TODO - return null; + ContractClient client = getClient(contractId); + ContractRequest request = new ContractRequest(); + request.setContractID(contractId); + request.setAction("getGlobal"); + request.setPublicKey(client.contractMeta.getPubkey()); + request.doSignature(client.contractMeta.contract.key); + ContractResult result = JsonUtil.fromJson(executeLocally(request, null), ContractResult.class); + return JsonUtil.toJson(result.result); } public String executeLocally(ContractRequest c, OnHashCallback cb) {