Skip to content

Commit

Permalink
Update node overview
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Aug 14, 2023
1 parent 5ba89ae commit 5dbdc52
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public NodesController(NodesServiceImpl nodesService,
@ApiOperation(value = "Get block count to next round")
@GetMapping(value = "/block-count-to-next-round")
public ResponseBean getBlkCountToNxtRnd() {
long blkCountToNxtRnd = nodesService.getBlkCountToNxtRnd();
long leftTime2NextRound = nodesService.getLeftTimeToNextRound();
NodeOverview nodeOverview = nodesService.getNodeOverviewInfo();
long maxStakingChangeCount = configService.getMaxStakingChangeCount();
if (blkCountToNxtRnd < 0 || leftTime2NextRound < 0 || maxStakingChangeCount <= 0) {
if (nodeOverview == null || maxStakingChangeCount <= 0) {
return new ResponseBean(ErrorInfo.INNER_ERROR.code(), ErrorInfo.INNER_ERROR.desc(), "");
}
JSONObject result = new JSONObject();
result.put("count_to_next_round", blkCountToNxtRnd);
result.put("count_to_next_round", nodeOverview.getBlkCntToNxtRnd());
result.put("max_staking_change_count", maxStakingChangeCount);
result.put("left_time_to_next_round", leftTime2NextRound);
result.put("left_time_to_next_round", nodeOverview.getLeftTimeToNextRnd());
result.put("round_start_time", nodeOverview.getRndStartTime());
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@
@Repository
public interface NodeOverviewMapper extends Mapper<NodeOverview> {

Long selectBlkCountToNxtRnd();

Long selectLeftTimeToNxtRnd();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public class NodeOverview {
@Column(name = "blk_cnt_to_nxt_rnd")
private Long blkCntToNxtRnd;

@Column(name = "left_time_to_next_rnd")
private Integer leftTimeToNextRnd;

@Column(name = "rnd_start_time")
private Integer rndStartTime;

/**
* @return id
*/
Expand Down Expand Up @@ -38,4 +44,20 @@ public Long getBlkCntToNxtRnd() {
public void setBlkCntToNxtRnd(Long blkCntToNxtRnd) {
this.blkCntToNxtRnd = blkCntToNxtRnd;
}

public Integer getLeftTimeToNextRnd() {
return leftTimeToNextRnd;
}

public void setLeftTimeToNextRnd(Integer leftTimeToNextRnd) {
this.leftTimeToNextRnd = leftTimeToNextRnd;
}

public Integer getRndStartTime() {
return rndStartTime;
}

public void setRndStartTime(Integer rndStartTime) {
this.rndStartTime = rndStartTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,12 @@ private synchronized void initSDK() {
}
}

public long getBlkCountToNxtRnd() {
public NodeOverview getNodeOverviewInfo() {
try {
return nodeOverviewMapper.selectBlkCountToNxtRnd();
return nodeOverviewMapper.selectByPrimaryKey(1);
} catch (Exception e) {
log.warn("Getting block count to next round failed: {}", e.getMessage());
return -1;
}
}

public long getLeftTimeToNextRound() {
try {
return nodeOverviewMapper.selectLeftTimeToNxtRnd();
} catch (Exception e) {
log.warn("Getting left time to next round failed: {}", e.getMessage());
return -1;
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE tbl_node_overview ADD COLUMN `rnd_start_time` int(11) DEFAULT NULL COMMENT '当前周期开始时间';
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.github.ontio.mapper.NodeOverviewMapper">
<resultMap id="BaseResultMap" type="com.github.ontio.model.dao.NodeOverview">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="blk_cnt_to_nxt_rnd" jdbcType="BIGINT" property="blkCntToNxtRnd"/>
</resultMap>
Expand All @@ -15,16 +12,4 @@
<property name="readOnly" value="false"/>
</cache>

<select id="selectBlkCountToNxtRnd" resultType="java.lang.Long" useCache="true">
SELECT blk_cnt_to_nxt_rnd
FROM tbl_node_overview
WHERE id = 1;
</select>

<select id="selectLeftTimeToNxtRnd" resultType="java.lang.Long" useCache="true">
SELECT left_time_to_next_rnd
FROM tbl_node_overview
WHERE id = 1;
</select>

</mapper>

0 comments on commit 5dbdc52

Please sign in to comment.