Skip to content

Commit

Permalink
types: Improve type Authority
Browse files Browse the repository at this point in the history
The fields are semantically maps, they are only encoded as arrays.
So Authority now uses StringInt64Map.
  • Loading branch information
tchap committed Aug 19, 2017
1 parent 480ea8d commit 79c5181
Showing 1 changed file with 3 additions and 40 deletions.
43 changes: 3 additions & 40 deletions types/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 79c5181

Please sign in to comment.