Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into master-plus-sdk-0.1…
Browse files Browse the repository at this point in the history
…5.0-alpha.1
  • Loading branch information
tinker-michaelj committed May 29, 2021
2 parents a45d460 + 614c671 commit aaee84b
Show file tree
Hide file tree
Showing 51 changed files with 237 additions and 382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import static com.hedera.services.utils.EntityIdUtils.contractParsedFromSolidityAddress;
import static java.util.Collections.emptyList;
import static org.ethereum.core.BlockchainImpl.EMPTY_LIST_HASH;
import static org.ethereum.util.ByteUtil.longToBytesNoLeadZeroes;

public class DomainUtils {
public static Block fakeBlock(Instant at) {
Expand All @@ -55,7 +54,7 @@ public static Block fakeBlock(Instant at) {
new byte[32],
new byte[0],
0,
longToBytesNoLeadZeroes(Long.MAX_VALUE),
ByteUtil.longToBytesNoLeadZeroes(Long.MAX_VALUE),
0,
at.getEpochSecond(),
new byte[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.Map;
import java.util.regex.Pattern;

import static org.apache.commons.codec.binary.Hex.encodeHexString;
import com.swirlds.common.CommonUtils;

public class MetadataMapFactory {
private static final Logger log = LogManager.getLogger(MetadataMapFactory.class);
Expand Down Expand Up @@ -72,7 +72,7 @@ static HFileMeta toAttr(byte[] bytes) {
try {
return (bytes == null) ? null : HFileMeta.deserialize(bytes);
} catch (Exception internal) {
log.warn("Argument 'bytes={}' was not a serialized HFileMeta!", encodeHexString(bytes));
log.warn("Argument 'bytes={}' was not a serialized HFileMeta!", CommonUtils.hex(bytes));
throw new IllegalArgumentException(internal);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*/

import com.hedera.services.legacy.core.AccountKeyListObj;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.ByteArrayInputStream;
import java.io.ObjectInput;
Expand All @@ -34,8 +32,6 @@
import java.util.Map;

public class LegacyEd25519KeyReader {
private static final Logger log = LogManager.getLogger(LegacyEd25519KeyReader.class);

public String hexedABytesFrom(String b64EncodedKeyPairLoc, String keyPairId) {
try {
var b64Encoded = Files.readString(Paths.get(b64EncodedKeyPairLoc));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public List<KeyPairObj> getKeyPairList() {
return keyPairList;
}

public void setKeyPairList(List<KeyPairObj> keyPairList) {
this.keyPairList = keyPairList;
}

public AccountID getAccountId() {
return accountId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
* ‍
*/

import com.hedera.services.utils.MiscUtils;
import com.swirlds.common.CommonUtils;
import net.i2p.crypto.eddsa.EdDSAPublicKey;
import org.apache.commons.codec.DecoderException;

import java.io.Serializable;
import java.security.PublicKey;
Expand All @@ -39,20 +38,12 @@ public KeyPairObj(String publicKey, String privateKey) {
this.privateKey = privateKey;
}

public String getPublicKeyStr() {
return publicKey;
public String getPublicKeyAbyteStr() throws InvalidKeySpecException {
return CommonUtils.hex(((EdDSAPublicKey)getPublicKey()).getAbyte());
}

public String getPrivateKeyStr() {
return privateKey;
}

public String getPublicKeyAbyteStr() throws InvalidKeySpecException, DecoderException {
return MiscUtils.commonsBytesToHex(((EdDSAPublicKey)getPublicKey()).getAbyte());
}

private PublicKey getPublicKey() throws DecoderException, InvalidKeySpecException {
byte[] pubKeybytes = MiscUtils.commonsHexToBytes(publicKey);
private PublicKey getPublicKey() throws IllegalArgumentException, InvalidKeySpecException {
byte[] pubKeybytes = CommonUtils.unhex(publicKey);
X509EncodedKeySpec pencoded = new X509EncodedKeySpec(pubKeybytes);
EdDSAPublicKey pubKey = new EdDSAPublicKey(pencoded);
return pubKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* ‍
*/

import com.hedera.services.utils.MiscUtils;
import com.swirlds.common.CommonUtils;

/**
* Maps to proto KeyList.
Expand All @@ -38,18 +38,14 @@ public JECDSA_384Key(byte[] ECDSA_384Key) {

@Override
public String toString() {
return "<JECDSA_384Key: ECDSA_384Key hex=" + MiscUtils.commonsBytesToHex(ECDSA_384Key) + ">";
return "<JECDSA_384Key: ECDSA_384Key hex=" + CommonUtils.hex(ECDSA_384Key) + ">";
}

@Override
public boolean isEmpty() {
return ((null == ECDSA_384Key) || (0 == ECDSA_384Key.length));
}

public boolean hasECDSA_384Key() {
return true;
}

public byte[] getECDSA384() {
return ECDSA_384Key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* ‍
*/

import com.hedera.services.utils.MiscUtils;
import com.swirlds.common.CommonUtils;

/**
* Maps to proto Key of type ed25519.
Expand All @@ -39,7 +39,7 @@ public JEd25519Key(byte[] ed25519) {

@Override
public String toString() {
return "<JEd25519Key: ed25519 hex=" + MiscUtils.commonsBytesToHex(ed25519) + ">";
return "<JEd25519Key: ed25519 hex=" + CommonUtils.hex(ed25519) + ">";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* ‍
*/

import com.hedera.services.utils.MiscUtils;
import com.swirlds.common.CommonUtils;

/**
* Maps to proto Key of type RSA_3072.
Expand All @@ -38,7 +38,7 @@ public JRSA_3072Key(byte[] RSA_3072Key) {

@Override
public String toString() {
return "<JRSA_3072Key: RSA_3072Key hex=" + MiscUtils.commonsBytesToHex(RSA_3072Key) + ">";
return "<JRSA_3072Key: RSA_3072Key hex=" + CommonUtils.hex(RSA_3072Key) + ">";
}

public boolean hasRSA_3072Key() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.swirlds.common.io.SelfSerializable;
import com.swirlds.common.io.SerializableDataInputStream;
import com.swirlds.common.io.SerializableDataOutputStream;
import org.apache.commons.codec.binary.Hex;
import com.swirlds.common.CommonUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -283,7 +283,7 @@ public String toString() {
}
if (topicRunningHash != MISSING_RUNNING_HASH) {
helper.add("topicSeqNo", topicSequenceNumber);
helper.add("topicRunningHash", Hex.encodeHexString(topicRunningHash));
helper.add("topicRunningHash", CommonUtils.hex(topicRunningHash));
helper.add("runningHashVersion", runningHashVersion);
}
helper.add("newTotalTokenSupply", newTotalSupply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import org.ethereum.vm.program.invoke.ProgramInvokeFactory;
import org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl;
import org.ethereum.vm.program.invoke.ProgramInvokeImpl;
import org.spongycastle.util.encoders.Hex;
import com.swirlds.common.CommonUtils;

import java.math.BigInteger;
import java.time.Instant;
Expand Down Expand Up @@ -93,7 +93,6 @@
import static org.ethereum.util.BIUtil.toBI;
import static org.ethereum.util.BIUtil.transfer;
import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY;
import static org.ethereum.util.ByteUtil.toHexString;
import static org.ethereum.vm.VMUtils.saveProgramTraceFile;
import static org.ethereum.vm.VMUtils.zipAndEncode;

Expand Down Expand Up @@ -182,10 +181,10 @@ public SolidityExecutor(
this.trackingRepository = repository.startTracking();
this.dynamicProperties = dynamicProperties;
this.payerAddress = Optional.ofNullable(payerAddress)
.map(ByteUtil::hexStringToBytes)
.map(CommonUtils::unhex)
.orElse(solidityTxn.getSender());
this.fundingAddress = Optional.ofNullable(fundingAddress)
.map(ByteUtil::hexStringToBytes)
.map(CommonUtils::unhex)
.orElse(EMPTY_BYTE_ARRAY);

commonConfig = CommonConfig.getDefault();
Expand Down Expand Up @@ -249,7 +248,7 @@ private void call() {
errorCode = (gasSupplied.compareTo(gasLimit) < 0) ? INSUFFICIENT_GAS : MAX_GAS_LIMIT_EXCEEDED;
setError(String.format(
"OOG calling precompiled contract 0x%s (%s required, %s remaining)",
Hex.toHexString(targetAddress), gasRequired, gasLeft));
CommonUtils.hex(targetAddress), gasRequired, gasLeft));
gasLeft = ZERO;
return;
} else {
Expand All @@ -258,7 +257,7 @@ private void call() {
if (!out.getLeft()) {
errorCode = CONTRACT_EXECUTION_EXCEPTION;
setError(String.format("Error executing precompiled contract 0x%s",
Hex.toHexString(targetAddress)));
CommonUtils.hex(targetAddress)));
gasLeft = ZERO;
return;
}
Expand All @@ -267,7 +266,7 @@ private void call() {
byte[] code = repository.getCode(targetAddress);
if (isEmpty(code)) {
errorCode = CONTRACT_BYTECODE_EMPTY;
setError(String.format("Error: Bytecode is empty for contract 0x%s", Hex.toHexString(targetAddress)));
setError(String.format("Error: Bytecode is empty for contract 0x%s", CommonUtils.hex(targetAddress)));
} else {
var programInvoke = programInvokeFactory.createProgramInvoke(
solidityTxn, block, trackingRepository, repository, NULL_BLOCK_STORE);
Expand Down Expand Up @@ -304,7 +303,7 @@ private void create() {
var alreadyExtant = trackingRepository.getAccountState(newContractAddress);
if (alreadyExtant != null && alreadyExtant.isContractExist(blockchainConfig)) {
errorCode = CONTRACT_EXECUTION_EXCEPTION;
setError(String.format("Cannot overwrite extant contract @ 0x%s!", Hex.toHexString(newContractAddress)));
setError(String.format("Cannot overwrite extant contract @ 0x%s!", CommonUtils.hex(newContractAddress)));
gasLeft = ZERO;
return;
}
Expand Down Expand Up @@ -532,7 +531,7 @@ public TransactionExecutionSummary finalizeExecution() {
if (config.vmTraceCompressed()) {
trace = zipAndEncode(trace);
}
var hash = toHexString(solidityTxn.getHash());
var hash = CommonUtils.hex(solidityTxn.getHash());
saveProgramTraceFile(config, hash, trace);
listener.onVMTraceCreated(hash, trace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@
import com.hederahashgraph.api.proto.java.TransactionRecord;
import com.hederahashgraph.builder.RequestBuilder;
import com.hederahashgraph.fee.FeeBuilder;
import com.swirlds.common.CommonUtils;
import com.swirlds.fcmap.FCMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.ethereum.core.Transaction;
import org.ethereum.db.ServicesRepositoryRoot;
import org.ethereum.util.ByteUtil;
import org.spongycastle.pqc.math.linearalgebra.ByteUtils;
import org.spongycastle.util.encoders.DecoderException;

import java.math.BigInteger;
Expand Down Expand Up @@ -181,7 +180,7 @@ public TransactionRecord createContract(
}
String contractByteCodeString = new String(contractByteCode);
if (createContract.getConstructorParameters() != null && !createContract.getConstructorParameters().isEmpty()) {
String constructorParamsHexString = ByteUtils.toHexString(
final var constructorParamsHexString = CommonUtils.hex(
createContract.getConstructorParameters().toByteArray());
contractByteCodeString += constructorParamsHexString;
}
Expand Down Expand Up @@ -448,7 +447,7 @@ public TransactionRecord contractCall(TransactionBody transaction, Instant conse
String data = "";
if (contractCall.getFunctionParameters() != null
&& !contractCall.getFunctionParameters().isEmpty()) {
data = ByteUtil.toHexString(contractCall.getFunctionParameters().toByteArray());
data = CommonUtils.hex(contractCall.getFunctionParameters().toByteArray());
}
BigInteger value = BigInteger.ZERO;
if (contractCall.getAmount() > 0) {
Expand Down Expand Up @@ -550,8 +549,7 @@ public ContractCallLocalResponse contractCallLocal(
String data = "";
if (transactionContractCallLocal.getFunctionParameters() != null
&& !transactionContractCallLocal.getFunctionParameters().isEmpty()) {
data = ByteUtil
.toHexString(transactionContractCallLocal.getFunctionParameters().toByteArray());
data = CommonUtils.hex(transactionContractCallLocal.getFunctionParameters().toByteArray());
}
BigInteger value = BigInteger.ZERO;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


import com.swirlds.common.crypto.TransactionSignature;
import org.apache.commons.codec.binary.Hex;
import com.swirlds.common.CommonUtils;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -83,8 +83,8 @@ public static boolean allVaryingMaterialEquals(List<TransactionSignature> aSigs,
public static String pkSigRepr(List<TransactionSignature> sigs) {
return sigs.stream().map(sig -> String.format(
"(PK = %s | SIG = %s | %s)",
Hex.encodeHexString(sig.getExpandedPublicKeyDirect()),
Hex.encodeHexString(Arrays.copyOfRange(
CommonUtils.hex(sig.getExpandedPublicKeyDirect()),
CommonUtils.hex(Arrays.copyOfRange(
sig.getContentsDirect(),
sig.getSignatureOffset(),
sig.getSignatureOffset() + sig.getSignatureLength())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.hedera.services.legacy.exception.KeyPrefixMismatchException;
import com.hederahashgraph.api.proto.java.SignatureMap;
import com.hederahashgraph.api.proto.java.SignaturePair;
import org.spongycastle.util.encoders.Hex;
import com.swirlds.common.CommonUtils;

import java.util.Arrays;

Expand Down Expand Up @@ -57,8 +57,8 @@ public byte[] sigBytesFor(byte[] pubKey) throws KeyPrefixMismatchException {
if (beginsWith(pubKey, pubKeyPrefix)) {
if (sigBytes != EMPTY_SIG) {
throw new KeyPrefixMismatchException(
"Source signature map with prefix " + Hex.toHexString(pubKeyPrefix) +
" is ambiguous for given public key! (" + Hex.toHexString(pubKey) + ")");
"Source signature map with prefix " + CommonUtils.hex(pubKeyPrefix) +
" is ambiguous for given public key! (" + CommonUtils.hex(pubKey) + ")");
}
sigBytes = sigBytesFor(sigPair);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.hedera.services.ServicesState;
import com.hedera.services.context.domain.trackers.IssEventInfo;
import com.swirlds.common.AddressBook;
import com.swirlds.common.CommonUtils;
import com.swirlds.common.InvalidSignedStateListener;
import com.swirlds.common.NodeId;
import com.swirlds.common.Platform;
Expand All @@ -33,8 +34,6 @@

import java.time.Instant;

import static org.apache.commons.codec.binary.Hex.encodeHexString;

public class IssListener implements InvalidSignedStateListener {
private static final Logger log = LogManager.getLogger(IssListener.class);

Expand Down Expand Up @@ -70,7 +69,7 @@ public void notifyError(
var msg = String.format(
ISS_ERROR_MSG_PATTERN,
round, self.getId(), other.getId(),
encodeHexString(sig), encodeHexString(hash));
CommonUtils.hex(sig), CommonUtils.hex(hash));
log.error(msg);
fcmDump.dumpFrom(issState, self, round);
issState.logSummary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@
import com.hederahashgraph.api.proto.java.Key;
import com.hederahashgraph.api.proto.java.KeyList;
import com.swirlds.common.AddressBook;
import com.swirlds.common.CommonUtils;
import com.swirlds.fcmap.FCMap;
import org.apache.commons.codec.DecoderException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import static com.hedera.services.state.submerkle.EntityId.MISSING_ENTITY_ID;
import static com.hedera.services.utils.MiscUtils.asFcKeyUnchecked;
import static com.hedera.services.utils.MiscUtils.commonsHexToBytes;

public class BackedSystemAccountsCreator implements SystemAccountsCreator {
private static final Logger log = LogManager.getLogger(BackedSystemAccountsCreator.class);
Expand Down Expand Up @@ -132,9 +131,9 @@ private JKey getGenesisKey() {
genesisKey = asFcKeyUnchecked(Key.newBuilder()
.setKeyList(KeyList.newBuilder()
.addKeys(Key.newBuilder()
.setEd25519(ByteString.copyFrom(commonsHexToBytes(getHexedABytes())))))
.setEd25519(ByteString.copyFrom(CommonUtils.unhex(getHexedABytes())))))
.build());
} catch (DecoderException e) {
} catch (IllegalArgumentException e) {
throw new IllegalStateException("Could not construct genesis key!", e);
}
}
Expand Down
Loading

0 comments on commit aaee84b

Please sign in to comment.