Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/codex32/_bitcoin_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,15 @@ def initialize(
continue
# Checked last, after any wait above: a pruning node keeps pruning while it waits.
self.check_history(timestamp)
# Core's "now" is its tip's time: the genesis block's on an offline signer that never
# synced, and watch-only exports carry it. A new wallet takes this computer's clock,
# a day early like a record's date, so a fast clock cannot skip its first payments.
records = core_descriptors(
secret,
account=account,
testnet=self.chain != "main",
private=True,
timestamp=timestamp,
timestamp=max(0, int(time.time()) - 86400) if timestamp == "now" else timestamp,
)
imported = self._rpc(
"importdescriptors",
Expand Down
4 changes: 3 additions & 1 deletion tests/test_bitcoin_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ def test_encrypted_import_retries_without_a_passphrase_verifies_and_relocks(
"_rpc",
lambda client, *args, wallet=None, stdin=None: rpc(client, *args, wallet=wallet, stdin=stdin),
)
monkeypatch.setattr("codex32._bitcoin_core.time.time", lambda: 1_700_000_000.5)
client = BitcoinCore("bitcoin-cli", "main", 300000)
messages: list[str] = []
delays: list[int] = []
Expand All @@ -411,7 +412,8 @@ def unlock(seconds: int) -> None:
assert arguments == ("importdescriptors",) and wallet == "signer"
assert private_stdin is not None and private_stdin.endswith("\n")
records = json.loads(private_stdin)
assert len(records) == 4 and all(record["timestamp"] == "now" for record in records)
# A new wallet's "now" is this computer's clock less a day, not Core's tip (genesis offline).
assert len(records) == 4 and all(record["timestamp"] == 1_700_000_000 - 86400 for record in records)
assert all("xprv" in record["desc"] for record in records)
assert all("xprv" not in " ".join((*args, selected or "")) for args, selected, _data in rpc.calls)
assert sum(args[:2] == ("-named", "derivehdkey") for args, _wallet, _stdin in rpc.calls) == 4
Expand Down
Loading