From 87e6fe8fe99a964737bf6e5a1486468e73f21c8d Mon Sep 17 00:00:00 2001 From: omani <3346207+omani@users.noreply.github.com> Date: Tue, 1 Aug 2023 18:09:30 +0000 Subject: [PATCH] Provide UnmarshalJSON() for common.uint160 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 <3346207+omani@users.noreply.github.com> --- common/uint160.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/uint160.go b/common/uint160.go index 00ff12761..bc407f5b8 100644 --- a/common/uint160.go +++ b/common/uint160.go @@ -94,6 +94,13 @@ func (f Uint160) MarshalJSON() ([]byte, error) { return []byte("\"" + str + "\""), err } +func (f Uint160) UnmarshalJSON(in []byte) (err error) { + if len(in) > 1 { + 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)