11package analyzer
22
33import (
4+ "encoding/json"
45 "fmt"
56
67 "github.com/smartcontractkit/mcms/sdk"
78 "github.com/smartcontractkit/mcms/sdk/ton"
89 "github.com/smartcontractkit/mcms/types"
910
10- "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
11-
1211 "github.com/smartcontractkit/chainlink-ton/pkg/bindings"
1312)
1413
@@ -29,37 +28,43 @@ func AnalyzeTONTransactions(ctx ProposalContext, chainSelector uint64, txs []typ
2928
3029// AnalyzeTONTransaction decodes a single TON transaction using the MCMS TON decoder.
3130//
32- // Unlike Aptos/Sui analyzers, this function does not unmarshal AdditionalFields because
33- // the TON decoder only requires tx.Data (BOC cell) and tx.ContractType (metadata).
34- // AdditionalFields in TON is only used by the encoder/timelock_converter for the Value field.
35- //
3631// On decode failure, this function returns a DecodedCall with the error in the Method field
3732// instead of returning an error. This allows the proposal to continue processing even if
3833// a single transaction fails to decode.
3934func AnalyzeTONTransaction (ctx ProposalContext , decoder sdk.Decoder , chainSelector uint64 , mcmsTx types.Transaction ) (* DecodedCall , error ) {
40- contractTypeAndVersion , err := deployment .TypeAndVersionFromString (mcmsTx .ContractTypeAndVersion )
41- if err != nil {
42- contractType , contractVersion := resolveContractInfo (ctx , chainSelector , mcmsTx )
43- errStr := fmt .Errorf ("failed to decode TON transaction: failed to parse contract type and version: %w" , err )
35+ contractType , contractVersion := resolveContractInfo (ctx , chainSelector , mcmsTx )
4436
45- return & DecodedCall {
46- Address : mcmsTx .To ,
47- Method : errStr .Error (),
48- ContractType : contractType ,
49- ContractVersion : contractVersion ,
50- }, nil
51- }
52- decodedOp , err := decoder .Decode (mcmsTx , contractTypeAndVersion .Type .String ())
53- if err != nil {
37+ var typeErr string
38+ fullyQualifiedName := func () string {
39+ var additionalFields ton.AdditionalFields
40+ if err := json .Unmarshal (mcmsTx .AdditionalFields , & additionalFields ); err != nil {
41+ typeErr = fmt .Sprintf ("; additionally failed to unmarshal TON additional fields: %s" , err )
42+ return ""
43+ }
44+
45+ fullyQualifiedName := string (additionalFields .ContractTypeFull )
46+ // If ContractVersion is provided, append it to the fully qualified name to ensure the decoder uses the correct version.
47+ // If it is skipped, the decoder will use the latest version available for the contract type.
48+ // Note: we don't use contractVersion from resolveContractInfo because that only represents the short type used by the datastore.
49+ if mcmsTx .ContractVersion != nil {
50+ fullyQualifiedName += "@" + mcmsTx .ContractVersion .String ()
51+ }
52+
53+ return fullyQualifiedName
54+ }()
55+
56+ decodedOp , errDec := decoder .Decode (mcmsTx , fullyQualifiedName )
57+ if errDec != nil {
5458 // Don't return an error to not block the whole proposal decoding because of a single transaction decode failure.
5559 // Instead, put the error message in the Method field so it's visible in the report.
56- errStr := fmt . Errorf ( "failed to decode TON transaction: %w" , err )
60+ errStr := "failed to decode TON transaction: " + errDec . Error () + typeErr
5761
62+ //nolint:nilerr // We are intentionally not returning an error here to allow the proposal to be processed even if decoding fails.
5863 return & DecodedCall {
5964 Address : mcmsTx .To ,
60- Method : errStr . Error () ,
61- ContractType : contractTypeAndVersion . Type . String () ,
62- ContractVersion : contractTypeAndVersion . Version . String () ,
65+ Method : errStr ,
66+ ContractType : contractType ,
67+ ContractVersion : contractVersion ,
6368 }, nil
6469 }
6570
@@ -73,7 +78,7 @@ func AnalyzeTONTransaction(ctx ProposalContext, decoder sdk.Decoder, chainSelect
7378 Method : decodedOp .MethodName (),
7479 Inputs : namedArgs ,
7580 Outputs : []NamedField {},
76- ContractType : contractTypeAndVersion . Type . String () ,
77- ContractVersion : contractTypeAndVersion . Version . String () ,
81+ ContractType : contractType ,
82+ ContractVersion : contractVersion ,
7883 }, nil
7984}
0 commit comments