preparing for state finalization
This commit is contained in:
parent
3f7891ff36
commit
9f70c014a1
|
@ -3,6 +3,7 @@ package org.ethereum.core;
|
||||||
import org.ethereum.crypto.ECKey;
|
import org.ethereum.crypto.ECKey;
|
||||||
import org.ethereum.crypto.HashUtil;
|
import org.ethereum.crypto.HashUtil;
|
||||||
import org.ethereum.util.RLP;
|
import org.ethereum.util.RLP;
|
||||||
|
import org.ethereum.util.RLPList;
|
||||||
import org.ethereum.util.Utils;
|
import org.ethereum.util.Utils;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
@ -48,6 +49,16 @@ public class AccountState {
|
||||||
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) {
|
public AccountState(ECKey ecKey, BigInteger nonce, BigInteger balance) {
|
||||||
this.ecKey = ecKey;
|
this.ecKey = ecKey;
|
||||||
this.nonce = nonce;
|
this.nonce = nonce;
|
||||||
|
@ -71,6 +82,8 @@ public class AccountState {
|
||||||
this.nonce = nonce.add(BigInteger.ONE);
|
this.nonce = nonce.add(BigInteger.ONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCodeHash(byte[] codeHash){ this.codeHash = codeHash; }
|
||||||
|
|
||||||
public BigInteger getBalance() {
|
public BigInteger getBalance() {
|
||||||
return balance;
|
return balance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,19 @@ public class Trie {
|
||||||
return c.asBytes();
|
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
|
* Delete a key/value pair from the trie
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue