update nexa 全网算力调用三方api修改
This commit is contained in:
parent
5d7e3e6401
commit
779aaca109
|
@ -0,0 +1,47 @@
|
||||||
|
package com.m2pool.pool.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 文件
|
||||||
|
* @Date 2024/6/14 15:57
|
||||||
|
* @Author dy
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BlockNewInfo implements Serializable {
|
||||||
|
|
||||||
|
/** 全网报块 */
|
||||||
|
private long blocks;
|
||||||
|
|
||||||
|
|
||||||
|
private long currentblocksize;
|
||||||
|
|
||||||
|
private long currentblocktx;
|
||||||
|
|
||||||
|
private long currentmaxblocksize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全网难度
|
||||||
|
*/
|
||||||
|
private BigDecimal difficulty;
|
||||||
|
|
||||||
|
private String errors;
|
||||||
|
|
||||||
|
private BigDecimal networkhashps;
|
||||||
|
|
||||||
|
private long pooledtx;
|
||||||
|
|
||||||
|
private String chain;
|
||||||
|
|
||||||
|
private Map<String, MinerInfo> miners;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MinerInfo {
|
||||||
|
private Long lastrequest;
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,7 +49,7 @@ public class NodeTask {
|
||||||
blockInfo = NodeRpc.getBlock("nexa");
|
blockInfo = NodeRpc.getBlock("nexa");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
System.out.println("blockInfo 的信息"+blockInfo);
|
||||||
if(StringUtils.isNotNull(blockInfo)){
|
if(StringUtils.isNotNull(blockInfo)){
|
||||||
if(StringUtils.isNotNull(blockInfo.getPower())){
|
if(StringUtils.isNotNull(blockInfo.getPower())){
|
||||||
redisService.setCacheObject("nexa_block",blockInfo);
|
redisService.setCacheObject("nexa_block",blockInfo);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||||
import com.m2pool.common.core.text.Convert;
|
import com.m2pool.common.core.text.Convert;
|
||||||
import com.m2pool.common.core.utils.StringUtils;
|
import com.m2pool.common.core.utils.StringUtils;
|
||||||
import com.m2pool.pool.entity.BlockInfo;
|
import com.m2pool.pool.entity.BlockInfo;
|
||||||
|
import com.m2pool.pool.entity.BlockNewInfo;
|
||||||
import com.m2pool.pool.enums.NodeConfig;
|
import com.m2pool.pool.enums.NodeConfig;
|
||||||
import com.m2pool.pool.enums.NodeConstant;
|
import com.m2pool.pool.enums.NodeConstant;
|
||||||
import org.apache.http.HttpHeaders;
|
import org.apache.http.HttpHeaders;
|
||||||
|
@ -29,7 +30,7 @@ public class NodeRpc{
|
||||||
public static String getResult(String coin,String method,String[] params) {
|
public static String getResult(String coin,String method,String[] params) {
|
||||||
|
|
||||||
NodeConfig config = (NodeConfig) EnumUtils.get(NodeConfig.class, coin);
|
NodeConfig config = (NodeConfig) EnumUtils.get(NodeConfig.class, coin);
|
||||||
|
System.out.println("----------执行rpc接口调用");
|
||||||
String uri ="http://"+config.getIp()+":"+config.getHost();
|
String uri ="http://"+config.getIp()+":"+config.getHost();
|
||||||
|
|
||||||
String auth =config.getUser()+":"+config.getPwd();
|
String auth =config.getUser()+":"+config.getPwd();
|
||||||
|
@ -38,7 +39,10 @@ public class NodeRpc{
|
||||||
requestBody.put("jsonrpc", "1.0");
|
requestBody.put("jsonrpc", "1.0");
|
||||||
requestBody.put("id", "testnet");
|
requestBody.put("id", "testnet");
|
||||||
requestBody.put("method", method);
|
requestBody.put("method", method);
|
||||||
requestBody.put("params",params);
|
if(config.getCoin() != "nexa"){
|
||||||
|
requestBody.put("params",params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String body = HttpRequest
|
String body = HttpRequest
|
||||||
|
@ -201,8 +205,7 @@ public class NodeRpc{
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] params = {nowHeight,"2"};
|
String[] params = {nowHeight,"2"};
|
||||||
String result = getResult(coin, "getblock", params);
|
String result = getResult(coin, "getmininginfo", params);
|
||||||
|
|
||||||
BlockInfo blockInfo = new BlockInfo();
|
BlockInfo blockInfo = new BlockInfo();
|
||||||
|
|
||||||
if(StringUtils.isBlank(result)){
|
if(StringUtils.isBlank(result)){
|
||||||
|
@ -216,44 +219,51 @@ public class NodeRpc{
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject jsonObject = JSON.parseObject(result);
|
JSONObject jsonObject = JSON.parseObject(result);
|
||||||
long height = jsonObject.getLongValue("height");
|
long height = jsonObject.getLongValue("blocks");
|
||||||
blockInfo.setHeight(height);
|
blockInfo.setHeight(height);
|
||||||
|
|
||||||
BigDecimal difficulty = jsonObject.getBigDecimal("difficulty");
|
BigDecimal difficulty = jsonObject.getBigDecimal("difficulty");
|
||||||
|
|
||||||
if(StringUtils.isNotNull(difficulty)){
|
if(StringUtils.isNotNull(difficulty)){
|
||||||
blockInfo.setDifficulty(difficulty.setScale(2,BigDecimal.ROUND_HALF_UP));
|
blockInfo.setDifficulty(difficulty.setScale(2,BigDecimal.ROUND_HALF_UP));
|
||||||
NodeConstant constant = (NodeConstant) EnumUtils.get(NodeConstant.class, coin);
|
//NodeConstant constant = (NodeConstant) EnumUtils.get(NodeConstant.class, coin);
|
||||||
BigDecimal factor = constant.getFactor();
|
//BigDecimal factor = constant.getFactor();
|
||||||
if(StringUtils.isNotNull(factor)){
|
//if(StringUtils.isNotNull(factor)){
|
||||||
blockInfo.setPower(difficulty.multiply(factor).setScale(2,BigDecimal.ROUND_HALF_UP));
|
// blockInfo.setPower(difficulty.multiply(factor).setScale(2,BigDecimal.ROUND_HALF_UP));
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
BigDecimal netPower = jsonObject.getBigDecimal("networkhashps");
|
||||||
JSONArray txs = jsonObject.getJSONArray("tx");
|
if (StringUtils.isNotNull(netPower)){
|
||||||
if(StringUtils.isNull(txs)){
|
blockInfo.setPower(netPower);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//JSONArray txs = jsonObject.getJSONArray("tx");
|
||||||
|
//if(StringUtils.isNull(txs)){
|
||||||
|
// return null;
|
||||||
|
//}
|
||||||
//System.out.println(txs);
|
//System.out.println(txs);
|
||||||
final double[] reward = {0};
|
final double[] reward = {0};
|
||||||
final double[] fees = {0};
|
final double[] fees = {0};
|
||||||
txs.iterator().forEachRemaining(e -> {
|
//txs.iterator().forEachRemaining(e -> {
|
||||||
JSONObject json = (JSONObject) e;
|
// JSONObject json = (JSONObject) e;
|
||||||
String vin = json.getString("vin");
|
// String vin = json.getString("vin");
|
||||||
if(StringUtils.isNotNull(vin)){
|
// if(StringUtils.isNotNull(vin)){
|
||||||
if(vin.length() == 2){
|
// if(vin.length() == 2){
|
||||||
reward[0] = json.getDoubleValue("sends");
|
// reward[0] = json.getDoubleValue("sends");
|
||||||
}else if(vin.length() > 2){
|
// }else if(vin.length() > 2){
|
||||||
BigDecimal fee = json.getBigDecimal("fee");
|
// BigDecimal fee = json.getBigDecimal("fee");
|
||||||
BigDecimal newFees = fee.add(BigDecimal.valueOf(fees[0]));
|
// BigDecimal newFees = fee.add(BigDecimal.valueOf(fees[0]));
|
||||||
fees[0] = newFees.doubleValue();
|
// fees[0] = newFees.doubleValue();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
//});
|
||||||
|
|
||||||
blockInfo.setReward(BigDecimal.valueOf(reward[0]));
|
blockInfo.setReward(BigDecimal.valueOf(reward[0]));
|
||||||
blockInfo.setFees(BigDecimal.valueOf(fees[0]));
|
blockInfo.setFees(BigDecimal.valueOf(fees[0]));
|
||||||
blockInfo.setProfit(blockInfo.getReward().subtract(blockInfo.getFees()));
|
blockInfo.setProfit(blockInfo.getReward().subtract(blockInfo.getFees()));
|
||||||
|
System.out.println("blockInfo信息rpc"+blockInfo);
|
||||||
return blockInfo;
|
return blockInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue