From e700006e0a1eeaf90c1721a4abfad332ef3366c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= <93934272+Stefan-Ethernal@users.noreply.github.com> Date: Wed, 27 Sep 2023 17:06:33 +0200 Subject: [PATCH] Provide abi encoded exit event in hex format from `bridge_generateExitProof` JSON RPC (#1929) * Provide abi encoded exit event in hex format * Simplify EventAbi.Encode function in bindings --- command/bridge/exit/exit.go | 39 +++--- consensus/polybft/checkpoint_manager.go | 15 +-- consensus/polybft/consensus_runtime_test.go | 4 +- .../polybft/contractsapi/bindings-gen/main.go | 11 +- .../polybft/contractsapi/contractsapi.go | 120 +++++++++++++----- consensus/polybft/contractsapi/helper.go | 2 +- consensus/polybft/sc_integration_test.go | 3 +- consensus/polybft/state_store_checkpoint.go | 5 +- 8 files changed, 127 insertions(+), 72 deletions(-) diff --git a/command/bridge/exit/exit.go b/command/bridge/exit/exit.go index 98d2072db2..dceba85281 100644 --- a/command/bridge/exit/exit.go +++ b/command/bridge/exit/exit.go @@ -2,7 +2,7 @@ package exit import ( "bytes" - "encoding/json" + "encoding/hex" "errors" "fmt" "math/big" @@ -16,7 +16,6 @@ import ( "github.com/0xPolygon/polygon-edge/command/bridge/common" cmdHelper "github.com/0xPolygon/polygon-edge/command/helper" "github.com/0xPolygon/polygon-edge/command/rootchain/helper" - "github.com/0xPolygon/polygon-edge/consensus/polybft" "github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi" "github.com/0xPolygon/polygon-edge/txrelayer" "github.com/0xPolygon/polygon-edge/types" @@ -168,37 +167,31 @@ func run(cmd *cobra.Command, _ []string) { } // createExitTxn encodes parameters for exit function on root chain ExitHelper contract -func createExitTxn(sender ethgo.Address, proof types.Proof) (*ethgo.Transaction, *polybft.ExitEvent, error) { - exitEventMap, ok := proof.Metadata["ExitEvent"].(map[string]interface{}) +func createExitTxn(sender ethgo.Address, proof types.Proof) (*ethgo.Transaction, + *contractsapi.L2StateSyncedEvent, error) { + leafIndex, ok := proof.Metadata["LeafIndex"].(float64) if !ok { - return nil, nil, errors.New("could not get exit event from proof") + return nil, nil, errors.New("failed to convert proof leaf index") } - raw, err := json.Marshal(exitEventMap) - if err != nil { - return nil, nil, fmt.Errorf("failed to marshal exit event map to JSON. Error: %w", err) + checkpointBlock, ok := proof.Metadata["CheckpointBlock"].(float64) + if !ok { + return nil, nil, errors.New("failed to convert proof checkpoint block") } - var exitEvent *polybft.ExitEvent - if err = json.Unmarshal(raw, &exitEvent); err != nil { - return nil, nil, fmt.Errorf("failed to unmarshal exit event from JSON. Error: %w", err) + exitEventHex, ok := proof.Metadata["ExitEvent"].(string) + if !ok { + return nil, nil, errors.New("failed to convert exit event") } - var exitEventAPI contractsapi.L2StateSyncedEvent - - exitEventEncoded, err := exitEventAPI.Encode(exitEvent.L2StateSyncedEvent) + exitEventEncoded, err := hex.DecodeString(exitEventHex) if err != nil { - return nil, nil, fmt.Errorf("failed to encode exit event: %w", err) + return nil, nil, fmt.Errorf("failed to decode hex-encoded exit event '%s': %w", exitEventHex, err) } - leafIndex, ok := proof.Metadata["LeafIndex"].(float64) - if !ok { - return nil, nil, errors.New("failed to convert proof leaf index") - } - - checkpointBlock, ok := proof.Metadata["CheckpointBlock"].(float64) - if !ok { - return nil, nil, errors.New("failed to convert proof checkpoint block") + exitEvent := new(contractsapi.L2StateSyncedEvent) + if err := exitEvent.Decode(exitEventEncoded); err != nil { + return nil, nil, fmt.Errorf("failed to decode exit event: %w", err) } exitFn := &contractsapi.ExitExitHelperFn{ diff --git a/consensus/polybft/checkpoint_manager.go b/consensus/polybft/checkpoint_manager.go index 1f3c2ec550..efde527c09 100644 --- a/consensus/polybft/checkpoint_manager.go +++ b/consensus/polybft/checkpoint_manager.go @@ -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 exitEventAPI contractsapi.L2StateSyncedEvent - - e, err := exitEventAPI.Encode(exitEvent.L2StateSyncedEvent) + exitEventEncoded, err := exitEvent.L2StateSyncedEvent.Encode() if err != nil { return types.Proof{}, err } @@ -422,23 +420,25 @@ func (c *checkpointManager) GenerateExitProof(exitID uint64) (types.Proof, error return types.Proof{}, err } - leafIndex, err := tree.LeafIndex(e) + leafIndex, err := tree.LeafIndex(exitEventEncoded) if err != nil { return types.Proof{}, err } - proof, err := tree.GenerateProof(e) + proof, err := tree.GenerateProof(exitEventEncoded) if err != nil { return types.Proof{}, err } c.logger.Debug("Generated proof for exit", "exitID", exitID, "leafIndex", leafIndex, "proofLen", len(proof)) + exitEventHex := hex.EncodeToString(exitEventEncoded) + return types.Proof{ Data: proof, Metadata: map[string]interface{}{ "LeafIndex": leafIndex, - "ExitEvent": exitEvent, + "ExitEvent": exitEventHex, "CheckpointBlock": checkpointBlock, }, }, nil @@ -449,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 } diff --git a/consensus/polybft/consensus_runtime_test.go b/consensus/polybft/consensus_runtime_test.go index 168169959a..8b20ee4916 100644 --- a/consensus/polybft/consensus_runtime_test.go +++ b/consensus/polybft/consensus_runtime_test.go @@ -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" @@ -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 diff --git a/consensus/polybft/contractsapi/bindings-gen/main.go b/consensus/polybft/contractsapi/bindings-gen/main.go index 2e01e373b7..d302d15b6e 100644 --- a/consensus/polybft/contractsapi/bindings-gen/main.go +++ b/consensus/polybft/contractsapi/bindings-gen/main.go @@ -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) { @@ -659,7 +659,12 @@ func ({{.Sig}} *{{.TName}}) ParseLog(log *ethgo.Log) (bool, error) { } return true, decodeEvent({{.ContractName}}.Abi.Events["{{.Name}}"], log, {{.Sig}}) -}` +} + +func ({{.Sig}} *{{.TName}}) Decode(input []byte) error { + return {{.ContractName}}.Abi.Events["{{.Name}}"].Inputs.DecodeStruct(input, &{{.Sig}}) +} +` inputs := map[string]interface{}{ "Structs": res, diff --git a/consensus/polybft/contractsapi/contractsapi.go b/consensus/polybft/contractsapi/contractsapi.go index 9f3d0968ce..36ce2faeb5 100644 --- a/consensus/polybft/contractsapi/contractsapi.go +++ b/consensus/polybft/contractsapi/contractsapi.go @@ -87,8 +87,8 @@ func (*StateSyncResultEvent) Sig() ethgo.Hash { return StateReceiver.Abi.Events["StateSyncResult"].ID() } -func (*StateSyncResultEvent) Encode(inputs interface{}) ([]byte, error) { - return StateReceiver.Abi.Events["StateSyncResult"].Inputs.Encode(inputs) +func (s *StateSyncResultEvent) Encode() ([]byte, error) { + return StateReceiver.Abi.Events["StateSyncResult"].Inputs.Encode(s) } func (s *StateSyncResultEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -99,6 +99,10 @@ func (s *StateSyncResultEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(StateReceiver.Abi.Events["StateSyncResult"], log, s) } +func (s *StateSyncResultEvent) Decode(input []byte) error { + return StateReceiver.Abi.Events["StateSyncResult"].Inputs.DecodeStruct(input, &s) +} + type NewCommitmentEvent struct { StartID *big.Int `abi:"startId"` EndID *big.Int `abi:"endId"` @@ -109,8 +113,8 @@ func (*NewCommitmentEvent) Sig() ethgo.Hash { return StateReceiver.Abi.Events["NewCommitment"].ID() } -func (*NewCommitmentEvent) Encode(inputs interface{}) ([]byte, error) { - return StateReceiver.Abi.Events["NewCommitment"].Inputs.Encode(inputs) +func (n *NewCommitmentEvent) Encode() ([]byte, error) { + return StateReceiver.Abi.Events["NewCommitment"].Inputs.Encode(n) } func (n *NewCommitmentEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -121,6 +125,10 @@ func (n *NewCommitmentEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(StateReceiver.Abi.Events["NewCommitment"], log, n) } +func (n *NewCommitmentEvent) Decode(input []byte) error { + return StateReceiver.Abi.Events["NewCommitment"].Inputs.DecodeStruct(input, &n) +} + type SyncStateStateSenderFn struct { Receiver types.Address `abi:"receiver"` Data []byte `abi:"data"` @@ -149,8 +157,8 @@ func (*StateSyncedEvent) Sig() ethgo.Hash { return StateSender.Abi.Events["StateSynced"].ID() } -func (*StateSyncedEvent) Encode(inputs interface{}) ([]byte, error) { - return StateSender.Abi.Events["StateSynced"].Inputs.Encode(inputs) +func (s *StateSyncedEvent) Encode() ([]byte, error) { + return StateSender.Abi.Events["StateSynced"].Inputs.Encode(s) } func (s *StateSyncedEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -161,6 +169,10 @@ func (s *StateSyncedEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(StateSender.Abi.Events["StateSynced"], log, s) } +func (s *StateSyncedEvent) Decode(input []byte) error { + return StateSender.Abi.Events["StateSynced"].Inputs.DecodeStruct(input, &s) +} + type L2StateSyncedEvent struct { ID *big.Int `abi:"id"` Sender types.Address `abi:"sender"` @@ -172,8 +184,8 @@ func (*L2StateSyncedEvent) Sig() ethgo.Hash { return L2StateSender.Abi.Events["L2StateSynced"].ID() } -func (*L2StateSyncedEvent) Encode(inputs interface{}) ([]byte, error) { - return L2StateSender.Abi.Events["L2StateSynced"].Inputs.Encode(inputs) +func (l *L2StateSyncedEvent) Encode() ([]byte, error) { + return L2StateSender.Abi.Events["L2StateSynced"].Inputs.Encode(l) } func (l *L2StateSyncedEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -184,6 +196,10 @@ func (l *L2StateSyncedEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(L2StateSender.Abi.Events["L2StateSynced"], log, l) } +func (l *L2StateSyncedEvent) Decode(input []byte) error { + return L2StateSender.Abi.Events["L2StateSynced"].Inputs.DecodeStruct(input, &l) +} + type CheckpointManagerConstructorFn struct { Initiator types.Address `abi:"initiator"` } @@ -548,8 +564,8 @@ func (*TokenMappedEvent) Sig() ethgo.Hash { return RootERC20Predicate.Abi.Events["TokenMapped"].ID() } -func (*TokenMappedEvent) Encode(inputs interface{}) ([]byte, error) { - return RootERC20Predicate.Abi.Events["TokenMapped"].Inputs.Encode(inputs) +func (t *TokenMappedEvent) Encode() ([]byte, error) { + return RootERC20Predicate.Abi.Events["TokenMapped"].Inputs.Encode(t) } func (t *TokenMappedEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -560,6 +576,10 @@ func (t *TokenMappedEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(RootERC20Predicate.Abi.Events["TokenMapped"], log, t) } +func (t *TokenMappedEvent) Decode(input []byte) error { + return RootERC20Predicate.Abi.Events["TokenMapped"].Inputs.DecodeStruct(input, &t) +} + type InitializeChildMintableERC20PredicateFn struct { NewStateSender types.Address `abi:"newStateSender"` NewExitHelper types.Address `abi:"newExitHelper"` @@ -588,8 +608,8 @@ func (*MintableTokenMappedEvent) Sig() ethgo.Hash { return ChildMintableERC20Predicate.Abi.Events["MintableTokenMapped"].ID() } -func (*MintableTokenMappedEvent) Encode(inputs interface{}) ([]byte, error) { - return ChildMintableERC20Predicate.Abi.Events["MintableTokenMapped"].Inputs.Encode(inputs) +func (m *MintableTokenMappedEvent) Encode() ([]byte, error) { + return ChildMintableERC20Predicate.Abi.Events["MintableTokenMapped"].Inputs.Encode(m) } func (m *MintableTokenMappedEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -600,6 +620,10 @@ func (m *MintableTokenMappedEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(ChildMintableERC20Predicate.Abi.Events["MintableTokenMapped"], log, m) } +func (m *MintableTokenMappedEvent) Decode(input []byte) error { + return ChildMintableERC20Predicate.Abi.Events["MintableTokenMapped"].Inputs.DecodeStruct(input, &m) +} + type BalanceOfRootERC20Fn struct { Account types.Address `abi:"account"` } @@ -889,8 +913,8 @@ func (*L2MintableTokenMappedEvent) Sig() ethgo.Hash { return RootMintableERC1155PredicateACL.Abi.Events["L2MintableTokenMapped"].ID() } -func (*L2MintableTokenMappedEvent) Encode(inputs interface{}) ([]byte, error) { - return RootMintableERC1155PredicateACL.Abi.Events["L2MintableTokenMapped"].Inputs.Encode(inputs) +func (l *L2MintableTokenMappedEvent) Encode() ([]byte, error) { + return RootMintableERC1155PredicateACL.Abi.Events["L2MintableTokenMapped"].Inputs.Encode(l) } func (l *L2MintableTokenMappedEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -901,6 +925,10 @@ func (l *L2MintableTokenMappedEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(RootMintableERC1155PredicateACL.Abi.Events["L2MintableTokenMapped"], log, l) } +func (l *L2MintableTokenMappedEvent) Decode(input []byte) error { + return RootMintableERC1155PredicateACL.Abi.Events["L2MintableTokenMapped"].Inputs.DecodeStruct(input, &l) +} + type InitializeChildERC1155Fn struct { RootToken_ types.Address `abi:"rootToken_"` Uri_ string `abi:"uri_"` @@ -1256,8 +1284,8 @@ func (*ValidatorRegisteredEvent) Sig() ethgo.Hash { return CustomSupernetManager.Abi.Events["ValidatorRegistered"].ID() } -func (*ValidatorRegisteredEvent) Encode(inputs interface{}) ([]byte, error) { - return CustomSupernetManager.Abi.Events["ValidatorRegistered"].Inputs.Encode(inputs) +func (v *ValidatorRegisteredEvent) Encode() ([]byte, error) { + return CustomSupernetManager.Abi.Events["ValidatorRegistered"].Inputs.Encode(v) } func (v *ValidatorRegisteredEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -1268,6 +1296,10 @@ func (v *ValidatorRegisteredEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(CustomSupernetManager.Abi.Events["ValidatorRegistered"], log, v) } +func (v *ValidatorRegisteredEvent) Decode(input []byte) error { + return CustomSupernetManager.Abi.Events["ValidatorRegistered"].Inputs.DecodeStruct(input, &v) +} + type AddedToWhitelistEvent struct { Validator types.Address `abi:"validator"` } @@ -1276,8 +1308,8 @@ func (*AddedToWhitelistEvent) Sig() ethgo.Hash { return CustomSupernetManager.Abi.Events["AddedToWhitelist"].ID() } -func (*AddedToWhitelistEvent) Encode(inputs interface{}) ([]byte, error) { - return CustomSupernetManager.Abi.Events["AddedToWhitelist"].Inputs.Encode(inputs) +func (a *AddedToWhitelistEvent) Encode() ([]byte, error) { + return CustomSupernetManager.Abi.Events["AddedToWhitelist"].Inputs.Encode(a) } func (a *AddedToWhitelistEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -1288,6 +1320,10 @@ func (a *AddedToWhitelistEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(CustomSupernetManager.Abi.Events["AddedToWhitelist"], log, a) } +func (a *AddedToWhitelistEvent) Decode(input []byte) error { + return CustomSupernetManager.Abi.Events["AddedToWhitelist"].Inputs.DecodeStruct(input, &a) +} + type InitializeStakeManagerFn struct { NewStakingToken types.Address `abi:"newStakingToken"` } @@ -1397,8 +1433,8 @@ func (*ChildManagerRegisteredEvent) Sig() ethgo.Hash { return StakeManager.Abi.Events["ChildManagerRegistered"].ID() } -func (*ChildManagerRegisteredEvent) Encode(inputs interface{}) ([]byte, error) { - return StakeManager.Abi.Events["ChildManagerRegistered"].Inputs.Encode(inputs) +func (c *ChildManagerRegisteredEvent) Encode() ([]byte, error) { + return StakeManager.Abi.Events["ChildManagerRegistered"].Inputs.Encode(c) } func (c *ChildManagerRegisteredEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -1409,6 +1445,10 @@ func (c *ChildManagerRegisteredEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(StakeManager.Abi.Events["ChildManagerRegistered"], log, c) } +func (c *ChildManagerRegisteredEvent) Decode(input []byte) error { + return StakeManager.Abi.Events["ChildManagerRegistered"].Inputs.DecodeStruct(input, &c) +} + type StakeAddedEvent struct { ID *big.Int `abi:"id"` Validator types.Address `abi:"validator"` @@ -1419,8 +1459,8 @@ func (*StakeAddedEvent) Sig() ethgo.Hash { return StakeManager.Abi.Events["StakeAdded"].ID() } -func (*StakeAddedEvent) Encode(inputs interface{}) ([]byte, error) { - return StakeManager.Abi.Events["StakeAdded"].Inputs.Encode(inputs) +func (s *StakeAddedEvent) Encode() ([]byte, error) { + return StakeManager.Abi.Events["StakeAdded"].Inputs.Encode(s) } func (s *StakeAddedEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -1431,6 +1471,10 @@ func (s *StakeAddedEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(StakeManager.Abi.Events["StakeAdded"], log, s) } +func (s *StakeAddedEvent) Decode(input []byte) error { + return StakeManager.Abi.Events["StakeAdded"].Inputs.DecodeStruct(input, &s) +} + type StakeWithdrawnEvent struct { Validator types.Address `abi:"validator"` Recipient types.Address `abi:"recipient"` @@ -1441,8 +1485,8 @@ func (*StakeWithdrawnEvent) Sig() ethgo.Hash { return StakeManager.Abi.Events["StakeWithdrawn"].ID() } -func (*StakeWithdrawnEvent) Encode(inputs interface{}) ([]byte, error) { - return StakeManager.Abi.Events["StakeWithdrawn"].Inputs.Encode(inputs) +func (s *StakeWithdrawnEvent) Encode() ([]byte, error) { + return StakeManager.Abi.Events["StakeWithdrawn"].Inputs.Encode(s) } func (s *StakeWithdrawnEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -1453,6 +1497,10 @@ func (s *StakeWithdrawnEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(StakeManager.Abi.Events["StakeWithdrawn"], log, s) } +func (s *StakeWithdrawnEvent) Decode(input []byte) error { + return StakeManager.Abi.Events["StakeWithdrawn"].Inputs.DecodeStruct(input, &s) +} + type Epoch struct { StartBlock *big.Int `abi:"startBlock"` EndBlock *big.Int `abi:"endBlock"` @@ -1547,8 +1595,8 @@ func (*TransferEvent) Sig() ethgo.Hash { return ValidatorSet.Abi.Events["Transfer"].ID() } -func (*TransferEvent) Encode(inputs interface{}) ([]byte, error) { - return ValidatorSet.Abi.Events["Transfer"].Inputs.Encode(inputs) +func (t *TransferEvent) Encode() ([]byte, error) { + return ValidatorSet.Abi.Events["Transfer"].Inputs.Encode(t) } func (t *TransferEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -1559,6 +1607,10 @@ func (t *TransferEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(ValidatorSet.Abi.Events["Transfer"], log, t) } +func (t *TransferEvent) Decode(input []byte) error { + return ValidatorSet.Abi.Events["Transfer"].Inputs.DecodeStruct(input, &t) +} + type WithdrawalRegisteredEvent struct { Account types.Address `abi:"account"` Amount *big.Int `abi:"amount"` @@ -1568,8 +1620,8 @@ func (*WithdrawalRegisteredEvent) Sig() ethgo.Hash { return ValidatorSet.Abi.Events["WithdrawalRegistered"].ID() } -func (*WithdrawalRegisteredEvent) Encode(inputs interface{}) ([]byte, error) { - return ValidatorSet.Abi.Events["WithdrawalRegistered"].Inputs.Encode(inputs) +func (w *WithdrawalRegisteredEvent) Encode() ([]byte, error) { + return ValidatorSet.Abi.Events["WithdrawalRegistered"].Inputs.Encode(w) } func (w *WithdrawalRegisteredEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -1580,6 +1632,10 @@ func (w *WithdrawalRegisteredEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(ValidatorSet.Abi.Events["WithdrawalRegistered"], log, w) } +func (w *WithdrawalRegisteredEvent) Decode(input []byte) error { + return ValidatorSet.Abi.Events["WithdrawalRegistered"].Inputs.DecodeStruct(input, &w) +} + type WithdrawalEvent struct { Account types.Address `abi:"account"` Amount *big.Int `abi:"amount"` @@ -1589,8 +1645,8 @@ func (*WithdrawalEvent) Sig() ethgo.Hash { return ValidatorSet.Abi.Events["Withdrawal"].ID() } -func (*WithdrawalEvent) Encode(inputs interface{}) ([]byte, error) { - return ValidatorSet.Abi.Events["Withdrawal"].Inputs.Encode(inputs) +func (w *WithdrawalEvent) Encode() ([]byte, error) { + return ValidatorSet.Abi.Events["Withdrawal"].Inputs.Encode(w) } func (w *WithdrawalEvent) ParseLog(log *ethgo.Log) (bool, error) { @@ -1601,6 +1657,10 @@ func (w *WithdrawalEvent) ParseLog(log *ethgo.Log) (bool, error) { return true, decodeEvent(ValidatorSet.Abi.Events["Withdrawal"], log, w) } +func (w *WithdrawalEvent) Decode(input []byte) error { + return ValidatorSet.Abi.Events["Withdrawal"].Inputs.DecodeStruct(input, &w) +} + type InitializeRewardPoolFn struct { NewRewardToken types.Address `abi:"newRewardToken"` NewRewardWallet types.Address `abi:"newRewardWallet"` diff --git a/consensus/polybft/contractsapi/helper.go b/consensus/polybft/contractsapi/helper.go index 6332104a6f..d71b585972 100644 --- a/consensus/polybft/contractsapi/helper.go +++ b/consensus/polybft/contractsapi/helper.go @@ -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) } diff --git a/consensus/polybft/sc_integration_test.go b/consensus/polybft/sc_integration_test.go index 30a2eb8ad9..0bf377ccfa 100644 --- a/consensus/polybft/sc_integration_test.go +++ b/consensus/polybft/sc_integration_test.go @@ -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) diff --git a/consensus/polybft/state_store_checkpoint.go b/consensus/polybft/state_store_checkpoint.go index c5f0df8986..b3ea364a5e 100644 --- a/consensus/polybft/state_store_checkpoint.go +++ b/consensus/polybft/state_store_checkpoint.go @@ -7,11 +7,12 @@ import ( "fmt" "sort" + "github.com/umbracle/ethgo" + bolt "go.etcd.io/bbolt" + "github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi" "github.com/0xPolygon/polygon-edge/helper/common" "github.com/0xPolygon/polygon-edge/types" - "github.com/umbracle/ethgo" - bolt "go.etcd.io/bbolt" ) var (