Skip to content

Commit

Permalink
Update insert and update node info offchain
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed May 27, 2024
1 parent 42ac2e1 commit 41cec95
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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.", "");
}
Expand All @@ -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);
Expand Down

0 comments on commit 41cec95

Please sign in to comment.