1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2019-2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT
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();

    // we need to add manually init actors for V0.
    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)]
/// Checks if the provided actor code CID is valid for the given actor (any version).
pub fn [<is_ $actor:lower _actor>](actor_code_cid: &Cid) -> bool {
    [<$actor:upper _ACTOR_CIDS>]
        .iter()
        .any(|(_, cid)| cid == actor_code_cid)
}

#[allow(unused)]
/// Checks if the provided actor code CID and version are valid for the given actor.
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
);

// A special snowflake which has a slightly different type and and package name.
impl_actor_cids_type_actor!(VerifiedRegistry, Verifreg);