mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-09 13:58:02 -05:00
Simulation: Add state to StateOverride (eth_call, eth_simulateV1). (#8166)
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
This commit is contained in:
committed by
GitHub
parent
6d51821614
commit
8d360a3d0e
@@ -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="
|
||||
|
||||
Reference in New Issue
Block a user