Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Fix bug patching profile with modInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Feb 7, 2017
1 parent 13224da commit bc3a525
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ func (n *OpenBazaarNode) PatchProfile(patch map[string]interface{}) error {
return err
}

modInfo, ok := patch["modInfo"]
if ok {
fee, ok := modInfo.(map[string]interface{})["fee"]
if ok {
fixedFee, ok := fee.(map[string]interface{})["fixedFee"]
if ok {
amt := fixedFee.(map[string]interface{})["amount"].(float64)
fixedFee.(map[string]interface{})["amount"] = uint64(amt)
}
}
}

// Assuming that `profile` map contains complete data, as it is read
// from storage, and `patch` map is possibly incomplete, merge first
// into second recursively, preserving new fields and adding missing
Expand All @@ -81,7 +93,7 @@ func (n *OpenBazaarNode) PatchProfile(patch map[string]interface{}) error {
newProfile, err := json.Marshal(patch)
p := new(pb.Profile)
if err := jsonpb.UnmarshalString(string(newProfile), p); err != nil {
return nil
return err
}
return n.UpdateProfile(p)
}
Expand Down

0 comments on commit bc3a525

Please sign in to comment.