Skip to content

Commit

Permalink
Provide UnmarshalJSON() for common.uint160
Browse files Browse the repository at this point in the history
fixes error `json: cannot unmarshal string into Go struct field
Account.ProgramHash of type common.Uint160` in case `nkn.Account` struct
is to be unmarshalled.

Signed-off-by: omani <[email protected]>
  • Loading branch information
omani committed Aug 1, 2023
1 parent f9a9a48 commit 990b25d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/uint160.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func (f Uint160) MarshalJSON() ([]byte, error) {
return []byte("\"" + str + "\""), err
}

func (f Uint160) UnmarshalJSON(in []byte) (err error) {
f, err = ToScriptHash(string(in[1 : len(in)-1]))
return
}

func (f *Uint160) ToAddress() (string, error) {
data := append(big.NewInt(FOOLPROOFPREFIX).Bytes(), f.ToArray()...)
temp := sha256.Sum256(data)
Expand Down

0 comments on commit 990b25d

Please sign in to comment.