|
| 1 | +/* |
| 2 | +Copyright IBM Corp. 2017 All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package main |
| 18 | + |
| 19 | +import ( |
| 20 | + "flag" |
| 21 | + "io/ioutil" |
| 22 | + |
| 23 | + genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" |
| 24 | + "github.com/hyperledger/fabric/common/configtx/tool/provisional" |
| 25 | + "github.com/hyperledger/fabric/protos/utils" |
| 26 | + |
| 27 | + logging "github.com/op/go-logging" |
| 28 | +) |
| 29 | + |
| 30 | +const ( |
| 31 | + DefaultGenesisFileLocation = "genesis.block" |
| 32 | +) |
| 33 | + |
| 34 | +var logger = logging.MustGetLogger("common/configtx/tool") |
| 35 | + |
| 36 | +func main() { |
| 37 | + var writePath, profile string |
| 38 | + |
| 39 | + dryRun := flag.Bool("dryRun", false, "Whether to only generate but not write the genesis block file.") |
| 40 | + flag.StringVar(&writePath, "path", DefaultGenesisFileLocation, "The path to write the genesis block to.") |
| 41 | + flag.StringVar(&profile, "profile", genesisconfig.SampleInsecureProfile, "The profile from configtx.yaml to use for generation.") |
| 42 | + flag.Parse() |
| 43 | + |
| 44 | + logging.SetLevel(logging.INFO, "") |
| 45 | + |
| 46 | + logger.Info("Loading configuration") |
| 47 | + config := genesisconfig.Load(profile) |
| 48 | + |
| 49 | + logger.Info("Generating genesis block") |
| 50 | + genesisBlock := provisional.New(config).GenesisBlock() |
| 51 | + |
| 52 | + if !*dryRun { |
| 53 | + logger.Info("Writing genesis block") |
| 54 | + ioutil.WriteFile(writePath, utils.MarshalOrPanic(genesisBlock), 0644) |
| 55 | + } |
| 56 | +} |
0 commit comments