diff --git a/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java b/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java index 5a45814a..a412ad86 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/AccountState.java @@ -3,6 +3,7 @@ package org.ethereum.core; import org.ethereum.crypto.ECKey; import org.ethereum.crypto.HashUtil; import org.ethereum.util.RLP; +import org.ethereum.util.RLPList; import org.ethereum.util.Utils; import java.math.BigInteger; @@ -45,7 +46,17 @@ public class AccountState { } public AccountState(ECKey ecKey) { - this(ecKey, BigInteger.ZERO, BigInteger.ZERO); + this(ecKey, BigInteger.ZERO, BigInteger.ZERO); + } + + public AccountState(byte[] rlpData){ + this.rlpEncoded = rlpData; + + RLPList items = (RLPList)RLP.decode2(rlpEncoded).get(0); + this.nonce = new BigInteger(1, ((items.get(0).getRLPData()) == null ? new byte[]{} : items.get(0).getRLPData())); + this.balance = new BigInteger(1, items.get(1).getRLPData()); + this.stateRoot = items.get(2).getRLPData(); + this.codeHash = items.get(3).getRLPData(); } public AccountState(ECKey ecKey, BigInteger nonce, BigInteger balance) { @@ -71,6 +82,8 @@ public class AccountState { this.nonce = nonce.add(BigInteger.ONE); } + public void setCodeHash(byte[] codeHash){ this.codeHash = codeHash; } + public BigInteger getBalance() { return balance; } diff --git a/ethereumj-core/src/main/java/org/ethereum/crypto/HashUtil.java b/ethereumj-core/src/main/java/org/ethereum/crypto/HashUtil.java index 0a5c30ed..ee363ba3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/crypto/HashUtil.java +++ b/ethereumj-core/src/main/java/org/ethereum/crypto/HashUtil.java @@ -25,7 +25,7 @@ public class HashUtil { public static byte[] sha256(byte[] input) { return sha256digest.digest(input); } - + public static byte[] sha3(byte[] input) { return SHA3Helper.sha3(input); } diff --git a/ethereumj-core/src/main/java/org/ethereum/trie/Trie.java b/ethereumj-core/src/main/java/org/ethereum/trie/Trie.java index cce04fd6..f19d1aa5 100644 --- a/ethereumj-core/src/main/java/org/ethereum/trie/Trie.java +++ b/ethereumj-core/src/main/java/org/ethereum/trie/Trie.java @@ -109,6 +109,19 @@ public class Trie { return c.asBytes(); } + /** + * Retrieve a value from a node + * + * @param key + * @return value + */ + public byte[] get(byte[] key) { + byte[] k = binToNibbles(key); + Value c = new Value( this.get(this.root, k) ); + return c.asBytes(); + } + + /** * Delete a key/value pair from the trie *