From 79c51815a49384da1e6f5d9e557048f156e2f088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Kupka?= Date: Sat, 19 Aug 2017 16:17:54 +0200 Subject: [PATCH] types: Improve type Authority The fields are semantically maps, they are only encoded as arrays. So Authority now uses StringInt64Map. --- types/operations.go | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/types/operations.go b/types/operations.go index 8f09d4f..682509f 100644 --- a/types/operations.go +++ b/types/operations.go @@ -6,9 +6,6 @@ import ( // RPC "github.com/go-steem/rpc/encoding/transaction" - - // Vendor - "github.com/pkg/errors" ) // FC_REFLECT( steemit::chain::report_over_production_operation, @@ -431,43 +428,9 @@ func (op *CommentOptionsOperation) Data() interface{} { } type Authority struct { - AccountAuths []*Auth `json:"account_auths"` - KeyAuths []*Auth `json:"key_auths"` - WeightThreshold uint32 `json:"weight_threshold"` -} - -// XXX: Not sure about the struct field names. -type Auth struct { - Key string - Check uint32 -} - -func (auth *Auth) UnmarshalJSON(data []byte) error { - // The auth object is [key, check]. - raw := make([]json.RawMessage, 2) - if err := json.Unmarshal(data, &raw); err != nil { - return err - } - if len(raw) != 2 { - return errors.Errorf("invalid auth object: %v", string(data)) - } - - // Unmarshal Key. - var key string - if err := json.Unmarshal(raw[0], &key); err != nil { - return errors.Wrapf(err, "failed to unmarshal Auth.Key: %v", string(raw[0])) - } - - // Unmarshal Check. - var check uint32 - if err := json.Unmarshal(raw[1], &check); err != nil { - return errors.Wrapf(err, "failed to unmarshal Auth.Check: %v", string(raw[1])) - } - - // Update fields. - auth.Key = key - auth.Check = check - return nil + AccountAuths StringInt64Map `json:"account_auths"` + KeyAuths StringInt64Map `json:"key_auths"` + WeightThreshold uint32 `json:"weight_threshold"` } type UnknownOperation struct {