@@ -62,10 +62,10 @@ const (
6262)
6363
6464type TONAccessor struct {
65- lggr logger.Logger
66- chainSelector ccipocr3.ChainSelector
67- client ton.APIClientWrapped
68- logPoller logpoller.Service
65+ lggr logger.Logger
66+ chainSelector ccipocr3.ChainSelector
67+ clientProvider func (context. Context ) ( ton.APIClientWrapped , error )
68+ logPoller logpoller.Service
6969 // Note: we might need to update this in the future to map[string][]address.Address
7070 // to support multi-bind addresses for the price aggregator contract: smartcontractkit/chainlink-ccip@main/pkg/contractreader/extended.go#L77-L79
7171 bindings map [string ]* address.Address
@@ -78,27 +78,31 @@ var _ ccipocr3.ChainAccessor = (*TONAccessor)(nil)
7878func NewTONAccessor (
7979 lggr logger.Logger ,
8080 chainSelector ccipocr3.ChainSelector ,
81- client ton.APIClientWrapped ,
81+ clientProvider func (context. Context ) ( ton.APIClientWrapped , error ) ,
8282 logPoller logpoller.Service ,
8383 addrCodec ccipocr3.ChainSpecificAddressCodec ,
8484) (ccipocr3.ChainAccessor , error ) {
8585 sLggr := logger .Sugared (lggr ).Named ("TONAccessor" ).Named (chainSelector .String ())
8686 return & TONAccessor {
87- lggr : sLggr ,
88- chainSelector : chainSelector ,
89- client : client ,
90- logPoller : logPoller ,
91- bindings : make (map [string ]* address.Address ),
92- bindingsMu : sync.RWMutex {},
93- addrCodec : addrCodec ,
87+ lggr : sLggr ,
88+ chainSelector : chainSelector ,
89+ clientProvider : clientProvider ,
90+ logPoller : logPoller ,
91+ bindings : make (map [string ]* address.Address ),
92+ bindingsMu : sync.RWMutex {},
93+ addrCodec : addrCodec ,
9494 }, nil
9595}
9696
9797// getCurrentMasterchainBlock retrieves and validates the current masterchain block.
9898// It ensures the returned block belongs to the masterchain (workchain -1) to prevent
9999// a compromised TON node from injecting base workchain data.
100100func (a * TONAccessor ) getCurrentMasterchainBlock (ctx context.Context ) (* ton.BlockIDExt , error ) {
101- block , err := a .client .CurrentMasterchainInfo (ctx )
101+ client , err := a .clientProvider (ctx )
102+ if err != nil {
103+ return nil , fmt .Errorf ("failed to get TON client: %w" , err )
104+ }
105+ block , err := client .CurrentMasterchainInfo (ctx )
102106 if err != nil {
103107 return nil , fmt .Errorf ("failed to get current masterchain info: %w" , err )
104108 }
@@ -411,7 +415,12 @@ func (a *TONAccessor) GetExpectedNextSequenceNumber(ctx context.Context, dest cc
411415 if err != nil {
412416 return 0 , fmt .Errorf ("failed to get current block: %w" , err )
413417 }
414- result , err := a .client .RunGetMethod (ctx , block , addr , "expectedNextSequenceNumber" , uint64 (dest ))
418+
419+ client , err := a .clientProvider (ctx )
420+ if err != nil {
421+ return 0 , fmt .Errorf ("failed to get TON client: %w" , err )
422+ }
423+ result , err := client .RunGetMethod (ctx , block , addr , "expectedNextSequenceNumber" , uint64 (dest ))
415424 if err != nil {
416425 return 0 , err
417426 }
@@ -448,8 +457,12 @@ func (a *TONAccessor) GetTokenPriceUSD(ctx context.Context, rawTokenAddress ccip
448457 if err != nil {
449458 return ccipocr3.TimestampedUnixBig {}, fmt .Errorf ("failed to get current block: %w" , err )
450459 }
460+ client , err := a .clientProvider (ctx )
461+ if err != nil {
462+ return ccipocr3.TimestampedUnixBig {}, fmt .Errorf ("failed to get TON client: %w" , err )
463+ }
451464
452- timestampedPrice , err := tvm .CallGetter (ctx , a . client , block , addr , feequoter .GetTokenPrice , tokenAddress )
465+ timestampedPrice , err := tvm .CallGetter (ctx , client , block , addr , feequoter .GetTokenPrice , tokenAddress )
453466 if err != nil {
454467 return ccipocr3.TimestampedUnixBig {}, err
455468 }
@@ -468,7 +481,13 @@ func (a *TONAccessor) GetFeeQuoterDestChainConfig(ctx context.Context, dest ccip
468481 if err != nil {
469482 return ccipocr3.FeeQuoterDestChainConfig {}, fmt .Errorf ("failed to get current block: %w" , err )
470483 }
471- cfg , err := tvm .CallGetter (ctx , a .client , block , addr , feequoter .GetDestChainConfig , uint64 (dest ))
484+
485+ client , err := a .clientProvider (ctx )
486+ if err != nil {
487+ return ccipocr3.FeeQuoterDestChainConfig {}, fmt .Errorf ("failed to get TON client: %w" , err )
488+ }
489+
490+ cfg , err := tvm .CallGetter (ctx , client , block , addr , feequoter .GetDestChainConfig , uint64 (dest ))
472491 if err != nil {
473492 return ccipocr3.FeeQuoterDestChainConfig {}, err
474493 }
@@ -780,8 +799,13 @@ func (a *TONAccessor) GetChainFeePriceUpdate(ctx context.Context, selectors []cc
780799 return nil , fmt .Errorf ("failed to get current block: %w" , err )
781800 }
782801
802+ client , err := a .clientProvider (ctx )
803+ if err != nil {
804+ return nil , fmt .Errorf ("failed to get TON client: %w" , err )
805+ }
806+
783807 for _ , selector := range selectors {
784- gasPrice , err := tvm .CallGetter (ctx , a . client , block , addr , feequoter .GetDestinationChainGasPrice , uint64 (selector ))
808+ gasPrice , err := tvm .CallGetter (ctx , client , block , addr , feequoter .GetDestinationChainGasPrice , uint64 (selector ))
785809 // The plugin is built with EVM behaviour in mind: if a value doesn't exist the zero value is returned
786810 var execError ton.ContractExecError
787811 if errors .As (err , & execError ) && execError .Code == int32 (feequoter .ErrorUnknownDestChainSelector ) {
@@ -829,7 +853,11 @@ func (a *TONAccessor) GetLatestPriceSeqNr(ctx context.Context) (ccipocr3.SeqNum,
829853 if err != nil {
830854 return 0 , fmt .Errorf ("failed to get current block: %w" , err )
831855 }
832- result , err := a .client .RunGetMethod (ctx , block , addr , "latestPriceSequenceNumber" )
856+ client , err := a .clientProvider (ctx )
857+ if err != nil {
858+ return 0 , fmt .Errorf ("failed to get TON client: %w" , err )
859+ }
860+ result , err := client .RunGetMethod (ctx , block , addr , "latestPriceSequenceNumber" )
833861 if err != nil {
834862 return 0 , err
835863 }
@@ -873,6 +901,11 @@ func (a *TONAccessor) GetFeeQuoterTokenUpdates(
873901 return nil , fmt .Errorf ("failed to get current block: %w" , err )
874902 }
875903
904+ client , err := a .clientProvider (ctx )
905+ if err != nil {
906+ return nil , fmt .Errorf ("failed to get TON client: %w" , err )
907+ }
908+
876909 prices := make (map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedUnixBig , len (tokens ))
877910 for _ , token := range tokens {
878911 strAddr , err2 := a .addrCodec .AddressBytesToString (token )
@@ -884,7 +917,7 @@ func (a *TONAccessor) GetFeeQuoterTokenUpdates(
884917 return nil , fmt .Errorf ("failed to ParseAddr %s for encodedTokens: %w" , strAddr , err2 )
885918 }
886919
887- tokenPrice , err := tvm .CallGetter (ctx , a . client , block , addr , feequoter .GetTokenPrice , addrParsed )
920+ tokenPrice , err := tvm .CallGetter (ctx , client , block , addr , feequoter .GetTokenPrice , addrParsed )
888921 if err != nil {
889922 // The plugin is built with EVM behaviour in mind: if a value doesn't exist the zero value is returned
890923 var execError ton.ContractExecError
0 commit comments