use codec::{Decode, Encode};
use scale_info::{
prelude::{fmt::Debug, vec::Vec},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
#[derive(PartialEq, Clone, Encode, Decode, Eq, Hash, Debug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum HasherAlgo {
Blake2,
Keccak256,
}
#[derive(PartialEq, Clone, Encode, Decode, Eq, Hash, Debug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum CryptoAlgo {
Ed25519,
Sr25519,
Ecdsa,
}
#[derive(PartialEq, Clone, Encode, Decode, Eq, Hash, Debug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct GatewayABISpecs {
pub block_number_size: u8,
pub hash_size: u8,
pub hasher: u8,
pub crypto: u8,
pub address_size: u8,
pub value_type_size: u8,
}
#[derive(PartialEq, Clone, Encode, Decode, Eq, Hash, Debug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct GatewayABIConfig {
pub block_number_type_size: u16,
pub hash_size: u16,
pub hasher: HasherAlgo,
pub crypto: CryptoAlgo,
pub address_length: u16,
pub value_type_size: u16,
}
impl Default for GatewayABIConfig {
fn default() -> GatewayABIConfig {
GatewayABIConfig {
block_number_type_size: 32,
hash_size: 32,
hasher: HasherAlgo::Blake2,
crypto: CryptoAlgo::Sr25519,
address_length: 32, value_type_size: 16, }
}
}
#[derive(PartialEq, Clone, Encode, Decode, Eq, Hash, Debug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct ContractActionDesc<Hash, TargetId, AccountId> {
pub action_id: Hash,
pub target_id: Option<TargetId>,
pub to: Option<AccountId>,
}
pub fn decode_buf2val<D: Decode>(buf: Vec<u8>) -> Result<D, &'static str> {
D::decode(&mut &buf[..]).map_err(|_| "Decoding error: decode_buf2val")
}