From 28d7a096a8516d5b2c7ef3fba8b3546919294bc0 Mon Sep 17 00:00:00 2001 From: leej1012 Date: Wed, 22 May 2024 14:45:39 +0800 Subject: [PATCH] Update nodeInfo --- .../java/com/github/ontio/model/dto/NodeStakeDto.java | 6 ++++-- .../github/ontio/service/impl/AddressServiceImpl.java | 10 ++++++++-- .../db/migration/V1.82__tbl_node_info_offchain.sql | 3 +++ .../main/resources/mapper/NodeInfoOffChainMapper.xml | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 back-end-projects/Explorer/src/main/resources/db/migration/V1.82__tbl_node_info_offchain.sql diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/NodeStakeDto.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/NodeStakeDto.java index 3257c170..389c53b4 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/NodeStakeDto.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/NodeStakeDto.java @@ -21,7 +21,10 @@ public class NodeStakeDto { // 1-待生效;2-质押中;3-可提取;4-取消中 private int state; - // 1-候选节点;2-共识节点;3-节点退出 + // 1-候选节点;2-共识节点 + private int nodeType; + + // 0-节点退出;1-节点运行中 private int nodeState; private boolean allowStake; @@ -30,5 +33,4 @@ public class NodeStakeDto { // user apr private String apr; - } diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/AddressServiceImpl.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/AddressServiceImpl.java index 0637da48..a0a5624d 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/AddressServiceImpl.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/AddressServiceImpl.java @@ -1586,7 +1586,6 @@ public ResponseBean getAddressStakingInfo(String address) { int currentRound = sdk.getGovernanceView(); List currentOffChainInfo = nodeInfoOffChainMapper.selectAllStakingNodeInfo(); List nodeStakeDtos = new ArrayList<>(); - initSDK(); for (NodeInfoOffChain nodeInfoOffChain : currentOffChainInfo) { String publicKey = nodeInfoOffChain.getPublicKey(); try { @@ -1607,8 +1606,11 @@ private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOff String nodeName = nodeInfoOffChain.getName(); String address = nodeInfoOffChain.getAddress(); String progress = nodeInfoOffChain.getProgress(); + int nodeType = nodeInfoOffChain.getNodeType(); + // 节点存在且质押进度没到100%,则可以质押 boolean allowStake = progress != null && !"100.00%".equals(progress); - int nodeStatus = Optional.ofNullable(nodeInfoOffChain.getStatus()).orElse(3); + // 判断节点存在是否存在 + int nodeStatus = progress == null ? 0 : 1; String userApy = Optional.ofNullable(nodeInfoOffChain.getUserApy()).orElse(""); JSONObject stakingInfoObj = JSONObject.parseObject(stakingInfo); Long consensusPos = stakingInfoObj.getLong("consensusPos"); @@ -1626,6 +1628,7 @@ private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOff dto.setNodeWalletAddress(address); dto.setAmount(Long.toString(amount)); dto.setState(StakeStatusEnum.IN_STAKE.state()); + dto.setNodeType(nodeType); dto.setNodeState(nodeStatus); dto.setAllowStake(allowStake); dto.setCurrentRound(currentRound); @@ -1639,6 +1642,7 @@ private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOff dto.setNodeWalletAddress(address); dto.setAmount(newPos.toString()); dto.setState(StakeStatusEnum.PENDING.state()); + dto.setNodeType(nodeType); dto.setNodeState(nodeStatus); dto.setAllowStake(allowStake); dto.setCurrentRound(currentRound); @@ -1652,6 +1656,7 @@ private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOff dto.setNodeWalletAddress(address); dto.setAmount(withdrawUnfreezePos.toString()); dto.setState(StakeStatusEnum.WITHDRAWABLE.state()); + dto.setNodeType(nodeType); dto.setNodeState(nodeStatus); dto.setAllowStake(allowStake); dto.setCurrentRound(currentRound); @@ -1666,6 +1671,7 @@ private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOff dto.setNodeWalletAddress(address); dto.setAmount(Long.toString(amount)); dto.setState(StakeStatusEnum.CANCELLING.state()); + dto.setNodeType(nodeType); dto.setNodeState(nodeStatus); dto.setAllowStake(allowStake); dto.setCurrentRound(currentRound); diff --git a/back-end-projects/Explorer/src/main/resources/db/migration/V1.82__tbl_node_info_offchain.sql b/back-end-projects/Explorer/src/main/resources/db/migration/V1.82__tbl_node_info_offchain.sql new file mode 100644 index 00000000..0a79905d --- /dev/null +++ b/back-end-projects/Explorer/src/main/resources/db/migration/V1.82__tbl_node_info_offchain.sql @@ -0,0 +1,3 @@ +ALTER TABLE tbl_node_info_off_chain CHANGE `node_type` `node_type` int(11) NOT NULL COMMENT '节点类型:1-候选节点;2-共识节点'; + +UPDATE tbl_node_info_off_chain SET node_type = 1 WHERE node_type NOT IN (1,2); \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/resources/mapper/NodeInfoOffChainMapper.xml b/back-end-projects/Explorer/src/main/resources/mapper/NodeInfoOffChainMapper.xml index ff94a464..acf577bd 100644 --- a/back-end-projects/Explorer/src/main/resources/mapper/NodeInfoOffChainMapper.xml +++ b/back-end-projects/Explorer/src/main/resources/mapper/NodeInfoOffChainMapper.xml @@ -96,7 +96,7 @@ a.public_key, a.name, a.address, - b.status, + a.node_type, b.progress, c.user_apy FROM tbl_node_info_off_chain a