Skip to content

Commit

Permalink
add protocolSchedule
Browse files Browse the repository at this point in the history
  • Loading branch information
gtebrean committed Feb 15, 2024
1 parent db8cc63 commit 64741c0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 31 additions & 6 deletions src/main/kotlin/org/web3j/evm/EmbeddedEthereum.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ import java.util.Optional
import org.web3j.abi.datatypes.Address as wAddress
import org.web3j.protocol.core.methods.request.Transaction as wTransaction
import org.web3j.protocol.core.methods.response.TransactionReceipt as wTransactionReceipt
import com.google.common.io.Resources
import java.nio.charset.StandardCharsets
import org.hyperledger.besu.cli.config.EthNetworkConfig
import org.hyperledger.besu.cli.config.NetworkName
import org.hyperledger.besu.config.GenesisConfigFile
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec
import org.hyperledger.besu.ethereum.core.PrivacyParameters
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule
import org.hyperledger.besu.evm.internal.EvmConfiguration
import org.web3j.evm.utils.TestAccountsConstants
import org.web3j.protocol.core.methods.response.EthBlock.Withdrawal

/**
* Embedded Web3j Ethereum blockchain.
*/
class EmbeddedEthereum(
configuration: Configuration,
private val configuration: Configuration,
operationTracer: OperationTracer
) {
private val chain = InMemoryBesuChain(configuration, operationTracer)
Expand Down Expand Up @@ -125,10 +131,29 @@ class EmbeddedEthereum(
fun getTransactionReceipt(transactionHashParam: String): wTransactionReceipt? {
val hash = Hash.fromHexStringLenient(transactionHashParam)

val defaultProtocolSchedule = DefaultProtocolSchedule(Optional.of(chain.chainId))
defaultProtocolSchedule.putBlockNumberMilestone(0, ProtocolSpec())
val genesisConfig = if (configuration.genesisFileUrl === null) {
val networkConfig = EthNetworkConfig.getNetworkConfig(NetworkName.DEV)
GenesisConfigFile.fromConfig(networkConfig.genesisConfig)
} else {
GenesisConfigFile.fromConfig(
@Suppress("UnstableApiUsage")
Resources.toString(
configuration.genesisFileUrl,
StandardCharsets.UTF_8
)
)
}
val configOptions = genesisConfig.getConfigOptions(InMemoryBesuChain.DEFAULT_GENESIS_OVERRIDES)

val protocolSchedule = MainnetProtocolSchedule.fromConfig(
configOptions,
PrivacyParameters.DEFAULT,
true,
EvmConfiguration.DEFAULT
)

val result = blockchainQueries
.transactionReceiptByTransactionHash(hash, DefaultProtocolSchedule(Optional.of(chain.chainId)))
.transactionReceiptByTransactionHash(hash, protocolSchedule)
.map { receipt -> getResult(receipt) }
.orElse(null)
?: return null
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/web3j/evm/InMemoryBesuChain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class InMemoryBesuChain(

companion object {
private val LOG = LoggerFactory.getLogger(InMemoryBesuChain::class.java)
private val DEFAULT_GENESIS_OVERRIDES = mapOf(
internal val DEFAULT_GENESIS_OVERRIDES = mapOf(
"londonblock" to "1",
"petersburgblock" to "0"
)
Expand Down

0 comments on commit 64741c0

Please sign in to comment.