本文整理汇总了Java中org.ethereum.util.Value类的典型用法代码示例。如果您正苦于以下问题:Java Value类的具体用法?Java Value怎么用?Java Value使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Value类属于org.ethereum.util包,在下文中一共展示了Value类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import org.ethereum.util.Value; //导入依赖的package包/类
public String toString() {
StringBuilder payload = new StringBuilder();
payload.append("count( ").append(dataList.size()).append(" )");
if (logger.isTraceEnabled()) {
payload.append(" ");
for (Value value : dataList) {
payload.append(value).append(" | ");
}
if (!dataList.isEmpty()) {
payload.delete(payload.length() - 3, payload.length());
}
}
return "[" + getCommand().name() + " " + payload + "]";
}
示例2: processGetNodeData
import org.ethereum.util.Value; //导入依赖的package包/类
protected synchronized void processGetNodeData(GetNodeDataMessage msg) {
if (logger.isTraceEnabled()) logger.trace(
"Peer {}: processing GetNodeData, size [{}]",
channel.getPeerIdShort(),
msg.getNodeKeys().size()
);
List<Value> nodeValues = new ArrayList<>();
for (byte[] nodeKey : msg.getNodeKeys()) {
byte[] rawNode = stateSource.get(nodeKey);
if (rawNode != null) {
Value value = new Value(rawNode);
nodeValues.add(value);
logger.trace("Eth63: " + Hex.toHexString(nodeKey).substring(0, 8) + " -> " + value);
}
}
sendMessage(new NodeDataMessage(nodeValues));
}
示例3: get
import org.ethereum.util.Value; //导入依赖的package包/类
/****************************************
* Private functions *
****************************************/
private Object get(Object node, byte[] key) {
// Return the node if key is empty (= found)
if (key.length == 0 || isEmptyNode(node)) {
return node;
}
Value currentNode = this.getNode(node);
if (currentNode == null) return null;
if (currentNode.length() == PAIR_SIZE) {
// Decode the key
byte[] k = unpackToNibbles(currentNode.get(0).asBytes());
Object v = currentNode.get(1).asObj();
if (key.length >= k.length && Arrays.equals(k, copyOfRange(key, 0, k.length))) {
return this.get(v, copyOfRange(key, k.length, key.length));
} else {
return "";
}
} else {
return this.get(currentNode.get(key[0]).asObj(), copyOfRange(key, 1, key.length));
}
}
示例4: getNode
import org.ethereum.util.Value; //导入依赖的package包/类
/**
* Helper method to retrieve the actual node
* If the node is not a list and length is > 32
* bytes get the actual node from the db
*
* @param node -
* @return
*/
private Value getNode(Object node) {
Value val = new Value(node);
// in that case we got a node
// so no need to encode it
if (!val.isBytes()) {
return val;
}
byte[] keyBytes = val.asBytes();
if (keyBytes.length == 0) {
return val;
} else if (keyBytes.length < 32) {
return new Value(keyBytes);
}
return this.cache.get(keyBytes);
}
示例5: parse
import org.ethereum.util.Value; //导入依赖的package包/类
private void parse() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
dataList = new ArrayList<>();
for (int i = 0; i < paramsList.size(); ++i) {
// Need it AS IS
dataList.add(Value.fromRlpEncoded(paramsList.get(i).getRLPData()));
}
parsed = true;
}
示例6: encode
import org.ethereum.util.Value; //导入依赖的package包/类
private void encode() {
List<byte[]> dataListRLP = new ArrayList<>();
for (Value value: dataList) {
if (value == null) continue; // Bad sign
dataListRLP.add(RLP.encodeElement(value.getData()));
}
byte[][] encodedElementArray = dataListRLP.toArray(new byte[dataListRLP.size()][]);
this.encoded = RLP.encodeList(encodedElementArray);
}
示例7: getRootHash
import org.ethereum.util.Value; //导入依赖的package包/类
@Override
public byte[] getRootHash() {
if (root == null
|| (root instanceof byte[] && ((byte[]) root).length == 0)
|| (root instanceof String && "".equals((String) root))) {
return ByteUtil.EMPTY_BYTE_ARRAY;
} else if (root instanceof byte[]) {
return (byte[]) this.getRoot();
} else {
Value rootValue = new Value(this.getRoot());
byte[] val = rootValue.encode();
return HashUtil.sha3(val);
}
}
示例8: copyNode
import org.ethereum.util.Value; //导入依赖的package包/类
private Object[] copyNode(Value currentNode) {
Object[] itemList = emptyStringSlice(LIST_SIZE);
for (int i = 0; i < LIST_SIZE; i++) {
Object cpy = currentNode.get(i).asObj();
if (cpy != null)
itemList[i] = cpy;
}
return itemList;
}
示例9: getTrieDump
import org.ethereum.util.Value; //导入依赖的package包/类
public String getTrieDump() {
String root = "";
TraceAllNodes traceAction = new TraceAllNodes();
this.scanTree(this.getRootHash(), traceAction);
if (this.getRoot() instanceof Value) {
root = "root: " + Hex.toHexString(getRootHash()) + " => " + this.getRoot() + "\n";
} else {
root = "root: " + Hex.toHexString(getRootHash()) + "\n";
}
return root + traceAction.getOutput();
}
示例10: put
import org.ethereum.util.Value; //导入依赖的package包/类
/**
* Put the node in the cache if RLP encoded value is longer than 32 bytes
*
* @param o the Node which could be a pair-, multi-item Node or single Value
* @return sha3 hash of RLP encoded node if length > 32 otherwise return node itself
*/
public Object put(Object o) {
Value value = new Value(o);
byte[] enc = value.encode();
if (enc.length >= 32) {
byte[] sha = HashUtil.sha3(enc);
this.nodes.put(new ByteArrayWrapper(sha), new Node(value, true));
this.isDirty = true;
return sha;
}
return value;
}
示例11: get
import org.ethereum.util.Value; //导入依赖的package包/类
public Value get(byte[] key) {
ByteArrayWrapper keyObj = new ByteArrayWrapper(key);
// First check if the key is the cache
if (this.nodes.get(keyObj) != null) {
return this.nodes.get(keyObj).getValue();
}
// Get the key of the database instead and cache it
byte[] data = this.db.get(key);
Value value = Value.fromRlpEncoded(data);
// Create caching node
this.nodes.put(keyObj, new Node(value, false));
return value;
}
示例12: workNode
import org.ethereum.util.Value; //导入依赖的package包/类
private void workNode(Value currentNode) {
if (currentNode.length() == 2) {
byte[] k = unpackToNibbles(currentNode.get(0).asBytes());
if (currentNode.get(1).asString() == "") {
this.workNode(currentNode.get(1));
} else {
if (k[k.length-1] == 16) {
this.values.add(currentNode.get(1).asString());
} else {
this.shas.add(currentNode.get(1).asBytes());
this.getNode(currentNode.get(1).asBytes());
}
}
} else {
for (int i = 0; i < currentNode.length(); i++) {
if (i == 16 && currentNode.get(i).length() != 0) {
this.values.add(currentNode.get(i).asString());
} else {
if (currentNode.get(i).asString() == "") {
this.workNode(currentNode.get(i));
} else {
String val = currentNode.get(i).asString();
if (val != "") {
this.shas.add(currentNode.get(1).asBytes());
this.getNode(val.getBytes());
}
}
}
}
}
}
示例13: collect
import org.ethereum.util.Value; //导入依赖的package包/类
private List<byte[]> collect() {
if (this.trie.getRoot() == "") {
return null;
}
this.getNode(new Value(this.trie.getRoot()).asBytes());
return this.shas;
}
示例14: serialize
import org.ethereum.util.Value; //导入依赖的package包/类
@Override
public byte[] serialize(Value object) {
return object.encode();
}
示例15: deserialize
import org.ethereum.util.Value; //导入依赖的package包/类
@Override
public Value deserialize(byte[] stream) {
return Value.fromRlpEncoded(stream);
}