Skip to content

Commit

Permalink
Fix empty verification map on error
Browse files Browse the repository at this point in the history
  • Loading branch information
erwin-willems committed Feb 8, 2024
1 parent 2aa0d40 commit d752171
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
2 changes: 2 additions & 0 deletions routes/global_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ func (gs *GlobalState) Get(key []byte) (value []byte, _err error) {
err := gs.GlobalStateDB.View(func(txn *badger.Txn) error {
item, err := txn.Get(key)
if err != nil {
// Todo: I think this error needs to be processed. It could be a key not found error, then nil should be returned.
// If it's another error, it should be returned.
return nil
}
retValue, err = item.ValueCopy(nil)
Expand Down
12 changes: 1 addition & 11 deletions routes/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,8 @@ func (fes *APIServer) GetVerifiedUsernameToPKIDMapFromGlobalState() (_verificati
return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: Cannot Decode Verification Map: %v", err)
}
} else {
// Create the inital map structure
// Return an empty map structure
verifiedMapStruct.VerifiedUsernameToPKID = make(map[string]*lib.PKID)

// Encode the map and stick it in the database.
metadataDataBuf := bytes.NewBuffer([]byte{})
if err = gob.NewEncoder(metadataDataBuf).Encode(verifiedMapStruct); err != nil {
return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: cannot encode verifiedMap struct: %v", err)
}
err = fes.GlobalState.Put(_GlobalStatePrefixForVerifiedMap, metadataDataBuf.Bytes())
if err != nil {
return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: Cannot Decode Verification Map: %v", err)
}
}
// Return the verificationMap
return verifiedMapStruct.VerifiedUsernameToPKID, nil
Expand Down

0 comments on commit d752171

Please sign in to comment.