Skip to content

Commit

Permalink
Update updateOffChainInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Oct 30, 2024
1 parent f8e11ac commit aec912c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class ParamsConfig {

private List<String> nodeFoundationPublicKeys = new ArrayList<>();

private List<String> forbidNodes = new ArrayList<>();

private String consensusNodeDetailUrl;

private String nodeMapUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ForbidEditNode> {

}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +42,8 @@ public class ConfigService {
private NodeInfoOnChainMapper nodeInfoOnChainMapper;
@Autowired
private ConsensusNodeService consensusNodeService;
@Autowired
private ForbidEditNodeMapper forbidEditNodeMapper;


public String getMaxStakingChangeCount() {
Expand Down Expand Up @@ -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
Expand All @@ -182,13 +194,15 @@ public Response updateOffChainInfoByPublicKey(UpdateOffChainNodeInfoDto updateOf
nodeInfoOffChain.setName(name);
nodeInfoOffChain.setRegion("");
nodeInfoOffChain.setIntroduction("");
nodeInfoOffChain.setLogoUrl("");
}
nodeInfoOffChainMapper.insertSelective(nodeInfoOffChain);
} else {
if (forbidEditingName) {
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", "");
}
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -274,13 +299,15 @@ public Response updateOffChainInfoByLedger(UpdateOffChainNodeInfoDto updateOffCh
nodeInfoOffChain.setName(name);
nodeInfoOffChain.setRegion("");
nodeInfoOffChain.setIntroduction("");
nodeInfoOffChain.setLogoUrl("");
}
nodeInfoOffChainMapper.insertSelective(nodeInfoOffChain);
} else {
if (forbidEditingName) {
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", "");
}
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aec912c

Please sign in to comment.