Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Issue #1032 Use null safe method for bytes to hex string conversion #1069

Merged
merged 4 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import java.io.*;

import static org.ethereum.util.ByteUtil.toHexString;

/**
* Created by devrandom on 2015-04-12.
*/
Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
35 changes: 17 additions & 18 deletions ethereumj-core/src/main/java/org/ethereum/net/swarm/Manifest.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
/*
* Copyright (c) [2016] [ <ether.camp> ]
* 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 <http://www.gnu.org/licenses/>.
*/
/*
* Copyright (c) [2016] [ <ether.camp> ]
* 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 <http://www.gnu.org/licenses/>.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird. The comment is not changed at all, but GitHub is showing it to be changed.

package org.ethereum.net.swarm;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address is used only for logging, so no harm changing it here.

logger.info("Checking address {} for available ether.", address);
BigInteger balance = ethereum.getRepository().getBalance(addressBytes);
logger.info("Address {} balance: {} wei", address, balance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because duplicate imports

import java.math.BigInteger;
import java.nio.ByteBuffer;

Expand Down
19 changes: 10 additions & 9 deletions ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Boolean, byte[]> out = contract.execute(data);

Expand Down