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("