|
| 1 | +package sysgo |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/geth" |
| 7 | + "github.com/ethereum/go-ethereum/beacon/engine" |
| 8 | + "github.com/ethereum/go-ethereum/common" |
| 9 | + "github.com/ethereum/go-ethereum/common/hexutil" |
| 10 | + gn "github.com/ethereum/go-ethereum/node" |
| 11 | + "github.com/ethereum/go-ethereum/rpc" |
| 12 | + gethrpc "github.com/ethereum/go-ethereum/rpc" |
| 13 | +) |
| 14 | + |
| 15 | +type engineClient struct { |
| 16 | + inner *rpc.Client |
| 17 | +} |
| 18 | + |
| 19 | +func dialEngine(ctx context.Context, endpoint string, jwtSecret [32]byte) (*engineClient, error) { |
| 20 | + engineCl, err := gethrpc.DialOptions(ctx, endpoint, rpc.WithHTTPAuth(gn.NewJWTAuth(jwtSecret))) |
| 21 | + if err != nil { |
| 22 | + return nil, err |
| 23 | + } |
| 24 | + return &engineClient{ |
| 25 | + inner: engineCl, |
| 26 | + }, nil |
| 27 | +} |
| 28 | + |
| 29 | +var _ geth.EngineAPI = (*engineClient)(nil) |
| 30 | + |
| 31 | +func (e *engineClient) forkchoiceUpdated(fs engine.ForkchoiceStateV1, pa *engine.PayloadAttributes, method string) (engine.ForkChoiceResponse, error) { |
| 32 | + var x engine.ForkChoiceResponse |
| 33 | + if err := e.inner.CallContext(context.Background(), &x, method, fs, pa); err != nil { |
| 34 | + return engine.ForkChoiceResponse{}, err |
| 35 | + } |
| 36 | + return x, nil |
| 37 | +} |
| 38 | + |
| 39 | +func (e *engineClient) ForkchoiceUpdatedV2(fs engine.ForkchoiceStateV1, pa *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) { |
| 40 | + return e.forkchoiceUpdated(fs, pa, "engine_forkchoiceUpdatedV2") |
| 41 | +} |
| 42 | + |
| 43 | +func (e *engineClient) ForkchoiceUpdatedV3(fs engine.ForkchoiceStateV1, pa *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) { |
| 44 | + return e.forkchoiceUpdated(fs, pa, "engine_forkchoiceUpdatedV3") |
| 45 | +} |
| 46 | + |
| 47 | +func (e *engineClient) getPayload(id engine.PayloadID, method string) (*engine.ExecutionPayloadEnvelope, error) { |
| 48 | + var result engine.ExecutionPayloadEnvelope |
| 49 | + if err := e.inner.CallContext(context.Background(), &result, method, id); err != nil { |
| 50 | + return nil, err |
| 51 | + } |
| 52 | + return &result, nil |
| 53 | +} |
| 54 | + |
| 55 | +func (e *engineClient) GetPayloadV2(id engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) { |
| 56 | + return e.getPayload(id, "engine_getPayloadV2") |
| 57 | +} |
| 58 | + |
| 59 | +func (e *engineClient) GetPayloadV3(id engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) { |
| 60 | + return e.getPayload(id, "engine_getPayloadV3") |
| 61 | +} |
| 62 | + |
| 63 | +func (e *engineClient) GetPayloadV4(id engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) { |
| 64 | + return e.getPayload(id, "engine_getPayloadV4") |
| 65 | +} |
| 66 | + |
| 67 | +func (e *engineClient) NewPayloadV2(data engine.ExecutableData) (engine.PayloadStatusV1, error) { |
| 68 | + var result engine.PayloadStatusV1 |
| 69 | + if err := e.inner.CallContext(context.Background(), &result, "engine_newPayloadV2", data); err != nil { |
| 70 | + return engine.PayloadStatusV1{}, err |
| 71 | + } |
| 72 | + return result, nil |
| 73 | +} |
| 74 | + |
| 75 | +func (e *engineClient) NewPayloadV3(data engine.ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash) (engine.PayloadStatusV1, error) { |
| 76 | + var result engine.PayloadStatusV1 |
| 77 | + if err := e.inner.CallContext(context.Background(), &result, "engine_newPayloadV3", data, versionedHashes, beaconRoot); err != nil { |
| 78 | + return engine.PayloadStatusV1{}, err |
| 79 | + } |
| 80 | + return result, nil |
| 81 | +} |
| 82 | + |
| 83 | +func (e *engineClient) NewPayloadV4(data engine.ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash, executionRequests []hexutil.Bytes) (engine.PayloadStatusV1, error) { |
| 84 | + var result engine.PayloadStatusV1 |
| 85 | + if err := e.inner.CallContext(context.Background(), &result, "engine_newPayloadV4", data, versionedHashes, beaconRoot, executionRequests); err != nil { |
| 86 | + return engine.PayloadStatusV1{}, err |
| 87 | + } |
| 88 | + return result, nil |
| 89 | +} |
0 commit comments