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.
This commit is contained in:
Tobin C. Harding 2023-02-10 12:02:00 +11:00
parent 657dd51e8b
commit 2eb2420b40
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 5 additions and 0 deletions

View File

@ -66,6 +66,11 @@ pub use self::types::*;
/// Encodes an integer in script(minimal CScriptNum) format. /// Encodes an integer in script(minimal CScriptNum) format.
/// ///
/// Writes bytes into the buffer and returns the number of bytes written. /// 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`]: <https://github.com/bitcoin/bitcoin/blob/8ae2808a4354e8dcc697f76bacc5e2f2befe9220/src/script/script.h#L345>
pub fn write_scriptint(out: &mut [u8; 8], n: i64) -> usize { pub fn write_scriptint(out: &mut [u8; 8], n: i64) -> usize {
let mut len = 0; let mut len = 0;
if n == 0 { return len; } if n == 0 { return len; }