use frc42_dispatch::method_hash;
use fvm_actor_utils::receiver::{ReceiverHook, ReceiverHookError, ReceiverType, RecipientData};
use fvm_ipld_encoding::RawBytes;
use fvm_shared::{address::Address, econ::TokenAmount, ActorID};
use serde_tuple::{Deserialize_tuple, Serialize_tuple};
pub const FRC46_TOKEN_TYPE: ReceiverType = method_hash!("FRC46") as u32;
pub trait FRC46ReceiverHook<T: RecipientData> {
fn new_frc46(
address: Address,
frc46_params: FRC46TokenReceived,
result_data: T,
) -> std::result::Result<ReceiverHook<T>, ReceiverHookError>;
}
impl<T: RecipientData> FRC46ReceiverHook<T> for ReceiverHook<T> {
fn new_frc46(
address: Address,
frc46_params: FRC46TokenReceived,
result_data: T,
) -> std::result::Result<ReceiverHook<T>, ReceiverHookError> {
Ok(ReceiverHook::new(
address,
RawBytes::serialize(frc46_params)?,
FRC46_TOKEN_TYPE,
result_data,
))
}
}
#[derive(Serialize_tuple, Deserialize_tuple, PartialEq, Eq, Clone, Debug)]
pub struct FRC46TokenReceived {
pub from: ActorID,
pub to: ActorID,
pub operator: ActorID,
pub amount: TokenAmount,
pub operator_data: RawBytes,
pub token_data: RawBytes,
}