alloy_primitives/
aliases.rs

1//! Type aliases for common primitive types.
2
3use crate::{FixedBytes, Signed, Uint};
4
5pub use ruint::aliases::{U0, U1, U1024, U2048, U320, U384, U4096, U448};
6
7macro_rules! int_aliases {
8    ($($unsigned:ident, $signed:ident<$BITS:literal, $LIMBS:literal>),* $(,)?) => {$(
9        #[doc = concat!($BITS, "-bit [unsigned integer type][Uint], consisting of ", $LIMBS, ", 64-bit limbs.")]
10        pub type $unsigned = Uint<$BITS, $LIMBS>;
11
12        #[doc = concat!($BITS, "-bit [signed integer type][Signed], consisting of ", $LIMBS, ", 64-bit limbs.")]
13        pub type $signed = Signed<$BITS, $LIMBS>;
14
15        const _: () = assert!($LIMBS == ruint::nlimbs($BITS));
16    )*};
17}
18
19/// The 0-bit signed integer type, capable of representing 0.
20pub type I0 = Signed<0, 0>;
21
22/// The 1-bit signed integer type, capable of representing 0 and -1.
23pub type I1 = Signed<1, 1>;
24
25int_aliases! {
26      U8,   I8<  8, 1>,
27     U16,  I16< 16, 1>,
28     U24,  I24< 24, 1>,
29     U32,  I32< 32, 1>,
30     U40,  I40< 40, 1>,
31     U48,  I48< 48, 1>,
32     U56,  I56< 56, 1>,
33     U64,  I64< 64, 1>,
34
35     U72,  I72< 72, 2>,
36     U80,  I80< 80, 2>,
37     U88,  I88< 88, 2>,
38     U96,  I96< 96, 2>,
39    U104, I104<104, 2>,
40    U112, I112<112, 2>,
41    U120, I120<120, 2>,
42    U128, I128<128, 2>,
43
44    U136, I136<136, 3>,
45    U144, I144<144, 3>,
46    U152, I152<152, 3>,
47    U160, I160<160, 3>,
48    U168, I168<168, 3>,
49    U176, I176<176, 3>,
50    U184, I184<184, 3>,
51    U192, I192<192, 3>,
52
53    U200, I200<200, 4>,
54    U208, I208<208, 4>,
55    U216, I216<216, 4>,
56    U224, I224<224, 4>,
57    U232, I232<232, 4>,
58    U240, I240<240, 4>,
59    U248, I248<248, 4>,
60    U256, I256<256, 4>,
61
62    U512, I512<512, 8>,
63}
64
65macro_rules! fixed_bytes_aliases {
66    ($($(#[$attr:meta])* $name:ident<$N:literal>),* $(,)?) => {$(
67        #[doc = concat!($N, "-byte [fixed byte-array][FixedBytes] type.")]
68        $(#[$attr])*
69        pub type $name = FixedBytes<$N>;
70    )*};
71}
72
73fixed_bytes_aliases! {
74    B8<1>,
75    B16<2>,
76    B32<4>,
77    B64<8>,
78    B96<12>,
79    B128<16>,
80    /// See [`crate::B160`] as to why you likely want to use
81    /// [`Address`](crate::Address) instead.
82    #[doc(hidden)]
83    B160<20>,
84    B192<24>,
85    B224<28>,
86    B256<32>,
87    B512<64>,
88    B1024<128>,
89    B2048<256>,
90}
91
92/// A block hash.
93pub type BlockHash = B256;
94
95/// A block number.
96pub type BlockNumber = u64;
97
98/// A block timestamp.
99pub type BlockTimestamp = u64;
100
101/// A transaction hash is a keccak hash of an RLP encoded signed transaction.
102#[doc(alias = "TransactionHash")]
103pub type TxHash = B256;
104
105/// The sequence number of all existing transactions.
106#[doc(alias = "TransactionNumber")]
107pub type TxNumber = u64;
108
109/// The nonce of a transaction.
110#[doc(alias = "TransactionNonce")]
111pub type TxNonce = u64;
112
113/// The index of transaction in a block.
114#[doc(alias = "TransactionIndex")]
115pub type TxIndex = u64;
116
117/// Chain identifier type (introduced in EIP-155).
118pub type ChainId = u64;
119
120/// An account storage key.
121pub type StorageKey = B256;
122
123/// An account storage value.
124pub type StorageValue = U256;
125
126/// Solidity contract functions are addressed using the first four bytes of the
127/// Keccak-256 hash of their signature.
128pub type Selector = FixedBytes<4>;