Fix impl-rlp for uint in primitive-types (#117)

* Fix impl-rlp for uint in primitive-types

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Fix impl_uint_rlp

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Fix impl_uint_rlp

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
This commit is contained in:
Qinxuan Chen 2019-03-27 21:00:33 +08:00 committed by Andronik Ordian
parent c64e1b52e6
commit 0ddf13c260
1 changed files with 3 additions and 3 deletions

View File

@ -20,8 +20,8 @@ macro_rules! impl_uint_rlp {
($name: ident, $size: expr) => {
impl $crate::rlp::Encodable for $name {
fn rlp_append(&self, s: &mut $crate::rlp::RlpStream) {
let leading_empty_bytes = $size - (self.bits() + 7) / 8;
let mut buffer = [0u8; $size];
let leading_empty_bytes = $size * 8 - (self.bits() + 7) / 8;
let mut buffer = [0u8; $size * 8];
self.to_big_endian(&mut buffer);
s.encoder().encode_value(&buffer[leading_empty_bytes..]);
}
@ -32,7 +32,7 @@ macro_rules! impl_uint_rlp {
rlp.decoder().decode_value(|bytes| {
if !bytes.is_empty() && bytes[0] == 0 {
Err($crate::rlp::DecoderError::RlpInvalidIndirection)
} else if bytes.len() <= $size {
} else if bytes.len() <= $size * 8 {
Ok($name::from(bytes))
} else {
Err($crate::rlp::DecoderError::RlpIsTooBig)