-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* (chore): disallow unknown fields in 29-fee ack * Fixed comment * Fix docstring * Use json.Unmarshal rather than direct call * Wrap the error in ibcerrors.ErrInvalidType * Use json.Unmarshal in tests (cherry picked from commit 8440245) Co-authored-by: Nikolas De Giorgis <nikolas.degiorgis@interchain.io> Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
- Loading branch information
1 parent
09326c8
commit 295f50f
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package types | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
) | ||
|
||
// UnmarshalJSON implements the Unmarshaller interface for IncentivizedAcknowledgement. | ||
func (ack *IncentivizedAcknowledgement) UnmarshalJSON(bz []byte) error { | ||
// Recursion protection. We cannot unmarshal into IncentivizedAcknowledgment directly | ||
// else UnmarshalJSON is going to get invoked again, ad infinum. Create an alias | ||
// and unmarshal into that, instead. | ||
type ackAlias IncentivizedAcknowledgement | ||
|
||
d := json.NewDecoder(bytes.NewReader(bz)) | ||
// Raise errors during decoding if unknown fields are encountered. | ||
d.DisallowUnknownFields() | ||
|
||
var alias ackAlias | ||
if err := d.Decode(&alias); err != nil { | ||
return err | ||
} | ||
|
||
*ack = IncentivizedAcknowledgement(alias) | ||
return nil | ||
} |