FROM fedora:40

ENV UV_PYTHON=3.12
ENV BITCOIN_VERSION=27.1
ENV SOURCE_DATE_EPOCH=1672531200
ENV RUSTFLAGS="-C link-arg=-Wl,--build-id=none"

WORKDIR /tmp

RUN dnf update -y && \
	dnf groupinstall -y \
		'C Development Tools and Libraries' \
		'Development Tools' && \
	dnf install -y \
		clang \
		libsq3-devel \
		redhat-lsb \
		net-tools \
		valgrind \
		wget \
		git \
		jq \
		xz \
		zlib-devel \
		libsodium-devel \
		which \
		sed \
		gettext-devel \
		gmp-devel \
		python3-devel \
		python3-pip \
		python3-poetry \
		postgresql-devel && \
	dnf clean all

# Install Rust via rustup (for lockfile v4 support)
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.92.0
ENV PATH="/root/.cargo/bin:${PATH}"

# Install lowdown
RUN wget https://github.com/kristapsdz/lowdown/archive/refs/tags/VERSION_1_0_2.tar.gz && \
	tar -xzf VERSION_1_0_2.tar.gz && \
	cd lowdown-VERSION_1_0_2 && \
	./configure && \
	make && \
	make install && \
	ldconfig && \
	cd /tmp && \
	rm -rf VERSION_1_0_2.tar.gz lowdown-VERSION_1_0_2

# Install Bitcoin Core
RUN wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-x86_64-linux-gnu.tar.gz \
    -O bitcoin.tar.gz && \
    tar -xvzf bitcoin.tar.gz && \
    mv bitcoin-$BITCOIN_VERSION/bin/bitcoin* /usr/local/bin/ && \
    mv bitcoin-$BITCOIN_VERSION/lib/* /usr/local/lib/ && \
    mv bitcoin-$BITCOIN_VERSION/include/* /usr/local/include/ && \
    mv bitcoin-$BITCOIN_VERSION/share/man/man1/* /usr/share/man/man1 && \
    rm -rf bitcoin.tar.gz bitcoin-$BITCOIN_VERSION

# Install uv
ENV PATH="${PATH}:/root/.local/bin"
RUN wget -qO- https://astral.sh/uv/install.sh | sh
