diff --git a/CHANGELOG.md b/CHANGELOG.md index 058a965..4472b91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.9.7](https://github.com/streamingfast/substreams-ethereum/releases/tag/v0.9.6) +## [0.9.8](https://github.com/streamingfast/substreams-ethereum/releases/tag/v0.9.8) +* Fix bug where Int was not encoded properly in ABI generator + +## [0.9.7](https://github.com/streamingfast/substreams-ethereum/releases/tag/v0.9.7) * Blocks with `DetailLevel` set to `Base` now have transaction receipt information. Transaction successfulness is now supported. ## [0.9.6](https://github.com/streamingfast/substreams-ethereum/releases/tag/v0.9.6) diff --git a/abigen-tests/src/abi/tests.rs b/abigen-tests/src/abi/tests.rs index 8b57e6d..86a6576 100644 --- a/abigen-tests/src/abi/tests.rs +++ b/abigen-tests/src/abi/tests.rs @@ -520,7 +520,15 @@ ethabi::Token::FixedBytes(self.param3.as_ref().to_vec()), { let non_full_signed_bytes = self.param4.to_signed_bytes_be(); - let mut full_signed_bytes = [255i32 as u8; 32]; + let full_signed_bytes_init = if non_full_signed_bytes[0] + & 0x80 == 0x80 + { + 0xff + } else { + 0x00 + }; + let mut full_signed_bytes = [full_signed_bytes_init + as u8; 32]; non_full_signed_bytes .into_iter() .rev() @@ -698,7 +706,15 @@ &[ { let non_full_signed_bytes = self.arg0.to_signed_bytes_be(); - let mut full_signed_bytes = [0i32 as u8; 32]; + let full_signed_bytes_init = if non_full_signed_bytes[0] + & 0x80 == 0x80 + { + 0xff + } else { + 0x00 + }; + let mut full_signed_bytes = [full_signed_bytes_init + as u8; 32]; non_full_signed_bytes .into_iter() .rev() @@ -773,7 +789,15 @@ &[ { let non_full_signed_bytes = self.param0.to_signed_bytes_be(); - let mut full_signed_bytes = [255i32 as u8; 32]; + let full_signed_bytes_init = if non_full_signed_bytes[0] + & 0x80 == 0x80 + { + 0xff + } else { + 0x00 + }; + let mut full_signed_bytes = [full_signed_bytes_init + as u8; 32]; non_full_signed_bytes .into_iter() .rev() @@ -848,7 +872,15 @@ &[ { let non_full_signed_bytes = self.param0.to_signed_bytes_be(); - let mut full_signed_bytes = [255i32 as u8; 32]; + let full_signed_bytes_init = if non_full_signed_bytes[0] + & 0x80 == 0x80 + { + 0xff + } else { + 0x00 + }; + let mut full_signed_bytes = [full_signed_bytes_init + as u8; 32]; non_full_signed_bytes .into_iter() .rev() @@ -923,7 +955,15 @@ &[ { let non_full_signed_bytes = self.param0.to_signed_bytes_be(); - let mut full_signed_bytes = [255i32 as u8; 32]; + let full_signed_bytes_init = if non_full_signed_bytes[0] + & 0x80 == 0x80 + { + 0xff + } else { + 0x00 + }; + let mut full_signed_bytes = [full_signed_bytes_init + as u8; 32]; non_full_signed_bytes .into_iter() .rev() @@ -1036,7 +1076,15 @@ &[ { let non_full_signed_bytes = self.param0.to_signed_bytes_be(); - let mut full_signed_bytes = [255i32 as u8; 32]; + let full_signed_bytes_init = if non_full_signed_bytes[0] + & 0x80 == 0x80 + { + 0xff + } else { + 0x00 + }; + let mut full_signed_bytes = [full_signed_bytes_init + as u8; 32]; non_full_signed_bytes .into_iter() .rev() @@ -1048,7 +1096,15 @@ }, { let non_full_signed_bytes = self.param1.to_signed_bytes_be(); - let mut full_signed_bytes = [255i32 as u8; 32]; + let full_signed_bytes_init = if non_full_signed_bytes[0] + & 0x80 == 0x80 + { + 0xff + } else { + 0x00 + }; + let mut full_signed_bytes = [full_signed_bytes_init + as u8; 32]; non_full_signed_bytes .into_iter() .rev() @@ -1060,7 +1116,15 @@ }, { let non_full_signed_bytes = self.param2.to_signed_bytes_be(); - let mut full_signed_bytes = [255i32 as u8; 32]; + let full_signed_bytes_init = if non_full_signed_bytes[0] + & 0x80 == 0x80 + { + 0xff + } else { + 0x00 + }; + let mut full_signed_bytes = [full_signed_bytes_init + as u8; 32]; non_full_signed_bytes .into_iter() .rev() @@ -1072,7 +1136,15 @@ }, { let non_full_signed_bytes = self.param3.to_signed_bytes_be(); - let mut full_signed_bytes = [255i32 as u8; 32]; + let full_signed_bytes_init = if non_full_signed_bytes[0] + & 0x80 == 0x80 + { + 0xff + } else { + 0x00 + }; + let mut full_signed_bytes = [full_signed_bytes_init + as u8; 32]; non_full_signed_bytes .into_iter() .rev() diff --git a/abigen/src/lib.rs b/abigen/src/lib.rs index 9bd29ec..8415cbe 100644 --- a/abigen/src/lib.rs +++ b/abigen/src/lib.rs @@ -245,12 +245,14 @@ fn to_token(name: &proc_macro2::TokenStream, kind: &ParamType) -> proc_macro2::T } ParamType::Bytes => quote! { ethabi::Token::Bytes(#name.clone()) }, ParamType::FixedBytes(_) => quote! { ethabi::Token::FixedBytes(#name.as_ref().to_vec()) }, - ParamType::Int(size) => { - let full_signed_bytes_init = if size == 128 { 0x00 } else { 0xff }; + ParamType::Int(_) => { + // The check non_full_signed_bytes[0] & 0x80 == 0x80 is checking if the leftmost bit of the first byte is set. + // If it is, the number is negative and full_signed_bytes_init is set to 0xff. Otherwise, it's set to 0x00. quote! { { let non_full_signed_bytes = #name.to_signed_bytes_be(); - let mut full_signed_bytes = [#full_signed_bytes_init as u8; 32]; + let full_signed_bytes_init = if non_full_signed_bytes[0] & 0x80 == 0x80 { 0xff } else { 0x00 }; + let mut full_signed_bytes = [full_signed_bytes_init as u8; 32]; non_full_signed_bytes.into_iter().rev().enumerate().for_each(|(i, byte)| full_signed_bytes[31 - i] = byte); ethabi::Token::Int(ethabi::Int::from_big_endian(full_signed_bytes.as_ref()))