Skip to content

Commit

Permalink
[1760]: Tweak the MetadataAddress.Format method: add some comments an…
Browse files Browse the repository at this point in the history
…d remove the p and T cases which never get actually used.
  • Loading branch information
SpicyLemon committed May 8, 2024
1 parent 378c796 commit cd11009
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions x/metadata/types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,16 +634,18 @@ func (ma MetadataAddress) Format(s fmt.State, verb rune) {
out = fmt.Sprintf(fmt.FormatString(s, verb), ma.String())
case 'v':
if s.Flag('#') {
// We can't provide the same MetadataAddress arg back to Sprintf here (infinite recursion).
// So we cast it as a byte slice, string that, then change the "[]byte" part to "MetadataAddress".
out = fmt.Sprintf(fmt.FormatString(s, verb), []byte(ma))
out = "MetadataAddress" + strings.TrimPrefix(out, "[]byte")
} else {
// The auto-generated gogoproto.stringer methods use "%v" for the MetadataAddress fields.
// So here, we return the bech32 for "%v" so that those other strings look right.
// So here, we return the bech32 for "%v" so that MetadataAddress fields look right in those strings.
out = fmt.Sprintf(fmt.FormatString(s, verb), ma.String())
}
case 'p', 'T':
out = fmt.Sprintf(fmt.FormatString(s, verb), ma)
default:
// The 'p' (pointer) and 'T' (type) verbs are never processed using this Format method.
// That's how %T returns the correct type even though it would actually return "[]byte" if run through this.
out = fmt.Sprintf(fmt.FormatString(s, verb), []byte(ma))
}

Expand Down
1 change: 1 addition & 0 deletions x/metadata/types/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ func (s *AddressTestSuite) TestContractSpecAddressConverters() {
}
}

// mockState satisfies the fmt.State interface, but always returns an error from Write, and doesn't do anything else.
type mockState struct {
err string
}
Expand Down

0 comments on commit cd11009

Please sign in to comment.