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

Function CreateRandomBlock

types/util.go:59–95  ·  view source on GitHub ↗

CreateRandomBlock create a new random block

(parent hash.Hash, isGenesis bool)

Source from the content-addressed store, hash-verified

57
58// CreateRandomBlock create a new random block
59func CreateRandomBlock(parent hash.Hash, isGenesis bool) (b *Block, err error) {
60 // Generate key pair
61 priv, _, err := asymmetric.GenSecp256k1KeyPair()
62
63 if err != nil {
64 return
65 }
66
67 h := hash.Hash{}
68 rand.Read(h[:])
69
70 b = &Block{
71 SignedHeader: SignedHeader{
72 Header: Header{
73 Version: 0x01000000,
74 Producer: proto.NodeID(h.String()),
75 GenesisHash: genesisHash,
76 ParentHash: parent,
77 Timestamp: time.Now().UTC(),
78 },
79 },
80 }
81
82 if isGenesis {
83 emptyNode := &proto.RawNodeID{}
84 b.SignedHeader.ParentHash = hash.Hash{}
85 b.SignedHeader.GenesisHash = hash.Hash{}
86 b.SignedHeader.Producer = emptyNode.ToNodeID()
87 b.SignedHeader.MerkleRoot = hash.Hash{}
88
89 err = b.PackAsGenesis()
90 return
91 }
92
93 err = b.PackAndSignBlock(priv)
94 return
95}

Callers 11

startTestServiceFunction · 0.92
createRandomBlockFunction · 0.92
TestSingleDatabaseFunction · 0.92
TestInitFailedFunction · 0.92
TestDatabaseRecycleFunction · 0.92
TestDBMSFunction · 0.92
TestSignAndVerifyFunction · 0.85
TestGenesisFunction · 0.85

Calls 7

StringMethod · 0.95
ToNodeIDMethod · 0.95
GenSecp256k1KeyPairFunction · 0.92
NodeIDTypeAlias · 0.92
PackAsGenesisMethod · 0.80
ReadMethod · 0.65
PackAndSignBlockMethod · 0.45

Tested by 11

startTestServiceFunction · 0.74
createRandomBlockFunction · 0.74
TestSingleDatabaseFunction · 0.74
TestInitFailedFunction · 0.74
TestDatabaseRecycleFunction · 0.74
TestDBMSFunction · 0.74
TestSignAndVerifyFunction · 0.68
TestGenesisFunction · 0.68