@ -45,7 +45,7 @@ public class VerkleEntryFactory {
trieKeyAdapter = new TrieKeyBatchAdapter ( hasher ) ;
trieKeyAdapter = new TrieKeyBatchAdapter ( hasher ) ;
}
}
public void generateAccountKeys ForRemoval ( final Address address ) {
public void generateAccountKeyForRemoval ( final Address address ) {
keysForRemoval . add ( trieKeyAdapter . basicDataKey ( address ) ) ;
keysForRemoval . add ( trieKeyAdapter . basicDataKey ( address ) ) ;
}
}
@ -58,8 +58,7 @@ public class VerkleEntryFactory {
}
}
}
}
public void generateStorageKeysForRemoval (
public void generateStorageKeyForRemoval ( final Address address , final StorageSlotKey storageKey ) {
final Address address , final StorageSlotKey storageKey ) {
keysForRemoval . add ( trieKeyAdapter . storageKey ( address , storageKey . getSlotKey ( ) . orElseThrow ( ) ) ) ;
keysForRemoval . add ( trieKeyAdapter . storageKey ( address , storageKey . getSlotKey ( ) . orElseThrow ( ) ) ) ;
}
}
@ -69,32 +68,39 @@ public class VerkleEntryFactory {
Bytes32 basicDataValue ;
Bytes32 basicDataValue ;
if ( ( basicDataValue = nonStorageKeyValuesForUpdate . get ( basicDataKey ) ) = = null ) {
if ( ( basicDataValue = nonStorageKeyValuesForUpdate . get ( basicDataKey ) ) = = null ) {
basicDataValue = Bytes32 . ZERO ;
basicDataValue = Bytes32 . ZERO ;
} else {
basicDataValue = SuffixTreeEncoder . eraseVersion ( basicDataValue ) ;
basicDataValue = SuffixTreeEncoder . eraseNonce ( basicDataValue ) ;
basicDataValue = SuffixTreeEncoder . eraseBalance ( basicDataValue ) ;
}
}
basicDataValue = SuffixTreeEncoder . addVersionIntoValue ( basicDataValue , Bytes32 . ZERO ) ;
basicDataValue = SuffixTreeEncoder . setVersionInValue ( basicDataValue , Bytes . of ( 0 ) ) ;
basicDataValue = SuffixTreeEncoder . addNonceIntoValue ( basicDataValue , UInt256 . valueOf ( nonce ) ) ;
basicDataValue = SuffixTreeEncoder . setNonceInValue ( basicDataValue , Bytes . ofUnsignedLong ( nonce ) ) ;
basicDataValue = SuffixTreeEncoder . addBalanceIntoValue ( basicDataValue , balance ) ;
basicDataValue =
SuffixTreeEncoder . setBalanceInValue (
basicDataValue ,
// balance size is exactly 16 bytes
balance . slice ( 16 ) ) ;
nonStorageKeyValuesForUpdate . put ( basicDataKey , basicDataValue ) ;
nonStorageKeyValuesForUpdate . put ( basicDataKey , basicDataValue ) ;
}
}
public void generateCodeHashKeyValueForUpdate ( final Address address , final Hash codeHash ) {
nonStorageKeyValuesForUpdate . put ( trieKeyAdapter . codeHashKey ( address ) , codeHash ) ;
}
public void generateCodeKeyValuesForUpdate (
public void generateCodeKeyValuesForUpdate (
final Address address , final Bytes code , final Hash codeHash ) {
final Address address , final Bytes code , final Hash codeHash ) {
Bytes32 basicDataKey = trieKeyAdapter . basicDataKey ( address ) ;
Bytes32 basicDataKey = trieKeyAdapter . basicDataKey ( address ) ;
Bytes32 basicDataValue ;
Bytes32 basicDataValue ;
if ( ( basicDataValue = nonStorageKeyValuesForUpdate . get ( basicDataKey ) ) = = null ) {
if ( ( basicDataValue = nonStorageKeyValuesForUpdate . get ( basicDataKey ) ) = = null ) {
basicDataValue = Bytes32 . ZERO ;
basicDataValue = Bytes32 . ZERO ;
} else {
basicDataValue = SuffixTreeEncoder . eraseCodeSize ( basicDataValue ) ;
}
}
basicDataValue =
basicDataValue =
SuffixTreeEncoder . addCodeSizeIntoValue ( basicDataValue , UInt256 . valueOf ( code . size ( ) ) ) ;
SuffixTreeEncoder . setCodeSizeInValue (
basicDataValue ,
// code size is exactly 3 bytes
Bytes . ofUnsignedInt ( code . size ( ) ) . slice ( 1 ) ) ;
nonStorageKeyValuesForUpdate . put ( basicDataKey , basicDataValue ) ;
nonStorageKeyValuesForUpdate . put ( basicDataKey , basicDataValue ) ;
nonStorageKeyValuesForUpdate . put ( trieKeyAdapter . codeHashKey ( address ) , codeHash ) ;
generateCodeHashKeyValueForUpdate ( address , codeHash ) ;
List < UInt256 > codeChunks = trieKeyAdapter . chunkifyCode ( code ) ;
List < UInt256 > codeChunks = trieKeyAdapter . chunkifyCode ( code ) ;
for ( int i = 0 ; i < codeChunks . size ( ) ; i + + ) {
for ( int i = 0 ; i < codeChunks . size ( ) ; i + + ) {
nonStorageKeyValuesForUpdate . put (
nonStorageKeyValuesForUpdate . put (