git.delta.rocks / unique-network / refs/commits / aa6b9ea4ef79

difftreelog

source

crates/evm-coder/src/abi/traits.rs1.2 KiBsourcehistory
1use super::{AbiReader, AbiWriter};2use crate::{3	custom_signature::*,4	execution::{Result, ResultWithPostInfo},5};6use core::str::from_utf8;78/// Helper for type.9pub trait AbiType {10	/// Signature for Etherium ABI.11	const SIGNATURE: SignatureUnit;1213	/// Signature as str.14	fn as_str() -> &'static str {15		from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")16	}1718	/// Is type dynamic sized.19	fn is_dynamic() -> bool;2021	/// Size for type aligned to [`ABI_ALIGNMENT`].22	fn size() -> usize;23}2425/// [`AbiReader`] implements reading of many types.26pub trait AbiRead {27	/// Read item from current position, advanding decoder28	fn abi_read(reader: &mut AbiReader) -> Result<Self>29	where30		Self: Sized;31}3233/// For questions about inability to provide custom implementations,34/// see [`AbiRead`]35pub trait AbiWrite {36	/// Write value to end of specified encoder37	fn abi_write(&self, writer: &mut AbiWriter);38	/// Specialization for [`crate::solidity_interface`] implementation,39	/// see comment in `impl AbiWrite for ResultWithPostInfo`40	fn to_result(&self) -> ResultWithPostInfo<AbiWriter> {41		let mut writer = AbiWriter::new();42		self.abi_write(&mut writer);43		Ok(writer.into())44	}45}