#![allow(clippy::assign_op_pattern)]
#![allow(clippy::ptr_offset_with_cast)]
use crate::{Bytes, Bytes32};
use borsh::{BorshDeserialize, BorshSerialize};
use std::io;
use uint::construct_uint;
pub type Address = [u8; 20];
pub type FixedBytes = Vec<u8>;
pub type Uint = U256;
pub type Word = [u8; 32];
pub type Int = Uint;
construct_uint! {
pub struct U256(4);
}
impl BorshDeserialize for U256 {
fn deserialize(bytes: &mut &[u8]) -> Result<Self, io::Error> {
let values: [u8; 32] = BorshDeserialize::deserialize(bytes)?;
Ok(U256::from_big_endian(&values))
}
}
impl BorshSerialize for U256 {
fn serialize<W>(&self, writer: &mut W) -> Result<(), io::Error>
where
W: io::Write,
{
let mut v = [0u8; 32];
self.to_big_endian(&mut v);
BorshSerialize::serialize(&v, writer)
}
}
impl From<&U256> for Bytes32 {
fn from(u: &U256) -> Self {
let mut v = Bytes32::default();
u.to_big_endian(&mut v);
v
}
}
#[derive(Debug, PartialEq, Clone)]
pub enum Token {
Address(Address),
FixedBytes(FixedBytes),
Bytes(Bytes),
Uint(Uint),
Int(Int),
String(String),
}
#[derive(PartialEq)]
pub enum ParamType {
Address,
Bytes,
Uint(usize),
Int(usize),
String,
FixedBytes(usize),
}
impl ParamType {
pub fn is_empty_bytes_valid_encoding(&self) -> bool {
match self {
ParamType::FixedBytes(len) => *len == 0,
_ => false,
}
}
}