use cid::multihash::{Code, MultihashDigest as _};
use cid::Cid;
use fil_actors_shared::v11::runtime::builtins::Type;
use once_cell::sync::Lazy;
use paste::paste;
macro_rules! impl_actor_cids_type_actor {
($($actor_type:ident, $actor:ident),*) => {
$(
paste! {
static [<$actor:upper _ACTOR_CIDS>]: Lazy<Vec<(u64, Cid)>> = Lazy::new(|| {
let mut actors: Vec<_> = crate::networks::ACTOR_BUNDLES_METADATA
.values()
.filter_map(|bundle| {
if let Ok(cid) = bundle.manifest.get(Type::$actor_type) {
Some((bundle.actor_major_version().ok()?, cid))
} else {
None
}
})
.collect();
if Type::$actor_type == Type::Init {
let init = Cid::new_v1(fvm_ipld_encoding::IPLD_RAW, Code::Identity.digest(b"fil/1/init"));
actors.push((0, init));
}
actors
});
#[allow(unused)]
pub fn [<is_ $actor:lower _actor>](actor_code_cid: &Cid) -> bool {
[<$actor:upper _ACTOR_CIDS>]
.iter()
.any(|(_, cid)| cid == actor_code_cid)
}
#[allow(unused)]
pub fn [<is_ $actor:lower _cid_version>](actor_code_cid: &Cid, version: u64) -> bool {
[<$actor:upper _ACTOR_CIDS>]
.iter()
.any(|(v, cid)| *v == version && cid == actor_code_cid)
}
}
)*
};
}
macro_rules! impl_actor_cids {
($($actor:ident),*) => {
$(
impl_actor_cids_type_actor!($actor, $actor);
)*
};
}
impl_actor_cids!(
System,
Init,
Cron,
Account,
Power,
Miner,
Market,
PaymentChannel,
Multisig,
Reward,
DataCap,
Placeholder,
EVM,
EAM,
EthAccount
);
impl_actor_cids_type_actor!(VerifiedRegistry, Verifreg);