1 // Copyright (c) 2015-2016 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
12 "github.com/btcsuite/btcd/chaincfg/chainhash"
13 "github.com/btcsuite/btcd/database"
16 // fetchBlockCmd defines the configuration options for the fetchblock command.
17 type fetchBlockCmd struct{}
20 // fetchBlockCfg defines the configuration options for the command.
21 fetchBlockCfg = fetchBlockCmd{}
24 // Execute is the main entry point for the command. It's invoked by the parser.
25 func (cmd *fetchBlockCmd) Execute(args []string) error {
26 // Setup the global config options and ensure they are valid.
27 if err := setupGlobalConfig(); err != nil {
32 return errors.New("required block hash parameter not specified")
34 blockHash, err := chainhash.NewHashFromStr(args[0])
39 // Load the block database.
40 db, err := loadBlockDB()
46 return db.View(func(tx database.Tx) error {
47 log.Infof("Fetching block %s", blockHash)
48 startTime := time.Now()
49 blockBytes, err := tx.FetchBlock(blockHash)
53 log.Infof("Loaded block in %v", time.Since(startTime))
54 log.Infof("Block Hex: %s", hex.EncodeToString(blockBytes))
59 // Usage overrides the usage display for the command.
60 func (cmd *fetchBlockCmd) Usage() string {