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

difftreelog

source

crates/evm-coder/src/lib.rs1.4 KiBsourcehistory
1#![cfg_attr(not(feature = "std"), no_std)]2#[cfg(not(feature = "std"))]3extern crate alloc;45pub use evm_coder_macros::{event_topic, fn_selector, solidity_interface, solidity, ToLog};6pub mod abi;7pub mod events;8pub use events::ToLog;910/// Solidity type definitions11pub mod types {12	#![allow(non_camel_case_types)]1314	#[cfg(not(feature = "std"))]15	use alloc::{vec::Vec};16	use primitive_types::{U256, H160, H256};1718	pub type address = H160;1920	pub type uint8 = u8;21	pub type uint16 = u16;22	pub type uint32 = u32;23	pub type uint64 = u64;24	pub type uint128 = u128;25	pub type uint256 = U256;2627	pub type bytes4 = u32;2829	pub type topic = H256;3031	#[cfg(not(feature = "std"))]32	pub type string = ::alloc::string::String;33	#[cfg(feature = "std")]34	pub type string = ::std::string::String;35	pub type bytes = Vec<u8>;3637	pub type void = ();3839	//#region Special types40	/// Makes function payable41	pub type value = U256;42	/// Makes function caller-sensitive43	pub type caller = address;44	//#endregion4546	pub struct Msg<C> {47		pub call: C,48		pub caller: H160,49		pub value: U256,50	}51}5253#[cfg(test)]54mod tests {55	use super::*;5657	#[test]58	fn function_selector_generation() {59		assert_eq!(fn_selector!(transfer(address, uint256)), 0xa9059cbb);60	}6162	#[test]63	fn event_topic_generation() {64		assert_eq!(65			hex::encode(&event_topic!(Transfer(address, address, uint256))[..]),66			"ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",67		);68	}69}