NC-1244 Implement JSON-RPC method "eth_getWork" (#111)

JAX-B is no longer shipped with Java 11.  Guava provides similar
hex printing functionality.
Danno Ferrin 6 years ago committed by GitHub
parent 9fe2cdfdf0
commit 570ba55520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWork.java
  2. 10
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWorkTest.java

@ -24,8 +24,8 @@ import tech.pegasys.pantheon.ethereum.mainnet.DirectAcyclicGraphSeed;
import tech.pegasys.pantheon.ethereum.mainnet.EthHashSolverInputs; import tech.pegasys.pantheon.ethereum.mainnet.EthHashSolverInputs;
import java.util.Optional; import java.util.Optional;
import javax.xml.bind.DatatypeConverter;
import com.google.common.io.BaseEncoding;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
public class EthGetWork implements JsonRpcMethod { public class EthGetWork implements JsonRpcMethod {
@ -49,8 +49,8 @@ public class EthGetWork implements JsonRpcMethod {
EthHashSolverInputs rawResult = solver.get(); EthHashSolverInputs rawResult = solver.get();
byte[] dagSeed = DirectAcyclicGraphSeed.dagSeed(rawResult.getBlockNumber()); byte[] dagSeed = DirectAcyclicGraphSeed.dagSeed(rawResult.getBlockNumber());
String[] result = { String[] result = {
"0x" + DatatypeConverter.printHexBinary(rawResult.getPrePowHash()).toLowerCase(), "0x" + BaseEncoding.base16().lowerCase().encode(rawResult.getPrePowHash()),
"0x" + DatatypeConverter.printHexBinary(dagSeed).toLowerCase(), "0x" + BaseEncoding.base16().lowerCase().encode(dagSeed),
rawResult.getTarget().toHexString() rawResult.getTarget().toHexString()
}; };
return new JsonRpcSuccessResponse(req.getId(), result); return new JsonRpcSuccessResponse(req.getId(), result);

@ -26,8 +26,8 @@ import tech.pegasys.pantheon.ethereum.mainnet.EthHashSolverInputs;
import tech.pegasys.pantheon.util.uint.UInt256; import tech.pegasys.pantheon.util.uint.UInt256;
import java.util.Optional; import java.util.Optional;
import javax.xml.bind.DatatypeConverter;
import com.google.common.io.BaseEncoding;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -59,7 +59,7 @@ public class EthGetWorkTest {
final JsonRpcRequest request = requestWithParams(); final JsonRpcRequest request = requestWithParams();
final EthHashSolverInputs values = final EthHashSolverInputs values =
new EthHashSolverInputs( new EthHashSolverInputs(
UInt256.fromHexString(hexValue), DatatypeConverter.parseHexBinary(hexValue), 0); UInt256.fromHexString(hexValue), BaseEncoding.base16().lowerCase().decode(hexValue), 0);
final String[] expectedValue = { final String[] expectedValue = {
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000",
@ -78,10 +78,12 @@ public class EthGetWorkTest {
final JsonRpcRequest request = requestWithParams(); final JsonRpcRequest request = requestWithParams();
final EthHashSolverInputs values = final EthHashSolverInputs values =
new EthHashSolverInputs( new EthHashSolverInputs(
UInt256.fromHexString(hexValue), DatatypeConverter.parseHexBinary(hexValue), 30000); UInt256.fromHexString(hexValue),
BaseEncoding.base16().lowerCase().decode(hexValue),
30000);
final String[] expectedValue = { final String[] expectedValue = {
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"0x" + DatatypeConverter.printHexBinary(DirectAcyclicGraphSeed.dagSeed(30000)).toLowerCase(), "0x" + BaseEncoding.base16().lowerCase().encode(DirectAcyclicGraphSeed.dagSeed(30000)),
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
}; };
final JsonRpcResponse expectedResponse = final JsonRpcResponse expectedResponse =

Loading…
Cancel
Save