Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the transfer of RBT tokens between DIDs that are present on the same node #207

Merged
merged 8 commits into from
Dec 26, 2024
45 changes: 34 additions & 11 deletions core/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"strconv"
"time"
"strings"

"github.com/rubixchain/rubixgoplatform/core/ipfsport"
"github.com/rubixchain/rubixgoplatform/core/model"
Expand Down Expand Up @@ -99,7 +100,10 @@ func (c *Core) CheckQuorumStatusResponse(req *ensweb.Request) *ensweb.Result { /
func (c *Core) CheckQuorumStatus(peerID string, did string) (string, bool, error) { //
q := make(map[string]string)
if peerID == "" {
peerID = c.qm.GetPeerID(did)
peerID = c.qm.GetPeerID(did, c.peerID)
}
if peerID == "" {
return "Quorum Connection Error", false, fmt.Errorf("unable to find Quorum DID info and peer for %v", did)
}
p, err := c.pm.OpenPeerConn(peerID, "", c.getCoreAppName(peerID))
if err != nil {
Expand Down Expand Up @@ -202,20 +206,39 @@ func (c *Core) GetPeerInfoResponse(req *ensweb.Request) *ensweb.Result { //PingR

pInfo.PeerID = c.w.GetPeerID(peerDID)
if pInfo.PeerID == "" {
c.log.Error("sender does not have prev pledged quorum in DIDPeerTable", peerDID)
resp.Message = "Couldn't fetch peer id for did: " + peerDID
resp.Status = false
return c.l.RenderJSON(req, &resp, http.StatusOK)
_, err := c.w.GetDID(peerDID)
if err != nil {
c.log.Error("sender does not have prev pledged quorum in DIDPeerTable", peerDID)
resp.Message = "Couldn't fetch peer id for did: " + peerDID
resp.Status = false
return c.l.RenderJSON(req, &resp, http.StatusOK)
} else {
pInfo.PeerID = c.peerID
}
}

qDidType, err := c.w.GetPeerDIDType(peerDID)
if err != nil || qDidType == -1 {
c.log.Error("could not fetch did type for quorum:", peerDID, "error", err)
pInfo.DIDType = nil
resp.PeerInfo = pInfo
resp.Status = true
resp.Message = "could not fetch did type, only sharing peerId"
return c.l.RenderJSON(req, &resp, http.StatusOK)
if strings.Contains(err.Error(), "no records found") {
didInfo, err := c.w.GetDID(peerDID)
if err != nil {
c.log.Error("unable to find DID in DIDTable, could not fetch did type for quorum:", peerDID, "error", err)
pInfo.DIDType = nil
resp.PeerInfo = pInfo
resp.Status = true
resp.Message = "could not fetch did type, only sharing peerId"
return c.l.RenderJSON(req, &resp, http.StatusOK)
} else {
pInfo.DIDType = &didInfo.Type
}
} else {
c.log.Error("could not fetch did type for quorum:", peerDID, "error", err)
pInfo.DIDType = nil
resp.PeerInfo = pInfo
resp.Status = true
resp.Message = "could not fetch did type, only sharing peerId"
return c.l.RenderJSON(req, &resp, http.StatusOK)
}
} else {
pInfo.DIDType = &qDidType
}
Expand Down
20 changes: 14 additions & 6 deletions core/quorum.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func NewQuorumManager(s storage.Storage, log logger.Logger) (*QuorumManager, err
}

// GetQuorum will get the configured or available quorum
func (qm *QuorumManager) GetQuorum(t int, lastChar string) []string {
func (qm *QuorumManager) GetQuorum(t int, lastChar string, selfPeer string) []string {
//QuorumTypeOne is to select quorums from the public pool of quorums instead of a private subnet.
//Once a new node is created, it will create a DID. Using the command "registerdid", the peerID and DID will be
//published in the network, and all the nodes listening to the subscription will have the DID added on the DIDPeerTable
Expand Down Expand Up @@ -130,7 +130,7 @@ func (qm *QuorumManager) GetQuorum(t int, lastChar string) []string {
var quorumAddrList []string
quorumAddrCount := 0
for _, q := range qm.ql {
peerID := qm.GetPeerID(q)
peerID := qm.GetPeerID(q, selfPeer)
addr := string(peerID + "." + q)
quorumAddrList = append(quorumAddrList, addr)
quorumAddrCount = quorumAddrCount + 1
Expand Down Expand Up @@ -165,11 +165,19 @@ func (qm *QuorumManager) RemoveAllQuorum(t int) error {
return err
}

func (qm *QuorumManager) GetPeerID(did string) string {
func (qm *QuorumManager) GetPeerID(did string, selfPeer string) string {
var dm QuorumDIDPeerMap
err := qm.s.Read(wallet.DIDPeerStorage, &dm, "did=?", did)
if err != nil {
return ""
if err != nil && strings.Contains(err.Error(), "no records found") {
// Check if the Quorum DID is part of the same node by looking in DIDTable
var dt wallet.DIDType
err2 := qm.s.Read(wallet.DIDStorage, &dt, "did=?", did)
if err2 != nil {
return ""
} else {
return selfPeer
}
} else {
return dm.PeerID
}
return dm.PeerID
}
Loading
Loading