code: func ExtractCoinbaseHeight(coinbaseTx *btcutil.Tx) (int32, error) {
  	sigScript := coinbaseTx.MsgTx().TxIn[0].SignatureScript
  	if len(sigScript) < 1 {
  		str := "the coinbase signature script for blocks of " +
  			"version %d or greater must start with the " +
  			"length of the serialized block height"
  		str = fmt.Sprintf(str, serializedHeightVersion)
  		return 0, ruleError(ErrMissingCoinbaseHeight, str)
  	}
  
  	// Detect the case when the block height is a small integer encoded with
  	// as single byte.
  	opcode := int(sigScript[0])
  	if opcode == txscript.OP_0 {
  		return 0, nil
  	}
  	if opcode >= txscript.OP_1 && opcode <= txscript.OP_16 {
  		return int32(opcode - (txscript.OP_1 - 1)), nil
  	}
  
  	// Otherwise, the opcode is the length of the following bytes which
  	// encode in the block height.
  	serializedLen := int(sigScript[0])
  	if len(sigScript[1:]) < serializedLen {
  		str := "the coinbase signature script for blocks of " +
  			"version %d or greater must start with the " +
  			"serialized block height"
  		str = fmt.Sprintf(str, serializedLen)
  		return 0, ruleError(ErrMissingCoinbaseHeight, str)
  	}
  
  	serializedHeightBytes := make([]byte, 8)
  	copy(serializedHeightBytes, sigScript[1:serializedLen+1])
  	serializedHeight := binary.LittleEndian.Uint64(serializedHeightBytes)
  
  	return int32(serializedHeight), nil
  }
docs: // ExtractCoinbaseHeight attempts to extract the height of the block from the
  // scriptSig of a coinbase transaction.  Coinbase heights are only present in
  // blocks of version 2 or later.  This was added as part of BIP0034.