2023-07-06 11:42:34 +03:00
|
|
|
// Copyright 2023 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package catalyst
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-01-10 18:45:08 +03:00
|
|
|
"time"
|
2023-07-06 11:42:34 +03:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2024-01-10 18:45:08 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
2023-07-06 11:42:34 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2024-01-10 18:45:08 +03:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2023-07-06 11:42:34 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type api struct {
|
2024-01-10 18:45:08 +03:00
|
|
|
sim *SimulatedBeacon
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) loop() {
|
|
|
|
var (
|
|
|
|
newTxs = make(chan core.NewTxsEvent)
|
|
|
|
sub = a.sim.eth.TxPool().SubscribeTransactions(newTxs, true)
|
|
|
|
)
|
|
|
|
defer sub.Unsubscribe()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-a.sim.shutdownCh:
|
|
|
|
return
|
|
|
|
case w := <-a.sim.withdrawals.pending:
|
|
|
|
withdrawals := append(a.sim.withdrawals.gatherPending(9), w)
|
|
|
|
if err := a.sim.sealBlock(withdrawals, uint64(time.Now().Unix())); err != nil {
|
|
|
|
log.Warn("Error performing sealing work", "err", err)
|
|
|
|
}
|
|
|
|
case <-newTxs:
|
|
|
|
a.sim.Commit()
|
|
|
|
}
|
|
|
|
}
|
2023-07-06 11:42:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) AddWithdrawal(ctx context.Context, withdrawal *types.Withdrawal) error {
|
2024-01-10 18:45:08 +03:00
|
|
|
return a.sim.withdrawals.add(withdrawal)
|
2023-07-06 11:42:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) SetFeeRecipient(ctx context.Context, feeRecipient common.Address) {
|
2024-01-10 18:45:08 +03:00
|
|
|
a.sim.setFeeRecipient(feeRecipient)
|
2023-07-06 11:42:34 +03:00
|
|
|
}
|