diff --git a/contracts/sui/libs/sui_rlp/sources/encoder.move b/contracts/sui/libs/sui_rlp/sources/encoder.move index 5e2b93b1..1e63672b 100644 --- a/contracts/sui/libs/sui_rlp/sources/encoder.move +++ b/contracts/sui/libs/sui_rlp/sources/encoder.move @@ -49,7 +49,7 @@ module sui_rlp::encoder { vector::append(&mut encoded_list,result); } else { - let length_bytes = utils::to_bytes_u64(len,false); + let length_bytes = utils::to_bytes_u64_sign(len,false); let prefix = (0xf7 + vector::length(&length_bytes)) as u8; vector::push_back(&mut encoded_list, prefix); vector::append(&mut encoded_list, length_bytes); @@ -69,7 +69,7 @@ module sui_rlp::encoder { let len_u8=(len as u8); vector::push_back(&mut length_info,(offset+len_u8)); }else { - let length_bytes=utils::to_bytes_u64(len,false); + let length_bytes=utils::to_bytes_u64_sign(len,false); let length_byte_len=vector::length(&length_bytes); let length_byte_len=offset+(length_byte_len as u8); vector::push_back(&mut length_info,length_byte_len); @@ -86,19 +86,19 @@ module sui_rlp::encoder { } public fun encode_u32(num:u32):vector{ - let vec= utils::to_bytes_u32(num,true); + let vec= utils::to_bytes_u32_sign(num,true); encode(&vec) } public fun encode_u64(num:u64):vector{ - let vec= utils::to_bytes_u64(num,true); + let vec= utils::to_bytes_u64_sign(num,true); encode(&vec) } public fun encode_u128(num:u128):vector{ - let vec= utils::to_bytes_u128(num,true); + let vec= utils::to_bytes_u128_sign(num,true); encode(&vec) } diff --git a/contracts/sui/libs/sui_rlp/sources/utils.move b/contracts/sui/libs/sui_rlp/sources/utils.move index af37a07d..53529c3d 100644 --- a/contracts/sui/libs/sui_rlp/sources/utils.move +++ b/contracts/sui/libs/sui_rlp/sources/utils.move @@ -41,18 +41,35 @@ module sui_rlp::utils { } - public fun to_bytes_u128(number:u128,signed:bool):vector{ + //Deprecated + public fun to_bytes_u128(number:u128):vector{ + let bytes=bcs::to_bytes(&number); + to_signed_bytes(bytes,true) + } + + public fun to_bytes_u128_sign(number:u128,signed:bool):vector{ let bytes=bcs::to_bytes(&number); to_signed_bytes(bytes,signed) } + //Deprecated + public fun to_bytes_u64(number:u64):vector{ + let bytes=bcs::to_bytes(&number); + to_signed_bytes(bytes,true) + } - public fun to_bytes_u64(number:u64,signed:bool):vector{ + public fun to_bytes_u64_sign(number:u64,signed:bool):vector{ let bytes=bcs::to_bytes(&number); to_signed_bytes(bytes,signed) } + + //Deprecated + public fun to_bytes_u32(number: u32): vector { + let bytes=bcs::to_bytes(&number); + to_signed_bytes(bytes,true) + } - public fun to_bytes_u32(number: u32,signed:bool): vector { + public fun to_bytes_u32_sign(number: u32,signed:bool): vector { let bytes=bcs::to_bytes(&number); to_signed_bytes(bytes,signed) } @@ -120,7 +137,7 @@ module sui_rlp::utils_test { #[test] fun test_u32_conversion() { let num= (122 as u32); - let bytes= utils::to_bytes_u32(num,true); + let bytes= utils::to_bytes_u32_sign(num,true); let converted=utils::from_bytes_u32(&bytes); assert!(num==converted,0x01); @@ -129,7 +146,7 @@ module sui_rlp::utils_test { #[test] fun test_u64_conversion() { let num= (55000 as u64); - let bytes= utils::to_bytes_u64(num,true); + let bytes= utils::to_bytes_u64_sign(num,true); let converted=utils::from_bytes_u64(&bytes); std::debug::print(&bytes); std::debug::print(&converted); @@ -140,7 +157,7 @@ module sui_rlp::utils_test { #[test] fun test_u128_conversion() { let num= (1222223333 as u128); - let bytes= utils::to_bytes_u128(num,true); + let bytes= utils::to_bytes_u128_sign(num,true); std::debug::print(&bytes); let converted=utils::from_bytes_u128(&bytes); std::debug::print(&converted);