# Copyright 2010-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

RUST_MIN_VER="1.85"
CRATES="
	aho-corasick-1.1.4
	android_system_properties-0.1.5
	anyhow-1.0.100
	arrayvec-0.7.6
	autocfg-1.5.0
	bech32-0.10.0-beta
	bitcoin-0.31.2
	bitcoin-internals-0.2.0
	bitcoin_hashes-0.13.0
	bitflags-2.10.0
	bumpalo-3.19.0
	bytecount-0.6.9
	bytes-1.11.0
	cc-1.2.48
	cfg-if-1.0.4
	chrono-0.4.42
	cln-plugin-0.5.0
	cln-rpc-0.5.0
	core-foundation-sys-0.8.7
	find-msvc-tools-0.1.5
	fnv-1.0.7
	futures-0.3.31
	futures-channel-0.3.31
	futures-core-0.3.31
	futures-executor-0.3.31
	futures-io-0.3.31
	futures-macro-0.3.31
	futures-sink-0.3.31
	futures-task-0.3.31
	futures-util-0.3.31
	getrandom-0.3.4
	heck-0.5.0
	hex-0.4.3
	hex-conservative-0.1.2
	hex_lit-0.1.1
	iana-time-zone-0.1.64
	iana-time-zone-haiku-0.1.2
	itoa-1.0.15
	js-sys-0.3.83
	lazy_static-1.5.0
	libc-0.2.177
	libmimalloc-sys-0.1.44
	lock_api-0.4.14
	log-0.4.28
	log-panics-2.1.0
	matchers-0.2.0
	memchr-2.7.6
	mimalloc-0.1.48
	mio-1.1.0
	nu-ansi-term-0.50.3
	num-format-0.4.4
	num-traits-0.2.19
	once_cell-1.21.3
	papergrid-0.17.0
	parking_lot-0.12.5
	parking_lot_core-0.9.12
	pin-project-lite-0.2.16
	pin-utils-0.1.0
	ppv-lite86-0.2.21
	proc-macro-error-attr2-2.0.0
	proc-macro-error2-2.0.1
	proc-macro2-1.0.103
	quote-1.0.42
	r-efi-5.3.0
	rand-0.9.2
	rand_chacha-0.9.0
	rand_core-0.9.3
	redox_syscall-0.5.18
	regex-automata-0.4.13
	regex-syntax-0.8.8
	rustversion-1.0.22
	ryu-1.0.20
	scopeguard-1.2.0
	secp256k1-0.28.2
	secp256k1-sys-0.9.2
	serde-1.0.228
	serde_core-1.0.228
	serde_derive-1.0.228
	serde_json-1.0.145
	sharded-slab-0.1.7
	shlex-1.3.0
	slab-0.4.11
	smallvec-1.15.1
	socket2-0.6.1
	syn-2.0.111
	tabled-0.20.0
	tabled_derive-0.11.0
	testing_table-0.3.0
	thread_local-1.1.9
	tokio-1.48.0
	tokio-macros-2.6.0
	tokio-stream-0.1.17
	tokio-util-0.7.17
	tracing-0.1.43
	tracing-attributes-0.1.31
	tracing-core-0.1.35
	tracing-log-0.2.0
	tracing-subscriber-0.3.22
	unicode-ident-1.0.22
	unicode-width-0.2.2
	valuable-0.1.1
	wasi-0.11.1+wasi-snapshot-preview1
	wasip2-1.0.1+wasi-0.2.4
	wasm-bindgen-0.2.106
	wasm-bindgen-macro-0.2.106
	wasm-bindgen-macro-support-0.2.106
	wasm-bindgen-shared-0.2.106
	windows-core-0.62.2
	windows-implement-0.60.2
	windows-interface-0.59.3
	windows-link-0.2.1
	windows-result-0.4.1
	windows-strings-0.5.1
	windows-sys-0.60.2
	windows-sys-0.61.2
	windows-targets-0.53.5
	windows_aarch64_gnullvm-0.53.1
	windows_aarch64_msvc-0.53.1
	windows_i686_gnu-0.53.1
	windows_i686_gnullvm-0.53.1
	windows_i686_msvc-0.53.1
	windows_x86_64_gnu-0.53.1
	windows_x86_64_gnullvm-0.53.1
	windows_x86_64_msvc-0.53.1
	wit-bindgen-0.46.0
	zerocopy-0.8.30
	zerocopy-derive-0.8.30
"
# additional crates from cln-plugin, cln-rpc
CRATES+="
	async-stream-0.3.6
	async-stream-impl-0.3.6
	env_logger-0.10.2
	hermit-abi-0.5.2
	humantime-2.2.0
	is-terminal-0.4.16
	termcolor-1.4.1
	tokio-test-0.4.4
	winapi-util-0.1.9
"

inherit cargo eapi9-ver

DESCRIPTION="A Core Lightning plugin to automatically rebalance multiple channels"
HOMEPAGE="https://github.com/daywalker90/sling"
SRC_URI="${HOMEPAGE}/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
	$(cargo_crate_uris)"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64 ~amd64-linux ~arm ~arm64 ~mips ~ppc ~x86 ~x86-linux"

RDEPEND="
	>=net-p2p/core-lightning-23.11
"

PATCHES=(
	"${FILESDIR}/support-version-without-v.patch"
)

efmt() {
	: ${1:?} ; local l ; while read -r l ; do "${!#}" "${l}" ; done < <(fmt "${@:1:$#-1}")
}

src_install() {
	cargo_src_install
	insinto /usr/libexec/c-lightning/plugins
	mv -- "${ED}/usr/bin/sling" "${ED}/usr/libexec/c-lightning/plugins/" || die
}

pkg_postinst() {
	if ver_replacing -lt 4.0.0 ; then
		efmt ewarn <<-EOF
			This version of ${CATEGORY}/${PN} drops the config variables
			sling-refresh-peers-interval and sling-refresh-gossmap-interval.
			You will need to remove these from your lightningd.conf if they are present.
		EOF
	fi
}