From 11d642750f8127170bc7d6665fe0e6f7f85abec3 Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Wed, 9 May 2018 13:57:42 +0530 Subject: [PATCH 1/4] Use null safe method to convert bytes to hexString This commit replaces use of `org.spongycastle.util.encoders.Hex.toHexString()` (Not null safe) with `org.ethereum.util.ByteUtil.toHexString()` (null safe) while logging and in all toString() methods. This covers only logging in the implementation(`/src/main`) and doesn't cover any logging in tests(`/src/tests`) Issue #1032 --- .../org/ethereum/config/SystemProperties.java | 3 +- .../java/org/ethereum/core/AccountState.java | 7 ++-- .../main/java/org/ethereum/core/Block.java | 5 ++- .../org/ethereum/core/BlockHeaderWrapper.java | 3 +- .../org/ethereum/core/BlockIdentifier.java | 6 +-- .../org/ethereum/core/BlockchainImpl.java | 37 +++++++++--------- .../main/java/org/ethereum/core/Bloom.java | 5 ++- .../org/ethereum/core/PendingStateImpl.java | 11 +++--- .../ethereum/core/TransactionExecutor.java | 12 +++--- .../org/ethereum/core/TransactionReceipt.java | 10 ++--- .../main/java/org/ethereum/crypto/ECKey.java | 5 ++- .../datasource/leveldb/LevelDbDataSource.java | 16 ++++---- .../datasource/rocksdb/RocksDbDataSource.java | 17 +++++---- .../org/ethereum/db/ByteArrayWrapper.java | 6 +-- .../java/org/ethereum/db/prune/Pruner.java | 17 +++++---- .../org/ethereum/facade/EthereumImpl.java | 4 +- .../org/ethereum/listener/EventListener.java | 4 +- .../org/ethereum/manager/WorldManager.java | 3 +- .../main/java/org/ethereum/net/dht/Peer.java | 4 +- .../org/ethereum/net/eth/handler/Eth62.java | 5 +-- .../org/ethereum/net/eth/handler/Eth63.java | 6 +-- .../net/eth/message/BlockBodiesMessage.java | 4 +- .../net/eth/message/BlockHeadersMessage.java | 9 +++-- .../eth/message/GetBlockBodiesMessage.java | 4 +- .../net/eth/message/GetNodeDataMessage.java | 5 ++- .../net/eth/message/GetReceiptsMessage.java | 5 ++- .../net/eth/message/NewBlockMessage.java | 4 +- .../net/eth/message/StatusMessage.java | 6 ++- .../net/rlpx/AuthInitiateMessage.java | 10 ++--- .../net/rlpx/AuthInitiateMessageV4.java | 8 ++-- .../net/rlpx/AuthResponseMessage.java | 5 ++- .../net/rlpx/AuthResponseMessageV4.java | 5 ++- .../ethereum/net/rlpx/FindNodeMessage.java | 8 ++-- .../org/ethereum/net/rlpx/Handshaker.java | 4 +- .../java/org/ethereum/net/rlpx/Message.java | 10 ++--- .../org/ethereum/net/rlpx/MessageCodec.java | 8 ++-- .../main/java/org/ethereum/net/rlpx/Node.java | 3 +- .../org/ethereum/net/rlpx/PongMessage.java | 10 ++--- .../net/rlpx/discover/PacketDecoder.java | 5 ++- .../org/ethereum/net/server/PeerServer.java | 5 ++- .../ethereum/net/shh/ShhFilterMessage.java | 4 +- .../main/java/org/ethereum/net/shh/Topic.java | 4 +- .../org/ethereum/net/shh/WhisperMessage.java | 4 +- .../java/org/ethereum/net/swarm/Hive.java | 36 +++++++++--------- .../ethereum/net/swarm/bzz/PeerAddress.java | 38 +++++++++---------- .../samples/CreateContractSample.java | 4 +- .../ethereum/samples/EventListenerSample.java | 5 ++- .../ethereum/samples/PendingStateSample.java | 7 ++-- .../org/ethereum/samples/TransactionBomb.java | 3 +- .../org/ethereum/solidity/SolidityType.java | 5 ++- .../org/ethereum/sync/BlockDownloader.java | 4 +- .../org/ethereum/sync/FastSyncManager.java | 12 +++--- .../org/ethereum/sync/HeadersDownloader.java | 5 ++- .../java/org/ethereum/sync/SyncManager.java | 6 +-- .../java/org/ethereum/sync/SyncQueueImpl.java | 4 +- .../main/java/org/ethereum/trie/TrieImpl.java | 7 ++-- .../main/java/org/ethereum/trie/TrieKey.java | 5 +-- .../main/java/org/ethereum/util/Value.java | 6 ++- .../main/java/org/ethereum/vm/DataWord.java | 4 +- .../main/java/org/ethereum/vm/LogInfo.java | 9 ++--- .../invoke/ProgramInvokeFactoryImpl.java | 33 ++++++++-------- 61 files changed, 269 insertions(+), 240 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java b/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java index 46ba76125a..2a1f3970d6 100644 --- a/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java +++ b/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java @@ -53,6 +53,7 @@ import java.util.*; import static org.ethereum.crypto.HashUtil.sha3; +import static org.ethereum.util.ByteUtil.toHexString; /** * Utility class to retrieve property values from the ethereumj.conf files @@ -810,7 +811,7 @@ public boolean isFastSyncEnabled() { public byte[] getFastSyncPivotBlockHash() { if (!config.hasPath("sync.fast.pivotBlockHash")) return null; byte[] ret = Hex.decode(config.getString("sync.fast.pivotBlockHash")); - if (ret.length != 32) throw new RuntimeException("Invalid block hash length: " + Hex.toHexString(ret)); + if (ret.length != 32) throw new RuntimeException("Invalid block hash length: " + toHexString(ret)); return ret; } diff --git a/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java b/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java index 6b51f784cf..76d6811672 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java @@ -25,12 +25,11 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; - import java.math.BigInteger; import static org.ethereum.crypto.HashUtil.*; import static org.ethereum.util.FastByteComparisons.equal; +import static org.ethereum.util.ByteUtil.toHexString; public class AccountState { @@ -151,8 +150,8 @@ public boolean isEmpty() { public String toString() { String ret = " Nonce: " + this.getNonce().toString() + "\n" + " Balance: " + getBalance() + "\n" + - " State Root: " + Hex.toHexString(this.getStateRoot()) + "\n" + - " Code Hash: " + Hex.toHexString(this.getCodeHash()); + " State Root: " + toHexString(this.getStateRoot()) + "\n" + + " Code Hash: " + toHexString(this.getCodeHash()); return ret; } } diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Block.java b/ethereumj-core/src/main/java/org/ethereum/core/Block.java index f22768c530..80774acc50 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Block.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Block.java @@ -34,6 +34,7 @@ import static org.ethereum.crypto.HashUtil.sha3; import static org.ethereum.datasource.MemSizeEstimator.ByteArrayEstimator; +import static org.ethereum.util.ByteUtil.toHexString; /** * The block in Ethereum is the collection of relevant pieces of information @@ -69,7 +70,7 @@ private Block() { } public Block(byte[] rawData) { - logger.debug("new from [" + Hex.toHexString(rawData) + "]"); + logger.debug("new from [" + toHexString(rawData) + "]"); this.rlpEncoded = rawData; } @@ -304,7 +305,7 @@ public String toString() { parseRLP(); toStringBuff.setLength(0); - toStringBuff.append(Hex.toHexString(this.getEncoded())).append("\n"); + toStringBuff.append(toHexString(this.getEncoded())).append("\n"); toStringBuff.append("BlockData [ "); toStringBuff.append(header.toString()); diff --git a/ethereumj-core/src/main/java/org/ethereum/core/BlockHeaderWrapper.java b/ethereumj-core/src/main/java/org/ethereum/core/BlockHeaderWrapper.java index 009fa26364..16486c9859 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/BlockHeaderWrapper.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/BlockHeaderWrapper.java @@ -24,6 +24,7 @@ import java.util.Arrays; import java.util.List; +import static org.ethereum.util.ByteUtil.toHexString; /** *

Wraps {@link BlockHeader}

@@ -90,7 +91,7 @@ public boolean sentBy(byte[] nodeId) { public String toString() { return "BlockHeaderWrapper {" + "header=" + header + - ", nodeId=" + Hex.toHexString(nodeId) + + ", nodeId=" + toHexString(nodeId) + '}'; } } diff --git a/ethereumj-core/src/main/java/org/ethereum/core/BlockIdentifier.java b/ethereumj-core/src/main/java/org/ethereum/core/BlockIdentifier.java index 46fe39627a..324e9fce64 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/BlockIdentifier.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/BlockIdentifier.java @@ -17,15 +17,15 @@ */ package org.ethereum.core; -import org.ethereum.util.ByteUtil; import org.ethereum.util.RLP; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.util.Arrays; import static org.ethereum.util.ByteUtil.byteArrayToLong; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Block identifier holds block hash and number
@@ -75,7 +75,7 @@ public byte[] getEncoded() { @Override public String toString() { return "BlockIdentifier {" + - "hash=" + Hex.toHexString(hash) + + "hash=" + toHexString(hash) + ", number=" + number + '}'; } diff --git a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java index 252403f122..9ae878cdff 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java @@ -67,6 +67,7 @@ import static org.ethereum.core.Denomination.SZABO; import static org.ethereum.core.ImportResult.*; import static org.ethereum.crypto.HashUtil.sha3; +import static org.ethereum.util.ByteUtil.toHexString; /** * The Ethereum blockchain is in many ways similar to the Bitcoin blockchain, @@ -268,7 +269,7 @@ public TransactionInfo getTransactionInfo(byte[] hash) { } } if (txInfo == null) { - logger.warn("Can't find block from main chain for transaction " + Hex.toHexString(hash)); + logger.warn("Can't find block from main chain for transaction " + toHexString(hash)); return null; } @@ -410,7 +411,7 @@ public synchronized ImportResult tryToConnect(final Block block) { if (logger.isDebugEnabled()) logger.debug("Try connect block hash: {}, number: {}", - Hex.toHexString(block.getHash()).substring(0, 6), + toHexString(block.getHash()).substring(0, 6), block.getNumber()); if (blockStore.getMaxNumber() >= block.getNumber() && @@ -418,7 +419,7 @@ public synchronized ImportResult tryToConnect(final Block block) { if (logger.isDebugEnabled()) logger.debug("Block already exist hash: {}, number: {}", - Hex.toHexString(block.getHash()).substring(0, 6), + toHexString(block.getHash()).substring(0, 6), block.getNumber()); // retry of well known block @@ -582,22 +583,22 @@ public synchronized BlockSummary addImpl(Repository repo, final Block block) { // Sanity checks if (!FastByteComparisons.equal(block.getReceiptsRoot(), calcReceiptsTrie(receipts))) { - logger.warn("Block's given Receipt Hash doesn't match: {} != {}", Hex.toHexString(block.getReceiptsRoot()), Hex.toHexString(calcReceiptsTrie(receipts))); + logger.warn("Block's given Receipt Hash doesn't match: {} != {}", toHexString(block.getReceiptsRoot()), toHexString(calcReceiptsTrie(receipts))); logger.warn("Calculated receipts: " + receipts); repo.rollback(); summary = null; } if (!FastByteComparisons.equal(block.getLogBloom(), calcLogBloom(receipts))) { - logger.warn("Block's given logBloom Hash doesn't match: {} != {}", Hex.toHexString(block.getLogBloom()), Hex.toHexString(calcLogBloom(receipts))); + logger.warn("Block's given logBloom Hash doesn't match: {} != {}", toHexString(block.getLogBloom()), toHexString(calcLogBloom(receipts))); repo.rollback(); summary = null; } if (!FastByteComparisons.equal(block.getStateRoot(), repo.getRoot())) { - stateLogger.warn("BLOCK: State conflict or received invalid block. block: {} worldstate {} mismatch", block.getNumber(), Hex.toHexString(repo.getRoot())); - stateLogger.warn("Conflict block dump: {}", Hex.toHexString(block.getEncoded())); + stateLogger.warn("BLOCK: State conflict or received invalid block. block: {} worldstate {} mismatch", block.getNumber(), toHexString(repo.getRoot())); + stateLogger.warn("Conflict block dump: {}", toHexString(block.getEncoded())); // track.rollback(); // repository.rollback(); @@ -612,7 +613,7 @@ public synchronized BlockSummary addImpl(Repository repo, final Block block) { if (config.exitOnBlockConflict() && !byTest) { adminInfo.lostConsensus(); - System.out.println("CONFLICT: BLOCK #" + block.getNumber() + ", dump: " + Hex.toHexString(block.getEncoded())); + System.out.println("CONFLICT: BLOCK #" + block.getNumber() + ", dump: " + toHexString(block.getEncoded())); System.exit(1); } else { summary = null; @@ -718,8 +719,8 @@ private boolean isValid(Repository repo, Block block) { isValid = isValid(block.getHeader()); // Sanity checks - String trieHash = Hex.toHexString(block.getTxTrieRoot()); - String trieListHash = Hex.toHexString(calcTxTrie(block.getTransactionsList())); + String trieHash = toHexString(block.getTxTrieRoot()); + String trieListHash = toHexString(calcTxTrie(block.getTransactionsList())); if (!trieHash.equals(trieListHash)) { @@ -760,8 +761,8 @@ private boolean isValid(Repository repo, Block block) { } public boolean validateUncles(Block block) { - String unclesHash = Hex.toHexString(block.getHeader().getUnclesHash()); - String unclesListHash = Hex.toHexString(HashUtil.sha3(block.getHeader().getUnclesEncoded(block.getUncleList()))); + String unclesHash = toHexString(block.getHeader().getUnclesHash()); + String unclesListHash = toHexString(HashUtil.sha3(block.getHeader().getUnclesEncoded(block.getUncleList()))); if (!unclesHash.equals(unclesListHash)) { logger.warn("Block's given Uncle Hash doesn't match: {} != {}", unclesHash, unclesListHash); @@ -792,18 +793,18 @@ public boolean validateUncles(Block block) { ByteArrayWrapper uncleHash = new ByteArrayWrapper(uncle.getHash()); if (ancestors.contains(uncleHash)) { - logger.warn("Uncle is direct ancestor: " + Hex.toHexString(uncle.getHash())); + logger.warn("Uncle is direct ancestor: " + toHexString(uncle.getHash())); return false; } if (usedUncles.contains(uncleHash)) { - logger.warn("Uncle is not unique: " + Hex.toHexString(uncle.getHash())); + logger.warn("Uncle is not unique: " + toHexString(uncle.getHash())); return false; } Block uncleParent = blockStore.getBlockByHash(uncle.getParentHash()); if (!ancestors.contains(new ByteArrayWrapper(uncleParent.getHash()))) { - logger.warn("Uncle has no common parent: " + Hex.toHexString(uncle.getHash())); + logger.warn("Uncle has no common parent: " + toHexString(uncle.getHash())); return false; } } @@ -890,12 +891,12 @@ private BlockSummary applyBlock(Repository track, Block block) { } stateLogger.info("block: [{}] executed tx: [{}] \n state: [{}]", block.getNumber(), i, - Hex.toHexString(track.getRoot())); + toHexString(track.getRoot())); stateLogger.info("[{}] ", receipt.toString()); if (stateLogger.isInfoEnabled()) - stateLogger.info("tx[{}].receipt: [{}] ", i, Hex.toHexString(receipt.getEncoded())); + stateLogger.info("tx[{}].receipt: [{}] ", i, toHexString(receipt.getEncoded())); // TODO // if (block.getNumber() >= config.traceStartBlock()) @@ -911,7 +912,7 @@ private BlockSummary applyBlock(Repository track, Block block) { stateLogger.info("applied reward for block: [{}] \n state: [{}]", block.getNumber(), - Hex.toHexString(track.getRoot())); + toHexString(track.getRoot())); // TODO diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Bloom.java b/ethereumj-core/src/main/java/org/ethereum/core/Bloom.java index 059f6b2eb6..58f088d0e0 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Bloom.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Bloom.java @@ -18,10 +18,11 @@ package org.ethereum.core; import org.ethereum.util.ByteUtil; -import org.spongycastle.util.encoders.Hex; import java.util.Arrays; +import static org.ethereum.util.ByteUtil.toHexString; + /** * See http://www.herongyang.com/Java/Bit-String-Set-Bit-to-Byte-Array.html. * @@ -85,7 +86,7 @@ public Bloom copy() { @Override public String toString() { - return Hex.toHexString(data); + return toHexString(data); } @Override diff --git a/ethereumj-core/src/main/java/org/ethereum/core/PendingStateImpl.java b/ethereumj-core/src/main/java/org/ethereum/core/PendingStateImpl.java index 2c94971510..4b5717af74 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/PendingStateImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/PendingStateImpl.java @@ -43,10 +43,11 @@ import org.ethereum.vm.program.invoke.ProgramInvokeFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Keeps logic providing pending state management * @@ -199,7 +200,7 @@ private void fireTxUpdate(TransactionReceipt txReceipt, PendingTransactionState if (logger.isDebugEnabled()) { logger.debug(String.format("PendingTransactionUpdate: (Tot: %3s) %12s : %s %8s %s [%s]", getPendingTransactions().size(), - state, Hex.toHexString(txReceipt.getTransaction().getSender()).substring(0, 8), + state, toHexString(txReceipt.getTransaction().getSender()).substring(0, 8), ByteUtil.byteArrayToLong(txReceipt.getTransaction().getNonce()), block.getShortDescr(), txReceipt.getError())); } @@ -351,7 +352,7 @@ private void clearOutdated(final long blockNumber) { logger.trace( "Clear outdated pending transaction, block.number: [{}] hash: [{}]", tx.getBlockNumber(), - Hex.toHexString(tx.getHash()) + toHexString(tx.getHash()) ); pendingTransactions.removeAll(outdated); @@ -364,7 +365,7 @@ private void clearPending(Block block, List receipts) { if (pendingTransactions.remove(pend)) { try { - logger.trace("Clear pending transaction, hash: [{}]", Hex.toHexString(tx.getHash())); + logger.trace("Clear pending transaction, hash: [{}]", toHexString(tx.getHash())); TransactionReceipt receipt; if (receipts != null) { receipt = receipts.get(i); @@ -404,7 +405,7 @@ private void updateState(Block block) { private TransactionReceipt executeTx(Transaction tx) { - logger.trace("Apply pending state tx: {}", Hex.toHexString(tx.getHash())); + logger.trace("Apply pending state tx: {}", toHexString(tx.getHash())); Block best = getBestBlock(); diff --git a/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java b/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java index 214dc9f2b3..1605884cf1 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java @@ -33,7 +33,6 @@ import org.ethereum.vm.program.invoke.ProgramInvokeFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.util.List; @@ -45,6 +44,7 @@ import static org.ethereum.util.ByteUtil.toHexString; import static org.ethereum.vm.VMUtils.saveProgramTraceFile; import static org.ethereum.vm.VMUtils.zipAndEncode; +import static org.ethereum.util.ByteUtil.toHexString; /** * @author Roman Mandeleil @@ -218,7 +218,7 @@ private void call() { if (!localCall && m_endGas.compareTo(spendingGas) < 0) { // no refund // no endowment - execError("Out of Gas calling precompiled contract 0x" + Hex.toHexString(targetAddress) + + execError("Out of Gas calling precompiled contract 0x" + toHexString(targetAddress) + ", required: " + spendingGas + ", left: " + m_endGas); m_endGas = BigInteger.ZERO; return; @@ -230,7 +230,7 @@ private void call() { Pair out = precompiledContract.execute(tx.getData()); if (!out.getLeft()) { - execError("Error executing precompiled contract 0x" + Hex.toHexString(targetAddress)); + execError("Error executing precompiled contract 0x" + toHexString(targetAddress)); m_endGas = BigInteger.ZERO; return; } @@ -262,7 +262,7 @@ private void create() { AccountState existingAddr = cacheTrack.getAccountState(newContractAddress); if (existingAddr != null && existingAddr.isContractExist(blockchainConfig)) { - execError("Trying to create a contract with existing contract address: 0x" + Hex.toHexString(newContractAddress)); + execError("Trying to create a contract with existing contract address: 0x" + toHexString(newContractAddress)); m_endGas = BigInteger.ZERO; return; } @@ -426,12 +426,12 @@ public TransactionExecutionSummary finalization() { // Refund for gas leftover track.addBalance(tx.getSender(), summary.getLeftover().add(summary.getRefund())); - logger.info("Pay total refund to sender: [{}], refund val: [{}]", Hex.toHexString(tx.getSender()), summary.getRefund()); + logger.info("Pay total refund to sender: [{}], refund val: [{}]", toHexString(tx.getSender()), summary.getRefund()); // Transfer fees to miner track.addBalance(coinbase, summary.getFee()); touchedAccounts.add(coinbase); - logger.info("Pay fees to miner: [{}], feesEarned: [{}]", Hex.toHexString(coinbase), summary.getFee()); + logger.info("Pay fees to miner: [{}], feesEarned: [{}]", toHexString(coinbase), summary.getFee()); if (result != null) { logs = result.getLogInfoList(); diff --git a/ethereumj-core/src/main/java/org/ethereum/core/TransactionReceipt.java b/ethereumj-core/src/main/java/org/ethereum/core/TransactionReceipt.java index 27e9247378..82d3c22dbf 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/TransactionReceipt.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/TransactionReceipt.java @@ -25,7 +25,6 @@ import org.ethereum.util.RLPList; import org.ethereum.vm.LogInfo; import org.spongycastle.util.BigIntegers; -import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.nio.charset.StandardCharsets; @@ -35,6 +34,7 @@ import static org.apache.commons.lang3.ArrayUtils.nullToEmpty; import static org.ethereum.datasource.MemSizeEstimator.ByteArrayEstimator; import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY; +import static org.ethereum.util.ByteUtil.toHexString; /** * The transaction receipt is a tuple of three items @@ -278,11 +278,11 @@ public String toString() { return "TransactionReceipt[" + "\n , " + (hasTxStatus() ? ("txStatus=" + (isTxStatusOK() ? "OK" : "FAILED")) - : ("postTxState=" + Hex.toHexString(postTxState))) + - "\n , cumulativeGas=" + Hex.toHexString(cumulativeGas) + - "\n , gasUsed=" + Hex.toHexString(gasUsed) + + : ("postTxState=" + toHexString(postTxState))) + + "\n , cumulativeGas=" + toHexString(cumulativeGas) + + "\n , gasUsed=" + toHexString(gasUsed) + "\n , error=" + error + - "\n , executionResult=" + Hex.toHexString(executionResult) + + "\n , executionResult=" + toHexString(executionResult) + "\n , bloom=" + bloomFilter.toString() + "\n , logs=" + logInfoList + ']'; diff --git a/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java b/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java index 0e48d09087..126e7a7501 100644 --- a/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java +++ b/ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java @@ -91,6 +91,7 @@ import static org.ethereum.util.BIUtil.isLessThan; import static org.ethereum.util.ByteUtil.bigIntegerToBytes; +import static org.ethereum.util.ByteUtil.toHexString; /** *

Represents an elliptic curve public and (optionally) private key, usable for digital signatures but not encryption. @@ -553,7 +554,7 @@ public boolean isCompressed() { public String toString() { StringBuilder b = new StringBuilder(); - b.append("pub:").append(Hex.toHexString(pub.getEncoded(false))); + b.append("pub:").append(toHexString(pub.getEncoded(false))); return b.toString(); } @@ -568,7 +569,7 @@ public String toStringWithPrivate() { StringBuilder b = new StringBuilder(); b.append(toString()); if (privKey != null && privKey instanceof BCECPrivateKey) { - b.append(" priv:").append(Hex.toHexString(((BCECPrivateKey) privKey).getD().toByteArray())); + b.append(" priv:").append(toHexString(((BCECPrivateKey) privKey).getD().toByteArray())); } return b.toString(); } diff --git a/ethereumj-core/src/main/java/org/ethereum/datasource/leveldb/LevelDbDataSource.java b/ethereumj-core/src/main/java/org/ethereum/datasource/leveldb/LevelDbDataSource.java index 6e9c978791..c64c78bb32 100644 --- a/ethereumj-core/src/main/java/org/ethereum/datasource/leveldb/LevelDbDataSource.java +++ b/ethereumj-core/src/main/java/org/ethereum/datasource/leveldb/LevelDbDataSource.java @@ -24,7 +24,6 @@ import org.iq80.leveldb.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import java.io.File; @@ -39,6 +38,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import static org.fusesource.leveldbjni.JniDBFactory.factory; +import static org.ethereum.util.ByteUtil.toHexString; /** * @author Roman Mandeleil @@ -186,15 +186,15 @@ public String getName() { public byte[] get(byte[] key) { resetDbLock.readLock().lock(); try { - if (logger.isTraceEnabled()) logger.trace("~> LevelDbDataSource.get(): " + name + ", key: " + Hex.toHexString(key)); + if (logger.isTraceEnabled()) logger.trace("~> LevelDbDataSource.get(): " + name + ", key: " + toHexString(key)); try { byte[] ret = db.get(key); - if (logger.isTraceEnabled()) logger.trace("<~ LevelDbDataSource.get(): " + name + ", key: " + Hex.toHexString(key) + ", " + (ret == null ? "null" : ret.length)); + if (logger.isTraceEnabled()) logger.trace("<~ LevelDbDataSource.get(): " + name + ", key: " + toHexString(key) + ", " + (ret == null ? "null" : ret.length)); return ret; } catch (DBException e) { logger.warn("Exception. Retrying again...", e); byte[] ret = db.get(key); - if (logger.isTraceEnabled()) logger.trace("<~ LevelDbDataSource.get(): " + name + ", key: " + Hex.toHexString(key) + ", " + (ret == null ? "null" : ret.length)); + if (logger.isTraceEnabled()) logger.trace("<~ LevelDbDataSource.get(): " + name + ", key: " + toHexString(key) + ", " + (ret == null ? "null" : ret.length)); return ret; } } finally { @@ -206,9 +206,9 @@ public byte[] get(byte[] key) { public void put(byte[] key, byte[] value) { resetDbLock.readLock().lock(); try { - if (logger.isTraceEnabled()) logger.trace("~> LevelDbDataSource.put(): " + name + ", key: " + Hex.toHexString(key) + ", " + (value == null ? "null" : value.length)); + if (logger.isTraceEnabled()) logger.trace("~> LevelDbDataSource.put(): " + name + ", key: " + toHexString(key) + ", " + (value == null ? "null" : value.length)); db.put(key, value); - if (logger.isTraceEnabled()) logger.trace("<~ LevelDbDataSource.put(): " + name + ", key: " + Hex.toHexString(key) + ", " + (value == null ? "null" : value.length)); + if (logger.isTraceEnabled()) logger.trace("<~ LevelDbDataSource.put(): " + name + ", key: " + toHexString(key) + ", " + (value == null ? "null" : value.length)); } finally { resetDbLock.readLock().unlock(); } @@ -218,9 +218,9 @@ public void put(byte[] key, byte[] value) { public void delete(byte[] key) { resetDbLock.readLock().lock(); try { - if (logger.isTraceEnabled()) logger.trace("~> LevelDbDataSource.delete(): " + name + ", key: " + Hex.toHexString(key)); + if (logger.isTraceEnabled()) logger.trace("~> LevelDbDataSource.delete(): " + name + ", key: " + toHexString(key)); db.delete(key); - if (logger.isTraceEnabled()) logger.trace("<~ LevelDbDataSource.delete(): " + name + ", key: " + Hex.toHexString(key)); + if (logger.isTraceEnabled()) logger.trace("<~ LevelDbDataSource.delete(): " + name + ", key: " + toHexString(key)); } finally { resetDbLock.readLock().unlock(); } diff --git a/ethereumj-core/src/main/java/org/ethereum/datasource/rocksdb/RocksDbDataSource.java b/ethereumj-core/src/main/java/org/ethereum/datasource/rocksdb/RocksDbDataSource.java index a979d00da8..b1b7dff799 100644 --- a/ethereumj-core/src/main/java/org/ethereum/datasource/rocksdb/RocksDbDataSource.java +++ b/ethereumj-core/src/main/java/org/ethereum/datasource/rocksdb/RocksDbDataSource.java @@ -40,6 +40,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import static java.lang.System.arraycopy; +import static org.ethereum.util.ByteUtil.toHexString; /** * @author Mikhail Kalinin @@ -288,13 +289,13 @@ public void updateBatch(Map rows) { public void put(byte[] key, byte[] val) { resetDbLock.readLock().lock(); try { - if (logger.isTraceEnabled()) logger.trace("~> RocksDbDataSource.put(): " + name + ", key: " + Hex.toHexString(key) + ", " + (val == null ? "null" : val.length)); + if (logger.isTraceEnabled()) logger.trace("~> RocksDbDataSource.put(): " + name + ", key: " + toHexString(key) + ", " + (val == null ? "null" : val.length)); if (val != null) { db.put(key, val); } else { db.delete(key); } - if (logger.isTraceEnabled()) logger.trace("<~ RocksDbDataSource.put(): " + name + ", key: " + Hex.toHexString(key) + ", " + (val == null ? "null" : val.length)); + if (logger.isTraceEnabled()) logger.trace("<~ RocksDbDataSource.put(): " + name + ", key: " + toHexString(key) + ", " + (val == null ? "null" : val.length)); } catch (RocksDBException e) { logger.error("Failed to put into db '{}'", name, e); hintOnTooManyOpenFiles(e); @@ -308,9 +309,9 @@ public void put(byte[] key, byte[] val) { public byte[] get(byte[] key) { resetDbLock.readLock().lock(); try { - if (logger.isTraceEnabled()) logger.trace("~> RocksDbDataSource.get(): " + name + ", key: " + Hex.toHexString(key)); + if (logger.isTraceEnabled()) logger.trace("~> RocksDbDataSource.get(): " + name + ", key: " + toHexString(key)); byte[] ret = db.get(readOpts, key); - if (logger.isTraceEnabled()) logger.trace("<~ RocksDbDataSource.get(): " + name + ", key: " + Hex.toHexString(key) + ", " + (ret == null ? "null" : ret.length)); + if (logger.isTraceEnabled()) logger.trace("<~ RocksDbDataSource.get(): " + name + ", key: " + toHexString(key) + ", " + (ret == null ? "null" : ret.length)); return ret; } catch (RocksDBException e) { logger.error("Failed to get from db '{}'", name, e); @@ -325,9 +326,9 @@ public byte[] get(byte[] key) { public void delete(byte[] key) { resetDbLock.readLock().lock(); try { - if (logger.isTraceEnabled()) logger.trace("~> RocksDbDataSource.delete(): " + name + ", key: " + Hex.toHexString(key)); + if (logger.isTraceEnabled()) logger.trace("~> RocksDbDataSource.delete(): " + name + ", key: " + toHexString(key)); db.delete(key); - if (logger.isTraceEnabled()) logger.trace("<~ RocksDbDataSource.delete(): " + name + ", key: " + Hex.toHexString(key)); + if (logger.isTraceEnabled()) logger.trace("<~ RocksDbDataSource.delete(): " + name + ", key: " + toHexString(key)); } catch (RocksDBException e) { logger.error("Failed to delete from db '{}'", name, e); throw new RuntimeException(e); @@ -345,7 +346,7 @@ public byte[] prefixLookup(byte[] key, int prefixBytes) { resetDbLock.readLock().lock(); try { - if (logger.isTraceEnabled()) logger.trace("~> RocksDbDataSource.prefixLookup(): " + name + ", key: " + Hex.toHexString(key)); + if (logger.isTraceEnabled()) logger.trace("~> RocksDbDataSource.prefixLookup(): " + name + ", key: " + toHexString(key)); // RocksDB sets initial position of iterator to the first key which is greater or equal to the seek key // since keys in RocksDB are ordered in asc order iterator must be initiated with the lowest key @@ -366,7 +367,7 @@ public byte[] prefixLookup(byte[] key, int prefixBytes) { throw new RuntimeException(e); } - if (logger.isTraceEnabled()) logger.trace("<~ RocksDbDataSource.prefixLookup(): " + name + ", key: " + Hex.toHexString(key) + ", " + (ret == null ? "null" : ret.length)); + if (logger.isTraceEnabled()) logger.trace("<~ RocksDbDataSource.prefixLookup(): " + name + ", key: " + toHexString(key) + ", " + (ret == null ? "null" : ret.length)); return ret; diff --git a/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java b/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java index 013622deef..a200509c65 100644 --- a/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java +++ b/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java @@ -19,11 +19,11 @@ import org.ethereum.util.FastByteComparisons; -import org.spongycastle.util.encoders.Hex; - import java.io.Serializable; import java.util.Arrays; +import static org.ethereum.util.ByteUtil.toHexString; + /** * @author Roman Mandeleil * @since 11.06.2014 @@ -67,6 +67,6 @@ public byte[] getData() { @Override public String toString() { - return Hex.toHexString(data); + return toHexString(data); } } diff --git a/ethereumj-core/src/main/java/org/ethereum/db/prune/Pruner.java b/ethereumj-core/src/main/java/org/ethereum/db/prune/Pruner.java index bd9d994249..3b26171d7b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/db/prune/Pruner.java +++ b/ethereumj-core/src/main/java/org/ethereum/db/prune/Pruner.java @@ -8,7 +8,6 @@ import org.ethereum.util.ByteArraySet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import java.util.Arrays; import java.util.Collection; @@ -16,6 +15,8 @@ import java.util.Set; import java.util.stream.Collectors; +import static org.ethereum.util.ByteUtil.toHexString; + /** * This class is responsible for state pruning. * @@ -91,7 +92,7 @@ public boolean init(List forkWindow, int sizeInBlocks) { if (ready) return true; if (!forkWindow.isEmpty() && journal.get(forkWindow.get(0)) == null) { - logger.debug("pruner init aborted: can't fetch update " + Hex.toHexString(forkWindow.get(0))); + logger.debug("pruner init aborted: can't fetch update " + toHexString(forkWindow.get(0))); return false; } @@ -99,7 +100,7 @@ public boolean init(List forkWindow, int sizeInBlocks) { for (byte[] hash : forkWindow) { JournalSource.Update update = journal.get(hash); if (update == null) { - logger.debug("pruner init aborted: can't fetch update " + Hex.toHexString(hash)); + logger.debug("pruner init aborted: can't fetch update " + toHexString(hash)); return false; } update.getInsertedKeys().forEach(filter::insert); @@ -129,7 +130,7 @@ public void withSecondStep(List mainChainWindow, int sizeInBlocks) { update.getInsertedKeys().forEach(filter::insert); } logger.debug("distant filter initialized with set of " + (i < 0 ? mainChainWindow.size() : mainChainWindow.size() - i) + - " hashes, last hash " + Hex.toHexString(mainChainWindow.get(i < 0 ? 0 : i))); + " hashes, last hash " + toHexString(mainChainWindow.get(i < 0 ? 0 : i))); } else { logger.debug("distant filter initialized with empty set"); } @@ -216,7 +217,7 @@ public void prune(Segment segment) { public void persist(byte[] hash) { if (!ready || !withSecondStep()) return; - logger.trace("persist [{}]", Hex.toHexString(hash)); + logger.trace("persist [{}]", toHexString(hash)); long t = System.currentTimeMillis(); JournalSource.Update update = journal.get(hash); @@ -276,7 +277,7 @@ private int postpone(Chain chain) { for (byte[] hash : chain.getHashes()) { JournalSource.Update update = journal.get(hash); if (update == null) { - logger.debug("postponing: can't fetch update " + Hex.toHexString(hash)); + logger.debug("postponing: can't fetch update " + toHexString(hash)); continue; } // feed distant filter @@ -298,7 +299,7 @@ private int persist(Chain chain) { for (byte[] hash : chain.getHashes()) { JournalSource.Update update = journal.get(hash); if (update == null) { - logger.debug("pruning aborted: can't fetch update of main chain " + Hex.toHexString(hash)); + logger.debug("pruning aborted: can't fetch update of main chain " + toHexString(hash)); return 0; } // persist deleted keys @@ -339,7 +340,7 @@ private void revert(Chain chain) { for (byte[] hash : chain.getHashes()) { JournalSource.Update update = journal.get(hash); if (update == null) { - logger.debug("reverting chain " + chain + " aborted: can't fetch update " + Hex.toHexString(hash)); + logger.debug("reverting chain " + chain + " aborted: can't fetch update " + toHexString(hash)); return; } // clean up filter diff --git a/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java b/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java index bd09626005..7938310c7a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java @@ -60,6 +60,8 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import static org.ethereum.util.ByteUtil.toHexString; + /** * @author Roman Mandeleil * @since 27.07.2014 @@ -113,7 +115,7 @@ public EthereumImpl(final SystemProperties config, final CompositeEthereumListen this.config = config; System.out.println(); this.compositeEthereumListener.addListener(gasPriceTracker); - gLogger.info("EthereumJ node started: enode://" + Hex.toHexString(config.nodeId()) + "@" + config.externalIp() + ":" + config.listenPort()); + gLogger.info("EthereumJ node started: enode://" + toHexString(config.nodeId()) + "@" + config.externalIp() + ":" + config.listenPort()); } @Override diff --git a/ethereumj-core/src/main/java/org/ethereum/listener/EventListener.java b/ethereumj-core/src/main/java/org/ethereum/listener/EventListener.java index 0248f79124..f00fe5e3b5 100644 --- a/ethereumj-core/src/main/java/org/ethereum/listener/EventListener.java +++ b/ethereumj-core/src/main/java/org/ethereum/listener/EventListener.java @@ -30,7 +30,6 @@ import org.ethereum.vm.LogInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.util.ArrayList; @@ -40,6 +39,7 @@ import java.util.concurrent.Executors; import static org.ethereum.sync.BlockDownloader.MAX_IN_REQUEST; +import static org.ethereum.util.ByteUtil.toHexString; /** * The base class for tracking events generated by a Solidity contract @@ -183,7 +183,7 @@ public void onBlockImpl(BlockSummary blockSummary) { public void onPendingTransactionUpdateImpl(TransactionReceipt txReceipt, PendingTransactionState state, Block block) { try { if (state != PendingTransactionState.DROPPED || pendings.containsKey(txReceipt.getTransaction().getHash())) { - logger.debug("onPendingTransactionUpdate: " + Hex.toHexString(txReceipt.getTransaction().getHash()) + ", " + state); + logger.debug("onPendingTransactionUpdate: " + toHexString(txReceipt.getTransaction().getHash()) + ", " + state); } onReceipt(txReceipt, block, state); } catch (Exception e) { diff --git a/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java b/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java index b4a5da5eb9..33a4599380 100644 --- a/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java +++ b/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java @@ -47,6 +47,7 @@ import java.util.HashMap; import static org.ethereum.crypto.HashUtil.EMPTY_TRIE_HASH; +import static org.ethereum.util.ByteUtil.toHexString; /** * WorldManager is a singleton containing references to different parts of the system. @@ -221,7 +222,7 @@ public void loadBlockchain() { logger.info("*** Loaded up to block [{}] totalDifficulty [{}] with stateRoot [{}]", blockchain.getBestBlock().getNumber(), blockchain.getTotalDifficulty().toString(), - Hex.toHexString(blockchain.getBestBlock().getStateRoot())); + toHexString(blockchain.getBestBlock().getStateRoot())); } if (config.rootHashStart() != null) { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/dht/Peer.java b/ethereumj-core/src/main/java/org/ethereum/net/dht/Peer.java index 69ba4be94b..60d77454cb 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/dht/Peer.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/dht/Peer.java @@ -19,9 +19,9 @@ import org.ethereum.crypto.HashUtil; import org.spongycastle.util.BigIntegers; -import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; +import static org.ethereum.util.ByteUtil.toHexString; public class Peer { byte[] id; @@ -70,7 +70,7 @@ public void setId(byte[] id) { @Override public String toString() { - return String.format("Peer {\n id=%s, \n host=%s, \n port=%d\n}", Hex.toHexString(id), host, port); + return String.format("Peer {\n id=%s, \n host=%s, \n port=%d\n}", toHexString(id), host, port); } public String toBinaryString() { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/handler/Eth62.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/handler/Eth62.java index ad0b249985..a87959bc65 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/handler/Eth62.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/handler/Eth62.java @@ -39,7 +39,6 @@ import org.ethereum.validator.BlockHeaderValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -56,7 +55,7 @@ import static org.ethereum.sync.PeerState.*; import static org.ethereum.sync.PeerState.BLOCK_RETRIEVING; import static org.ethereum.util.Utils.longToTimePeriod; -import static org.spongycastle.util.encoders.Hex.toHexString; +import static org.ethereum.util.ByteUtil.toHexString; /** * Eth 62 @@ -740,7 +739,7 @@ private List validateAndMerge(BlockBodiesMessage response) { if (bodies.hasNext()) { logger.info("Peer {}: invalid BLOCK_BODIES response: at least one block body doesn't correspond to any of requested headers: ", - channel.getPeerIdShort(), Hex.toHexString(bodies.next())); + channel.getPeerIdShort(), toHexString(bodies.next())); return null; } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/handler/Eth63.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/handler/Eth63.java index 7f99bebc57..8d84cd0f0b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/handler/Eth63.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/handler/Eth63.java @@ -36,7 +36,6 @@ import org.ethereum.sync.PeerState; import org.ethereum.util.ByteArraySet; import org.ethereum.util.Value; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Scope; @@ -47,6 +46,7 @@ import java.util.Set; import static org.ethereum.net.eth.EthVersion.V63; +import static org.ethereum.util.ByteUtil.toHexString; /** * Fast synchronization (PV63) Handler @@ -114,7 +114,7 @@ protected synchronized void processGetNodeData(GetNodeDataMessage msg) { Value value = new Value(rawNode); nodeValues.add(value); if (nodeValues.size() >= MAX_HASHES_TO_SEND) break; - logger.trace("Eth63: " + Hex.toHexString(nodeKey).substring(0, 8) + " -> " + value); + logger.trace("Eth63: " + toHexString(nodeKey).substring(0, 8) + " -> " + value); } } @@ -194,7 +194,7 @@ protected synchronized void processNodeData(NodeDataMessage msg) { for (Value nodeVal : msg.getDataList()) { byte[] hash = nodeVal.hash(); if (!requestedNodes.contains(hash)) { - String err = "Received NodeDataMessage contains non-requested node with hash :" + Hex.toHexString(hash) + " . Dropping peer " + channel; + String err = "Received NodeDataMessage contains non-requested node with hash :" + toHexString(hash) + " . Dropping peer " + channel; dropUselessPeer(err); return; } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/BlockBodiesMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/BlockBodiesMessage.java index dfa75f9510..5041ac96d8 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/BlockBodiesMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/BlockBodiesMessage.java @@ -20,10 +20,10 @@ import org.ethereum.core.Block; import org.ethereum.util.RLP; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; import java.util.ArrayList; import java.util.List; +import static org.ethereum.util.ByteUtil.toHexString; /** * Wrapper around an Ethereum BlockBodies message on the network @@ -99,7 +99,7 @@ public String toString() { if (logger.isTraceEnabled()) { payload.append(" "); for (byte[] body : blockBodies) { - payload.append(Hex.toHexString(body)).append(" | "); + payload.append(toHexString(body)).append(" | "); } if (!blockBodies.isEmpty()) { payload.delete(payload.length() - 3, payload.length()); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/BlockHeadersMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/BlockHeadersMessage.java index 41c8dc71b1..6c80007d19 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/BlockHeadersMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/BlockHeadersMessage.java @@ -20,12 +20,13 @@ import org.ethereum.core.BlockHeader; import org.ethereum.util.RLP; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Wrapper around an Ethereum BlockHeaders message on the network * @@ -103,7 +104,7 @@ public String toString() { if (logger.isTraceEnabled()) { payload.append(" "); for (BlockHeader header : blockHeaders) { - payload.append(Hex.toHexString(header.getHash()).substring(0, 6)).append(" | "); + payload.append(toHexString(header.getHash()).substring(0, 6)).append(" | "); } if (!blockHeaders.isEmpty()) { payload.delete(payload.length() - 3, payload.length()); @@ -111,11 +112,11 @@ public String toString() { } else { if (blockHeaders.size() > 0) { payload.append("#").append(blockHeaders.get(0).getNumber()).append(" (") - .append(Hex.toHexString(blockHeaders.get(0).getHash()).substring(0, 8)).append(")"); + .append(toHexString(blockHeaders.get(0).getHash()).substring(0, 8)).append(")"); } if (blockHeaders.size() > 1) { payload.append(" ... #").append(blockHeaders.get(blockHeaders.size() - 1).getNumber()).append(" (") - .append(Hex.toHexString(blockHeaders.get(blockHeaders.size() - 1).getHash()).substring(0, 8)).append(")"); + .append(toHexString(blockHeaders.get(blockHeaders.size() - 1).getHash()).substring(0, 8)).append(")"); } } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetBlockBodiesMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetBlockBodiesMessage.java index 3266f70ed7..898f5541bb 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetBlockBodiesMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetBlockBodiesMessage.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.List; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Wrapper around an Ethereum GetBlockBodies message on the network * @@ -99,7 +101,7 @@ public String toString() { if (logger.isDebugEnabled()) { for (byte[] hash : blockHashes) { - payload.append(Hex.toHexString(hash).substring(0, 6)).append(" | "); + payload.append(toHexString(hash).substring(0, 6)).append(" | "); } if (!blockHashes.isEmpty()) { payload.delete(payload.length() - 3, payload.length()); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetNodeDataMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetNodeDataMessage.java index 1dcfd20c39..d46ed6335d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetNodeDataMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetNodeDataMessage.java @@ -20,11 +20,12 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPList; import org.ethereum.util.Utils; -import org.spongycastle.util.encoders.Hex; import java.util.ArrayList; import java.util.List; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Wrapper around an Ethereum GetNodeData message on the network * Could contain: @@ -102,7 +103,7 @@ public String toString() { if (logger.isDebugEnabled()) { for (byte[] hash : nodeKeys) { - payload.append(Hex.toHexString(hash).substring(0, 6)).append(" | "); + payload.append(toHexString(hash).substring(0, 6)).append(" | "); } if (!nodeKeys.isEmpty()) { payload.delete(payload.length() - 3, payload.length()); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetReceiptsMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetReceiptsMessage.java index a5852dc9f4..73e199db78 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetReceiptsMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetReceiptsMessage.java @@ -20,11 +20,12 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPList; import org.ethereum.util.Utils; -import org.spongycastle.util.encoders.Hex; import java.util.ArrayList; import java.util.List; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Wrapper around an Ethereum GetReceipts message on the network * @@ -99,7 +100,7 @@ public String toString() { if (logger.isDebugEnabled()) { for (byte[] hash : blockHashes) { - payload.append(Hex.toHexString(hash).substring(0, 6)).append(" | "); + payload.append(toHexString(hash).substring(0, 6)).append(" | "); } if (!blockHashes.isEmpty()) { payload.delete(payload.length() - 3, payload.length()); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NewBlockMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NewBlockMessage.java index 2b8bb6b876..012d9b1925 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NewBlockMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NewBlockMessage.java @@ -25,6 +25,8 @@ import java.math.BigInteger; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Wrapper around an Ethereum Blocks message on the network * @@ -98,6 +100,6 @@ public String toString() { String hash = this.getBlock().getShortHash(); long number = this.getBlock().getNumber(); - return "NEW_BLOCK [ number: " + number + " hash:" + hash + " difficulty: " + Hex.toHexString(difficulty) + " ]"; + return "NEW_BLOCK [ number: " + number + " hash:" + hash + " difficulty: " + toHexString(difficulty) + " ]"; } } \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/StatusMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/StatusMessage.java index 2ee76d9a6b..0b181cab16 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/StatusMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/StatusMessage.java @@ -25,6 +25,8 @@ import java.math.BigInteger; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Wrapper for Ethereum STATUS message.
* @@ -142,8 +144,8 @@ public String toString() { " protocolVersion=" + this.protocolVersion + " networkId=" + this.networkId + " totalDifficulty=" + ByteUtil.toHexString(this.totalDifficulty) + - " bestHash=" + Hex.toHexString(this.bestHash) + - " genesisHash=" + Hex.toHexString(this.genesisHash) + + " bestHash=" + toHexString(this.bestHash) + + " genesisHash=" + toHexString(this.genesisHash) + "]"; } } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthInitiateMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthInitiateMessage.java index 878c8b7a4f..ec7cd60e43 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthInitiateMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthInitiateMessage.java @@ -20,12 +20,12 @@ import org.ethereum.crypto.ECKey; import org.spongycastle.math.ec.ECPoint; import org.spongycastle.util.BigIntegers; -import org.spongycastle.util.encoders.Hex; import java.util.Arrays; import static org.ethereum.util.ByteUtil.merge; import static org.spongycastle.util.BigIntegers.asUnsignedByteArray; +import static org.ethereum.util.ByteUtil.toHexString; /** * Authentication initiation message, to be wrapped inside @@ -112,10 +112,10 @@ public String toString() { asUnsignedByteArray(signature.s), new byte[]{EncryptionHandshake.recIdFromSignatureV(signature.v)}); return "AuthInitiateMessage{" + - "\n sigBytes=" + Hex.toHexString(sigBytes) + - "\n ephemeralPublicHash=" + Hex.toHexString(ephemeralPublicHash) + - "\n publicKey=" + Hex.toHexString(publicKey.getEncoded(false)) + - "\n nonce=" + Hex.toHexString(nonce) + + "\n sigBytes=" + toHexString(sigBytes) + + "\n ephemeralPublicHash=" + toHexString(ephemeralPublicHash) + + "\n publicKey=" + toHexString(publicKey.getEncoded(false)) + + "\n nonce=" + toHexString(nonce) + "\n}"; } } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthInitiateMessageV4.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthInitiateMessageV4.java index 5a7ac41a3d..1c3069e339 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthInitiateMessageV4.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthInitiateMessageV4.java @@ -22,10 +22,10 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPList; import org.spongycastle.math.ec.ECPoint; -import org.spongycastle.util.encoders.Hex; import static org.ethereum.util.ByteUtil.merge; import static org.spongycastle.util.BigIntegers.asUnsignedByteArray; +import static org.ethereum.util.ByteUtil.toHexString; /** * Auth Initiate message defined by EIP-8 @@ -101,9 +101,9 @@ public String toString() { asUnsignedByteArray(signature.s), new byte[]{EncryptionHandshake.recIdFromSignatureV(signature.v)}); return "AuthInitiateMessage{" + - "\n sigBytes=" + Hex.toHexString(sigBytes) + - "\n publicKey=" + Hex.toHexString(publicKey.getEncoded(false)) + - "\n nonce=" + Hex.toHexString(nonce) + + "\n sigBytes=" + toHexString(sigBytes) + + "\n publicKey=" + toHexString(publicKey.getEncoded(false)) + + "\n nonce=" + toHexString(nonce) + "\n version=" + version + "\n}"; } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthResponseMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthResponseMessage.java index 32629cf3a9..9b4dba0a16 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthResponseMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthResponseMessage.java @@ -19,10 +19,11 @@ import org.ethereum.crypto.ECKey; import org.spongycastle.math.ec.ECPoint; -import org.spongycastle.util.encoders.Hex; import java.util.Arrays; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Authentication response message, to be wrapped inside * @@ -73,7 +74,7 @@ public byte[] encode() { public String toString() { return "AuthResponseMessage{" + "\n ephemeralPublicKey=" + ephemeralPublicKey + - "\n nonce=" + Hex.toHexString(nonce) + + "\n nonce=" + toHexString(nonce) + "\n isTokenUsed=" + isTokenUsed + '}'; } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthResponseMessageV4.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthResponseMessageV4.java index 0cae78b42e..cbca048838 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthResponseMessageV4.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/AuthResponseMessageV4.java @@ -22,7 +22,8 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPList; import org.spongycastle.math.ec.ECPoint; -import org.spongycastle.util.encoders.Hex; + +import static org.ethereum.util.ByteUtil.toHexString; /** * Auth Response message defined by EIP-8 @@ -73,7 +74,7 @@ public byte[] encode() { public String toString() { return "AuthResponseMessage{" + "\n ephemeralPublicKey=" + ephemeralPublicKey + - "\n nonce=" + Hex.toHexString(nonce) + + "\n nonce=" + toHexString(nonce) + "\n version=" + version + '}'; } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/FindNodeMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/FindNodeMessage.java index 9af1e32a13..93a2827216 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/FindNodeMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/FindNodeMessage.java @@ -22,9 +22,9 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPItem; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; import static org.ethereum.util.ByteUtil.longToBytesNoLeadZeroes; +import static org.ethereum.util.ByteUtil.toHexString; public class FindNodeMessage extends Message { @@ -78,10 +78,8 @@ public String toString() { long currTime = System.currentTimeMillis() / 1000; - String out = String.format("[FindNodeMessage] \n target: %s \n expires in %d seconds \n %s\n", - Hex.toHexString(target), (expires - currTime), super.toString()); - - return out; + return String.format("[FindNodeMessage] \n target: %s \n expires in %d seconds \n %s\n", + toHexString(target), (expires - currTime), super.toString()); } } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Handshaker.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Handshaker.java index 51ba9e71c5..da5b125880 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Handshaker.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Handshaker.java @@ -35,6 +35,8 @@ import java.net.URISyntaxException; import java.util.Arrays; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Created by devrandom on 2015-04-09. */ @@ -54,7 +56,7 @@ public static void main(String[] args) throws IOException, URISyntaxException { public Handshaker() { myKey = new ECKey(); nodeId = myKey.getNodeId(); - System.out.println("Node ID " + Hex.toHexString(nodeId)); + System.out.println("Node ID " + toHexString(nodeId)); } /** diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Message.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Message.java index 7a3c757afe..c3099b55b8 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Message.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Message.java @@ -20,12 +20,12 @@ import org.ethereum.crypto.ECKey; import org.ethereum.util.FastByteComparisons; import org.spongycastle.util.BigIntegers; -import org.spongycastle.util.encoders.Hex; import java.security.SignatureException; import static org.ethereum.crypto.HashUtil.sha3; import static org.ethereum.util.ByteUtil.merge; +import static org.ethereum.util.ByteUtil.toHexString; public abstract class Message { @@ -164,10 +164,10 @@ public byte[] getData() { @Override public String toString() { return "{" + - "mdc=" + Hex.toHexString(mdc) + - ", signature=" + Hex.toHexString(signature) + - ", type=" + Hex.toHexString(type) + - ", data=" + Hex.toHexString(data) + + "mdc=" + toHexString(mdc) + + ", signature=" + toHexString(signature) + + ", type=" + toHexString(type) + + ", data=" + toHexString(data) + '}'; } } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/MessageCodec.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/MessageCodec.java index 038879f7e8..f4b08feffb 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/MessageCodec.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/MessageCodec.java @@ -36,7 +36,6 @@ import org.ethereum.net.swarm.bzz.BzzMessageCodes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -47,6 +46,7 @@ import static java.lang.Math.min; import static org.ethereum.net.rlpx.FrameCodec.Frame; +import static org.ethereum.util.ByteUtil.toHexString; /** * The Netty codec which encodes/decodes RPLx frames to subprotocol Messages @@ -152,7 +152,7 @@ private Message decodeMessage(ChannelHandlerContext ctx, List frames) thr } if (loggerWire.isDebugEnabled()) - loggerWire.debug("Recv: Encoded: {} [{}]", frameType, Hex.toHexString(payload)); + loggerWire.debug("Recv: Encoded: {} [{}]", frameType, toHexString(payload)); Message msg; try { @@ -183,7 +183,7 @@ protected void encode(ChannelHandlerContext ctx, Message msg, List out) byte[] encoded = msg.getEncoded(); if (loggerWire.isDebugEnabled()) - loggerWire.debug("Send: Encoded: {} [{}]", getCode(msg.getCommand()), Hex.toHexString(encoded)); + loggerWire.debug("Send: Encoded: {} [{}]", getCode(msg.getCommand()), toHexString(encoded)); List frames = splitMessageToFrames(msg); @@ -271,7 +271,7 @@ private Message createMessage(byte code, byte[] payload) { return bzzMessageFactory.create(resolved, payload); } - throw new IllegalArgumentException("No such message: " + code + " [" + Hex.toHexString(payload) + "]"); + throw new IllegalArgumentException("No such message: " + code + " [" + toHexString(payload) + "]"); } public void setChannel(Channel channel){ diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Node.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Node.java index a4549a7b20..a2106ede81 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Node.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/Node.java @@ -32,6 +32,7 @@ import static org.ethereum.util.ByteUtil.byteArrayToInt; import static org.ethereum.util.ByteUtil.bytesToIp; import static org.ethereum.util.ByteUtil.hostToBytes; +import static org.ethereum.util.ByteUtil.toHexString; public class Node implements Serializable { private static final long serialVersionUID = -4267600517925770636L; @@ -183,7 +184,7 @@ public String toString() { return "Node{" + " host='" + host + '\'' + ", port=" + port + - ", id=" + Hex.toHexString(id) + + ", id=" + toHexString(id) + '}'; } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/PongMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/PongMessage.java index fb2cbfa221..f6bc971c6d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/PongMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/PongMessage.java @@ -22,10 +22,6 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPItem; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; - -import static org.ethereum.util.ByteUtil.longToBytes; -import static org.ethereum.util.ByteUtil.stripLeadingZeroes; public class PongMessage extends Message { @@ -40,8 +36,8 @@ public static PongMessage create(byte[] token, Node toNode, ECKey privKey) { /* RLP Encode data */ byte[] rlpToken = RLP.encodeElement(token); - byte[] tmpExp = longToBytes(expiration); - byte[] rlpExp = RLP.encodeElement(stripLeadingZeroes(tmpExp)); + byte[] tmpExp = ByteUtil.longToBytes(expiration); + byte[] rlpExp = RLP.encodeElement(ByteUtil.stripLeadingZeroes(tmpExp)); byte[] type = new byte[]{2}; byte[] data = RLP.encodeList(rlpToList, rlpToken, rlpExp); @@ -101,7 +97,7 @@ public String toString() { long currTime = System.currentTimeMillis() / 1000; String out = String.format("[PongMessage] \n token: %s \n expires in %d seconds \n %s\n", - Hex.toHexString(token), (expires - currTime), super.toString()); + ByteUtil.toHexString(token), (expires - currTime), super.toString()); return out; } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/discover/PacketDecoder.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/discover/PacketDecoder.java index 0fc53d59ef..e0da22cc2e 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/discover/PacketDecoder.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/discover/PacketDecoder.java @@ -25,10 +25,11 @@ import org.ethereum.crypto.ECKey; import org.ethereum.net.rlpx.Message; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import java.util.List; +import static org.ethereum.util.ByteUtil.toHexString; + public class PacketDecoder extends MessageToMessageDecoder { private static final org.slf4j.Logger logger = LoggerFactory.getLogger("discover"); @@ -42,7 +43,7 @@ public void decode(ChannelHandlerContext ctx, DatagramPacket packet, Listhttp://netty.io. @@ -96,7 +97,7 @@ public void start(int port) { // Start the client. logger.info("Listening for incoming connections, port: [{}] ", port); - logger.info("NodeId: [{}] ", Hex.toHexString(config.nodeId())); + logger.info("NodeId: [{}] ", toHexString(config.nodeId())); channelFuture = b.bind(port).sync(); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/shh/ShhFilterMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/shh/ShhFilterMessage.java index cec0ccf4f4..f9138e3638 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/shh/ShhFilterMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/shh/ShhFilterMessage.java @@ -20,9 +20,9 @@ import org.ethereum.db.ByteArrayWrapper; import org.ethereum.util.RLP; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; import static org.ethereum.net.shh.ShhMessageCodes.FILTER; +import static org.ethereum.util.ByteUtil.toHexString; /** * @author by Konstantin Shabalin @@ -81,7 +81,7 @@ public ShhMessageCodes getCommand() { public String toString() { if (!parsed) parse(); return "[" + this.getCommand().name() + - " hash=" + Hex.toHexString(bloomFilter) + "]"; + " hash=" + toHexString(bloomFilter) + "]"; } } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/shh/Topic.java b/ethereumj-core/src/main/java/org/ethereum/net/shh/Topic.java index 5e77414a0a..325b33552c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/shh/Topic.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/shh/Topic.java @@ -18,12 +18,12 @@ package org.ethereum.net.shh; import org.ethereum.util.RLP; -import org.spongycastle.util.encoders.Hex; import java.nio.charset.StandardCharsets; import java.util.Arrays; import static org.ethereum.crypto.HashUtil.sha3; +import static org.ethereum.util.ByteUtil.toHexString; /** * @author by Konstantin Shabalin @@ -85,6 +85,6 @@ public boolean equals(Object obj) { @Override public String toString() { - return "#" + Hex.toHexString(abrigedTopic) + (originalTopic == null ? "" : "(" + originalTopic + ")"); + return "#" + toHexString(abrigedTopic) + (originalTopic == null ? "" : "(" + originalTopic + ")"); } } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/shh/WhisperMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/shh/WhisperMessage.java index bf5d88f8d7..3dfd9eeef0 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/shh/WhisperMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/shh/WhisperMessage.java @@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory; import org.spongycastle.math.ec.ECPoint; import org.spongycastle.util.BigIntegers; -import org.spongycastle.util.encoders.Hex; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -35,6 +34,7 @@ import static org.ethereum.net.swarm.Util.rlpDecodeInt; import static org.ethereum.util.ByteUtil.merge; import static org.ethereum.util.ByteUtil.xor; +import static org.ethereum.util.ByteUtil.toHexString; /** * Created by Anton Nashatyrev on 25.09.2015. @@ -440,7 +440,7 @@ public String toString() { "topics=" + Arrays.toString(topics) + ", payload=" + (encrypted ? "" : new String(payload)) + ", to=" + (to == null ? "null" : to.substring(0, 16) + "...") + - ", from=" + (from == null ? "null" : Hex.toHexString(from.getPubKey()).substring(0,16) + "...") + + ", from=" + (from == null ? "null" : toHexString(from.getPubKey()).substring(0,16) + "...") + ", expire=" + expire + ", ttl=" + ttl + ", nonce=" + nonce + diff --git a/ethereumj-core/src/main/java/org/ethereum/net/swarm/Hive.java b/ethereumj-core/src/main/java/org/ethereum/net/swarm/Hive.java index 2d1a1ba02c..609a3c3e7f 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/swarm/Hive.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/swarm/Hive.java @@ -1,20 +1,20 @@ -/* - * Copyright (c) [2016] [ ] - * This file is part of the ethereumJ library. - * - * The ethereumJ library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The ethereumJ library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the ethereumJ library. If not, see . - */ +/* + * Copyright (c) [2016] [ ] + * This file is part of the ethereumJ library. + * + * The ethereumJ library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The ethereumJ library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the ethereumJ library. If not, see . + */ package org.ethereum.net.swarm; import org.ethereum.net.rlpx.Node; @@ -90,7 +90,7 @@ public Collection getPeers(Key key, int maxCount) { ArrayList ret = new ArrayList<>(); for (Node node : closestNodes) { // TODO connect to Node -// ret.add(thisPeer.getPeer(new PeerAddress(node))); + // ret.add(thisPeer.getPeer(new PeerAddress(node))); BzzProtocol peer = connectedPeers.get(node); if (peer != null) { ret.add(peer); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/swarm/bzz/PeerAddress.java b/ethereumj-core/src/main/java/org/ethereum/net/swarm/bzz/PeerAddress.java index 1f47712907..c3d7d9a15a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/swarm/bzz/PeerAddress.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/swarm/bzz/PeerAddress.java @@ -1,20 +1,20 @@ -/* - * Copyright (c) [2016] [ ] - * This file is part of the ethereumJ library. - * - * The ethereumJ library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The ethereumJ library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the ethereumJ library. If not, see . - */ +/* + * Copyright (c) [2016] [ ] + * This file is part of the ethereumJ library. + * + * The ethereumJ library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The ethereumJ library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the ethereumJ library. If not, see . + */ package org.ethereum.net.swarm.bzz; import com.google.common.base.Joiner; @@ -26,13 +26,13 @@ import org.ethereum.util.ByteUtil; import org.ethereum.util.RLP; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; import static org.ethereum.crypto.HashUtil.sha3; +import static org.ethereum.util.ByteUtil.toHexString; /** * Class similar for {@link Node} used in the swarm @@ -133,7 +133,7 @@ public String toString() { return "PeerAddress{" + "ip=" + Util.ipBytesToString(ip) + ", port=" + port + - ", id=" + Hex.toHexString(id) + + ", id=" + toHexString(id) + '}'; } } diff --git a/ethereumj-core/src/main/java/org/ethereum/samples/CreateContractSample.java b/ethereumj-core/src/main/java/org/ethereum/samples/CreateContractSample.java index 5e51e6bab0..947461e5fa 100644 --- a/ethereumj-core/src/main/java/org/ethereum/samples/CreateContractSample.java +++ b/ethereumj-core/src/main/java/org/ethereum/samples/CreateContractSample.java @@ -36,6 +36,8 @@ import java.math.BigInteger; import java.util.*; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Created by Anton Nashatyrev on 03.03.2016. */ @@ -92,7 +94,7 @@ public void onBlock(Block block, List receipts) { } byte[] contractAddress = receipt.getTransaction().getContractAddress(); - logger.info("Contract created: " + Hex.toHexString(contractAddress)); + logger.info("Contract created: " + toHexString(contractAddress)); logger.info("Calling the contract function 'inc'"); CallTransaction.Contract contract = new CallTransaction.Contract(metadata.abi); diff --git a/ethereumj-core/src/main/java/org/ethereum/samples/EventListenerSample.java b/ethereumj-core/src/main/java/org/ethereum/samples/EventListenerSample.java index 8ba0e397c4..e31f584d31 100644 --- a/ethereumj-core/src/main/java/org/ethereum/samples/EventListenerSample.java +++ b/ethereumj-core/src/main/java/org/ethereum/samples/EventListenerSample.java @@ -54,6 +54,7 @@ import java.util.Scanner; import static org.ethereum.crypto.HashUtil.sha3; +import static org.ethereum.util.ByteUtil.toHexString; /** * Sample usage of events listener API. @@ -271,7 +272,7 @@ private void waitForEther(byte[] address, BigInteger requiredBalance) throws Int while(true) { BigInteger balance = ethereum.getRepository().getBalance(address); if (balance.compareTo(requiredBalance) > 0) { - logger.info("Address {} successfully funded. Balance: {} wei", "0x" + Hex.toHexString(address), balance); + logger.info("Address {} successfully funded. Balance: {} wei", "0x" + toHexString(address), balance); break; } synchronized (this) { @@ -305,7 +306,7 @@ public void onBlock(Block block, List receipts) { } byte[] address = receipt.getTransaction().getContractAddress(); - logger.info("Contract created: " + Hex.toHexString(address)); + logger.info("Contract created: " + toHexString(address)); IncEventListener eventListener = new IncEventListener(pendingState, metadata.abi, address); ethereum.addListener(eventListener.listener); diff --git a/ethereumj-core/src/main/java/org/ethereum/samples/PendingStateSample.java b/ethereumj-core/src/main/java/org/ethereum/samples/PendingStateSample.java index 16a40095d2..7ff7f6b3b2 100644 --- a/ethereumj-core/src/main/java/org/ethereum/samples/PendingStateSample.java +++ b/ethereumj-core/src/main/java/org/ethereum/samples/PendingStateSample.java @@ -26,13 +26,14 @@ import org.ethereum.facade.EthereumFactory; import org.ethereum.listener.EthereumListenerAdapter; import org.ethereum.util.ByteUtil; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import java.math.BigInteger; import java.util.*; +import static org.ethereum.util.ByteUtil.toHexString; + /** * PendingState is the ability to track the changes made by transaction immediately and not wait for * the block containing that transaction. @@ -137,7 +138,7 @@ void onPendingTransactionReceived(Transaction tx) { if (Arrays.equals(tx.getSender(), senderAddress)) { BigInteger receiverBalance = ethereum.getRepository().getBalance(receiverAddress); BigInteger receiverBalancePending = pendingState.getRepository().getBalance(receiverAddress); - logger.info(" + New pending transaction 0x" + Hex.toHexString(tx.getHash()).substring(0, 8)); + logger.info(" + New pending transaction 0x" + toHexString(tx.getHash()).substring(0, 8)); pendingTxs.put(new ByteArrayWrapper(tx.getHash()), tx); @@ -156,7 +157,7 @@ public void onBlock(Block block, List receipts) { ByteArrayWrapper txHash = new ByteArrayWrapper(tx.getHash()); Transaction ptx = pendingTxs.get(txHash); if (ptx != null) { - logger.info(" - Pending transaction cleared 0x" + Hex.toHexString(tx.getHash()).substring(0, 8) + + logger.info(" - Pending transaction cleared 0x" + toHexString(tx.getHash()).substring(0, 8) + " in block " + block.getShortDescr()); pendingTxs.remove(txHash); diff --git a/ethereumj-core/src/main/java/org/ethereum/samples/TransactionBomb.java b/ethereumj-core/src/main/java/org/ethereum/samples/TransactionBomb.java index 6ee85459da..3a464a5ee2 100644 --- a/ethereumj-core/src/main/java/org/ethereum/samples/TransactionBomb.java +++ b/ethereumj-core/src/main/java/org/ethereum/samples/TransactionBomb.java @@ -30,6 +30,7 @@ import static org.ethereum.crypto.HashUtil.sha3; import static org.ethereum.util.ByteUtil.longToBytesNoLeadZeroes; +import static org.ethereum.util.ByteUtil.toHexString; public class TransactionBomb extends EthereumListenerAdapter { @@ -93,7 +94,7 @@ private void sendTx(long nonce){ tx.sign(privKey); ethereum.getChannelManager().sendTransaction(Collections.singletonList(tx), null); - System.err.println("Sending tx: " + Hex.toHexString(tx.getHash())); + System.err.println("Sending tx: " + toHexString(tx.getHash())); } private void sleep(int millis){ diff --git a/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java b/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java index 87f3a9e914..5393aa80a8 100644 --- a/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java +++ b/ethereumj-core/src/main/java/org/ethereum/solidity/SolidityType.java @@ -21,7 +21,6 @@ import com.fasterxml.jackson.annotation.JsonValue; import org.ethereum.util.ByteUtil; import org.ethereum.vm.DataWord; -import org.spongycastle.util.encoders.Hex; import java.lang.reflect.Array; import java.math.BigInteger; @@ -30,6 +29,8 @@ import java.util.Arrays; import java.util.List; +import static org.ethereum.util.ByteUtil.toHexString; + public abstract class SolidityType { protected String name; @@ -343,7 +344,7 @@ public byte[] encode(Object value) { byte[] addr = super.encode(value); for (int i = 0; i < 12; i++) { if (addr[i] != 0) { - throw new RuntimeException("Invalid address (should be 20 bytes length): " + Hex.toHexString(addr)); + throw new RuntimeException("Invalid address (should be 20 bytes length): " + toHexString(addr)); } } return addr; diff --git a/ethereumj-core/src/main/java/org/ethereum/sync/BlockDownloader.java b/ethereumj-core/src/main/java/org/ethereum/sync/BlockDownloader.java index 3194addefe..31b897780d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/sync/BlockDownloader.java +++ b/ethereumj-core/src/main/java/org/ethereum/sync/BlockDownloader.java @@ -26,7 +26,6 @@ import org.ethereum.validator.BlockHeaderValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import java.util.*; import java.util.concurrent.*; @@ -34,6 +33,7 @@ import static java.lang.Math.max; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; +import static org.ethereum.util.ByteUtil.toHexString; /** * Created by Anton Nashatyrev on 27.10.2016. @@ -366,7 +366,7 @@ private boolean validateAndAddHeaders(List headers, byte[] nodeId) if (!isValid(header)) { if (logger.isDebugEnabled()) { - logger.debug("{}: Invalid header RLP: {}", Hex.toHexString(header.getEncoded()), name); + logger.debug("{}: Invalid header RLP: {}", toHexString(header.getEncoded()), name); } return false; diff --git a/ethereumj-core/src/main/java/org/ethereum/sync/FastSyncManager.java b/ethereumj-core/src/main/java/org/ethereum/sync/FastSyncManager.java index c2862ac622..2e26f12d6b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/sync/FastSyncManager.java +++ b/ethereumj-core/src/main/java/org/ethereum/sync/FastSyncManager.java @@ -43,7 +43,6 @@ import org.ethereum.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; @@ -59,6 +58,7 @@ import static org.ethereum.listener.EthereumListener.SyncState.UNSECURE; import static org.ethereum.trie.TrieKey.fromPacked; import static org.ethereum.util.CompactEncoder.hasTerminator; +import static org.ethereum.util.ByteUtil.toHexString; /** * Created by Anton Nashatyrev on 24.10.2016. @@ -331,7 +331,7 @@ public void merge(TrieNodeRequest other) { public String toString() { return "TrieNodeRequest{" + "type=" + type + - ", nodeHash=" + Hex.toHexString(nodeHash) + + ", nodeHash=" + toHexString(nodeHash) + ", nodePath=" + nodePath + '}'; } @@ -413,7 +413,7 @@ public void onSuccess(List> result) { TrieNodeRequest request = pendingNodes.get(pair.getKey()); if (request == null) { long t = System.currentTimeMillis(); - logger.debug("Received node which was not requested: " + Hex.toHexString(pair.getKey()) + " from " + idle); + logger.debug("Received node which was not requested: " + toHexString(pair.getKey()) + " from " + idle); return; } Set intersection = request.requestIdsSnapshot(); @@ -591,7 +591,7 @@ private void syncSecure() { headersDownloader.waitForStop(); if (!FastByteComparisons.equal(headersDownloader.getGenesisHash(), config.getGenesis().getHash())) { logger.error("FASTSYNC FATAL ERROR: after downloading header chain starting from the pivot block (" + - pivot.getShortDescr() + ") obtained genesis block doesn't match ours: " + Hex.toHexString(headersDownloader.getGenesisHash())); + pivot.getShortDescr() + ") obtained genesis block doesn't match ours: " + toHexString(headersDownloader.getGenesisHash())); logger.error("Can't recover and exiting now. You need to restart from scratch (all DBs will be reset)"); System.exit(-666); } @@ -737,7 +737,7 @@ private BlockHeader getPivotBlock() throws InterruptedException { long s = start; if (pivotBlockHash != null) { - logger.info("FastSync: fetching trusted pivot block with hash " + Hex.toHexString(pivotBlockHash)); + logger.info("FastSync: fetching trusted pivot block with hash " + toHexString(pivotBlockHash)); } else { logger.info("FastSync: looking for best block number..."); BlockIdentifier bestKnownBlock; @@ -827,7 +827,7 @@ private BlockHeader getPivotHeaderByHash(byte[] pivotBlockHash) throws Exception return ret; } logger.warn("Peer " + bestIdle + " returned pivot block with another hash: " + - Hex.toHexString(ret.getHash()) + " Dropping the peer."); + toHexString(ret.getHash()) + " Dropping the peer."); bestIdle.disconnect(ReasonCode.USELESS_PEER); } else { logger.warn("Peer " + bestIdle + " doesn't returned correct pivot block. Dropping the peer."); diff --git a/ethereumj-core/src/main/java/org/ethereum/sync/HeadersDownloader.java b/ethereumj-core/src/main/java/org/ethereum/sync/HeadersDownloader.java index 7371c6a01b..a723089856 100644 --- a/ethereumj-core/src/main/java/org/ethereum/sync/HeadersDownloader.java +++ b/ethereumj-core/src/main/java/org/ethereum/sync/HeadersDownloader.java @@ -28,13 +28,14 @@ import org.ethereum.validator.BlockHeaderValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import java.util.List; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Created by Anton Nashatyrev on 27.10.2016. */ @@ -74,7 +75,7 @@ public HeadersDownloader(BlockHeaderValidator headerValidator) { } public void init(byte[] startFromBlockHash) { - logger.info("HeaderDownloader init: startHash = " + Hex.toHexString(startFromBlockHash)); + logger.info("HeaderDownloader init: startHash = " + toHexString(startFromBlockHash)); SyncQueueReverseImpl syncQueue = new SyncQueueReverseImpl(startFromBlockHash, true); super.init(syncQueue, syncPool, "HeadersDownloader"); syncPool.init(channelManager, blockchain); diff --git a/ethereumj-core/src/main/java/org/ethereum/sync/SyncManager.java b/ethereumj-core/src/main/java/org/ethereum/sync/SyncManager.java index 5fa9f80647..fd330558d3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/sync/SyncManager.java +++ b/ethereumj-core/src/main/java/org/ethereum/sync/SyncManager.java @@ -29,7 +29,6 @@ import org.ethereum.validator.BlockHeaderValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -48,6 +47,7 @@ import static java.util.Collections.singletonList; import static org.ethereum.core.ImportResult.*; import static org.ethereum.util.Utils.longToTimePeriod; +import static org.ethereum.util.ByteUtil.toHexString; /** * @author Mikhail Kalinin @@ -284,7 +284,7 @@ private void produceQueue() { wrapper.getBlock().getTransactionsList().size(), ts); if (syncDone && (importResult == IMPORTED_BEST || importResult == IMPORTED_NOT_BEST)) { - if (logger.isDebugEnabled()) logger.debug("Block dump: " + Hex.toHexString(wrapper.getBlock().getEncoded())); + if (logger.isDebugEnabled()) logger.debug("Block dump: " + toHexString(wrapper.getBlock().getEncoded())); // Propagate block to the net after successful import asynchronously if (wrapper.isNewBlock()) channelManager.onNewForeignBlock(wrapper); } @@ -301,7 +301,7 @@ private void produceQueue() { } catch (Throwable e) { if (wrapper != null) { logger.error("Error processing block {}: ", wrapper.getBlock().getShortDescr(), e); - logger.error("Block dump: {}", Hex.toHexString(wrapper.getBlock().getEncoded())); + logger.error("Block dump: {}", toHexString(wrapper.getBlock().getEncoded())); } else { logger.error("Error processing unknown block", e); } diff --git a/ethereumj-core/src/main/java/org/ethereum/sync/SyncQueueImpl.java b/ethereumj-core/src/main/java/org/ethereum/sync/SyncQueueImpl.java index fe1c244cf2..9fda262787 100644 --- a/ethereumj-core/src/main/java/org/ethereum/sync/SyncQueueImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/sync/SyncQueueImpl.java @@ -23,13 +23,13 @@ import org.ethereum.core.Blockchain; import org.ethereum.db.ByteArrayWrapper; import org.ethereum.util.ByteArrayMap; -import org.spongycastle.util.encoders.Hex; import java.util.*; import java.util.function.Function; import static java.lang.Math.min; import static org.ethereum.sync.BlockDownloader.MAX_IN_REQUEST; +import static org.ethereum.util.ByteUtil.toHexString; /** * Created by Anton Nashatyrev on 27.05.2016. @@ -82,7 +82,7 @@ public List split(int maxCount) { @Override public String toString() { return "HeadersRequest{" + - (hash == null ? "start=" + getStart() : "hash=" + Hex.toHexString(hash).substring(0, 8))+ + (hash == null ? "start=" + getStart() : "hash=" + toHexString(hash).substring(0, 8))+ ", count=" + getCount() + ", reverse=" + isReverse() + ", step=" + getStep() + diff --git a/ethereumj-core/src/main/java/org/ethereum/trie/TrieImpl.java b/ethereumj-core/src/main/java/org/ethereum/trie/TrieImpl.java index 8720622073..341c6d2ba4 100644 --- a/ethereumj-core/src/main/java/org/ethereum/trie/TrieImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/trie/TrieImpl.java @@ -41,6 +41,7 @@ import static org.ethereum.util.RLP.EMPTY_ELEMENT_RLP; import static org.ethereum.util.RLP.encodeElement; import static org.ethereum.util.RLP.encodeList; +import static org.ethereum.util.ByteUtil.toHexString; /** * Created by Anton Nashatyrev on 07.02.2017. @@ -112,8 +113,8 @@ public boolean resolveCheck() { private void resolve() { if (!resolveCheck()) { - logger.error("Invalid Trie state, can't resolve hash " + Hex.toHexString(hash)); - throw new RuntimeException("Invalid Trie state, can't resolve hash " + Hex.toHexString(hash)); + logger.error("Invalid Trie state, can't resolve hash " + toHexString(hash)); + throw new RuntimeException("Invalid Trie state, can't resolve hash " + toHexString(hash)); } } @@ -423,7 +424,7 @@ private String dumpContent(boolean recursion, boolean compact) { @Override public String toString() { - return getType() + (dirty ? " *" : "") + (hash == null ? "" : "(hash: " + Hex.toHexString(hash) + " )"); + return getType() + (dirty ? " *" : "") + (hash == null ? "" : "(hash: " + toHexString(hash) + " )"); } } diff --git a/ethereumj-core/src/main/java/org/ethereum/trie/TrieKey.java b/ethereumj-core/src/main/java/org/ethereum/trie/TrieKey.java index 91a0ae7864..909090dde3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/trie/TrieKey.java +++ b/ethereumj-core/src/main/java/org/ethereum/trie/TrieKey.java @@ -17,9 +17,8 @@ */ package org.ethereum.trie; -import org.spongycastle.util.encoders.Hex; - import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY; +import static org.ethereum.util.ByteUtil.toHexString; /** * Created by Anton Nashatyrev on 13.02.2017. @@ -180,6 +179,6 @@ public boolean equals(Object obj) { @Override public String toString() { - return Hex.toHexString(key).substring(off) + (isTerminal() ? "T" : ""); + return toHexString(key).substring(off) + (isTerminal() ? "T" : ""); } } diff --git a/ethereumj-core/src/main/java/org/ethereum/util/Value.java b/ethereumj-core/src/main/java/org/ethereum/util/Value.java index bcddcf6406..304ebcbd8a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/util/Value.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/Value.java @@ -27,6 +27,8 @@ import java.util.Arrays; import java.util.List; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Class to encapsulate an object and provide utilities for conversion */ @@ -337,7 +339,7 @@ public String toString() { StringBuilder output = new StringBuilder(); if (isHashCode()) { - output.append(Hex.toHexString(asBytes())); + output.append(toHexString(asBytes())); } else if (isReadableString()) { output.append("'"); for (byte oneByte : asBytes()) { @@ -350,7 +352,7 @@ public String toString() { output.append("'"); return output.toString(); } - return Hex.toHexString(this.asBytes()); + return toHexString(this.asBytes()); } else if (isString()) { return asString(); } diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java b/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java index 3709db071b..853406f24b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java @@ -28,6 +28,8 @@ import java.math.BigInteger; import java.nio.ByteBuffer; +import static org.ethereum.util.ByteUtil.toHexString; + /** * DataWord is the 32-byte array representation of a 256-bit number * Calculations can be done on this word with other DataWords @@ -339,7 +341,7 @@ public void mulmod(DataWord word1, DataWord word2) { @JsonValue @Override public String toString() { - return Hex.toHexString(data); + return toHexString(data); } public String toPrefixString() { diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/LogInfo.java b/ethereumj-core/src/main/java/org/ethereum/vm/LogInfo.java index 89feb0af9f..6e10611e5f 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/LogInfo.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/LogInfo.java @@ -25,12 +25,11 @@ import org.ethereum.util.RLPItem; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; - import java.util.ArrayList; import java.util.List; import static org.ethereum.datasource.MemSizeEstimator.ByteArrayEstimator; +import static org.ethereum.util.ByteUtil.toHexString; /** * @author Roman Mandeleil @@ -114,16 +113,16 @@ public String toString() { topicsStr.append("["); for (DataWord topic : topics) { - String topicStr = Hex.toHexString(topic.getData()); + String topicStr = toHexString(topic.getData()); topicsStr.append(topicStr).append(" "); } topicsStr.append("]"); return "LogInfo{" + - "address=" + Hex.toHexString(address) + + "address=" + toHexString(address) + ", topics=" + topicsStr + - ", data=" + Hex.toHexString(data) + + ", data=" + toHexString(data) + '}'; } diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/program/invoke/ProgramInvokeFactoryImpl.java b/ethereumj-core/src/main/java/org/ethereum/vm/program/invoke/ProgramInvokeFactoryImpl.java index 010a2aed2f..52e4f219c7 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/program/invoke/ProgramInvokeFactoryImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/program/invoke/ProgramInvokeFactoryImpl.java @@ -27,7 +27,6 @@ import org.ethereum.vm.program.Program; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -114,20 +113,20 @@ public ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository "difficulty={}\n" + "gaslimit={}\n", - Hex.toHexString(tx.getHash()), - Hex.toHexString(address), - Hex.toHexString(origin), - Hex.toHexString(caller), + ByteUtil.toHexString(tx.getHash()), + ByteUtil.toHexString(address), + ByteUtil.toHexString(origin), + ByteUtil.toHexString(caller), ByteUtil.bytesToBigInteger(balance), ByteUtil.bytesToBigInteger(gasPrice), ByteUtil.bytesToBigInteger(gas), ByteUtil.bytesToBigInteger(callValue), - Hex.toHexString(data), - Hex.toHexString(lastHash), - Hex.toHexString(coinbase), + ByteUtil.toHexString(data), + ByteUtil.toHexString(lastHash), + ByteUtil.toHexString(coinbase), timestamp, number, - Hex.toHexString(difficulty), + ByteUtil.toHexString(difficulty), gaslimit); } @@ -179,19 +178,19 @@ public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, Da "blockNumber={}\n" + "difficulty={}\n" + "gaslimit={}\n", - Hex.toHexString(address.getLast20Bytes()), - Hex.toHexString(origin.getLast20Bytes()), - Hex.toHexString(caller.getLast20Bytes()), + ByteUtil.toHexString(address.getLast20Bytes()), + ByteUtil.toHexString(origin.getLast20Bytes()), + ByteUtil.toHexString(caller.getLast20Bytes()), balance.toString(), gasPrice.longValue(), gas.longValue(), - Hex.toHexString(callValue.getNoLeadZeroesData()), - data == null ? "" : Hex.toHexString(data), - Hex.toHexString(lastHash.getData()), - Hex.toHexString(coinbase.getLast20Bytes()), + ByteUtil.toHexString(callValue.getNoLeadZeroesData()), + data == null ? "" : ByteUtil.toHexString(data), + ByteUtil.toHexString(lastHash.getData()), + ByteUtil.toHexString(coinbase.getLast20Bytes()), timestamp.longValue(), number.longValue(), - Hex.toHexString(difficulty.getNoLeadZeroesData()), + ByteUtil.toHexString(difficulty.getNoLeadZeroesData()), gasLimit.bigIntValue()); } From a8008c13dd9b2b94a11c5bc197727503eb81d8fd Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Wed, 16 May 2018 09:56:26 +0530 Subject: [PATCH 2/4] Use null safe method to convert bytes to hexString `hint` and `contract` are only being used in logs. Changing the toHexString function for them should not break anything. Issue #1032 --- .../main/java/org/ethereum/sync/SyncPool.java | 3 +- .../src/main/java/org/ethereum/vm/VM.java | 40 +++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/sync/SyncPool.java b/ethereumj-core/src/main/java/org/ethereum/sync/SyncPool.java index cd3440256f..fd8dc125b4 100644 --- a/ethereumj-core/src/main/java/org/ethereum/sync/SyncPool.java +++ b/ethereumj-core/src/main/java/org/ethereum/sync/SyncPool.java @@ -42,6 +42,7 @@ import static java.lang.Math.min; import static org.ethereum.util.BIUtil.isIn20PercentRange; +import static org.ethereum.util.ByteUtil.toHexString; /** *

Encapsulates logic which manages peers involved in blockchain sync

@@ -337,7 +338,7 @@ private synchronized void cleanupActive() { private void logDiscoveredNodes(List nodes) { StringBuilder sb = new StringBuilder(); for(NodeHandler n : nodes) { - sb.append(Utils.getNodeIdShort(Hex.toHexString(n.getNode().getId()))); + sb.append(Utils.getNodeIdShort(toHexString(n.getNode().getId()))); sb.append(", "); } if(sb.length() > 0) { diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java index 9c73b1e5e0..e7289228d4 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java @@ -24,7 +24,6 @@ import org.ethereum.vm.program.Stack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import java.math.BigInteger; @@ -35,6 +34,7 @@ import static org.ethereum.crypto.HashUtil.sha3; import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY; import static org.ethereum.vm.OpCode.*; +import static org.ethereum.util.ByteUtil.toHexString; /** * The Ethereum Virtual Machine (EVM) is responsible for initialization @@ -710,7 +710,7 @@ else if (oldValue != null && newValue.isZero()) { DataWord address = program.getOwnerAddress(); if (logger.isInfoEnabled()) - hint = "address: " + Hex.toHexString(address.getLast20Bytes()); + hint = "address: " + toHexString(address.getLast20Bytes()); program.stackPush(address); program.step(); @@ -722,7 +722,7 @@ else if (oldValue != null && newValue.isZero()) { if (logger.isInfoEnabled()) hint = "address: " - + Hex.toHexString(address.getLast20Bytes()) + + toHexString(address.getLast20Bytes()) + " balance: " + balance.toString(); program.stackPush(balance); @@ -733,7 +733,7 @@ else if (oldValue != null && newValue.isZero()) { DataWord originAddress = program.getOriginAddress(); if (logger.isInfoEnabled()) - hint = "address: " + Hex.toHexString(originAddress.getLast20Bytes()); + hint = "address: " + toHexString(originAddress.getLast20Bytes()); program.stackPush(originAddress); program.step(); @@ -743,7 +743,7 @@ else if (oldValue != null && newValue.isZero()) { DataWord callerAddress = program.getCallerAddress(); if (logger.isInfoEnabled()) - hint = "address: " + Hex.toHexString(callerAddress.getLast20Bytes()); + hint = "address: " + toHexString(callerAddress.getLast20Bytes()); program.stackPush(callerAddress); program.step(); @@ -788,7 +788,7 @@ else if (oldValue != null && newValue.isZero()) { byte[] msgData = program.getDataCopy(dataOffsetData, lengthData); if (logger.isInfoEnabled()) - hint = "data: " + Hex.toHexString(msgData); + hint = "data: " + toHexString(msgData); program.memorySave(memOffsetData.intValueSafe(), msgData); program.step(); @@ -816,7 +816,7 @@ else if (oldValue != null && newValue.isZero()) { } if (logger.isInfoEnabled()) - hint = "data: " + Hex.toHexString(msgData); + hint = "data: " + toHexString(msgData); program.memorySave(memOffsetData.intValueSafe(), msgData); program.step(); @@ -868,7 +868,7 @@ else if (oldValue != null && newValue.isZero()) { System.arraycopy(fullCode, codeOffset, codeCopy, 0, sizeToBeCopied); if (logger.isInfoEnabled()) - hint = "code: " + Hex.toHexString(codeCopy); + hint = "code: " + toHexString(codeCopy); program.memorySave(memOffset, codeCopy); program.step(); @@ -905,7 +905,7 @@ else if (oldValue != null && newValue.isZero()) { DataWord coinbase = program.getCoinbase(); if (logger.isInfoEnabled()) - hint = "coinbase: " + Hex.toHexString(coinbase.getLast20Bytes()); + hint = "coinbase: " + toHexString(coinbase.getLast20Bytes()); program.stackPush(coinbase); program.step(); @@ -1164,7 +1164,7 @@ else if (oldValue != null && newValue.isZero()) { byte[] data = program.sweep(nPush); if (logger.isInfoEnabled()) - hint = "" + Hex.toHexString(data); + hint = "" + toHexString(data); program.stackPush(data); } @@ -1214,7 +1214,7 @@ else if (oldValue != null && newValue.isZero()) { DataWord outDataSize = program.stackPop(); if (logger.isInfoEnabled()) { - hint = "addr: " + Hex.toHexString(codeAddress.getLast20Bytes()) + hint = "addr: " + toHexString(codeAddress.getLast20Bytes()) + " gas: " + adjustedCallGas.shortHex() + " inOff: " + inDataOffs.shortHex() + " inSize: " + inDataSize.shortHex(); @@ -1255,7 +1255,7 @@ else if (oldValue != null && newValue.isZero()) { program.setHReturn(hReturn); if (logger.isInfoEnabled()) - hint = "data: " + Hex.toHexString(hReturn) + hint = "data: " + toHexString(hReturn) + " offset: " + offset.value() + " size: " + size.value(); @@ -1275,7 +1275,7 @@ else if (oldValue != null && newValue.isZero()) { program.getResult().addTouchAccount(address.getLast20Bytes()); if (logger.isInfoEnabled()) - hint = "address: " + Hex.toHexString(program.getOwnerAddress().getLast20Bytes()); + hint = "address: " + toHexString(program.getOwnerAddress().getLast20Bytes()); program.stop(); } @@ -1366,16 +1366,16 @@ private void dumpLine(OpCode op, long gasBefore, long gasCost, long memWords, Pr for (DataWord key : storageKeys) { dumpLogger.trace("{} {}", - Hex.toHexString(key.getNoLeadZeroesData()), - Hex.toHexString(details.getStorage().get(key).getNoLeadZeroesData())); + toHexString(key.getNoLeadZeroesData()), + toHexString(details.getStorage().get(key).getNoLeadZeroesData())); } default: break; } - String addressString = Hex.toHexString(program.getOwnerAddress().getLast20Bytes()); - String pcString = Hex.toHexString(new DataWord(program.getPC()).getNoLeadZeroesData()); - String opString = Hex.toHexString(new byte[]{op.val()}); - String gasString = Hex.toHexString(program.getGas().getNoLeadZeroesData()); + String addressString = toHexString(program.getOwnerAddress().getLast20Bytes()); + String pcString = toHexString(new DataWord(program.getPC()).getNoLeadZeroesData()); + String opString = toHexString(new byte[]{op.val()}); + String gasString = toHexString(program.getGas().getNoLeadZeroesData()); dumpLogger.trace("{} {} {} {}", addressString, pcString, opString, gasString); } else if (config.dumpStyle().equals("pretty")) { @@ -1401,7 +1401,7 @@ private void dumpLine(OpCode op, long gasBefore, long gasCost, long memWords, Pr } int level = program.getCallDeep(); - String contract = Hex.toHexString(program.getOwnerAddress().getLast20Bytes()); + String contract = toHexString(program.getOwnerAddress().getLast20Bytes()); String internalSteps = String.format("%4s", Integer.toHexString(program.getPC())).replace(' ', '0').toUpperCase(); dumpLogger.trace("{} | {} | #{} | {} : {} | {} | -{} | {}x32", level, contract, vmCounter, internalSteps, op, From 510ce2d7a896122890e11d0418bd9e8a03d0bb51 Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Wed, 16 May 2018 10:08:20 +0530 Subject: [PATCH 3/4] Use null safe method to convert bytes to hexString Removed unused imports and other changes as asked for Issue #1032 --- .../src/main/java/org/ethereum/core/TransactionExecutor.java | 1 - .../java/org/ethereum/datasource/rocksdb/RocksDbDataSource.java | 1 - .../org/ethereum/net/eth/message/GetBlockBodiesMessage.java | 1 - .../main/java/org/ethereum/net/eth/message/NewBlockMessage.java | 2 -- .../main/java/org/ethereum/net/eth/message/StatusMessage.java | 2 -- .../src/main/java/org/ethereum/net/rlpx/PongMessage.java | 2 +- .../ethereum/vm/program/invoke/ProgramInvokeFactoryImpl.java | 2 +- 7 files changed, 2 insertions(+), 9 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java b/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java index 1605884cf1..df7539377b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java @@ -44,7 +44,6 @@ import static org.ethereum.util.ByteUtil.toHexString; import static org.ethereum.vm.VMUtils.saveProgramTraceFile; import static org.ethereum.vm.VMUtils.zipAndEncode; -import static org.ethereum.util.ByteUtil.toHexString; /** * @author Roman Mandeleil diff --git a/ethereumj-core/src/main/java/org/ethereum/datasource/rocksdb/RocksDbDataSource.java b/ethereumj-core/src/main/java/org/ethereum/datasource/rocksdb/RocksDbDataSource.java index b1b7dff799..5ab3675c3c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/datasource/rocksdb/RocksDbDataSource.java +++ b/ethereumj-core/src/main/java/org/ethereum/datasource/rocksdb/RocksDbDataSource.java @@ -28,7 +28,6 @@ import org.rocksdb.WriteBatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetBlockBodiesMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetBlockBodiesMessage.java index 898f5541bb..3ded170f0d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetBlockBodiesMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/GetBlockBodiesMessage.java @@ -20,7 +20,6 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPList; import org.ethereum.util.Utils; -import org.spongycastle.util.encoders.Hex; import java.util.ArrayList; import java.util.List; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NewBlockMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NewBlockMessage.java index 012d9b1925..f9598efd90 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NewBlockMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NewBlockMessage.java @@ -21,8 +21,6 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; - import java.math.BigInteger; import static org.ethereum.util.ByteUtil.toHexString; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/StatusMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/StatusMessage.java index 0b181cab16..43e7489ccd 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/StatusMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/StatusMessage.java @@ -21,8 +21,6 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; - import java.math.BigInteger; import static org.ethereum.util.ByteUtil.toHexString; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/PongMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/PongMessage.java index f6bc971c6d..0fe0af8a1e 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/PongMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/PongMessage.java @@ -97,7 +97,7 @@ public String toString() { long currTime = System.currentTimeMillis() / 1000; String out = String.format("[PongMessage] \n token: %s \n expires in %d seconds \n %s\n", - ByteUtil.toHexString(token), (expires - currTime), super.toString()); + ByteUtil.toHexString(token), (expires - currTime), super.toString()); return out; } diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/program/invoke/ProgramInvokeFactoryImpl.java b/ethereumj-core/src/main/java/org/ethereum/vm/program/invoke/ProgramInvokeFactoryImpl.java index 52e4f219c7..bbaaaff1e2 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/program/invoke/ProgramInvokeFactoryImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/program/invoke/ProgramInvokeFactoryImpl.java @@ -185,7 +185,7 @@ public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, Da gasPrice.longValue(), gas.longValue(), ByteUtil.toHexString(callValue.getNoLeadZeroesData()), - data == null ? "" : ByteUtil.toHexString(data), + ByteUtil.toHexString(data), ByteUtil.toHexString(lastHash.getData()), ByteUtil.toHexString(coinbase.getLast20Bytes()), timestamp.longValue(), From a5f4e74f18e64647021294a2eaf7b3a099e521ad Mon Sep 17 00:00:00 2001 From: Kishan Sagathiya Date: Wed, 16 May 2018 10:53:06 +0530 Subject: [PATCH 4/4] Use null safe method to convert bytes to hexString More conversions Issue #1032 --- .../config/blockchain/ByzantiumConfig.java | 1 - .../net/eth/message/NodeDataMessage.java | 1 - .../ethereum/net/rlpx/NeighborsMessage.java | 1 - .../org/ethereum/net/rlpx/RlpxConnection.java | 6 ++-- .../java/org/ethereum/net/shh/Whisper.java | 1 - .../java/org/ethereum/net/swarm/Manifest.java | 35 +++++++++---------- .../net/swarm/bzz/BzzStatusMessage.java | 2 -- .../ethereum/samples/EventListenerSample.java | 2 +- .../vm/program/InternalTransaction.java | 5 --- .../java/org/ethereum/vm/program/Program.java | 19 +++++----- 10 files changed, 32 insertions(+), 41 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/config/blockchain/ByzantiumConfig.java b/ethereumj-core/src/main/java/org/ethereum/config/blockchain/ByzantiumConfig.java index 98889fc15c..5d103c1695 100644 --- a/ethereumj-core/src/main/java/org/ethereum/config/blockchain/ByzantiumConfig.java +++ b/ethereumj-core/src/main/java/org/ethereum/config/blockchain/ByzantiumConfig.java @@ -23,7 +23,6 @@ import org.ethereum.core.Block; import org.ethereum.core.BlockHeader; import org.ethereum.core.Repository; -import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NodeDataMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NodeDataMessage.java index 7c18a94cb3..bfb1ba870b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NodeDataMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/message/NodeDataMessage.java @@ -20,7 +20,6 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPList; import org.ethereum.util.Value; -import org.spongycastle.util.encoders.Hex; import java.util.ArrayList; import java.util.List; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/NeighborsMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/NeighborsMessage.java index d770297622..897964d285 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/NeighborsMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/NeighborsMessage.java @@ -22,7 +22,6 @@ import org.ethereum.util.RLP; import org.ethereum.util.RLPItem; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; import java.util.ArrayList; import java.util.List; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/RlpxConnection.java b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/RlpxConnection.java index 550ffa1dcb..dfda6644be 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlpx/RlpxConnection.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/rlpx/RlpxConnection.java @@ -24,6 +24,8 @@ import java.io.*; +import static org.ethereum.util.ByteUtil.toHexString; + /** * Created by devrandom on 2015-04-12. */ @@ -57,14 +59,14 @@ public void handleNextMessage() throws IOException { // TODO handle disconnect byte[] wire = new byte[frame.size]; frame.payload.read(wire); - System.out.println("packet " + Hex.toHexString(wire)); + System.out.println("packet " + toHexString(wire)); handshakeMessage = HandshakeMessage.parse(wire); logger.info(" ===> " + handshakeMessage); } else { System.out.println("packet type " + frame.type); byte[] wire = new byte[frame.size]; frame.payload.read(wire); - System.out.println("packet " + Hex.toHexString(wire)); + System.out.println("packet " + toHexString(wire)); } } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/shh/Whisper.java b/ethereumj-core/src/main/java/org/ethereum/net/shh/Whisper.java index 0afcde5c59..ff83e9f8ca 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/shh/Whisper.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/shh/Whisper.java @@ -18,7 +18,6 @@ package org.ethereum.net.shh; import org.ethereum.crypto.ECKey; -import org.spongycastle.util.encoders.Hex; import org.springframework.stereotype.Component; /** diff --git a/ethereumj-core/src/main/java/org/ethereum/net/swarm/Manifest.java b/ethereumj-core/src/main/java/org/ethereum/net/swarm/Manifest.java index b43ed40dc1..1084b7a21c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/swarm/Manifest.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/swarm/Manifest.java @@ -1,20 +1,20 @@ -/* - * Copyright (c) [2016] [ ] - * This file is part of the ethereumJ library. - * - * The ethereumJ library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The ethereumJ library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the ethereumJ library. If not, see . - */ +/* + * Copyright (c) [2016] [ ] + * This file is part of the ethereumJ library. + * + * The ethereumJ library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The ethereumJ library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the ethereumJ library. If not, see . + */ package org.ethereum.net.swarm; import com.fasterxml.jackson.annotation.JsonAutoDetect; @@ -22,7 +22,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import org.spongycastle.util.encoders.Hex; import java.io.IOException; import java.nio.charset.StandardCharsets; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/swarm/bzz/BzzStatusMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/swarm/bzz/BzzStatusMessage.java index a70dfea809..9636425cd2 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/swarm/bzz/BzzStatusMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/swarm/bzz/BzzStatusMessage.java @@ -19,11 +19,9 @@ import org.ethereum.net.client.Capability; import org.ethereum.net.swarm.Util; -import org.ethereum.util.ByteUtil; import org.ethereum.util.RLP; import org.ethereum.util.RLPElement; import org.ethereum.util.RLPList; -import org.spongycastle.util.encoders.Hex; import java.util.ArrayList; import java.util.Arrays; diff --git a/ethereumj-core/src/main/java/org/ethereum/samples/EventListenerSample.java b/ethereumj-core/src/main/java/org/ethereum/samples/EventListenerSample.java index e31f584d31..5bef418226 100644 --- a/ethereumj-core/src/main/java/org/ethereum/samples/EventListenerSample.java +++ b/ethereumj-core/src/main/java/org/ethereum/samples/EventListenerSample.java @@ -225,7 +225,7 @@ public void onPendingTransactionUpdate(TransactionReceipt txReceipt, PendingTran } public void requestFreeEther(byte[] addressBytes) { - String address = "0x" + Hex.toHexString(addressBytes); + String address = "0x" + toHexString(addressBytes); logger.info("Checking address {} for available ether.", address); BigInteger balance = ethereum.getRepository().getBalance(addressBytes); logger.info("Address {} balance: {} wei", address, balance); diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/program/InternalTransaction.java b/ethereumj-core/src/main/java/org/ethereum/vm/program/InternalTransaction.java index e2cac74478..e389626569 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/program/InternalTransaction.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/program/InternalTransaction.java @@ -17,11 +17,6 @@ */ package org.ethereum.vm.program; -import static org.apache.commons.lang3.ArrayUtils.getLength; -import static org.apache.commons.lang3.ArrayUtils.isEmpty; -import static org.apache.commons.lang3.ArrayUtils.nullToEmpty; -import static org.ethereum.util.ByteUtil.toHexString; - import java.math.BigInteger; import java.nio.ByteBuffer; diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java b/ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java index b99667155e..243fa3d16c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java @@ -54,6 +54,7 @@ import static org.apache.commons.lang3.ArrayUtils.*; import static org.ethereum.util.BIUtil.*; import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY; +import static org.ethereum.util.ByteUtil.toHexString; /** * @author Roman Mandeleil @@ -375,7 +376,7 @@ public void suicide(DataWord obtainerAddress) { if (logger.isInfoEnabled()) logger.info("Transfer to: [{}] heritage: [{}]", - Hex.toHexString(obtainer), + toHexString(obtainer), balance); addInternalTx(null, null, owner, obtainer, balance, null, "suicide"); @@ -414,7 +415,7 @@ public void createContract(DataWord value, DataWord memStart, DataWord memSize) byte[] programCode = memoryChunk(memStart.intValue(), memSize.intValue()); if (logger.isInfoEnabled()) - logger.info("creating a new contract inside contract run: [{}]", Hex.toHexString(senderAddress)); + logger.info("creating a new contract inside contract run: [{}]", toHexString(senderAddress)); BlockchainConfig blockchainConfig = config.getBlockchainConfig().getConfigForBlock(getNumber().longValue()); // actual gas subtract @@ -468,7 +469,7 @@ this, new DataWord(newAddress), getOwnerAddress(), value, gasLimit, ProgramResult result = ProgramResult.createEmpty(); if (contractAlreadyExists) { - result.setException(new BytecodeExecutionException("Trying to create a contract with existing contract address: 0x" + Hex.toHexString(newAddress))); + result.setException(new BytecodeExecutionException("Trying to create a contract with existing contract address: 0x" + toHexString(newAddress))); } else if (isNotEmpty(programCode)) { VM vm = new VM(config); Program program = new Program(programCode, programInvoke, internalTx, config).withCommonConfig(commonConfig); @@ -500,7 +501,7 @@ this, new DataWord(newAddress), getOwnerAddress(), value, gasLimit, if (result.getException() != null || result.isRevert()) { logger.debug("contract run halted by Exception: contract: [{}], exception: [{}]", - Hex.toHexString(newAddress), + toHexString(newAddress), result.getException()); internalTx.reject(); @@ -528,7 +529,7 @@ this, new DataWord(newAddress), getOwnerAddress(), value, gasLimit, refundGas(refundGas, "remain gas from the internal call"); if (logger.isInfoEnabled()) { logger.info("The remaining gas is refunded, account: [{}], gas: [{}] ", - Hex.toHexString(getOwnerAddress().getLast20Bytes()), + toHexString(getOwnerAddress().getLast20Bytes()), refundGas); } } @@ -560,7 +561,7 @@ public void callToAddress(MessageCall msg) { if (logger.isInfoEnabled()) logger.info(msg.getType().name() + " for existing contract: address: [{}], outDataOffs: [{}], outDataSize: [{}] ", - Hex.toHexString(contextAddress), msg.getOutDataOffs().longValue(), msg.getOutDataSize().longValue()); + toHexString(contextAddress), msg.getOutDataOffs().longValue(), msg.getOutDataSize().longValue()); Repository track = getStorage().startTracking(); @@ -611,7 +612,7 @@ this, new DataWord(contextAddress), if (result.getException() != null || result.isRevert()) { logger.debug("contract run halted by Exception: contract: [{}], exception: [{}]", - Hex.toHexString(contextAddress), + toHexString(contextAddress), result.getException()); internalTx.reject(); @@ -658,7 +659,7 @@ this, new DataWord(contextAddress), refundGas(refundGas.longValue(), "remaining gas from the internal call"); if (logger.isInfoEnabled()) logger.info("The remaining gas refunded, account: [{}], gas: [{}] ", - Hex.toHexString(senderAddress), + toHexString(senderAddress), refundGas.toString()); } } else { @@ -1183,7 +1184,7 @@ public void callToPrecompiledAddress(MessageCall msg, PrecompiledContract contra } else { if (logger.isDebugEnabled()) - logger.debug("Call {}(data = {})", contract.getClass().getSimpleName(), Hex.toHexString(data)); + logger.debug("Call {}(data = {})", contract.getClass().getSimpleName(), toHexString(data)); Pair out = contract.execute(data);