Skip to content

Commit

Permalink
Merge pull request #201 from cherry1603/develop
Browse files Browse the repository at this point in the history
fix compare to byte
  • Loading branch information
LucasMLK authored Mar 13, 2023
2 parents 99c46df + 6d83f95 commit 1d62ad6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions docs/XDAGJ_RPC.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| Function namE | parameter | example | describe |
| --------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ----------------------------------------------------- |
| Function name | parameter | example | describe |
|-----------------------------------| ------------------------------------------------------------ | ------------------------------------------------------------ | ----------------------------------------------------- |
| **xdag_getBlockByHash** | BlockHash(String) | Req: <br />curl http://127.0.0.1:10001/ -s -X POST -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"xdag_getBlockByHash\",\"params\":[\"K/SSa8tdBR68IPdf7ArdWVNbJonW+kkR\"],\"id\":1}" <br />Resp: <br />{"jsonrpc":"2.0","id":1,"result":{"height":5,"balance":"0.000000000","blockTime":1652541119999,"timeStamp":1692202106879,"state":"Main","hash":"17c7ff3cb08b76b41149fad689265b5359dd0aec5ff720bc1e055dcb6b92f42b","address":"K/SSa8tdBR68IPdf7ArdWVNbJonW+kkR","remark":"XdagJ","diff":"0x227e96893d","type":"Main","flags":"3f","refs":[{"direction":2,"address":"K/SSa8tdBR68IPdf7ArdWVNbJonW+kkR","hashlow":"00000000000000001149fad689265b5359dd0aec5ff720bc1e055dcb6b92f42b","amount":"0.000000000"},{"direction":1,"address":"MzJG2KZdVOM16EmvDTZ8diuDlW0BScOc","hashlow":"00000000000000009cc349016d95832b767c360daf49e835e3545da6d8463233","amount":"0.000000000"}],"transactions":[{"direction":2,"hashlow":"00000000000000001149fad689265b5359dd0aec5ff720bc1e055dcb6b92f42b","address":"K/SSa8tdBR68IPdf7ArdWVNbJonW+kkR","amount":"1024.000000000","time":1652541119999,"remark":"XdagJ"},{"direction":1,"hashlow":"0000000000000000a040e909b697cfa5062a968f8acf9f00bb74520644e37455","address":"VXTjRAZSdLsAn8+Kj5YqBqXPl7YJ6UCg","amount":"1024.000000000","time":1652544234516,"remark":""}]}} | Enter blockhash to return the block information |
| **xdag_getBlockByNumber** | BlockHeight (String) | Req: <br />curl http://127.0.0.1:10001/ -s -X POST -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"xdag_blockNumber\",\"params\":[],\"id\":1}" <br />Resp: <br />{"jsonrpc":"2.0","id":1,"result":{"height":6,"balance":"0.000000000","blockTime":1652541375999,"timeStamp":1692202369023,"state":"Main","hash":"b6d9ae965c74b53ae521e9149fade12d82366ed3b6aed65282100c6e8e59c5d9","address":"2cVZjm4MEIJS1q620242gi3hrZ8U6SHl","remark":"XdagJ","diff":"0x23e5005c0a","type":"Main","flags":"3f","refs":[{"direction":2,"address":"2cVZjm4MEIJS1q620242gi3hrZ8U6SHl","hashlow":"0000000000000000e521e9149fade12d82366ed3b6aed65282100c6e8e59c5d9","amount":"0.000000000"},{"direction":1,"address":"K/SSa8tdBR68IPdf7ArdWVNbJonW+kkR","hashlow":"00000000000000001149fad689265b5359dd0aec5ff720bc1e055dcb6b92f42b","amount":"0.000000000"},{"direction":1,"address":"3asjCLlpKDXzRzHjrS5FjlHJtNkpziLt","hashlow":"0000000000000000ed22ce29d9b4c9518e452eade33147f3352869b90823abdd","amount":"0.000000000"}],"transactions":[{"direction":2,"hashlow":"0000000000000000e521e9149fade12d82366ed3b6aed65282100c6e8e59c5d9","address":"2cVZjm4MEIJS1q620242gi3hrZ8U6SHl","amount":"1024.000000000","time":1652541375999,"remark":"XdagJ"},{"direction":1,"hashlow":"0000000000000000da8fe5e906dd98d34b64fb26139d1b8845acd9b461b2a8e5","address":"5aiyYbTZrEWIG50TJvtkS9OY3Qbp5Y/a","amount":"1024.000000000","time":1652544234518,"remark":""}]}} | Enter block height to return block information |
| **xdag_blockNumber** | Null | Req: <br />curl http://127.0.0.1:10001/ -s -X POST -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"xdag_blockNumber\",\"params\":[],\"id\":1}" <br />Resp: <br />{"jsonrpc":"2.0","id":1,"result":"5"} | Used to return the current main block height |
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/io/xdag/mine/handler/Miner03.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ protected void processTaskShare(TaskShareMessage msg) {
//实际是当初有伪块时区别矿机和钱包用的
if (compareTo(msg.getEncoded().reverse().toArray(), 0, 20, channel.getAccountAddressHashByte(),0,20) != 0) {
//TODO: 确定矿机协议,不再获取区块,直接获取Base58或者公钥的hash
Miner oldMiner = channel.getMiner();

Miner miner = kernel.getMinerManager().getActivateMiners()
.get(channel.getAccountAddressHash());
Expand All @@ -159,11 +158,6 @@ protected void processTaskShare(TaskShareMessage msg) {
channel.updateMiner(miner);
log.debug("RandomX miner channel:{}, address:{}, workerName:{}",
channel.getInetAddress().toString(), PubkeyAddressUtils.toBase58(miner.getAddressHashByte()), channel.getWorkerName());

if (oldMiner != null) {
oldMiner.setMinerStates(MinerStates.MINER_ARCHIVE);
minerManager.getActivateMiners().remove(oldMiner.getAddressHash());
}
}

if (channel.getSharesCounts() <= kernel.getConfig().getPoolSpec().getMaxShareCountPerChannel()) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/xdag/mine/handler/MinerMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import static io.xdag.net.message.XdagMessageCodes.WORKER_NAME;

import java.io.IOException;
import java.math.BigInteger;
import java.util.List;

import jakarta.xml.bind.DatatypeConverter;
import org.apache.commons.codec.binary.Hex;
import org.apache.tuweni.bytes.MutableBytes;

Expand All @@ -50,7 +50,7 @@ public class MinerMessageHandler extends ByteToMessageCodec<byte[]> {

private final MinerChannel channel;
private final int DATA_SIZE = 32;// length of each field
private static final long WORKERNAME_HEADER_WORD = 0xf46b9853L;
private static final String WORKERNAME_HEADER_WORD = "f46b9853";
private MessageFactory messageFactory;

public MinerMessageHandler(MinerChannel channel) {
Expand Down Expand Up @@ -95,7 +95,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
in.readBytes(data);
BytesUtils.arrayReverse(data);
//The message received is the worker_name
if(BytesUtils.compareTo(data,28,4, BigInteger.valueOf(WORKERNAME_HEADER_WORD).toByteArray(),0,4)==0){
if(BytesUtils.compareTo(data,28,4, DatatypeConverter.parseHexBinary(WORKERNAME_HEADER_WORD),0,4)==0){
msg = messageFactory.create(WORKER_NAME.asByte(),MutableBytes.wrap(data));
}else {
if (channel.isServer()) {
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/io/xdag/mine/message/MinerMessageFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ public Message create(byte code, MutableBytes encoded) {
// 从当前版本中获取到有用的信息
XdagMessageCodes receivedCommand = XdagMessageCodes.fromByte(code, XdagVersion.V03);
switch (receivedCommand) {
case TASK_SHARE -> {
return new TaskShareMessage(encoded);
}
case NEW_TASK -> {
return new NewTaskMessage(encoded);
}
case NEW_BALANCE -> {
return new NewBalanceMessage(encoded);
}
case WORKER_NAME -> {
return new WorkerNameMessage(encoded);
}
default -> {
log.debug(encoded.toHexString());
throw new IllegalArgumentException("No such message code" + receivedCommand);
}
case TASK_SHARE -> {
return new TaskShareMessage(encoded);
}
case NEW_TASK -> {
return new NewTaskMessage(encoded);
}
case NEW_BALANCE -> {
return new NewBalanceMessage(encoded);
}
case WORKER_NAME -> {
return new WorkerNameMessage(encoded);
}
default -> {
log.debug(encoded.toHexString());
throw new IllegalArgumentException("No such message code" + receivedCommand);
}
}
}
}

0 comments on commit 1d62ad6

Please sign in to comment.