Format utility functions for consistency#802
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
This PR enhances the proposal analysis system by adding richer type information to decoded parameters and introducing utility functions for consistent number formatting. The changes introduce a TypeName field to the NamedField struct, which stores ABI type information (e.g., "uint64", "bytes32") for EVM transactions, and refactor numeric formatting logic into a reusable format package.
Changes:
- Added
TypeNamefield toNamedFieldstruct for storing explicit type information from ABI definitions - Created new
formatpackage withCommaGroupBigIntandFormatTokenAmountutilities for consistent number formatting - Refactored
commaGroupedfunction in funcmap.go to use the new format package and handle more numeric types via reflection - Updated decoder conversion logic to prioritize explicit
TypeNameover inferred types while maintaining backward compatibility - Minor template whitespace adjustment that adds consistent spacing after annotation blocks
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| experimental/analyzer/fields.go | Adds TypeName field to NamedField struct |
| experimental/analyzer/evm_tx_decoder.go | Populates TypeName from ABI type information in EVM decoder |
| experimental/analyzer/evm_tx_decoder_test.go | Updates test expectations to include TypeName values |
| engine/cld/mcms/proposalanalysis/format/format.go | New utility functions for number formatting |
| engine/cld/mcms/proposalanalysis/format/format_test.go | Comprehensive tests for format utilities |
| engine/cld/mcms/proposalanalysis/renderer/funcmap.go | Refactored commaGrouped to use format package with enhanced type support |
| engine/cld/mcms/proposalanalysis/decoder/convert.go | Updated to use TypeName with fallback to GetType() for backward compatibility |
| engine/cld/mcms/proposalanalysis/renderer/templates/markdown/annotations.tmpl | Consolidated template end statements affecting whitespace |
| engine/cld/mcms/proposalanalysis/renderer/testdata/golden_markdown.md | Updated golden file with new whitespace format |
Comments suppressed due to low confidence (1)
engine/cld/mcms/proposalanalysis/decoder/convert.go:112
- Consider adding a test case to verify that when TypeName is populated (as it now is in EVM decoders), the adaptNamedFields function correctly prioritizes it over the Value's GetType() method. This would ensure the new TypeName field is properly utilized in the decoder pipeline.
func adaptNamedFields(fields []experimentalanalyzer.NamedField) DecodedParameters {
if len(fields) == 0 {
return nil
}
params := make(DecodedParameters, len(fields))
for i, field := range fields {
ptype := field.TypeName
if ptype == "" && field.Value != nil {
ptype = field.Value.GetType()
}
value := any(field.Value)
if value == nil {
value = field.RawValue
}
params[i] = &decodedParameter{
name: field.Name,
ptype: ptype,
value: value,
rawValue: field.RawValue,
}
}
return params
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


This pull request introduces improvements to the representation and formatting of decoded parameters and field values in proposal analysis, with a focus on providing richer type information and enhanced formatting for numeric values.
https://smartcontract-it.atlassian.net/browse/OPT-443