erigon-pulse/cmd/devnet/contracts/backend.go
Mark Holt 751f62615d
Devnet sync events (#7911)
This request implements an end to end Polygon state sync in the devnet.

It does this by deploying smart contracts ont the L2 & L2 chain which
follow the polygon fx portal model with security checks removed to
simplify the code. The sync events generated are routed through a local
mock heimdal - to avoid the consensus process for testing purposes.

The commit also includes support code to help the delivery of additional
contract based scenratios.
2023-07-20 23:10:18 +01:00

66 lines
2.0 KiB
Go

package contracts
import (
"context"
"fmt"
"math/big"
ethereum "github.com/ledgerwatch/erigon"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/accounts/abi/bind"
"github.com/ledgerwatch/erigon/cmd/devnet/devnet"
"github.com/ledgerwatch/erigon/cmd/devnet/requests"
"github.com/ledgerwatch/erigon/core/types"
)
func NewBackend(node devnet.Node) bind.ContractBackend {
return contractBackend{node}
}
type contractBackend struct {
node devnet.Node
}
func (cb contractBackend) CodeAt(ctx context.Context, contract libcommon.Address, blockNumber *big.Int) ([]byte, error) {
return nil, fmt.Errorf("TODO")
}
func (cb contractBackend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
return nil, fmt.Errorf("TODO")
}
func (cb contractBackend) PendingCodeAt(ctx context.Context, account libcommon.Address) ([]byte, error) {
return nil, fmt.Errorf("TODO")
}
func (cb contractBackend) PendingNonceAt(ctx context.Context, account libcommon.Address) (uint64, error) {
res, err := cb.node.GetTransactionCount(account, requests.BlockNumbers.Pending)
if err != nil {
return 0, fmt.Errorf("failed to get transaction count for address 0x%x: %v", account, err)
}
return res.Uint64(), nil
}
func (cb contractBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
return nil, fmt.Errorf("TODO")
}
func (cb contractBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) {
return 0, fmt.Errorf("TODO")
}
func (cb contractBackend) SendTransaction(ctx context.Context, tx types.Transaction) error {
_, err := cb.node.SendTransaction(tx)
return err
}
func (cb contractBackend) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) {
return cb.node.FilterLogs(ctx, query)
}
func (cb contractBackend) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) {
return cb.node.SubscribeFilterLogs(ctx, query, ch)
}