Recalculate trie only when necessary

This commit is contained in:
nicksavers 2014-08-03 18:35:20 +02:00
parent 31fddb591b
commit 59d8dfbed0
1 changed files with 7 additions and 9 deletions

View File

@ -94,7 +94,11 @@ public class ContractDetails {
public byte[] getStorageHash() {
getEncoded();
storageTrie = new Trie(null);
// calc the trie for root hash
for (int i = 0; i < storageKeys.size(); ++i){
storageTrie.update(storageKeys.get(i).getData(), RLP.encodeElement( storageValues.get(i).getNoLeadZeroesData() ));
}
return storageTrie.getRootHash();
}
@ -149,12 +153,6 @@ public class ContractDetails {
values[i] = RLP.encodeElement(value.getNoLeadZeroesData());
}
storageTrie = new Trie(null);
// calc the trie for root hash
for (int i = 0; i < storageKeys.size(); ++i){
storageTrie.update(storageKeys.get(i).getData(), values[i]);
}
byte[] rlpKeysList = RLP.encodeList(keys);
byte[] rlpValuesList = RLP.encodeList(values);
byte[] rlpCode = RLP.encodeElement(code);