NewInitialBlock produces the first block for a new blockchain, using the given pubkeys and quorum for its NextPredicate.
(pubkeys []ed25519.PublicKey, quorum int, timestamp time.Time)
| 137 | // NewInitialBlock produces the first block for a new blockchain, |
| 138 | // using the given pubkeys and quorum for its NextPredicate. |
| 139 | func NewInitialBlock(pubkeys []ed25519.PublicKey, quorum int, timestamp time.Time) (*bc.Block, error) { |
| 140 | // TODO(kr): move this into a lower-level package (e.g. chain/protocol/bc) |
| 141 | // so that other packages (e.g. chain/protocol/validation) unit tests can |
| 142 | // call this function. |
| 143 | root := bc.TxMerkleRoot(nil) // calculate the zero value of the tx merkle root |
| 144 | patRoot := bc.NewHash(new(patricia.Tree).RootHash()) |
| 145 | |
| 146 | var pkBytes [][]byte |
| 147 | for _, pk := range pubkeys { |
| 148 | pkBytes = append(pkBytes, pk) |
| 149 | } |
| 150 | |
| 151 | b := &bc.Block{ |
| 152 | UnsignedBlock: &bc.UnsignedBlock{ |
| 153 | BlockHeader: &bc.BlockHeader{ |
| 154 | Version: 3, |
| 155 | Height: 1, |
| 156 | TimestampMs: bc.Millis(timestamp), |
| 157 | TransactionsRoot: &root, |
| 158 | ContractsRoot: &patRoot, |
| 159 | NoncesRoot: &patRoot, |
| 160 | NextPredicate: &bc.Predicate{ |
| 161 | Version: 1, |
| 162 | Quorum: int32(quorum), |
| 163 | Pubkeys: pkBytes, |
| 164 | }, |
| 165 | }, |
| 166 | }, |
| 167 | } |
| 168 | return b, nil |
| 169 | } |