runar-rs: add CallOptions.locktime to enable deadline-based contracts#41
Open
E-Jacko wants to merge 1 commit into
Open
runar-rs: add CallOptions.locktime to enable deadline-based contracts#41E-Jacko wants to merge 1 commit into
CallOptions.locktime to enable deadline-based contracts#41E-Jacko wants to merge 1 commit into
Conversation
The Rust SDK's call-tx builder previously wrote nLockTime = 0 unconditionally. Contracts that assert against extractLocktime(txPreimage) (e.g. an auction's close() requiring extractLocktime >= deadline) could not work for any non-zero deadline — the signed transaction's nLockTime was always 0. This change adds an optional `locktime: Option<u32>` field to CallOptions (and the lower-level CallTxOptions). Default `None` preserves legacy behavior (writes 0). `Some(n)` writes `n` as the tx's little-endian u32 locktime in both the non-terminal call path (calling.rs) and the terminal call path (contract.rs). Backwards compatibility: purely additive — every existing call site that does not set `locktime` sees byte-identical output. The 307 existing lib tests in runar-rs pass unchanged. Refs: icellan#40
This was referenced May 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #40.
Summary
Adds an optional
locktime: Option<u32>field toCallOptions(and the lower-levelCallTxOptions) inpackages/runar-rs/. Defaults toNone. When set, the SDK uses the provided value as the call transaction'snLockTime; when unset, the SDK falls back to the legacy hardcoded0.Unblocks contracts that assert against
extractLocktime(txPreimage)(deadline-based auctions, escrow timeouts, vesting releases, etc.).Changes
packages/runar-rs/src/sdk/types.rs— addlocktime: Option<u32>field toCallOptionspackages/runar-rs/src/sdk/calling.rs— add matching field toCallTxOptions+ readoptions.and_then(|o| o.locktime).unwrap_or(0)at the non-terminal call-tx build sitepackages/runar-rs/src/sdk/contract.rs— threadCallOptions.locktimethrough to both invocations ofbuild_call_transaction_ext(initial build + rebuild path) and into the terminal-path'sbuild_terminal_txclosureBackwards compatibility
Purely additive. Existing callers that don't set
locktimesee byte-identical output. All 307 lib tests inpackages/runar-rs/pass unchanged.Minor API note: callers that construct
CallOptionsfield-by-field without..Default::default()will see a missing-field compile error. Suggest documenting in the changelog. Happy to add#[non_exhaustive]if maintainers prefer (itself a breaking change but future-proofs the struct).Test plan
cargo test --release --libinpackages/runar-rs/— 307/307 passescargo checkcleanA regression test suite covering default + override behavior is in flight as a follow-up commit if helpful — happy to include in this PR or land separately.
Mainnet validation
The same patch (vendored locally against the same code paths) has been validated end-to-end on BSV mainnet. A test EnglishAuction was deployed and bid/closed using a non-zero deadline:
09814d16…6244cblock 949122779ea679…3606block 949222Without the
locktimeoverride, the close transaction is rejected withScript evaluated without error but finished with a false/empty top stack element(the script's deadline assertion failing). With this PR, the same transaction mines.Open design question
Should the default be the current chain tip rather than
0?0preserves legacy behavior (back-compat safe). Chain-tip default would be more "useful out of the box" but is a behavior change. Happy to discuss in review.Related
This is the first of three fixes that together enable auction-style terminal-method contracts to mine on mainnet:
nLockTimeoverride (deadline-assertion preconditions)Issues 2 and 3 will follow with their own PRs.