-
Notifications
You must be signed in to change notification settings - Fork 3
feat: ContractVersion in OperationMetadata (#979) #986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2aabdbf
5311b31
f7f09ea
42f1045
c314860
651039c
88be8e4
237b655
4d69cd7
d558e85
aad11d8
9620685
99a5e84
8bc04c0
5fa5480
dd9760c
c35fcdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "chainlink-deployments-framework": minor | ||
| --- | ||
|
|
||
| Use Metadata.ContractVersion instead of ContractTypeAndVersion |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,13 @@ | ||
| package analyzer | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/smartcontractkit/mcms/sdk" | ||
| "github.com/smartcontractkit/mcms/sdk/ton" | ||
| "github.com/smartcontractkit/mcms/types" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-deployments-framework/deployment" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-ton/pkg/bindings" | ||
| ) | ||
|
|
||
|
|
@@ -29,37 +28,43 @@ func AnalyzeTONTransactions(ctx ProposalContext, chainSelector uint64, txs []typ | |
|
|
||
| // AnalyzeTONTransaction decodes a single TON transaction using the MCMS TON decoder. | ||
| // | ||
| // Unlike Aptos/Sui analyzers, this function does not unmarshal AdditionalFields because | ||
| // the TON decoder only requires tx.Data (BOC cell) and tx.ContractType (metadata). | ||
| // AdditionalFields in TON is only used by the encoder/timelock_converter for the Value field. | ||
| // | ||
| // On decode failure, this function returns a DecodedCall with the error in the Method field | ||
| // instead of returning an error. This allows the proposal to continue processing even if | ||
| // a single transaction fails to decode. | ||
| func AnalyzeTONTransaction(ctx ProposalContext, decoder sdk.Decoder, chainSelector uint64, mcmsTx types.Transaction) (*DecodedCall, error) { | ||
| contractTypeAndVersion, err := deployment.TypeAndVersionFromString(mcmsTx.ContractTypeAndVersion) | ||
| if err != nil { | ||
| contractType, contractVersion := resolveContractInfo(ctx, chainSelector, mcmsTx) | ||
| errStr := fmt.Errorf("failed to decode TON transaction: failed to parse contract type and version: %w", err) | ||
| contractType, contractVersion := resolveContractInfo(ctx, chainSelector, mcmsTx) | ||
|
|
||
| return &DecodedCall{ | ||
| Address: mcmsTx.To, | ||
| Method: errStr.Error(), | ||
| ContractType: contractType, | ||
| ContractVersion: contractVersion, | ||
| }, nil | ||
| } | ||
| decodedOp, err := decoder.Decode(mcmsTx, contractTypeAndVersion.Type.String()) | ||
| if err != nil { | ||
| var typeErr string | ||
| fullyQualifiedName := func() string { | ||
| var additionalFields ton.AdditionalFields | ||
| if err := json.Unmarshal(mcmsTx.AdditionalFields, &additionalFields); err != nil { | ||
| typeErr = fmt.Sprintf("; additionally failed to unmarshal TON additional fields: %s", err) | ||
| return "" | ||
| } | ||
|
|
||
| fullyQualifiedName := string(additionalFields.ContractTypeFull) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Let's extract into a type/func which we document and allows anybody to produce a FQN |
||
| // If ContractVersion is provided, append it to the fully qualified name to ensure the decoder uses the correct version. | ||
| // If it is skipped, the decoder will use the latest version available for the contract type. | ||
| // Note: we don't use contractVersion from resolveContractInfo because that only represents the short type used by the datastore. | ||
|
patricios-space marked this conversation as resolved.
patricios-space marked this conversation as resolved.
|
||
| if mcmsTx.ContractVersion != nil { | ||
|
patricios-space marked this conversation as resolved.
|
||
| fullyQualifiedName += "@" + mcmsTx.ContractVersion.String() | ||
| } | ||
|
Comment on lines
+45
to
+51
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want this in TON because we only want to select a version explicitly via TX params |
||
|
|
||
| return fullyQualifiedName | ||
| }() | ||
|
|
||
| decodedOp, errDec := decoder.Decode(mcmsTx, fullyQualifiedName) | ||
| if errDec != nil { | ||
| // Don't return an error to not block the whole proposal decoding because of a single transaction decode failure. | ||
| // Instead, put the error message in the Method field so it's visible in the report. | ||
| errStr := fmt.Errorf("failed to decode TON transaction: %w", err) | ||
| errStr := "failed to decode TON transaction: " + errDec.Error() + typeErr | ||
|
|
||
| //nolint:nilerr // We are intentionally not returning an error here to allow the proposal to be processed even if decoding fails. | ||
| return &DecodedCall{ | ||
| Address: mcmsTx.To, | ||
| Method: errStr.Error(), | ||
| ContractType: contractTypeAndVersion.Type.String(), | ||
| ContractVersion: contractTypeAndVersion.Version.String(), | ||
| Method: errStr, | ||
| ContractType: contractType, | ||
| ContractVersion: contractVersion, | ||
| }, nil | ||
| } | ||
|
|
||
|
|
@@ -73,7 +78,7 @@ func AnalyzeTONTransaction(ctx ProposalContext, decoder sdk.Decoder, chainSelect | |
| Method: decodedOp.MethodName(), | ||
| Inputs: namedArgs, | ||
| Outputs: []NamedField{}, | ||
| ContractType: contractTypeAndVersion.Type.String(), | ||
| ContractVersion: contractTypeAndVersion.Version.String(), | ||
| ContractType: contractType, | ||
| ContractVersion: contractVersion, | ||
| }, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.