Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Addressed PR comments - user custom type for resource ID [32]bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlinaric committed Oct 11, 2021
1 parent fd01c75 commit abd13c8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions chains/evm/calls/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func PrepareErc20DepositInput(destDomainID uint8, resourceID types.ResourceID, d
return input, nil
}

func PrepareExecuteProposalInput(sourceDomainID uint8, depositNonce uint64, resourceID [32]byte, calldata []byte, revertOnFail bool) ([]byte, error) {
func PrepareExecuteProposalInput(sourceDomainID uint8, depositNonce uint64, resourceID types.ResourceID, calldata []byte, revertOnFail bool) ([]byte, error) {
a, err := abi.JSON(strings.NewReader(consts.BridgeABI))
if err != nil {
return []byte{}, err
Expand All @@ -65,7 +65,7 @@ func PrepareExecuteProposalInput(sourceDomainID uint8, depositNonce uint64, reso
return input, nil
}

func PrepareVoteProposalInput(sourceDomainID uint8, resourceID [32]byte, calldata []byte) ([]byte, error) {
func PrepareVoteProposalInput(sourceDomainID uint8, resourceID types.ResourceID, calldata []byte) ([]byte, error) {
a, err := abi.JSON(strings.NewReader(consts.BridgeABI))
if err != nil {
return []byte{}, err
Expand Down Expand Up @@ -119,7 +119,7 @@ func ParseIsRelayerOutput(output []byte) (bool, error) {
return *b, nil
}

func Deposit(client ChainClient, fabric TxFabric, bridgeAddress, recipient common.Address, amount *big.Int, resourceID [32]byte, destDomainID uint8) error {
func Deposit(client ChainClient, fabric TxFabric, bridgeAddress, recipient common.Address, amount *big.Int, resourceID types.ResourceID, destDomainID uint8) error {
data := ConstructErc20DepositData(recipient.Bytes(), amount)
input, err := PrepareErc20DepositInput(destDomainID, resourceID, data)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion chains/evm/listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ChainClient interface {
}

type EventHandler interface {
HandleEvent(sourceID, destID uint8, nonce uint64, rID [32]byte) (*relayer.Message, error)
HandleEvent(sourceID, destID uint8, nonce uint64, resourceID types.ResourceID) (*relayer.Message, error)
}

type EVMListener struct {
Expand Down
7 changes: 4 additions & 3 deletions chains/evm/voter/proposal/proposal.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package proposal

import (
"github.com/ChainSafe/chainbridge-core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)

func NewProposal(source uint8, depositNonce uint64, resourceId [32]byte, data []byte, handlerAddress, bridgeAddress common.Address) *Proposal {
func NewProposal(source uint8, depositNonce uint64, resourceId types.ResourceID, data []byte, handlerAddress, bridgeAddress common.Address) *Proposal {
return &Proposal{
Source: source,
DepositNonce: depositNonce,
Expand All @@ -19,7 +20,7 @@ func NewProposal(source uint8, depositNonce uint64, resourceId [32]byte, data []
type Proposal struct {
Source uint8 // Source domainID where message was initiated
DepositNonce uint64 // Nonce for the deposit
ResourceId [32]byte
ResourceId types.ResourceID
Payload []interface{} // data associated with event sequence
Data []byte
HandlerAddress common.Address
Expand All @@ -29,4 +30,4 @@ type Proposal struct {
// GetDataHash constructs and returns proposal data hash
func (p *Proposal) GetDataHash() common.Hash {
return crypto.Keccak256Hash(append(p.HandlerAddress.Bytes(), p.Data...))
}
}
7 changes: 4 additions & 3 deletions chains/substrate/listener/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ChainSafe/chainbridge-core/chains/substrate"
"github.com/ChainSafe/chainbridge-core/relayer"
"github.com/ChainSafe/chainbridge-core/types"
)

func FungibleTransferHandler(sourceID uint8, evtI interface{}) (*relayer.Message, error) {
Expand All @@ -17,7 +18,7 @@ func FungibleTransferHandler(sourceID uint8, evtI interface{}) (*relayer.Message
Source: sourceID,
Destination: uint8(evt.Destination),
DepositNonce: uint64(evt.DepositNonce),
ResourceId: evt.ResourceId,
ResourceId: types.ResourceID(evt.ResourceId),
Payload: []interface{}{
evt.Amount.Bytes(),
[]byte(evt.Recipient),
Expand All @@ -35,7 +36,7 @@ func NonFungibleTransferHandler(sourceID uint8, evtI interface{}) (*relayer.Mess
Source: sourceID,
Destination: uint8(evt.Destination),
DepositNonce: uint64(evt.DepositNonce),
ResourceId: evt.ResourceId,
ResourceId: types.ResourceID(evt.ResourceId),
Payload: []interface{}{
[]byte(evt.TokenId),
[]byte(evt.Recipient),
Expand All @@ -53,7 +54,7 @@ func GenericTransferHandler(sourceID uint8, evtI interface{}) (*relayer.Message,
Source: sourceID,
Destination: uint8(evt.Destination),
DepositNonce: uint64(evt.DepositNonce),
ResourceId: evt.ResourceId,
ResourceId: types.ResourceID(evt.ResourceId),
Payload: []interface{}{
[]byte(evt.Metadata),
},
Expand Down
3 changes: 2 additions & 1 deletion chains/substrate/writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ChainSafe/chainbridge-core/chains/substrate"
"github.com/ChainSafe/chainbridge-core/relayer"
internalTypes "github.com/ChainSafe/chainbridge-core/types"
"github.com/centrifuge/go-substrate-rpc-client/types"
"github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -109,7 +110,7 @@ func (w *SubstrateWriter) proposalValid(prop *SubstrateProposal) (bool, string,
}
}

func (w *SubstrateWriter) createProposal(sourceChain uint8, depositNonce uint64, resourceId [32]byte, args ...interface{}) (*SubstrateProposal, error) {
func (w *SubstrateWriter) createProposal(sourceChain uint8, depositNonce uint64, resourceId internalTypes.ResourceID, args ...interface{}) (*SubstrateProposal, error) {
meta := w.client.GetMetadata()
method, err := w.client.ResolveResourceId(resourceId)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion relayer/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package relayer
import (
"errors"
"math/big"

"github.com/ChainSafe/chainbridge-core/types"
)

type TransferType string
Expand Down Expand Up @@ -34,7 +36,7 @@ type Message struct {
Source uint8 // Source where message was initiated
Destination uint8 // Destination chain of message
DepositNonce uint64 // Nonce for the deposit
ResourceId [32]byte
ResourceId types.ResourceID
Payload []interface{} // data associated with event sequence
Type TransferType
}
Expand Down

0 comments on commit abd13c8

Please sign in to comment.