github.com/ChainSafe/chainbridge-core@v1.4.2/chains/evm/executor/proposal/proposal.go (about)

     1  package proposal
     2  
     3  import (
     4  	"github.com/ChainSafe/chainbridge-core/relayer/message"
     5  	"github.com/ChainSafe/chainbridge-core/types"
     6  	"github.com/ethereum/go-ethereum/common"
     7  	"github.com/ethereum/go-ethereum/crypto"
     8  )
     9  
    10  func NewProposal(source, destination uint8, depositNonce uint64, resourceId types.ResourceID, data []byte, handlerAddress, bridgeAddress common.Address, metadata message.Metadata) *Proposal {
    11  
    12  	return &Proposal{
    13  		Source:         source,
    14  		Destination:    destination,
    15  		DepositNonce:   depositNonce,
    16  		ResourceId:     resourceId,
    17  		Data:           data,
    18  		HandlerAddress: handlerAddress,
    19  		BridgeAddress:  bridgeAddress,
    20  		Metadata:       metadata,
    21  	}
    22  }
    23  
    24  type Proposal struct {
    25  	Source         uint8  // Source domainID where message was initiated
    26  	Destination    uint8  // Destination domainID where message is to be sent
    27  	DepositNonce   uint64 // Nonce for the deposit
    28  	ResourceId     types.ResourceID
    29  	Metadata       message.Metadata
    30  	Data           []byte
    31  	HandlerAddress common.Address
    32  	BridgeAddress  common.Address
    33  }
    34  
    35  // GetDataHash constructs and returns proposal data hash
    36  func (p *Proposal) GetDataHash() common.Hash {
    37  	return crypto.Keccak256Hash(append(p.HandlerAddress.Bytes(), p.Data...))
    38  }
    39  
    40  // GetID constructs proposal unique identifier
    41  func (p *Proposal) GetID() common.Hash {
    42  	return crypto.Keccak256Hash(append([]byte{p.Source}, byte(p.DepositNonce)))
    43  }