From aec912cc0abc1562a222aa67111ff0ab9c265666 Mon Sep 17 00:00:00 2001 From: leej1012 Date: Wed, 30 Oct 2024 15:23:16 +0800 Subject: [PATCH] Update updateOffChainInfo --- .../statistics/common/ParamsConfig.java | 2 -- .../mapper/ForbidEditNodeMapper.java | 10 ++++++ .../statistics/model/ForbidEditNode.java | 26 ++++++++++++++ .../statistics/service/ConfigService.java | 34 +++++++++++++++++-- src/main/resources/application.yml | 2 -- 5 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/github/ontio/explorer/statistics/mapper/ForbidEditNodeMapper.java create mode 100644 src/main/java/com/github/ontio/explorer/statistics/model/ForbidEditNode.java diff --git a/src/main/java/com/github/ontio/explorer/statistics/common/ParamsConfig.java b/src/main/java/com/github/ontio/explorer/statistics/common/ParamsConfig.java index baee62f..a0348b9 100644 --- a/src/main/java/com/github/ontio/explorer/statistics/common/ParamsConfig.java +++ b/src/main/java/com/github/ontio/explorer/statistics/common/ParamsConfig.java @@ -22,8 +22,6 @@ public class ParamsConfig { private List nodeFoundationPublicKeys = new ArrayList<>(); - private List forbidNodes = new ArrayList<>(); - private String consensusNodeDetailUrl; private String nodeMapUrl; diff --git a/src/main/java/com/github/ontio/explorer/statistics/mapper/ForbidEditNodeMapper.java b/src/main/java/com/github/ontio/explorer/statistics/mapper/ForbidEditNodeMapper.java new file mode 100644 index 0000000..c83300c --- /dev/null +++ b/src/main/java/com/github/ontio/explorer/statistics/mapper/ForbidEditNodeMapper.java @@ -0,0 +1,10 @@ +package com.github.ontio.explorer.statistics.mapper; + +import com.github.ontio.explorer.statistics.model.ForbidEditNode; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + +@Repository +public interface ForbidEditNodeMapper extends Mapper { + +} \ No newline at end of file diff --git a/src/main/java/com/github/ontio/explorer/statistics/model/ForbidEditNode.java b/src/main/java/com/github/ontio/explorer/statistics/model/ForbidEditNode.java new file mode 100644 index 0000000..9e383e2 --- /dev/null +++ b/src/main/java/com/github/ontio/explorer/statistics/model/ForbidEditNode.java @@ -0,0 +1,26 @@ +package com.github.ontio.explorer.statistics.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "tbl_forbid_edit_node") +public class ForbidEditNode { + @Id + @Column(name = "public_key") + @GeneratedValue(generator = "JDBC") + private String publicKey; + + @Column(name = "end_cycle") + private Integer endCycle; +} \ No newline at end of file diff --git a/src/main/java/com/github/ontio/explorer/statistics/service/ConfigService.java b/src/main/java/com/github/ontio/explorer/statistics/service/ConfigService.java index dc1d854..097678c 100644 --- a/src/main/java/com/github/ontio/explorer/statistics/service/ConfigService.java +++ b/src/main/java/com/github/ontio/explorer/statistics/service/ConfigService.java @@ -10,9 +10,11 @@ import com.github.ontio.explorer.statistics.common.ParamsConfig; import com.github.ontio.explorer.statistics.common.Response; import com.github.ontio.explorer.statistics.mapper.ConfigMapper; +import com.github.ontio.explorer.statistics.mapper.ForbidEditNodeMapper; import com.github.ontio.explorer.statistics.mapper.NodeInfoOffChainMapper; import com.github.ontio.explorer.statistics.mapper.NodeInfoOnChainMapper; import com.github.ontio.explorer.statistics.model.Config; +import com.github.ontio.explorer.statistics.model.ForbidEditNode; import com.github.ontio.explorer.statistics.model.NodeInfoOffChain; import com.github.ontio.explorer.statistics.model.NodeInfoOnChain; import com.github.ontio.explorer.statistics.model.dto.InsertOffChainNodeInfoDto; @@ -40,6 +42,8 @@ public class ConfigService { private NodeInfoOnChainMapper nodeInfoOnChainMapper; @Autowired private ConsensusNodeService consensusNodeService; + @Autowired + private ForbidEditNodeMapper forbidEditNodeMapper; public String getMaxStakingChangeCount() { @@ -173,7 +177,15 @@ public Response updateOffChainInfoByPublicKey(UpdateOffChainNodeInfoDto updateOf nodeInfoOffChain.setName(name); } - boolean forbidEditingName = paramsConfig.getForbidNodes().contains(nodePublicKey.toLowerCase()); + boolean forbidEditingName = false; + ForbidEditNode forbidEditNode = forbidEditNodeMapper.selectByPrimaryKey(nodePublicKey); + if (forbidEditNode != null) { + int currentCycle = ontSdkService.getGovernanceView().view; + Integer endCycle = forbidEditNode.getEndCycle(); + if (currentCycle < endCycle) { + forbidEditingName = true; + } + } NodeInfoOffChain existNodeInfo = nodeInfoOffChainMapper.selectByPrimaryKey(nodePublicKey); if (existNodeInfo == null) { // insert @@ -182,6 +194,7 @@ public Response updateOffChainInfoByPublicKey(UpdateOffChainNodeInfoDto updateOf nodeInfoOffChain.setName(name); nodeInfoOffChain.setRegion(""); nodeInfoOffChain.setIntroduction(""); + nodeInfoOffChain.setLogoUrl(""); } nodeInfoOffChainMapper.insertSelective(nodeInfoOffChain); } else { @@ -189,6 +202,7 @@ public Response updateOffChainInfoByPublicKey(UpdateOffChainNodeInfoDto updateOf String oldName = existNodeInfo.getName(); String oldRegion = existNodeInfo.getRegion(); String oldIntroduction = existNodeInfo.getIntroduction(); + String oldLogoUrl = existNodeInfo.getLogoUrl(); if (!oldName.equals(name)) { return new Response(61004, "Unable to edit node name temporarily", ""); } @@ -198,6 +212,9 @@ public Response updateOffChainInfoByPublicKey(UpdateOffChainNodeInfoDto updateOf if (!oldIntroduction.equals(nodeInfoOffChain.getIntroduction())) { return new Response(61004, "Unable to edit description temporarily", ""); } + if (!oldLogoUrl.equals(nodeInfoOffChain.getLogoUrl())) { + return new Response(61004, "Unable to edit icon temporarily", ""); + } } // update nodeInfoOffChain.setVerification(null); @@ -265,7 +282,15 @@ public Response updateOffChainInfoByLedger(UpdateOffChainNodeInfoDto updateOffCh nodeInfoOffChain.setName(name); } - boolean forbidEditingName = paramsConfig.getForbidNodes().contains(nodePublicKey.toLowerCase()); + boolean forbidEditingName = false; + ForbidEditNode forbidEditNode = forbidEditNodeMapper.selectByPrimaryKey(nodePublicKey); + if (forbidEditNode != null) { + int currentCycle = ontSdkService.getGovernanceView().view; + Integer endCycle = forbidEditNode.getEndCycle(); + if (currentCycle < endCycle) { + forbidEditingName = true; + } + } NodeInfoOffChain existNodeInfo = nodeInfoOffChainMapper.selectByPrimaryKey(nodePublicKey); if (existNodeInfo == null) { // insert @@ -274,6 +299,7 @@ public Response updateOffChainInfoByLedger(UpdateOffChainNodeInfoDto updateOffCh nodeInfoOffChain.setName(name); nodeInfoOffChain.setRegion(""); nodeInfoOffChain.setIntroduction(""); + nodeInfoOffChain.setLogoUrl(""); } nodeInfoOffChainMapper.insertSelective(nodeInfoOffChain); } else { @@ -281,6 +307,7 @@ public Response updateOffChainInfoByLedger(UpdateOffChainNodeInfoDto updateOffCh String oldName = existNodeInfo.getName(); String oldRegion = existNodeInfo.getRegion(); String oldIntroduction = existNodeInfo.getIntroduction(); + String oldLogoUrl = existNodeInfo.getLogoUrl(); if (!oldName.equals(name)) { return new Response(61004, "Unable to edit node name temporarily", ""); } @@ -290,6 +317,9 @@ public Response updateOffChainInfoByLedger(UpdateOffChainNodeInfoDto updateOffCh if (!oldIntroduction.equals(nodeInfoOffChain.getIntroduction())) { return new Response(61004, "Unable to edit description temporarily", ""); } + if (!oldLogoUrl.equals(nodeInfoOffChain.getLogoUrl())) { + return new Response(61004, "Unable to edit icon temporarily", ""); + } } // update nodeInfoOffChain.setVerification(null); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3bbb226..1723dea 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -73,8 +73,6 @@ config: - 03c8f63775536eb420c96228cdccc9de7d80e87f1b562a6eb93c0838064350aa53 evm-active-block: 16206729 cmc-api-key: 1 - forbid-nodes: - - 0207ce55d014519b547992ceb2824194e298cf28b548360f7bf2302be2cf29f4a4 node-schedule-task: update-on-chain-info: 300000