From a6579a05acf0d2cbcad7e020c6ce77e909d441a4 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 15 Oct 2020 14:50:51 +0300 Subject: [PATCH] core: refactor transaction.Attribute unmarshalling --- pkg/core/transaction/attribute.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/core/transaction/attribute.go b/pkg/core/transaction/attribute.go index 140c0bf34..ca3e1011e 100644 --- a/pkg/core/transaction/attribute.go +++ b/pkg/core/transaction/attribute.go @@ -81,21 +81,19 @@ func (attr *Attribute) UnmarshalJSON(data []byte) error { return err } switch aj.Type { - case "HighPriority": + case HighPriority.String(): attr.Type = HighPriority - case "OracleResponse": + return nil + case OracleResponseT.String(): attr.Type = OracleResponseT // Note: because `type` field will not be present in any attribute // value, we can unmarshal the same data. The overhead is minimal. attr.Value = new(OracleResponse) - return json.Unmarshal(data, attr.Value) - case "NotValidBefore": + case NotValidBeforeT.String(): attr.Type = NotValidBeforeT attr.Value = new(NotValidBefore) - return json.Unmarshal(data, attr.Value) default: return errors.New("wrong Type") - } - return nil + return json.Unmarshal(data, attr.Value) }