From 283662e659e22c315baf3935ef11d4d1551e77bd Mon Sep 17 00:00:00 2001 From: gerlofvanek Date: Fri, 29 May 2026 19:15:34 +0200 Subject: [PATCH] Fix: Median time one call. --- basicswap/interface/btc.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/basicswap/interface/btc.py b/basicswap/interface/btc.py index 3b4b1c9..913deb4 100644 --- a/basicswap/interface/btc.py +++ b/basicswap/interface/btc.py @@ -504,11 +504,21 @@ class BTCInterface(Secp256k1Interface): def getChainMedianTime(self) -> int: if self.useBackend(): - height = self._backend.getBlockHeight() - times = [] - for h in range(max(0, height - 10), height + 1): - header = self._getBlockHeaderFromHeightElectrum(h) - times.append(header["time"]) + import struct + + backend = self.getBackend() + if not backend: + raise ValueError("No electrum backend available") + height = backend.getBlockHeight() + start = max(0, height - 10) + count = height - start + 1 + result = backend._server.call("blockchain.block.headers", [start, count]) + header_bytes = bytes.fromhex(result["hex"]) + returned = result.get("count", count) + times = [ + struct.unpack("