add temporyaction

This commit is contained in:
CaiHQ 2023-06-09 18:20:26 +08:00
parent e925d0e9e7
commit 07e5070316
2 changed files with 20 additions and 2 deletions

View File

@ -169,7 +169,10 @@ public class TemporyTestAction {
Contract c = new Contract();
c.setScript(args.get("script").getAsString());
c.setOwner(args.get("owner").getAsString());
if (args.has("doipStartPort")) {
c.setDoipPort(args.get("doipStartPort").getAsInt());
} else
c.setDoipPort(1716);
ContractManager.instance.allocateKeyIfNotExists(c);
JsonObject jo = JsonUtil.parseObjectAsJsonObject(c);
jo.addProperty("action", "onAllocateKeyPair");

View File

@ -89,6 +89,8 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase implements
e.printStackTrace(new PrintStream(bo));
return replyStringWithStatus(doipMessage, "exception:" + new String(bo.toByteArray()), DoipResponseCode.Invalid);
}
digitalObject.attributes.addProperty("verifiedPubKey", doipMessage.credential.getSigner());
String path = null;
LOGGER.info("create BDO, bCoId:" + digitalObject.attributes.get("bCoId").getAsString());
@ -110,20 +112,31 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase implements
c.setOwner(doipMessage.credential.getSigner());
if (digitalObject.attributes.has("createParam")) {
c.setCreateParam(digitalObject.attributes.get("createParam"));
}
SM2KeyPair sm2Key;
if (digitalObject.attributes.has("sm2KeyPair"))
sm2Key = SM2KeyPair.fromJson(digitalObject.attributes.get("sm2KeyPair").getAsJsonObject().toString());
else sm2Key = SM2Util.generateSM2KeyPair();
String contractID = String.valueOf(sm2Key.getPublicKeyStr().hashCode());
c.setID(contractID); // contractID是根据hash算出来的
c.setKey(sm2Key.getPrivateKeyStr());
c.setPublicKey(sm2Key.getPublicKeyStr());
if (c.getCreateParam() != null && c.getCreateParam().isJsonObject()) {
c.getCreateParam().getAsJsonObject().addProperty("repoId", GlobalConf.instance.doaConf.repoDoid + "/" + c.getID());
}
registerBDOID(contractID);
String result = CMActions.manager.startContract(c);
//Please note startContractByYPK is invoked in sync mode method.
return replyStringWithStatus(doipMessage, result, DoipResponseCode.Success);
}
private void registerBDOID(String contractID) {
//TODO
}
@Override
public DoipMessage handleUpdate(DoipMessage doipMessage) {
return replyStringWithStatus(doipMessage, "not supported yet", DoipResponseCode.Declined);
@ -131,7 +144,9 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase implements
@Override
public DoipMessage handleDelete(DoipMessage doipMessage) {
String id = doipMessage.header.parameters.id;
String id = doipMessage.header.parameters.attributes.get("elementId").getAsString();
id = id.replaceAll(".*/", "");
LOGGER.info("handleDelete:" + id);
//TODO judge whethere the do exists
ContractMeta meta = CMActions.manager.statusRecorder.getContractMeta(id);
if (meta == null) {