git.delta.rocks / unique-network / refs/commits / 2e0d1a668d33

difftreelog

source

crates/evm-coder/src/abi/traits.rs1.3 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/// Sealed traits.26pub mod sealed {27	/// Not all types can be placed in vec, i.e `Vec<u8>` is restricted, `bytes` should be used instead28	pub trait CanBePlacedInVec {}29}3031/// [`AbiReader`] implements reading of many types.32pub trait AbiRead {33	/// Read item from current position, advanding decoder34	fn abi_read(reader: &mut AbiReader) -> Result<Self>35	where36		Self: Sized;37}3839/// For questions about inability to provide custom implementations,40/// see [`AbiRead`]41pub trait AbiWrite {42	/// Write value to end of specified encoder43	fn abi_write(&self, writer: &mut AbiWriter);44	/// Specialization for [`crate::solidity_interface`] implementation,45	/// see comment in `impl AbiWrite for ResultWithPostInfo`46	fn to_result(&self) -> ResultWithPostInfo<AbiWriter> {47		let mut writer = AbiWriter::new();48		self.abi_write(&mut writer);49		Ok(writer.into())50	}51}