Skip to content

Commit

Permalink
improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR552 committed Nov 15, 2021
1 parent f263994 commit 9bff7d2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
34 changes: 20 additions & 14 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
package etherman

import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/hermeznetwork/hermez-core/etherman/smartcontracts/proofofefficiency"
"github.com/hermeznetwork/hermez-core/state"
"github.com/ethereum/go-ethereum/ethclient"
)
type EtherMan struct {
Poe *proofofefficiency.Proofofefficiency
EtherClient *ethclient.Client
PoE *proofofefficiency.Proofofefficiency
}

func NewEtherman() (*EtherMan, error) {
func NewEtherman(url string, poeAddr common.Address) (*EtherMan, error) {
//TODO
var address common.Address
var backend bind.ContractBackend
poe, err := proofofefficiency.NewProofofefficiency(address, backend)
//Connect to ethereum node
ethClient, err := ethclient.Dial(url)
if err != nil {
log.Printf("GetEthClient - Client: error connecting to %s: %+v", url, err)
return nil, err
}
poe, err := proofofefficiency.NewProofofefficiency(poeAddr, ethClient)
if err != nil {
return nil, err
}

return &EtherMan{Poe: poe}, nil
return &EtherMan{EtherClient: ethClient, PoE: poe}, nil
}

//This function retrieves the ethereum block information by ethereum block number
// EthBlockByNumber function retrieves the ethereum block information by ethereum block number
func (etherMan *EtherMan) EthBlockByNumber(blockNum int64) (types.Block, error) {
//TODO
return types.Block{}, nil
}

//This function retrieves the batches information that are included in a specific ethereum block
// GetBatchesByBlock function retrieves the batches information that are included in a specific ethereum block
func (etherMan *EtherMan) GetBatchesByBlock(blockNum int64) ([]state.Batch, error) {
//TODO
return []state.Batch{}, nil
}

//This function retrieves the batches information that are included in all this ethereum blocks
// GetBatchesFromBlockTo function retrieves the batches information that are included in all this ethereum blocks
//from block x to block y
func (etherMan *EtherMan) GetBatchesFromBlockTo(fromBlock uint, toBlock uint) ([]state.Batch, error) {
//TODO
return []state.Batch{}, nil
}

//This function allows the sequencer send a new batch proposal to the rollup
func (etherMan *EtherMan) sendBatch(batch state.Batch) (common.Hash, error) {
// SendBatch function allows the sequencer send a new batch proposal to the rollup
func (etherMan *EtherMan) SendBatch(batch state.Batch) (common.Hash, error) {
//TODO
return common.Hash{}, nil
}

//This function allows the agregator send the proof for a batch and consolidate it
func (etherMan *EtherMan) consolidateBatch(batch state.Batch, proof state.Proof) (common.Hash, error) {
// ConsolidateBatch function allows the agregator send the proof for a batch and consolidate it
func (etherMan *EtherMan) ConsolidateBatch(batch state.Batch, proof state.Proof) (common.Hash, error) {
//TODO
return common.Hash{}, nil
}
14 changes: 10 additions & 4 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package synchronizer

import (
"github.com/hermeznetwork/hermez-core/state"
"github.com/ethereum/go-ethereum/common"
"github.com/hermeznetwork/hermez-core/etherman"
"github.com/hermeznetwork/hermez-core/state"
"github.com/hermeznetwork/hermez-core/state/db"
)

Expand All @@ -13,16 +14,21 @@ type Synchronizer struct {
}
func NewSynchronizer() (*Synchronizer, error) {
//TODO
//Read values from config file
var poeAddr common.Address
var ethNodeURL string
var db db.KeyValuer
st := state.NewState(db)
ethMan, err := etherman.NewEtherman()
ethMan, err := etherman.NewEtherman(ethNodeURL, poeAddr)
if err != nil {
return nil, err
}
return &Synchronizer{state: st, etherMan: ethMan}, nil
}

// This function will read the last state synced and will continue from that point
// Sync function will read the last state synced and will continue from that point.
// Sync() will read blockchain events to detect rollup updates. If it is already synced,
// It will keep waiting for a new event
func (s *Synchronizer) Sync() error {
//TODO
return nil
Expand All @@ -34,7 +40,7 @@ func (s *Synchronizer) resetState(ethBlockNum uint64) error {
return nil
}

// This function will check if there is a reorg and if so, fix the sync state
// This function will check if there is a reorg
func (s *Synchronizer) reorg() (uint64, error) {
//TODO
return 0, nil
Expand Down

0 comments on commit 9bff7d2

Please sign in to comment.