コード例 #1
0
ファイル: dropafter.go プロジェクト: ironbits/dcrd
func getSha(db database.Db, str string) (chainhash.Hash, error) {
	argtype, idx, sha, err := parsesha(str)
	if err != nil {
		log.Warnf("unable to decode [%v] %v", str, err)
		return chainhash.Hash{}, err
	}

	switch argtype {
	case argSha:
		// nothing to do
	case argHeight:
		sha, err = db.FetchBlockShaByHeight(idx)
		if err != nil {
			return chainhash.Hash{}, err
		}
	}
	if sha == nil {
		fmt.Printf("wtf sha is nil but err is %v", err)
	}
	return *sha, nil
}
コード例 #2
0
ファイル: showblock.go プロジェクト: ironbits/dcrd
func DumpBlock(database database.Db, height int64, fo io.Writer, rflag bool, fflag bool, tflag bool) error {
	sha, err := database.FetchBlockShaByHeight(height)

	if err != nil {
		return err
	}
	blk, err := database.FetchBlockBySha(sha)
	if err != nil {
		log.Warnf("Failed to fetch block %v, err %v", sha, err)
		return err
	}
	rblk, err := blk.Bytes()
	blkid := blk.Height()

	if rflag {
		log.Infof("Block %v depth %v %v", sha, blkid, spew.Sdump(rblk))
	}

	mblk := blk.MsgBlock()
	if fflag {
		log.Infof("Block %v depth %v %v", sha, blkid, spew.Sdump(mblk))
	}
	if tflag {
		log.Infof("Num transactions %v", len(mblk.Transactions))
		for i, tx := range mblk.Transactions {
			txsha := tx.TxSha()
			log.Infof("tx %v: %v", i, &txsha)

		}
	}
	if fo != nil {
		// generate and write header values
		binary.Write(fo, binary.LittleEndian, uint32(wire.SimNet))
		binary.Write(fo, binary.LittleEndian, uint32(len(rblk)))

		// write block
		fo.Write(rblk)
	}
	return nil
}