org.ethereum.util.Value Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ethereumj-core Show documentation
Show all versions of ethereumj-core Show documentation
Java implementation of the Ethereum protocol adapted to use for Hedera Smart Contract Service
The newest version!
/*
* 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.util;
import com.cedarsoftware.util.DeepEquals;
import org.ethereum.crypto.HashUtil;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
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
*/
public class Value {
private Object value;
private byte[] rlp;
private byte[] sha3;
private boolean decoded = false;
public static Value fromRlpEncoded(byte[] data) {
if (data != null && data.length != 0) {
Value v = new Value();
v.init(data);
return v;
}
return null;
}
public Value(){
}
public void init(byte[] rlp){
this.rlp = rlp;
}
public Value(Object obj) {
this.decoded = true;
if (obj == null) return;
if (obj instanceof Value) {
this.value = ((Value) obj).asObj();
} else {
this.value = obj;
}
}
public Value withHash(byte[] hash) {
sha3 = hash;
return this;
}
/* *****************
* Convert
* *****************/
public Object asObj() {
decode();
return value;
}
public List