polish code in the right style

pull/139/head
Minh Doan 6 years ago
parent 50af8e0de9
commit e572796a9c
  1. 4
      beaconchain/libs/beaconchain.go
  2. 20
      utils/utils.go

@ -36,7 +36,7 @@ func New(numShards int, ip, port string) *BeaconChain {
bc := BeaconChain{}
bc.log = log.New()
bc.NumberOfShards = numShards
bc.PubKey = generateIDCKeys()
bc.PubKey = generateBCKey()
bc.NumberOfNodesAdded = 0
bc.Port = port
bc.IP = ip
@ -44,7 +44,7 @@ func New(numShards int, ip, port string) *BeaconChain {
return &bc
}
func generateIDCKeys() kyber.Point {
func generateBCKey() kyber.Point {
r := rand.Intn(1000)
priKey := pki.GetPrivateKeyFromInt(r)
pubkey := pki.GetPublicKeyFromPrivateKey(priKey)

@ -69,20 +69,20 @@ func GenKey(ip, port string) (kyber.Scalar, kyber.Point) {
}
// AllocateShard uses the number of current nodes and number of shards
// to return the shardnum a new node belongs to, it also tells whether the node is a leader
func AllocateShard(numnode, numshards int) (int, bool) {
if numshards == 1 {
if numnode == 1 {
// to return the shardNum a new node belongs to, it also tells whether the node is a leader
func AllocateShard(numOfAddedNodes, numOfShards int) (int, bool) {
if numOfShards == 1 {
if numOfAddedNodes == 1 {
return 1, true
}
return 1, false
}
if numnode > numshards {
shardnum := numnode % numshards
if shardnum == 0 {
return numshards, false
if numOfAddedNodes > numOfShards {
shardNum := numOfAddedNodes % numOfShards
if shardNum == 0 {
return numOfShards, false
}
return shardnum, false
return shardNum, false
}
return numnode, true
return numOfAddedNodes, true
}

Loading…
Cancel
Save