Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pkg/loop/internal/pb/ccipocr3/models.pb.go

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

3 changes: 2 additions & 1 deletion pkg/loop/internal/pb/ccipocr3/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ message Message {

// BigInt represents a [big.Int].
message BigInt {
bytes value = 1;
bool negative = 1;
bytes value = 2;
}

// TokenAmount is a helper type that defines a token and an amount.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type CCIPProviderClient struct {
executePluginCodec ccipocr3.ExecutePluginCodec
tokenDataEncoder ccipocr3.TokenDataEncoder
sourceChainExtraDataCodec ccipocr3.SourceChainExtraDataCodec
messageHasher ccipocr3.MessageHasher
}

func NewCCIPProviderClient(b *net.BrokerExt, cc grpc.ClientConnInterface) *CCIPProviderClient {
Expand All @@ -48,6 +49,7 @@ func NewCCIPProviderClient(b *net.BrokerExt, cc grpc.ClientConnInterface) *CCIPP
c.executePluginCodec = NewExecutePluginCodecClient(b.WithName("ExecutePluginCodec"), cc)
c.tokenDataEncoder = NewTokenDataEncoderClient(b.WithName("TokenDataEncoder"), cc)
c.sourceChainExtraDataCodec = NewSourceChainExtraDataCodecClient(b.WithName("SourceChainExtraDataCodec"), cc)
c.messageHasher = NewMessageHasherClient(b.WithName("MessageHasher"), cc)

return c
}
Expand Down Expand Up @@ -76,6 +78,7 @@ func (p *CCIPProviderClient) Codec() ccipocr3.Codec {
ExecutePluginCodec: p.executePluginCodec,
TokenDataEncoder: p.tokenDataEncoder,
SourceChainExtraDataCodec: p.sourceChainExtraDataCodec,
MessageHasher: p.messageHasher,
}
}

Expand Down Expand Up @@ -104,4 +107,5 @@ func RegisterProviderServices(s *grpc.Server, provider types.CCIPProvider) {
ccipocr3pb.RegisterExecutePluginCodecServer(s, NewExecutePluginCodecServer(codec.ExecutePluginCodec))
ccipocr3pb.RegisterTokenDataEncoderServer(s, NewTokenDataEncoderServer(codec.TokenDataEncoder))
ccipocr3pb.RegisterSourceChainExtraDataCodecServer(s, NewSourceChainExtraDataCodecServer(codec.SourceChainExtraDataCodec))
ccipocr3pb.RegisterMsgHasherServer(s, NewMessageHasherServer(codec.MessageHasher))
}
50 changes: 50 additions & 0 deletions pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,3 +666,53 @@ func (s *extraDataCodecBundleServer) DecodeTokenAmountDestExecData(ctx context.C
DecodedMap: pbMap,
}, nil
}

// MessageHasher client
var _ ccipocr3.MessageHasher = (*messageHasherClient)(nil)

type messageHasherClient struct {
*net.BrokerExt
grpc ccipocr3pb.MsgHasherClient
}

func NewMessageHasherClient(broker *net.BrokerExt, cc grpc.ClientConnInterface) ccipocr3.MessageHasher {
return &messageHasherClient{
BrokerExt: broker,
grpc: ccipocr3pb.NewMsgHasherClient(cc),
}
}

func (c *messageHasherClient) Hash(ctx context.Context, message ccipocr3.Message) (ccipocr3.Bytes32, error) {
resp, err := c.grpc.HashMsg(ctx, &ccipocr3pb.HashMsgInput{
Msg: messageToPb(message),
})
if err != nil {
return ccipocr3.Bytes32{}, err
}
var hash ccipocr3.Bytes32
copy(hash[:], resp.Hash)
return hash, nil
}

// MessageHasher server
var _ ccipocr3pb.MsgHasherServer = (*messageHasherServer)(nil)

type messageHasherServer struct {
ccipocr3pb.UnimplementedMsgHasherServer
impl ccipocr3.MessageHasher
}

func NewMessageHasherServer(impl ccipocr3.MessageHasher) ccipocr3pb.MsgHasherServer {
return &messageHasherServer{impl: impl}
}

func (s *messageHasherServer) HashMsg(ctx context.Context, req *ccipocr3pb.HashMsgInput) (*ccipocr3pb.HashMsgOutput, error) {
message := pbToMessage(req.Msg)
hash, err := s.impl.Hash(ctx, message)
if err != nil {
return nil, err
}
return &ccipocr3pb.HashMsgOutput{
Hash: hash[:],
}, nil
}
30 changes: 19 additions & 11 deletions pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ func pbBigIntToInt(b *ccipocr3pb.BigInt) *big.Int {
return nil
}

if b.Value == nil {
return nil
}

if len(b.Value) == 0 {
return big.NewInt(0)
}
return new(big.Int).SetBytes(b.Value)

i := new(big.Int).SetBytes(b.Value)
if b.Negative {
i = i.Neg(i)
}
return i
}

// Helper function to convert protobuf BigInt to ccipocr3.BigInt, preserving nil
Expand All @@ -33,22 +34,26 @@ func pbToBigInt(b *ccipocr3pb.BigInt) ccipocr3.BigInt {
return ccipocr3.BigInt{Int: nil}
}

if b.Value == nil {
return ccipocr3.BigInt{Int: nil}
}

if len(b.Value) == 0 {
return ccipocr3.BigInt{Int: big.NewInt(0)}
}
return ccipocr3.NewBigInt(new(big.Int).SetBytes(b.Value))

i := new(big.Int).SetBytes(b.Value)
if b.Negative {
i = i.Neg(i)
}
return ccipocr3.NewBigInt(i)
}

// Helper function to convert big.Int to protobuf BigInt
func intToPbBigInt(i *big.Int) *ccipocr3pb.BigInt {
if i == nil {
return nil
}
return &ccipocr3pb.BigInt{Value: i.Bytes()}
return &ccipocr3pb.BigInt{
Negative: i.Sign() < 0,
Value: i.Bytes(),
}
}

// Helper function to convert ConfidenceLevel to protobuf uint32
Expand Down Expand Up @@ -864,6 +869,9 @@ func pbToTokenUpdatesUnix(pbUpdates map[string]*ccipocr3pb.TimestampedUnixBig) m
var value *big.Int
if pbUpdate.Value != nil && len(pbUpdate.Value.Value) > 0 {
value = new(big.Int).SetBytes(pbUpdate.Value.Value)
if pbUpdate.Value.Negative {
value = value.Neg(value)
}
} else {
value = big.NewInt(0)
}
Expand Down
Loading
Loading