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

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	/// Count of enum variants or struct fields.14	const FIELDS_COUNT: usize;1516	/// Signature as str.17	fn as_str() -> &'static str {18		from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")19	}2021	/// Is type dynamic sized.22	fn is_dynamic() -> bool;2324	/// Size for type aligned to [`ABI_ALIGNMENT`].25	fn size() -> usize;26}2728/// [`AbiReader`] implements reading of many types.29pub trait AbiRead {30	/// Read item from current position, advanding decoder31	fn abi_read(reader: &mut AbiReader) -> Result<Self>32	where33		Self: Sized;34}3536/// For questions about inability to provide custom implementations,37/// see [`AbiRead`]38pub trait AbiWrite {39	/// Write value to end of specified encoder40	fn abi_write(&self, writer: &mut AbiWriter);41	/// Specialization for [`crate::solidity_interface`] implementation,42	/// see comment in `impl AbiWrite for ResultWithPostInfo`43	fn to_result(&self) -> ResultWithPostInfo<AbiWriter> {44		let mut writer = AbiWriter::new();45		self.abi_write(&mut writer);46		Ok(writer.into())47	}48}