From 41cec95a62b0a7bec5720aeb07469ae3fcd78c6f Mon Sep 17 00:00:00 2001 From: leej1012 Date: Mon, 27 May 2024 14:22:46 +0800 Subject: [PATCH] Update insert and update node info offchain --- .../explorer/statistics/service/ConfigService.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 4658dde..59e6d15 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 @@ -1,6 +1,7 @@ package com.github.ontio.explorer.statistics.service; import com.alibaba.fastjson.JSONObject; +import com.github.ontio.common.Address; import com.github.ontio.common.Helper; import com.github.ontio.core.asset.Sig; import com.github.ontio.core.payload.InvokeCode; @@ -124,6 +125,10 @@ public Response updateOffChainInfoByPublicKey(UpdateOffChainNodeInfoDto updateOf JSONObject jsonObject = JSONObject.parseObject(peerInfo); int status = jsonObject.getIntValue("status"); String address = jsonObject.getString("address"); + String stakeAddress = Address.addressFromPubKey(stakePublicKey).toBase58(); + if (!address.equals(stakeAddress)) { + return new Response(62006, "Verify signature failed.", ""); + } nodeInfoOffChain.setAddress(address); nodeInfoOffChain.setNodeType(status); String name = nodeInfoOffChainMapper.selectNameByPublicKey(nodePublicKey); @@ -146,7 +151,7 @@ public Response updateOffChainInfoByPublicKey(UpdateOffChainNodeInfoDto updateOf public Response updateOffChainInfoByLedger(UpdateOffChainNodeInfoDto updateOffChainNodeInfoDto) throws Exception { String nodeInfo = updateOffChainNodeInfoDto.getNodeInfo(); - String publicKey = updateOffChainNodeInfoDto.getPublicKey(); + String stakePublicKey = updateOffChainNodeInfoDto.getPublicKey(); byte[] nodeInfoBytes = Helper.hexToBytes(nodeInfo); InvokeCode transaction = (InvokeCode) Transaction.deserializeFrom(nodeInfoBytes); @@ -157,7 +162,7 @@ public Response updateOffChainInfoByLedger(UpdateOffChainNodeInfoDto updateOffCh String tx = hex.substring(0, hex.length() - 2); byte[] data = Digest.hash256(Helper.hexToBytes(tx)); - boolean verify = ontSdkService.verifySignatureByPublicKey(publicKey, data, signature); + boolean verify = ontSdkService.verifySignatureByPublicKey(stakePublicKey, data, signature); if (!verify) { return new Response(62006, "Verify signature failed.", ""); } @@ -177,6 +182,10 @@ public Response updateOffChainInfoByLedger(UpdateOffChainNodeInfoDto updateOffCh JSONObject jsonObject = JSONObject.parseObject(peerInfo); int status = jsonObject.getIntValue("status"); String address = jsonObject.getString("address"); + String stakeAddress = Address.addressFromPubKey(stakePublicKey).toBase58(); + if (!address.equals(stakeAddress)) { + return new Response(62006, "Verify signature failed.", ""); + } nodeInfoOffChain.setAddress(address); nodeInfoOffChain.setNodeType(status); String name = nodeInfoOffChainMapper.selectNameByPublicKey(nodePublicKey);