Skip to content

Commit

Permalink
Update calculationUserIncentives
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed May 28, 2024
1 parent 7f54f52 commit 6ad0adc
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ public void exportAddressTransferTxs(
@RequestLimit(count = 30)
@ApiOperation(value = "get address staking info")
@GetMapping(value = "/{address}/staking-info")
public ResponseBean getAddressStakingInfo(@PathVariable @Length(min = 34, max = 42, message = "Incorrect address format") String address) {
return addressService.getAddressStakingInfo(address);
public ResponseBean getAddressStakingInfo(@PathVariable @Length(min = 34, max = 42, message = "Incorrect address format") String address,
@RequestParam(required = false) String channel) {
return addressService.getAddressStakingInfo(address, channel);
}

@RequestLimit(count = 30)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.ontio.model.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
Expand All @@ -8,6 +9,7 @@
* @date 2019/8/6
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class NodeStakeDto {

private String nodeName;
Expand All @@ -18,6 +20,8 @@ public class NodeStakeDto {

private String amount;

private String processingAmount;

// 1-待生效;2-质押中;3-可提取;4-取消中
private int state;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ResponseBean queryTransferTxsByTimeAndPage4Onto(String address, String assetName

void exportAddressTransferTxs(String token, String language, String address, Integer start, Integer end, HttpServletResponse resp) throws IOException;

ResponseBean getAddressStakingInfo(String address);
ResponseBean getAddressStakingInfo(String address, String channel);

ResponseBean getAddressStakingInfoWhenRoundStart(String address);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1581,26 +1581,40 @@ private boolean verifyReCAPTCHAToken(String token) {
}

@Override
public ResponseBean getAddressStakingInfo(String address) {
initSDK();
int currentRound = sdk.getGovernanceView();
public ResponseBean getAddressStakingInfo(String address, String channel) {
List<NodeInfoOffChain> currentOffChainInfo = nodeInfoOffChainMapper.selectAllStakingNodeInfo();
List<NodeStakeDto> nodeStakeDtos = new ArrayList<>();
for (NodeInfoOffChain nodeInfoOffChain : currentOffChainInfo) {
String publicKey = nodeInfoOffChain.getPublicKey();
try {
if (!publicKey.startsWith(ConstantParam.FAKE_NODE_PUBKEY_PREFIX)) {
String stakingInfo = sdk.getAuthorizeInfo(publicKey, address);
putStakingInfoList(stakingInfo, nodeInfoOffChain, nodeStakeDtos, currentRound);
if (ConstantParam.CHANNEL_ONTO.equalsIgnoreCase(channel)) {
initSDK();
int currentRound = sdk.getGovernanceView();
for (NodeInfoOffChain nodeInfoOffChain : currentOffChainInfo) {
String publicKey = nodeInfoOffChain.getPublicKey();
try {
if (!publicKey.startsWith(ConstantParam.FAKE_NODE_PUBKEY_PREFIX)) {
String stakingInfo = sdk.getAuthorizeInfo(publicKey, address);
putStakingInfoList4Onto(stakingInfo, nodeInfoOffChain, nodeStakeDtos, currentRound);
}
} catch (Exception e) {
log.error("getAddressStakingInfo error:{},{},{}", address, publicKey, e.getMessage());
}
}
} else {
for (NodeInfoOffChain nodeInfoOffChain : currentOffChainInfo) {
String publicKey = nodeInfoOffChain.getPublicKey();
try {
if (!publicKey.startsWith(ConstantParam.FAKE_NODE_PUBKEY_PREFIX)) {
String stakingInfo = sdk.getAuthorizeInfo(publicKey, address);
putStakingInfoList(stakingInfo, nodeInfoOffChain, nodeStakeDtos);
}
} catch (Exception e) {
log.error("getAddressStakingInfo error:{},{},{}", address, publicKey, e.getMessage());
}
} catch (Exception e) {
log.error("getAddressStakingInfo error:{},{},{}", address, publicKey, e.getMessage());
}
}
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), nodeStakeDtos);
}

private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOffChain, List<NodeStakeDto> nodeStakeDtos, int currentRound) {
private void putStakingInfoList4Onto(String stakingInfo, NodeInfoOffChain nodeInfoOffChain, List<NodeStakeDto> nodeStakeDtos, int currentRound) {
if (stakingInfo != null) {
String publicKey = nodeInfoOffChain.getPublicKey();
String nodeName = nodeInfoOffChain.getName();
Expand All @@ -1621,14 +1635,15 @@ private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOff
Long withdrawPos = stakingInfoObj.getLong("withdrawPos");
Long withdrawFreezePos = stakingInfoObj.getLong("withdrawFreezePos");
Long withdrawUnfreezePos = stakingInfoObj.getLong("withdrawUnfreezePos");
long stakedAmount = consensusPos + freezePos;

if (consensusPos + freezePos > 0) {
long amount = consensusPos + freezePos;
if (newPos > 0 || stakedAmount > 0) {
NodeStakeDto dto = new NodeStakeDto();
dto.setNodeName(nodeName);
dto.setNodePubKey(publicKey);
dto.setNodeWalletAddress(address);
dto.setAmount(Long.toString(amount));
dto.setAmount(String.valueOf(stakedAmount));
dto.setProcessingAmount(newPos.toString());
dto.setState(StakeStatusEnum.IN_STAKE.state());
dto.setNodeType(nodeType);
dto.setNodeState(nodeStatus);
Expand All @@ -1639,22 +1654,6 @@ private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOff
dto.setApr(userApy);
nodeStakeDtos.add(dto);
}
if (newPos > 0) {
NodeStakeDto dto = new NodeStakeDto();
dto.setNodeName(nodeName);
dto.setNodePubKey(publicKey);
dto.setNodeWalletAddress(address);
dto.setAmount(newPos.toString());
dto.setState(StakeStatusEnum.PENDING.state());
dto.setNodeType(nodeType);
dto.setNodeState(nodeStatus);
dto.setAllowStake(allowStake);
dto.setTotalPos(totalPos);
dto.setMaxAuthorize(maxAuthorize);
dto.setCurrentRound(currentRound);
dto.setApr(userApy);
nodeStakeDtos.add(dto);
}
if (withdrawUnfreezePos > 0) {
NodeStakeDto dto = new NodeStakeDto();
dto.setNodeName(nodeName);
Expand Down Expand Up @@ -1691,6 +1690,55 @@ private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOff
}
}

private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOffChain, List<NodeStakeDto> nodeStakeDtos) {
if (stakingInfo != null) {
String publicKey = nodeInfoOffChain.getPublicKey();
String nodeName = nodeInfoOffChain.getName();
JSONObject stakingInfoObj = JSONObject.parseObject(stakingInfo);
Long consensusPos = stakingInfoObj.getLong("consensusPos");
Long freezePos = stakingInfoObj.getLong("freezePos");
Long newPos = stakingInfoObj.getLong("newPos");
Long withdrawPos = stakingInfoObj.getLong("withdrawPos");
Long withdrawFreezePos = stakingInfoObj.getLong("withdrawFreezePos");
Long withdrawUnfreezePos = stakingInfoObj.getLong("withdrawUnfreezePos");

if (newPos > 0) {
NodeStakeDto dto = new NodeStakeDto();
dto.setNodeName(nodeName);
dto.setNodePubKey(publicKey);
dto.setAmount(newPos.toString());
dto.setState(StakeStatusEnum.PENDING.state());
nodeStakeDtos.add(dto);
}
if (consensusPos + freezePos > 0) {
NodeStakeDto dto = new NodeStakeDto();
dto.setNodeName(nodeName);
dto.setNodePubKey(publicKey);
Long amount = consensusPos + freezePos;
dto.setAmount(amount.toString());
dto.setState(StakeStatusEnum.IN_STAKE.state());
nodeStakeDtos.add(dto);
}
if (withdrawUnfreezePos > 0) {
NodeStakeDto dto = new NodeStakeDto();
dto.setNodeName(nodeName);
dto.setNodePubKey(publicKey);
dto.setAmount(withdrawUnfreezePos.toString());
dto.setState(StakeStatusEnum.WITHDRAWABLE.state());
nodeStakeDtos.add(dto);
}
if (withdrawPos + withdrawFreezePos > 0) {
NodeStakeDto dto = new NodeStakeDto();
dto.setNodeName(nodeName);
dto.setNodePubKey(publicKey);
Long amount = withdrawPos + withdrawFreezePos;
dto.setAmount(amount.toString());
dto.setState(StakeStatusEnum.CANCELLING.state());
nodeStakeDtos.add(dto);
}
}
}

@Override
public ResponseBean getAddressStakingInfoWhenRoundStart(String address) {
List<GovernanceInfoDto> stakingInfoList = commonMapper.getStakingInfoByAddress(address);
Expand Down

0 comments on commit 6ad0adc

Please sign in to comment.