Java Code Examples for org.ethereum.util.Value#length()
The following examples show how to use
org.ethereum.util.Value#length() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrieImpl.java From ethereumj with MIT License | 6 votes |
/**************************************** * 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)); } }
Example 2
Source File: TrieIterator.java From ethereumj with MIT License | 5 votes |
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()); } } } } } }
Example 3
Source File: TrieImpl.java From ethereumj with MIT License | 4 votes |
private boolean isEmptyNode(Object node) { Value n = new Value(node); return (node == null || (n.isString() && (n.asString() == "" || n.get(0).isNull())) || n.length() == 0); }