@@ -7,8 +7,12 @@ import (
77
88 "github.com/smartcontractkit/chainlink-common/pkg/logger"
99 "github.com/smartcontractkit/chainlink-common/pkg/types"
10+ "github.com/smartcontractkit/chainlink-common/pkg/types/query"
11+ "github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"
1012
13+ "github.com/smartcontractkit/chainlink-ccip/pkg/consts"
1114 "github.com/smartcontractkit/chainlink-ccip/pkg/contractreader"
15+ "github.com/smartcontractkit/chainlink-ccip/pkg/logutil"
1216 cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
1317)
1418
@@ -59,16 +63,13 @@ func (l *LegacyAccessor) GetContractAddress(contractName string) ([]byte, error)
5963 return addressBytes , nil
6064}
6165
62- func (l * LegacyAccessor ) GetChainFeeComponents (
63- ctx context.Context ,
64- ) map [cciptypes.ChainSelector ]cciptypes.ChainFeeComponents {
65- // TODO(NONEVM-1865): implement
66- panic ("implement me" )
67- }
66+ func (l * LegacyAccessor ) GetChainFeeComponents (ctx context.Context ) (cciptypes.ChainFeeComponents , error ) {
67+ fc , err := l .contractWriter .GetFeeComponents (ctx )
68+ if err != nil {
69+ return cciptypes.ChainFeeComponents {}, fmt .Errorf ("get fee components: %w" , err )
70+ }
6871
69- func (l * LegacyAccessor ) GetDestChainFeeComponents (ctx context.Context ) (types.ChainFeeComponents , error ) {
70- // TODO(NONEVM-1865): implement
71- panic ("implement me" )
72+ return * fc , nil
7273}
7374
7475func (l * LegacyAccessor ) Sync (ctx context.Context , contracts cciptypes.ContractAddresses ) error {
@@ -78,11 +79,82 @@ func (l *LegacyAccessor) Sync(ctx context.Context, contracts cciptypes.ContractA
7879
7980func (l * LegacyAccessor ) MsgsBetweenSeqNums (
8081 ctx context.Context ,
81- dest cciptypes.ChainSelector ,
82+ destChainSelector cciptypes.ChainSelector ,
8283 seqNumRange cciptypes.SeqNumRange ,
8384) ([]cciptypes.Message , error ) {
84- // TODO(NONEVM-1865): implement
85- panic ("implement me" )
85+ lggr := logutil .WithContextValues (ctx , l .lggr )
86+ seq , err := l .contractReader .ExtendedQueryKey (
87+ ctx ,
88+ consts .ContractNameOnRamp ,
89+ query.KeyFilter {
90+ Key : consts .EventNameCCIPMessageSent ,
91+ Expressions : []query.Expression {
92+ query .Comparator (consts .EventAttributeSourceChain , primitives.ValueComparator {
93+ Value : l .chainSelector ,
94+ Operator : primitives .Eq ,
95+ }),
96+ query .Comparator (consts .EventAttributeDestChain , primitives.ValueComparator {
97+ Value : destChainSelector ,
98+ Operator : primitives .Eq ,
99+ }),
100+ query .Comparator (consts .EventAttributeSequenceNumber , primitives.ValueComparator {
101+ Value : seqNumRange .Start (),
102+ Operator : primitives .Gte ,
103+ }, primitives.ValueComparator {
104+ Value : seqNumRange .End (),
105+ Operator : primitives .Lte ,
106+ }),
107+ query .Confidence (primitives .Finalized ),
108+ },
109+ },
110+ query.LimitAndSort {
111+ SortBy : []query.SortBy {
112+ query .NewSortBySequence (query .Asc ),
113+ },
114+ Limit : query.Limit {
115+ Count : uint64 (seqNumRange .End () - seqNumRange .Start () + 1 ),
116+ },
117+ },
118+ & SendRequestedEvent {},
119+ )
120+ if err != nil {
121+ return nil , fmt .Errorf ("failed to query onRamp: %w" , err )
122+ }
123+
124+ lggr .Infow ("queried messages between sequence numbers" ,
125+ "numMsgs" , len (seq ),
126+ "sourceChainSelector" , l .chainSelector ,
127+ "seqNumRange" , seqNumRange .String (),
128+ )
129+
130+ onRampAddress , err := l .GetContractAddress (consts .ContractNameOnRamp )
131+ if err != nil {
132+ return nil , fmt .Errorf ("failed to get onRamp contract address: %w" , err )
133+ }
134+
135+ msgs := make ([]cciptypes.Message , 0 )
136+ for _ , item := range seq {
137+ msg , ok := item .Data .(* SendRequestedEvent )
138+ if ! ok {
139+ return nil , fmt .Errorf ("failed to cast %v to Message" , item .Data )
140+ }
141+
142+ if err := ValidateSendRequestedEvent (msg , l .chainSelector , destChainSelector , seqNumRange ); err != nil {
143+ lggr .Errorw ("validate send requested event" , "err" , err , "message" , msg )
144+ continue
145+ }
146+
147+ msg .Message .Header .OnRamp = onRampAddress
148+ msgs = append (msgs , msg .Message )
149+ }
150+
151+ lggr .Infow ("decoded messages between sequence numbers" ,
152+ "msgs" , msgs ,
153+ "sourceChainSelector" , l .chainSelector ,
154+ "seqNumRange" , seqNumRange .String (),
155+ )
156+
157+ return msgs , nil
86158}
87159
88160func (l * LegacyAccessor ) LatestMsgSeqNum (ctx context.Context , dest cciptypes.ChainSelector ) (cciptypes.SeqNum , error ) {
0 commit comments