dev
dart 20 lines 847 Bytes
Raw
1 import "dart:typed_data";
2
3 /// Anti-fee-sniping locktime, set to the current chain tip (exact-tip).
4 ///
5 /// Matches the exact-tip cluster (payjoin-cli, ldk-node, Bull Bitcoin) and Core's
6 /// default for externally-constructed transactions, and takes Cake off its unique
7 /// `nLockTime = 0` fingerprint. It intentionally skips the ~10% backdate
8 /// Core/Electrum apply for delayed-broadcast privacy, which does not apply here.
9 /// Returns 0 when not synced or the tip is unknown, to avoid emitting a stale
10 /// height.
11 int antiFeeSnipingLocktime({
12 required int chainTip,
13 required bool synced,
14 }) {
15 if (!synced || chainTip <= 0) return 0;
16 return chainTip;
17 }
18
19 /// Little-endian 4-byte encoding for `BtcTransaction.locktime`.
20 List<int> locktimeToBytes(int locktime) => (ByteData(4)..setUint32(0, locktime, Endian.little)).buffer.asUint8List();