Skip to content

Commit

Permalink
chore: bump packages (#236)
Browse files Browse the repository at this point in the history
Co-authored-by: mj52951 <[email protected]>
  • Loading branch information
mj52951 and mj52951 committed Dec 11, 2023
1 parent e2e7ef9 commit a53e07e
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 178 deletions.
4 changes: 2 additions & 2 deletions chains/substrate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type SubstrateConfig struct {
StartBlock *big.Int
BlockInterval *big.Int
BlockRetryInterval time.Duration
SubstrateNetwork uint8
SubstrateNetwork uint16
Tip uint64
}

Expand Down Expand Up @@ -90,7 +90,7 @@ func NewSubstrateConfig(chainConfig map[string]interface{}) (*SubstrateConfig, e
BlockRetryInterval: time.Duration(c.BlockRetryInterval) * time.Second,
StartBlock: big.NewInt(c.StartBlock),
BlockInterval: big.NewInt(c.BlockInterval),
SubstrateNetwork: uint8(c.SubstrateNetwork),
SubstrateNetwork: uint16(c.SubstrateNetwork),
Tip: uint64(c.Tip),
}

Expand Down
4 changes: 2 additions & 2 deletions chains/substrate/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *NewSubstrateConfigTestSuite) Test_ValidConfig() {
},
StartBlock: big.NewInt(0),
ChainID: big.NewInt(5),
SubstrateNetwork: uint8(0),
SubstrateNetwork: uint16(0),
BlockInterval: big.NewInt(5),
BlockRetryInterval: time.Duration(5) * time.Second,
})
Expand Down Expand Up @@ -89,7 +89,7 @@ func (s *NewSubstrateConfigTestSuite) Test_ValidConfigWithCustomParams() {
Id: id,
},
ChainID: big.NewInt(5),
SubstrateNetwork: uint8(0),
SubstrateNetwork: uint16(0),
StartBlock: big.NewInt(1000),
BlockInterval: big.NewInt(2),
BlockRetryInterval: time.Duration(10) * time.Second,
Expand Down
4 changes: 2 additions & 2 deletions chains/substrate/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (c *Connection) UpdateMetatdata() error {
}

func (c *Connection) GetBlockEvents(hash types.Hash) ([]*parser.Event, error) {
provider := state.NewProvider(c.State)
eventRetriever, err := retriever.NewDefaultEventRetriever(provider)
provider := state.NewEventProvider(c.State)
eventRetriever, err := retriever.NewDefaultEventRetriever(provider, c.State)
if err != nil {
return nil, err
}
Expand Down
72 changes: 65 additions & 7 deletions chains/substrate/listener/event-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ChainSafe/chainbridge-core/relayer/message"
"github.com/ChainSafe/sygma-relayer/chains/substrate/events"
"github.com/centrifuge/go-substrate-rpc-client/v4/registry"
"github.com/centrifuge/go-substrate-rpc-client/v4/registry/parser"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -41,6 +42,67 @@ func (eh *SystemUpdateEventHandler) HandleEvents(evts []*parser.Event, msgChan c
return nil
}

func DecodeEventToDeposit(evtFields registry.DecodedFields) (events.Deposit, error) {
var d events.Deposit

for _, evtField := range evtFields {
switch evtField.Name {
case "dest_domain_id":
err := mapstructure.Decode(evtField.Value, &d.DestDomainID)
if err != nil {
return events.Deposit{}, err
}
case "resource_id":
err := mapstructure.Decode(evtField.Value, &d.ResourceID)
if err != nil {
return events.Deposit{}, err
}
case "deposit_nonce":
err := mapstructure.Decode(evtField.Value, &d.DepositNonce)
if err != nil {
return events.Deposit{}, err
}
case "sygma_traits_TransferType":
err := mapstructure.Decode(evtField.Value, &d.TransferType)
if err != nil {
return events.Deposit{}, err
}
case "deposit_data":
err := mapstructure.Decode(evtField.Value, &d.CallData)
if err != nil {
return events.Deposit{}, err
}
case "handler_response":
err := mapstructure.Decode(evtField.Value, &d.Handler)
if err != nil {
return events.Deposit{}, err
}
}
}
return d, nil
}

func DecodeEventToRetry(evtFields registry.DecodedFields) (events.Retry, error) {
var er events.Retry

for _, evtField := range evtFields {
switch evtField.Name {
case "deposit_on_block_height":
err := mapstructure.Decode(evtField.Value, &er.DepositOnBlockHeight)
if err != nil {
return events.Retry{}, err
}
case "dest_domain_id":
err := mapstructure.Decode(evtField.Value, &er.DestDomainID)
if err != nil {
return events.Retry{}, err
}
}
}

return er, nil
}

type DepositHandler interface {
HandleDeposit(sourceID uint8, destID types.U8, nonce types.U64, resourceID types.Bytes32, calldata []byte, transferType types.U8) (*message.Message, error)
}
Expand Down Expand Up @@ -70,9 +132,7 @@ func (eh *FungibleTransferEventHandler) HandleEvents(evts []*parser.Event, msgCh
log.Error().Msgf("panic occured while handling deposit %+v", evt)
}
}()

var d events.Deposit
err := mapstructure.Decode(evt.Fields, &d)
d, err := DecodeEventToDeposit(evt.Fields)
if err != nil {
log.Error().Err(err).Msgf("%v", err)
return
Expand Down Expand Up @@ -135,8 +195,7 @@ func (rh *RetryEventHandler) HandleEvents(evts []*parser.Event, msgChan chan []*
log.Error().Msgf("panic occured while handling retry event %+v because %s", evt, r)
}
}()
var er events.Retry
err = mapstructure.Decode(evt.Fields, &er)
er, err := DecodeEventToRetry(evt.Fields)
if err != nil {
return err
}
Expand All @@ -158,8 +217,7 @@ func (rh *RetryEventHandler) HandleEvents(evts []*parser.Event, msgChan chan []*

for _, event := range bEvts {
if event.Name == events.DepositEvent {
var d events.Deposit
err = mapstructure.Decode(event.Fields, &d)
d, err := DecodeEventToDeposit(event.Fields)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit a53e07e

Please sign in to comment.