Skip to content

Commit

Permalink
Simplify EventAbi.Encode function in bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Sep 27, 2023
1 parent 4ba32a7 commit 9f990e1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 43 deletions.
7 changes: 2 additions & 5 deletions consensus/polybft/checkpoint_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@ func (c *checkpointManager) GenerateExitProof(exitID uint64) (types.Proof, error
return types.Proof{}, fmt.Errorf("checkpoint block not found for exit ID %d", exitID)
}

var exitEventABI contractsapi.L2StateSyncedEvent

exitEventEncoded, err := exitEventABI.Encode(exitEvent.L2StateSyncedEvent)
exitEventEncoded, err := exitEvent.L2StateSyncedEvent.Encode()
if err != nil {
return types.Proof{}, err
}
Expand Down Expand Up @@ -451,9 +449,8 @@ func createExitTree(exitEvents []*ExitEvent) (*merkle.MerkleTree, error) {
numOfEvents := len(exitEvents)
data := make([][]byte, numOfEvents)

var exitEventAPI contractsapi.L2StateSyncedEvent
for i := 0; i < numOfEvents; i++ {
b, err := exitEventAPI.Encode(exitEvents[i].L2StateSyncedEvent)
b, err := exitEvents[i].L2StateSyncedEvent.Encode()
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions consensus/polybft/consensus_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/0xPolygon/go-ibft/messages/proto"
"github.com/0xPolygon/polygon-edge/consensus"
"github.com/0xPolygon/polygon-edge/consensus/polybft/bitmap"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
bls "github.com/0xPolygon/polygon-edge/consensus/polybft/signer"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/consensus/polybft/wallet"
Expand Down Expand Up @@ -1078,9 +1077,8 @@ func encodeExitEvents(t *testing.T, exitEvents []*ExitEvent) [][]byte {

encodedEvents := make([][]byte, len(exitEvents))

var exitEventAPI contractsapi.L2StateSyncedEvent
for i, e := range exitEvents {
encodedEvent, err := exitEventAPI.Encode(e.L2StateSyncedEvent)
encodedEvent, err := e.L2StateSyncedEvent.Encode()
require.NoError(t, err)

encodedEvents[i] = encodedEvent
Expand Down
4 changes: 2 additions & 2 deletions consensus/polybft/contractsapi/bindings-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,8 @@ func (*{{.TName}}) Sig() ethgo.Hash {
return {{.ContractName}}.Abi.Events["{{.Name}}"].ID()
}
func (*{{.TName}}) Encode(inputs interface{}) ([]byte, error) {
return {{.ContractName}}.Abi.Events["{{.Name}}"].Inputs.Encode(inputs)
func ({{.Sig}} *{{.TName}}) Encode() ([]byte, error) {
return {{.ContractName}}.Abi.Events["{{.Name}}"].Inputs.Encode({{.Sig}})
}
func ({{.Sig}} *{{.TName}}) ParseLog(log *ethgo.Log) (bool, error) {
Expand Down
60 changes: 30 additions & 30 deletions consensus/polybft/contractsapi/contractsapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion consensus/polybft/contractsapi/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type EventAbi interface {
// Sig returns the event ABI signature or ID (which is unique for all event types)
Sig() ethgo.Hash
// Encode does abi encoding of given event
Encode(inputs interface{}) ([]byte, error)
Encode() ([]byte, error)
// ParseLog parses the provided receipt log to given event type
ParseLog(log *ethgo.Log) (bool, error)
}
Expand Down
3 changes: 1 addition & 2 deletions consensus/polybft/sc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ func TestIntegration_PerformExit(t *testing.T) {
res := getField(exitHelperContractAddress, contractsapi.ExitHelper.Abi, "processedExits", exits[0].ID)
require.Equal(t, 0, int(res[31]))

var exitEventAPI contractsapi.L2StateSyncedEvent
proofExitEvent, err := exitEventAPI.Encode(exits[0].L2StateSyncedEvent)
proofExitEvent, err := exits[0].L2StateSyncedEvent.Encode()
require.NoError(t, err)

proof, err := exitTree.GenerateProof(proofExitEvent)
Expand Down

0 comments on commit 9f990e1

Please sign in to comment.