Skip to content

Commit

Permalink
Merge pull request #213 from rubixchain/maneesha/maintain-GoStandard-…
Browse files Browse the repository at this point in the history
…CamelCase

Maintaining CamelCase
  • Loading branch information
thewebchap authored Aug 30, 2024
2 parents 90be7e7 + f3d0b0f commit 9b99373
Show file tree
Hide file tree
Showing 23 changed files with 378 additions and 381 deletions.
86 changes: 43 additions & 43 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ const (
)

const (
Initiator_NLSS_share string = "nlss_share_signature"
Initiator_Private_sign string = "priv_signature"
Initiator_DID string = "initiator_did"
Initiator_Hash string = "hash"
Initiator_SignType string = "sign_type"
InitiatorNLSSShare string = "nlss_share_signature"
InitiatorPrivateSign string = "priv_signature"
InitiatorDID string = "InitiatorDID"
InitiatorHash string = "hash"
InitiatorSignType string = "sign_type"
)

const (
CreditSig_Signature string = "signature"
CreditSig_PrivSignature string = "priv_signature"
CreditSig_DID string = "did"
CreditSig_Hash string = "hash"
CreditSig_SignType string = "sign_type"
CreditSigSignature string = "signature"
CreditSigPrivSignature string = "priv_signature"
CreditSigDID string = "did"
CreditSigHash string = "hash"
CreditSigSignType string = "sign_type"
)

type TokenChainBlock struct {
Expand Down Expand Up @@ -113,11 +113,11 @@ type CreditSignature struct {
}

type InitiatorSignature struct {
NLSS_share string `json:"nlss_share_signature"`
Private_sign string `json:"priv_signature"`
DID string `json:"initiator_did"`
Hash string `json:"hash"`
SignType int `json:"sign_type"` //represents sign type (PkiSign == 0 or NlssSign==1)
NLSSShare string `json:"nlss_share_signature"`
PrivateSign string `json:"priv_signature"`
DID string `json:"InitiatorDID"`
Hash string `json:"hash"`
SignType int `json:"sign_type"` //represents sign type (PkiSign == 0 or NlssSign==1)
}

type BlockOption func(b *Block)
Expand Down Expand Up @@ -744,58 +744,58 @@ func (b *Block) GetEpoch() int64 {

// Fetch initiator signature details from the given block
func (b *Block) GetInitiatorSignature() *InitiatorSignature {
var initiator_sign InitiatorSignature
var initiatorSign InitiatorSignature
s, ok := b.bm[TCInitiatorSignatureKey]
if !ok || s == nil {
return nil
}
//fetch initiator did
did_ := util.GetFromMap(s, Initiator_DID)
initiator_sign.DID = did_.(string)
did := util.GetFromMap(s, InitiatorDID)
initiatorSign.DID = did.(string)
//fetch initiator sign type
sign_type_ := util.GetFromMap(s, Initiator_SignType)
initiator_sign.SignType = int(sign_type_.(uint64))
signType := util.GetFromMap(s, InitiatorSignType)
initiatorSign.SignType = int(signType.(uint64))
//fetch initiator nlss share sign
nlss_share_ := util.GetFromMap(s, Initiator_NLSS_share)
initiator_sign.NLSS_share = nlss_share_.(string)
nlssShare := util.GetFromMap(s, InitiatorNLSSShare)
initiatorSign.NLSSShare = nlssShare.(string)
//fetch initiator private sign
priv_sign_ := util.GetFromMap(s, Initiator_Private_sign)
initiator_sign.Private_sign = priv_sign_.(string)
privSign := util.GetFromMap(s, InitiatorPrivateSign)
initiatorSign.PrivateSign = privSign.(string)
//fetch initiator hash / signed data
signed_data_ := util.GetFromMap(s, Initiator_Hash)
initiator_sign.Hash = signed_data_.(string)
signedData := util.GetFromMap(s, InitiatorHash)
initiatorSign.Hash = signedData.(string)

return &initiator_sign
return &initiatorSign
}

// Fetch quorums' signature details from the given block
func (b *Block) GetQuorumSignatureList() ([]CreditSignature, error) {
var quorum_sign_list []CreditSignature
var quorumSignList []CreditSignature
s := b.bm[TCQuorumSignatureKey]

qrmSignList_map, ok := s.([]interface{})
qrmSignListMap, ok := s.([]interface{})
if !ok {
fmt.Println("not of type []interface{}")
return nil, fmt.Errorf("failed to fetch quorums' signature information from block map")
}
for _, qrmSignList_ := range qrmSignList_map {
var quorum_sig CreditSignature
for _, qrmSignListMap := range qrmSignListMap {
var quorumSig CreditSignature
//fetch quorum did
qrm_did := util.GetFromMap(qrmSignList_, CreditSig_DID)
quorum_sig.DID = qrm_did.(string)
qrmDID := util.GetFromMap(qrmSignListMap, CreditSigDID)
quorumSig.DID = qrmDID.(string)
// //fetch quorum sign type
sign_type_ := util.GetFromMap(qrmSignList_, CreditSig_SignType)
quorum_sig.SignType = sign_type_.(string)
signType := util.GetFromMap(qrmSignListMap, CreditSigSignType)
quorumSig.SignType = signType.(string)
// //fetch quorum nlss share sign
nlss_share_ := util.GetFromMap(qrmSignList_, CreditSig_Signature)
quorum_sig.Signature = nlss_share_.(string)
nlssShare := util.GetFromMap(qrmSignListMap, CreditSigSignature)
quorumSig.Signature = nlssShare.(string)
// //fetch quorum private sign
priv_sign_ := util.GetFromMap(qrmSignList_, CreditSig_PrivSignature)
quorum_sig.PrivSignature = priv_sign_.(string)
quorum_sign_list = append(quorum_sign_list, quorum_sig)
privSign := util.GetFromMap(qrmSignListMap, CreditSigPrivSignature)
quorumSig.PrivSignature = privSign.(string)
quorumSignList = append(quorumSignList, quorumSig)
}

return quorum_sign_list, nil
return quorumSignList, nil
}

// calculate block hash from block data
Expand All @@ -811,7 +811,7 @@ func (b *Block) CalculateBlockHash() (string, error) {
return "", fmt.Errorf("invalid block, block content missing")
}
hb := util.CalculateHash(bc.([]byte), "SHA3-256")
block_hash := util.HexToStr(hb)
blockHash := util.HexToStr(hb)

return block_hash, nil
return blockHash, nil
}
4 changes: 2 additions & 2 deletions client/addpeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"github.com/rubixchain/rubixgoplatform/setup"
)

func (c *Client) AddPeer(peer_detail *wallet.DIDPeerMap) (string, bool) {
func (c *Client) AddPeer(peerDetail *wallet.DIDPeerMap) (string, bool) {

var rm model.BasicResponse
err := c.sendJSONRequest("POST", setup.APIAddPeerDetails, nil, &peer_detail, &rm)
err := c.sendJSONRequest("POST", setup.APIAddPeerDetails, nil, &peerDetail, &rm)
if err != nil {
return err.Error(), false
}
Expand Down
4 changes: 2 additions & 2 deletions client/quorum.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (c *Client) AddQuorum(quorumList string) (string, bool) {
return "Length of Quorum list should be atleast 5", false
}
for _, q := range ql {
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(q.Address)
if !strings.HasPrefix(q.Address, "bafybmi") || len(q.Address) != 59 || !is_alphanumeric {
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(q.Address)
if !strings.HasPrefix(q.Address, "bafybmi") || len(q.Address) != 59 || !isAlphanumeric {
c.log.Error(fmt.Sprintf("Invalid quorum DID : %s", q.Address))
return fmt.Sprintf("Invalid quorum DID : %s", q.Address), false
}
Expand Down
4 changes: 2 additions & 2 deletions client/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func (c *Client) GetPinnedInfo(TokenStateHash string) (*model.BasicResponse, err
return &br, nil
}

func (c *Client) ValidateTokenchain(user_did string, smartContractChainValidation bool, token string, blockCount int) (*model.BasicResponse, error) {
func (c *Client) ValidateTokenchain(userDID string, smartContractChainValidation bool, token string, blockCount int) (*model.BasicResponse, error) {
q := make(map[string]string)
q["did"] = user_did
q["did"] = userDID
q["token"] = token
q["blockcount"] = strconv.Itoa(blockCount)
q["SCChainValidation"] = strconv.FormatBool(smartContractChainValidation)
Expand Down
14 changes: 7 additions & 7 deletions command/addingpeerdetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func (cmd *Command) AddPeerDetails() {
} else {
peerID = cmd.peerID
}
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.peerID)
if !strings.HasPrefix(cmd.peerID, "12D3KooW") || len(cmd.peerID) != 52 || !is_alphanumeric {
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.peerID)
if !strings.HasPrefix(cmd.peerID, "12D3KooW") || len(cmd.peerID) != 52 || !isAlphanumeric {
cmd.log.Error("Invalid PeerID")
return
}
Expand All @@ -38,24 +38,24 @@ func (cmd *Command) AddPeerDetails() {
} else {
did = cmd.did
}
is_alphanumeric = regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !is_alphanumeric {
isAlphanumeric = regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !isAlphanumeric {
cmd.log.Error("Invalid DID")
return
}

// did_type = cmd.didType
// didType = cmd.didType
if cmd.didType < 0 || cmd.didType > 4 {
cmd.log.Error("DID Type should be between 0 and 4")
return
}

peer_detail := wallet.DIDPeerMap{
peerDetail := wallet.DIDPeerMap{
PeerID: peerID,
DID: did,
DIDType: &cmd.didType,
}
msg, status := cmd.c.AddPeer(&peer_detail)
msg, status := cmd.c.AddPeer(&peerDetail)
if !status {
cmd.log.Error("Failed to add peer in DB", "message", msg)
return
Expand Down
8 changes: 4 additions & 4 deletions command/data_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func (cmd *Command) createDataToken() {
return
}
}
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !is_alphanumeric {
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !isAlphanumeric {
cmd.log.Error("Invalid DID")
return
}
Expand Down Expand Up @@ -84,8 +84,8 @@ func (cmd *Command) commitDataToken() {
return
}
}
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !is_alphanumeric {
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !isAlphanumeric {
cmd.log.Error("Invalid DID")
return
}
Expand Down
8 changes: 4 additions & 4 deletions command/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ func (cmd *Command) dumpTokenChain() {
return
}
}
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.token)
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.token)

if len(cmd.token) != 46 || !strings.HasPrefix(cmd.token, "Qm") || !is_alphanumeric {
if len(cmd.token) != 46 || !strings.HasPrefix(cmd.token, "Qm") || !isAlphanumeric {
cmd.log.Error("Invalid token")
return
}
Expand Down Expand Up @@ -203,9 +203,9 @@ func (cmd *Command) dumpSmartContractTokenChain() {
return
}
}
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.smartContractToken)
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.smartContractToken)

if len(cmd.smartContractToken) != 46 || !strings.HasPrefix(cmd.smartContractToken, "Qm") || !is_alphanumeric {
if len(cmd.smartContractToken) != 46 || !strings.HasPrefix(cmd.smartContractToken, "Qm") || !isAlphanumeric {
cmd.log.Error("Invalid smart contract token")
return
}
Expand Down
12 changes: 6 additions & 6 deletions command/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ func (cmd *Command) RegsiterDIDCmd() {
return
}
}
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !is_alphanumeric {
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !isAlphanumeric {
cmd.log.Error("Invalid DID")
return
}
Expand All @@ -223,8 +223,8 @@ func (cmd *Command) RegsiterDIDCmd() {
}

func (cmd *Command) SetupDIDCmd() {
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !is_alphanumeric {
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !isAlphanumeric {
cmd.log.Error("Invalid DID")
return
}
Expand Down Expand Up @@ -357,8 +357,8 @@ func (cmd *Command) GetAccountInfo() {
return
}
}
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !is_alphanumeric {
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !isAlphanumeric {
cmd.log.Error("Invalid DID")
return
}
Expand Down
8 changes: 4 additions & 4 deletions command/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func (cmd *Command) ping() {
cmd.log.Error("PeerID cannot be empty. Please use flag peerId")
return
}
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.peerID)
if !strings.HasPrefix(cmd.peerID, "12D3KooW") || len(cmd.peerID) != 52 || !is_alphanumeric {
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.peerID)
if !strings.HasPrefix(cmd.peerID, "12D3KooW") || len(cmd.peerID) != 52 || !isAlphanumeric {
cmd.log.Error("Invalid PeerID")
return
}
Expand All @@ -34,8 +34,8 @@ func (cmd *Command) checkQuorumStatus() {
return
}
}
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.quorumAddr)
if !strings.HasPrefix(cmd.quorumAddr, "bafybmi") || len(cmd.quorumAddr) != 59 || !is_alphanumeric {
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.quorumAddr)
if !strings.HasPrefix(cmd.quorumAddr, "bafybmi") || len(cmd.quorumAddr) != 59 || !isAlphanumeric {
cmd.log.Error("Invalid DID of the quorum")
return
}
Expand Down
4 changes: 2 additions & 2 deletions command/quorurm.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (cmd *Command) SetupQuorum() {
return
}
}
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !is_alphanumeric {
isAlphanumeric := regexp.MustCompile(`^[a-zA-Z0-9]*$`).MatchString(cmd.did)
if !strings.HasPrefix(cmd.did, "bafybmi") || len(cmd.did) != 59 || !isAlphanumeric {
cmd.log.Error("Invalid DID")
return
}
Expand Down
Loading

0 comments on commit 9b99373

Please sign in to comment.