-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from Zondax/nat/fix_msg_prefix
Use varuint to prefix message len
- Loading branch information
Showing
26 changed files
with
122 additions
and
143 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
APPVERSION_M=0 | ||
APPVERSION_N=22 | ||
APPVERSION_P=9 | ||
APPVERSION_N=23 | ||
APPVERSION_P=0 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use core::fmt::{self, Write}; | ||
use core::fmt::Write; | ||
use nom::{ | ||
branch::permutation, | ||
bytes::complete::take, | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use super::ParserError; | ||
use nom::number::complete::{le_u16, le_u32, le_u64, le_u8}; | ||
|
||
const FD_PREFIX: u8 = 0xfd; | ||
const FE_PREFIX: u8 = 0xfe; | ||
const FF_PREFIX: u8 = 0xff; | ||
|
||
// stick to the bitcoin spec | ||
// refer to https://learnmeabitcoin.com/technical/varint | ||
// for more detail | ||
pub fn read_varint(input: &[u8]) -> Result<(&[u8], u64), nom::Err<ParserError>> { | ||
// read len prefix | ||
let (rem, prefix) = le_u8(input)?; | ||
|
||
// check prefix | ||
match prefix { | ||
FD_PREFIX => { | ||
// the next 2-bytes are the next field len | ||
le_u16(rem).map(|(rem, len)| (rem, len as u64)) | ||
} | ||
FE_PREFIX => { | ||
// the next 4-bytes are the next field len | ||
le_u32(rem).map(|(rem, len)| (rem, len as u64)) | ||
} | ||
FF_PREFIX => { | ||
// the next 4-bytes are the next field len | ||
le_u64(rem) | ||
} | ||
// the prefix is the actual len | ||
_ => Ok((rem, prefix as _)), | ||
} | ||
} |
Oops, something went wrong.