diff --git a/src/main/java/org/bdware/sc/server/DoipLocalSingleton.java b/src/main/java/org/bdware/sc/server/DoipLocalSingleton.java index aa77700d8f9b2eb685b6335dabd0b16a8e0f2e1b..b890d7f718c1892c258f8b7de4b1d70031f2a8fd 100644 --- a/src/main/java/org/bdware/sc/server/DoipLocalSingleton.java +++ b/src/main/java/org/bdware/sc/server/DoipLocalSingleton.java @@ -20,6 +20,7 @@ import org.zz.gmhelper.SM2KeyPair; import java.net.URI; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.UUID; public class DoipLocalSingleton { @@ -66,36 +67,46 @@ public class DoipLocalSingleton { e.printStackTrace(); } SM2KeyPair keyPair = JavaScriptEntry.getKeyPair(); - String repoID = "bdtest/BDRepo/" + UUID.randomUUID().toString(); + String repoID = ""; String owner = ContractProcess.instance.getContract().getOwner(); String repoType = "BDO"; EndpointConfig config = null; try { if (otherConfigs != null && otherConfigs.isJsonObject()) { config = new TempConfigStorage(otherConfigs.toString()).loadAsEndpointConfig(); + // 获取合约启动配置 if (otherConfigs.getAsJsonObject().has("repoID")) { repoID = otherConfigs.getAsJsonObject().get("repoID").getAsString(); } + if (otherConfigs.getAsJsonObject().has("publicKey")) { + owner = otherConfigs.getAsJsonObject().get("publicKey").getAsString(); + } if (config.privateKey == null || config.publicKey == null) { config.privateKey = keyPair.getPrivateKeyStr(); config.publicKey = keyPair.getPublicKeyStr(); } + if (config.routerURI != null && config.repoName != null) { - AuditIrpClient irpClient = new AuditIrpClient(config); - EndpointInfo endpointInfo = null; - for (int i = 0; i < 10; i++) { - endpointInfo = irpClient.getEndpointInfo(); - if (endpointInfo == null) - Thread.sleep(200); - } - if (endpointInfo != null) { - repoID = endpointInfo.getDoId(); - owner = endpointInfo.getPubKey(); - infos.clear(); + try { + AuditIrpClient irpClient = new AuditIrpClient(config); + EndpointInfo endpointInfo = null; + for (int i = 0; i < 10; i++) { + endpointInfo = irpClient.getEndpointInfo(); + if (endpointInfo == null) + Thread.sleep(200); + } + // 已合约自己的配置为主 + if (endpointInfo != null) { + repoID = Objects.equals(repoID, "") ? endpointInfo.getDoId() : repoID; + owner = owner.equals(config.publicKey) ? owner : endpointInfo.getPubKey(); + infos.clear(); + } + infos.add(new DoipListenerConfig(endpointInfo.getURI(), "2.1")); + port = new URI(endpointInfo.getURI()).getPort(); + SharableVarManager.initSharableVarManager(repoID, config); + } catch (Exception e) { + e.printStackTrace(); } - infos.add(new DoipListenerConfig(endpointInfo.getURI(), "2.1")); - port = new URI(endpointInfo.getURI()).getPort(); - SharableVarManager.initSharableVarManager(repoID, config); } } // 如果启动参数中添加了 doipStartPort 参数,使用该参数作为启动端口