Skip to content

Commit

Permalink
Update node info offchain node type
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed May 22, 2024
1 parent 6866327 commit 9338515
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
6 changes: 0 additions & 6 deletions sql/update20230407.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,20 @@ public Response insertOffChainInfo(InsertOffChainNodeInfoDto insertOffChainNodeI
String address = insertOffChainNodeInfoDto.getAddress();
String name = insertOffChainNodeInfoDto.getName();
String publicKey = insertOffChainNodeInfoDto.getPublicKey();
if (StringUtils.isEmpty(publicKey)) {
if (!StringUtils.hasLength(publicKey)) {
return new Response(61001, "Public key is blank", "");
}
String peerInfo = ontSdkService.getPeerInfo(publicKey);
if (!StringUtils.isEmpty(peerInfo)) {
if (StringUtils.hasLength(peerInfo)) {
JSONObject jsonObject = JSONObject.parseObject(peerInfo);
int status = jsonObject.getIntValue("status");
NodeInfoOffChain nodeInfoOffChain = new NodeInfoOffChain();
nodeInfoOffChain.setPublicKey(publicKey);
nodeInfoOffChain.setAddress(address);
nodeInfoOffChain.setName(name);
nodeInfoOffChain.setVerification(0);
nodeInfoOffChain.setOntId("");
nodeInfoOffChain.setNodeType(1);
nodeInfoOffChain.setNodeType(status);
nodeInfoOffChain.setOpenFlag(true);
nodeInfoOffChainMapper.insertSelective(nodeInfoOffChain);
return new Response(0, "SUCCESS", "SUCCESS");
Expand All @@ -109,14 +111,22 @@ public Response updateOffChainInfoByPublicKey(UpdateOffChainNodeInfoDto updateOf
if (ontId == null) {
nodeInfoOffChain.setOntId("");
}
nodeInfoOffChain.setNodeType(1);
String nodePublicKey = nodeInfoOffChain.getPublicKey();
String name = nodeInfoOffChainMapper.selectNameByPublicKey(nodePublicKey);
if (StringUtils.isEmpty(name)) {
if (!StringUtils.hasLength(name)) {
// insert
String peerInfo = ontSdkService.getPeerInfo(nodePublicKey);
if (StringUtils.hasLength(peerInfo)) {
JSONObject jsonObject = JSONObject.parseObject(peerInfo);
int status = jsonObject.getIntValue("status");
nodeInfoOffChain.setNodeType(status);
} else {
nodeInfoOffChain.setNodeType(1);
}
nodeInfoOffChainMapper.insertSelective(nodeInfoOffChain);
} else {
// update
nodeInfoOffChain.setNodeType(null);
nodeInfoOffChainMapper.updateByPrimaryKeySelective(nodeInfoOffChain);
}
return new Response(0, "SUCCESS", "SUCCESS");
Expand Down Expand Up @@ -147,14 +157,22 @@ public Response updateOffChainInfoByLedger(UpdateOffChainNodeInfoDto updateOffCh
if (ontId == null) {
nodeInfoOffChain.setOntId("");
}
nodeInfoOffChain.setNodeType(1);
String nodePublicKey = nodeInfoOffChain.getPublicKey();
String name = nodeInfoOffChainMapper.selectNameByPublicKey(nodePublicKey);
if (StringUtils.isEmpty(name)) {
if (!StringUtils.hasLength(name)) {
// insert
String peerInfo = ontSdkService.getPeerInfo(nodePublicKey);
if (StringUtils.hasLength(peerInfo)) {
JSONObject jsonObject = JSONObject.parseObject(peerInfo);
int status = jsonObject.getIntValue("status");
nodeInfoOffChain.setNodeType(status);
} else {
nodeInfoOffChain.setNodeType(1);
}
nodeInfoOffChainMapper.insertSelective(nodeInfoOffChain);
} else {
// update
nodeInfoOffChain.setNodeType(null);
nodeInfoOffChainMapper.updateByPrimaryKeySelective(nodeInfoOffChain);
}
return new Response(0, "SUCCESS", "SUCCESS");
Expand Down
15 changes: 7 additions & 8 deletions src/main/resources/mapper/NodeInfoOffChainMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@
<insert id="syncWithOnChainNodes">
INSERT INTO tbl_node_info_off_chain ( name, public_key, address, node_type, ont_id, open_flag ) SELECT
CASE
onchain.name
name
WHEN '' THEN
CONCAT('Node','_',SUBSTRING(onchain.public_key,1,6)) ELSE onchain.name
CONCAT('Node','_',SUBSTRING(public_key,1,6)) ELSE name
END,
onchain.public_key,
onchain.address,
onchain.STATUS,
public_key,
address,
status,
'',
1
FROM
tbl_node_info_on_chain onchain
LEFT JOIN tbl_node_info_off_chain offchain ON onchain.public_key = offchain.public_key
WHERE
offchain.public_key IS NULL;
ON DUPLICATE KEY UPDATE
node_type = VALUES(node_type)
</insert>


Expand Down

0 comments on commit 9338515

Please sign in to comment.