mirror of https://github.com/hyperledger/besu
Engine RPC endpoint (#3470)
Code originally written by jflo on the merge branch. Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>pull/3391/head
parent
1c39d48143
commit
435c9e388c
@ -0,0 +1,74 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu contributors |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results; |
||||
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader; |
||||
import org.hyperledger.besu.ethereum.core.Difficulty; |
||||
|
||||
import java.util.List; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonGetter; |
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; |
||||
import com.fasterxml.jackson.databind.JsonNode; |
||||
|
||||
@JsonPropertyOrder({ |
||||
"number", |
||||
"blockHash", |
||||
"mixHash", |
||||
"parentHash", |
||||
"nonce", |
||||
"sha3Uncles", |
||||
"logsBloom", |
||||
"transactionsRoot", |
||||
"stateRoot", |
||||
"receiptsRoot", |
||||
"miner", |
||||
"difficulty", |
||||
"totalDifficulty", |
||||
"extraData", |
||||
"baseFee", |
||||
"size", |
||||
"gasLimit", |
||||
"gasUsed", |
||||
"timestamp", |
||||
"uncles", |
||||
"transactions" |
||||
}) |
||||
public class ConsensusBlockResult extends BlockResult { |
||||
|
||||
private final List<String> opaqueTransactions; |
||||
|
||||
public ConsensusBlockResult( |
||||
final BlockHeader header, |
||||
final List<String> transactions, |
||||
final List<JsonNode> ommers, |
||||
final Difficulty totalDifficulty, |
||||
final int size, |
||||
final boolean includeCoinbase) { |
||||
super(header, null, ommers, totalDifficulty, size, includeCoinbase); |
||||
this.opaqueTransactions = transactions; |
||||
} |
||||
|
||||
@Override |
||||
@JsonGetter(value = "blockHash") |
||||
public String getHash() { |
||||
return hash; |
||||
} |
||||
|
||||
@JsonGetter(value = "transactions") |
||||
public List<String> getOpaqueTransactions() { |
||||
return opaqueTransactions; |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu contributors |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results; |
||||
|
||||
import java.util.Set; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue; |
||||
|
||||
public class OpaqueTransactionsResult implements TransactionResult { |
||||
|
||||
private final Set<String> transactionInfoResults; |
||||
|
||||
public OpaqueTransactionsResult(final Set<String> transactionInfoSet) { |
||||
transactionInfoResults = |
||||
transactionInfoSet.stream().map(String::new).collect(Collectors.toSet()); |
||||
} |
||||
|
||||
@JsonValue |
||||
public Set<String> getResults() { |
||||
return transactionInfoResults; |
||||
} |
||||
} |
@ -0,0 +1,58 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.api.jsonrpc.methods; |
||||
|
||||
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator; |
||||
import org.hyperledger.besu.ethereum.ProtocolContext; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineExecutePayload; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineForkchoiceUpdated; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayload; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; |
||||
import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; |
||||
|
||||
import java.util.Map; |
||||
|
||||
import io.vertx.core.Vertx; |
||||
import io.vertx.core.VertxOptions; |
||||
|
||||
public class ExecutionEngineJsonRpcMethods extends ApiGroupJsonRpcMethods { |
||||
|
||||
private final BlockResultFactory blockResultFactory = new BlockResultFactory(); |
||||
|
||||
private final MergeMiningCoordinator mergeCoordinator; |
||||
private final ProtocolContext protocolContext; |
||||
|
||||
ExecutionEngineJsonRpcMethods( |
||||
final MiningCoordinator miningCoordinator, final ProtocolContext protocolContext) { |
||||
this.mergeCoordinator = (MergeMiningCoordinator) miningCoordinator; |
||||
this.protocolContext = protocolContext; |
||||
} |
||||
|
||||
@Override |
||||
protected String getApiGroup() { |
||||
return RpcApis.ENGINE.name(); |
||||
} |
||||
|
||||
@Override |
||||
protected Map<String, JsonRpcMethod> create() { |
||||
Vertx syncVertx = Vertx.vertx(new VertxOptions().setWorkerPoolSize(1)); |
||||
return mapOf( |
||||
new EngineGetPayload(syncVertx, protocolContext, blockResultFactory), |
||||
new EngineExecutePayload(syncVertx, protocolContext, mergeCoordinator), |
||||
new EngineForkchoiceUpdated(syncVertx, protocolContext, mergeCoordinator)); |
||||
} |
||||
} |
Loading…
Reference in new issue