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 := BeaconChain{}
bc.log = log.New() bc.log = log.New()
bc.NumberOfShards = numShards bc.NumberOfShards = numShards
bc.PubKey = generateIDCKeys() bc.PubKey = generateBCKey()
bc.NumberOfNodesAdded = 0 bc.NumberOfNodesAdded = 0
bc.Port = port bc.Port = port
bc.IP = ip bc.IP = ip
@ -44,7 +44,7 @@ func New(numShards int, ip, port string) *BeaconChain {
return &bc return &bc
} }
func generateIDCKeys() kyber.Point { func generateBCKey() kyber.Point {
r := rand.Intn(1000) r := rand.Intn(1000)
priKey := pki.GetPrivateKeyFromInt(r) priKey := pki.GetPrivateKeyFromInt(r)
pubkey := pki.GetPublicKeyFromPrivateKey(priKey) 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 // 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 // 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) { func AllocateShard(numOfAddedNodes, numOfShards int) (int, bool) {
if numshards == 1 { if numOfShards == 1 {
if numnode == 1 { if numOfAddedNodes == 1 {
return 1, true return 1, true
} }
return 1, false return 1, false
} }
if numnode > numshards { if numOfAddedNodes > numOfShards {
shardnum := numnode % numshards shardNum := numOfAddedNodes % numOfShards
if shardnum == 0 { if shardNum == 0 {
return numshards, false return numOfShards, false
} }
return shardnum, false return shardNum, false
} }
return numnode, true return numOfAddedNodes, true
} }

Loading…
Cancel
Save