Skip to content

Commit

Permalink
updated return error
Browse files Browse the repository at this point in the history
  • Loading branch information
ashi31 committed Jun 14, 2024
1 parent 0590554 commit 1666237
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions core/wallet/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wallet

import (
"encoding/hex"
"fmt"

"github.com/ipfs/go-cid"
)
Expand Down Expand Up @@ -90,15 +91,10 @@ func (w *Wallet) IsDIDExist(did string) bool {
}

func (w *Wallet) AddDIDPeerMap(did string, peerID string, didType int) error {
// Parse the did
c, err := cid.Decode(did)
lastChar, err := w.GetLastChar(did)
if err != nil {
w.log.Error("Failed to decode DID: %v", err)
return err
}
multihashDigest := c.Hash()
// Convert the multihash digest to hexadecimal - to compare with txnID
hexDigest := hex.EncodeToString(multihashDigest)
lastChar := string(hexDigest[len(hexDigest)-1])
var dm DIDPeerMap
err = w.s.Read(DIDStorage, &dm, "did=?", did)
if err == nil {
Expand Down Expand Up @@ -131,15 +127,10 @@ func (w *Wallet) AddDIDLastChar() error {
}
for _, dm := range existingDIDPeer {
did := dm.DID
// Parse the did
c, err := cid.Decode(did)
lastChar, err := w.GetLastChar(did)
if err != nil {
w.log.Error("Failed to decode DID: %v", err)
continue
}
multihashDigest := c.Hash()
// Convert the multihash digest to hexadecimal - to compare with txnID
hexDigest := hex.EncodeToString(multihashDigest)
lastChar := string(hexDigest[len(hexDigest)-1])
dm.DIDLastChar = lastChar
err = w.s.Update(DIDPeerStorage, &dm, "did=?", did)
w.log.Info("DID Peer table updated")
Expand All @@ -150,6 +141,21 @@ func (w *Wallet) AddDIDLastChar() error {
}
return nil
}

func (w *Wallet) GetLastChar(did string) (string, error) {
// Parse the did
c, err := cid.Decode(did)
if err != nil {
w.log.Error(fmt.Sprintf("Failed to decode DID %v : %v", did, err))
return "", err
}
multihashDigest := c.Hash()
// Convert the multihash digest to hexadecimal - to compare with txnID
hexDigest := hex.EncodeToString(multihashDigest)
lastchar := string(hexDigest[len(hexDigest)-1])
return lastchar, nil
}

func (w *Wallet) GetPeerID(did string) string {
var dm DIDPeerMap
err := w.s.Read(DIDPeerStorage, &dm, "did=?", did)
Expand Down

0 comments on commit 1666237

Please sign in to comment.