MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / registerNodesWithPublicKey

Function registerNodesWithPublicKey

sqlchain/xxx_test.go:210–246  ·  view source on GitHub ↗
(pub *asymmetric.PublicKey, diff int, num int)

Source from the content-addressed store, hash-verified

208}
209
210func registerNodesWithPublicKey(pub *asymmetric.PublicKey, diff int, num int) (
211 nis []cpuminer.NonceInfo, err error) {
212 nis = make([]cpuminer.NonceInfo, num)
213
214 miner := cpuminer.NewCPUMiner(nil)
215 nCh := make(chan cpuminer.NonceInfo)
216 defer close(nCh)
217 block := cpuminer.MiningBlock{
218 Data: pub.Serialize(),
219 NonceChan: nCh,
220 Stop: nil,
221 }
222 next := cpuminer.Uint256{}
223 wg := &sync.WaitGroup{}
224
225 for i := range nis {
226 wg.Add(1)
227 go func() {
228 defer wg.Done()
229 _ = miner.ComputeBlockNonce(block, next, diff)
230 }()
231 n := <-nCh
232 nis[i] = n
233 next = n.Nonce
234 next.Inc()
235
236 if err = kms.SetPublicKey(proto.NodeID(n.Hash.String()), n.Nonce, pub); err != nil {
237 return
238 }
239
240 wg.Wait()
241 }
242
243 // Register a local nonce, don't know what is the matter though
244 kms.SetLocalNodeIDNonce(nis[0].Hash[:], &nis[0].Nonce)
245 return
246}
247
248func createRandomBlock(parent hash.Hash, isGenesis bool) (b *types.Block, err error) {
249 b, err = types.CreateRandomBlock(parent, isGenesis)

Callers 1

createTestPeersFunction · 0.85

Calls 10

ComputeBlockNonceMethod · 0.95
IncMethod · 0.95
NewCPUMinerFunction · 0.92
SetPublicKeyFunction · 0.92
NodeIDTypeAlias · 0.92
SetLocalNodeIDNonceFunction · 0.92
WaitMethod · 0.80
SerializeMethod · 0.45
AddMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected