difftreelog
fix each tuple should be decoded via subresult
in: master
1 file changed
crates/evm-coder/src/abi.rsdiffbeforeafterboth211 self.memory(value.as_bytes())211 self.memory(value.as_bytes())212 }212 }213214 pub fn bytes(&mut self, value: &[u8]) {215 self.memory(value)216 }213217214 pub fn finish(mut self) -> Vec<u8> {218 pub fn finish(mut self) -> Vec<u8> {215 for (static_offset, part) in self.dynamic_part {219 for (static_offset, part) in self.dynamic_part {261 Self: AbiRead<R>,265 Self: AbiRead<R>,262{266{263 fn abi_read(&mut self) -> Result<Vec<R>> {267 fn abi_read(&mut self) -> Result<Vec<R>> {264 todo!()268 let mut sub = self.subresult()?;269 let size = sub.read_usize()?;270 sub.subresult_offset = sub.offset;271 let mut out = Vec::with_capacity(size);272 for _ in 0..size {273 out.push(<Self as AbiRead<R>>::abi_read(&mut sub)?);274 }275 Ok(out)265 }276 }266}277}267278273 $(Self: AbiRead<$ident>),+284 $(Self: AbiRead<$ident>),+274 {285 {275 fn abi_read(&mut self) -> Result<($($ident,)+)> {286 fn abi_read(&mut self) -> Result<($($ident,)+)> {287 let mut subresult = self.subresult()?;276 Ok((288 Ok((277 $(<Self as AbiRead<$ident>>::abi_read(self)?,)+289 $(<Self as AbiRead<$ident>>::abi_read(&mut subresult)?,)+278 ))290 ))279 }291 }280 }292 }318 writer.string(self)330 writer.string(self)319 }331 }320}332}333impl AbiWrite for &Vec<u8> {334 fn abi_write(&self, writer: &mut AbiWriter) {335 writer.bytes(self)336 }337}321338322impl AbiWrite for () {339impl AbiWrite for () {323 fn abi_write(&self, _writer: &mut AbiWriter) {}340 fn abi_write(&self, _writer: &mut AbiWriter) {}353370354#[cfg(test)]371#[cfg(test)]355pub mod test {372pub mod test {373 use crate::{374 abi::AbiRead,375 types::{string, uint256},376 };377356 use super::{AbiReader, AbiWriter};378 use super::{AbiReader, AbiWriter};357 use hex_literal::hex;379 use hex_literal::hex;401 assert_eq!(decoder.string().unwrap(), "Test URI");423 assert_eq!(decoder.string().unwrap(), "Test URI");402 }424 }425426 #[test]427 fn mint_bulk() {428 let (call, mut decoder) = AbiReader::new_call(&hex!(429 "430 36543006431 00000000000000000000000053744e6da587ba10b32a2554d2efdcd985bc27a3 // address432 0000000000000000000000000000000000000000000000000000000000000040 // offset of (uint256, string)[]433 0000000000000000000000000000000000000000000000000000000000000003 // length of (uint256, string)[]434435 0000000000000000000000000000000000000000000000000000000000000060 // offset of first elem436 00000000000000000000000000000000000000000000000000000000000000e0 // offset of second elem437 0000000000000000000000000000000000000000000000000000000000000160 // offset of third elem438439 0000000000000000000000000000000000000000000000000000000000000001 // first token id? #60440 0000000000000000000000000000000000000000000000000000000000000040 // offset of string441 000000000000000000000000000000000000000000000000000000000000000a // size of string442 5465737420555249203000000000000000000000000000000000000000000000 // string443444 000000000000000000000000000000000000000000000000000000000000000b // second token id? Why ==11? #e0445 0000000000000000000000000000000000000000000000000000000000000040 // offset of string446 000000000000000000000000000000000000000000000000000000000000000a // size of string447 5465737420555249203100000000000000000000000000000000000000000000 // string448449 000000000000000000000000000000000000000000000000000000000000000c // third token id? Why ==12? #160450 0000000000000000000000000000000000000000000000000000000000000040 // offset of string451 000000000000000000000000000000000000000000000000000000000000000a // size of string452 5465737420555249203200000000000000000000000000000000000000000000 // string453 "454 ))455 .unwrap();456 assert_eq!(call, 0x36543006);457 let _ = decoder.address().unwrap();458 let data =459 <AbiReader<'_> as AbiRead<Vec<(uint256, string)>>>::abi_read(&mut decoder).unwrap();460 assert_eq!(461 data,462 vec![463 (1.into(), "Test URI 0".to_string()),464 (11.into(), "Test URI 1".to_string()),465 (12.into(), "Test URI 2".to_string())466 ]467 );468 }403}469}404470