preparing for state finalization

This commit is contained in:
romanman 2014-06-06 15:16:44 +01:00
parent 3f7891ff36
commit 9f70c014a1
3 changed files with 28 additions and 2 deletions

View File

@ -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;
@ -48,6 +49,16 @@ public class AccountState {
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) {
this.ecKey = ecKey;
this.nonce = nonce;
@ -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;
}

View File

@ -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
*