Merge branch 'main' into zkbesu

# Conflicts:
#	.github/pull_request_template.md
#	.github/workflows/sonarcloud.yml
This commit is contained in:
Fabio Di Fabio
2025-02-03 14:15:40 +01:00
105 changed files with 2156 additions and 602 deletions

View File

@@ -52,8 +52,25 @@ public enum RequestType {
case 0x01 -> WITHDRAWAL;
case 0x02 -> CONSOLIDATION;
default ->
throw new IllegalArgumentException(
throw new InvalidRequestTypeException(
String.format("Unsupported request type: 0x%02X", serializedTypeValue));
};
}
/**
* Exception thrown when an invalid request type is encountered.
*
* <p>This exception is thrown when a serialized type value does not correspond to any {@link
* RequestType}.
*/
public static class InvalidRequestTypeException extends IllegalArgumentException {
/**
* Constructs an {@link InvalidRequestTypeException} with the specified detail message.
*
* @param message the detail message.
*/
public InvalidRequestTypeException(final String message) {
super(message);
}
}
}

View File

@@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.datatypes;
import static com.google.common.base.Preconditions.checkState;
import org.hyperledger.besu.datatypes.parameters.UnsignedLongParameter;
import java.util.Map;
@@ -35,6 +37,7 @@ public class StateOverride {
private final Optional<Wei> balance;
private final Optional<Long> nonce;
private final Optional<String> code;
private final Optional<Map<String, String>> state;
private final Optional<Map<String, String>> stateDiff;
private final Optional<Address> movePrecompileToAddress;
@@ -42,11 +45,13 @@ public class StateOverride {
final Optional<Wei> balance,
final Optional<Long> nonce,
final Optional<String> code,
final Optional<Map<String, String>> state,
final Optional<Map<String, String>> stateDiff,
final Optional<Address> movePrecompileToAddress) {
this.balance = balance;
this.nonce = nonce;
this.code = code;
this.state = state;
this.stateDiff = stateDiff;
this.movePrecompileToAddress = movePrecompileToAddress;
}
@@ -83,6 +88,15 @@ public class StateOverride {
*
* @return the state override map if present
*/
public Optional<Map<String, String>> getState() {
return state;
}
/**
* Gets the state diff override map
*
* @return the state diff override map if present
*/
public Optional<Map<String, String>> getStateDiff() {
return stateDiff;
}
@@ -102,6 +116,7 @@ public class StateOverride {
private Optional<Wei> balance = Optional.empty();
private Optional<Long> nonce = Optional.empty();
private Optional<String> code = Optional.empty();
private Optional<Map<String, String>> state = Optional.empty();
private Optional<Map<String, String>> stateDiff = Optional.empty();
private Optional<Address> movePrecompileToAddress = Optional.empty();
@@ -141,6 +156,17 @@ public class StateOverride {
return this;
}
/**
* Sets the state override
*
* @param state the map of state overrides
* @return the builder
*/
public Builder withState(final Map<String, String> state) {
this.state = Optional.ofNullable(state);
return this;
}
/**
* Sets the state diff override
*
@@ -169,7 +195,8 @@ public class StateOverride {
* @return account override
*/
public StateOverride build() {
return new StateOverride(balance, nonce, code, stateDiff, movePrecompileToAddress);
checkState(state.isEmpty() || stateDiff.isEmpty(), "Cannot set both state and stateDiff");
return new StateOverride(balance, nonce, code, state, stateDiff, movePrecompileToAddress);
}
}
@@ -200,12 +227,13 @@ public class StateOverride {
return balance.equals(stateOverride.balance)
&& nonce.equals(stateOverride.nonce)
&& code.equals(stateOverride.code)
&& state.equals(stateOverride.state)
&& stateDiff.equals(stateOverride.stateDiff);
}
@Override
public int hashCode() {
return Objects.hash(balance, nonce, code, stateDiff);
return Objects.hash(balance, nonce, code, state, stateDiff);
}
@Override
@@ -217,6 +245,8 @@ public class StateOverride {
+ nonce
+ ", code="
+ code
+ ", state="
+ state
+ ", stateDiff="
+ stateDiff
+ ", movePrecompileToAddress="