From 2eb2420b4043134bfe1323e376bc94c826f92c45 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 10 Feb 2023 12:02:00 +1100 Subject: [PATCH] Add comment on rountripping read/write scripint We only support reads of upto 4 bytes where as Bitcoin Core allows reading a `CScriptNum` with more bytes than that. Add a rustdoc comment (incl. link to Bitcoin Core) mentioning that. --- bitcoin/src/blockdata/script/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs index c4e027fa..5e00b1a5 100644 --- a/bitcoin/src/blockdata/script/mod.rs +++ b/bitcoin/src/blockdata/script/mod.rs @@ -66,6 +66,11 @@ pub use self::types::*; /// Encodes an integer in script(minimal CScriptNum) format. /// /// Writes bytes into the buffer and returns the number of bytes written. +/// +/// Note that `write_scriptint`/`read_scriptint` do not roundtrip if the value written requires +/// more than 4 bytes, this is in line with Bitcoin Core (see [`CScriptNum::serialize`]). +/// +/// [`CScriptNum::serialize`]: pub fn write_scriptint(out: &mut [u8; 8], n: i64) -> usize { let mut len = 0; if n == 0 { return len; }