From 570ba555203649a6e8933a5d03765f9b68638033 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Fri, 19 Oct 2018 15:10:00 -0600 Subject: [PATCH] NC-1244 Implement JSON-RPC method "eth_getWork" (#111) JAX-B is no longer shipped with Java 11. Guava provides similar hex printing functionality. --- .../ethereum/jsonrpc/internal/methods/EthGetWork.java | 6 +++--- .../jsonrpc/internal/methods/EthGetWorkTest.java | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWork.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWork.java index 4c7407467a..e93bc854cb 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWork.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWork.java @@ -24,8 +24,8 @@ import tech.pegasys.pantheon.ethereum.mainnet.DirectAcyclicGraphSeed; import tech.pegasys.pantheon.ethereum.mainnet.EthHashSolverInputs; import java.util.Optional; -import javax.xml.bind.DatatypeConverter; +import com.google.common.io.BaseEncoding; import org.apache.logging.log4j.Logger; public class EthGetWork implements JsonRpcMethod { @@ -49,8 +49,8 @@ public class EthGetWork implements JsonRpcMethod { EthHashSolverInputs rawResult = solver.get(); byte[] dagSeed = DirectAcyclicGraphSeed.dagSeed(rawResult.getBlockNumber()); String[] result = { - "0x" + DatatypeConverter.printHexBinary(rawResult.getPrePowHash()).toLowerCase(), - "0x" + DatatypeConverter.printHexBinary(dagSeed).toLowerCase(), + "0x" + BaseEncoding.base16().lowerCase().encode(rawResult.getPrePowHash()), + "0x" + BaseEncoding.base16().lowerCase().encode(dagSeed), rawResult.getTarget().toHexString() }; return new JsonRpcSuccessResponse(req.getId(), result); diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWorkTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWorkTest.java index fcab8ab01b..bc8e848b0b 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWorkTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthGetWorkTest.java @@ -26,8 +26,8 @@ import tech.pegasys.pantheon.ethereum.mainnet.EthHashSolverInputs; import tech.pegasys.pantheon.util.uint.UInt256; import java.util.Optional; -import javax.xml.bind.DatatypeConverter; +import com.google.common.io.BaseEncoding; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -59,7 +59,7 @@ public class EthGetWorkTest { final JsonRpcRequest request = requestWithParams(); final EthHashSolverInputs values = new EthHashSolverInputs( - UInt256.fromHexString(hexValue), DatatypeConverter.parseHexBinary(hexValue), 0); + UInt256.fromHexString(hexValue), BaseEncoding.base16().lowerCase().decode(hexValue), 0); final String[] expectedValue = { "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -78,10 +78,12 @@ public class EthGetWorkTest { final JsonRpcRequest request = requestWithParams(); final EthHashSolverInputs values = new EthHashSolverInputs( - UInt256.fromHexString(hexValue), DatatypeConverter.parseHexBinary(hexValue), 30000); + UInt256.fromHexString(hexValue), + BaseEncoding.base16().lowerCase().decode(hexValue), + 30000); final String[] expectedValue = { "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "0x" + DatatypeConverter.printHexBinary(DirectAcyclicGraphSeed.dagSeed(30000)).toLowerCase(), + "0x" + BaseEncoding.base16().lowerCase().encode(DirectAcyclicGraphSeed.dagSeed(30000)), "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" }; final JsonRpcResponse expectedResponse =