Skip to content

Commit

Permalink
actor_name_by_code (#1218)
Browse files Browse the repository at this point in the history
Co-authored-by: /raw PONG _GHMoaCXLT <58883403+q9f@users.noreply.github.com>
  • Loading branch information
ec2 and q9f authored Oct 18, 2021
1 parent 5845cdf commit 6091097
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions vm/actor/src/builtin/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@

use cid::{multihash::MultihashDigest, Cid, Code::Identity, RAW};

pub const SYSTEM_ACTOR_CODE_ID_NAME: &str = "fil/4/system";
pub const INIT_ACTOR_CODE_ID_NAME: &str = "fil/4/init";
pub const CRON_ACTOR_CODE_ID_NAME: &str = "fil/4/cron";
pub const ACCOUNT_ACTOR_CODE_ID_NAME: &str = "fil/4/account";
pub const POWER_ACTOR_CODE_ID_NAME: &str = "fil/4/storagepower";
pub const MINER_ACTOR_CODE_ID_NAME: &str = "fil/4/storageminer";
pub const MARKET_ACTOR_CODE_ID_NAME: &str = "fil/4/storagemarket";
pub const PAYCH_ACTOR_CODE_ID_NAME: &str = "fil/4/paymentchannel";
pub const MULTISIG_ACTOR_CODE_ID_NAME: &str = "fil/4/multisig";
pub const REWARD_ACTOR_CODE_ID_NAME: &str = "fil/4/reward";
pub const VERIFREG_ACTOR_CODE_ID_NAME: &str = "fil/4/verifiedregistry";
pub const CHAOS_ACTOR_CODE_ID_NAME: &str = "fil/4/chaos";

lazy_static! {
pub static ref SYSTEM_ACTOR_CODE_ID: Cid = make_builtin(b"fil/5/system");
pub static ref INIT_ACTOR_CODE_ID: Cid = make_builtin(b"fil/5/init");
Expand Down Expand Up @@ -61,3 +74,22 @@ pub fn is_account_actor(code: &Cid) -> bool {
pub fn is_principal(code: &Cid) -> bool {
CALLER_TYPES_SIGNABLE.iter().any(|c| c == code)
}

/// Given an actor code Cid, returns the name of the actor.
pub fn actor_name_by_code(code: &Cid) -> Result<&str, String> {
match code {
x if x == &*SYSTEM_ACTOR_CODE_ID => Ok(SYSTEM_ACTOR_CODE_ID_NAME),
x if x == &*INIT_ACTOR_CODE_ID => Ok(INIT_ACTOR_CODE_ID_NAME),
x if x == &*CRON_ACTOR_CODE_ID => Ok(CRON_ACTOR_CODE_ID_NAME),
x if x == &*ACCOUNT_ACTOR_CODE_ID => Ok(ACCOUNT_ACTOR_CODE_ID_NAME),
x if x == &*POWER_ACTOR_CODE_ID => Ok(POWER_ACTOR_CODE_ID_NAME),
x if x == &*MINER_ACTOR_CODE_ID => Ok(MINER_ACTOR_CODE_ID_NAME),
x if x == &*MARKET_ACTOR_CODE_ID => Ok(MARKET_ACTOR_CODE_ID_NAME),
x if x == &*PAYCH_ACTOR_CODE_ID => Ok(PAYCH_ACTOR_CODE_ID_NAME),
x if x == &*MULTISIG_ACTOR_CODE_ID => Ok(MULTISIG_ACTOR_CODE_ID_NAME),
x if x == &*REWARD_ACTOR_CODE_ID => Ok(REWARD_ACTOR_CODE_ID_NAME),
x if x == &*VERIFREG_ACTOR_CODE_ID => Ok(VERIFREG_ACTOR_CODE_ID_NAME),
x if x == &*CHAOS_ACTOR_CODE_ID => Ok(CHAOS_ACTOR_CODE_ID_NAME),
_ => Err(format!("{} is not a valid code", code)),
}
}

0 comments on commit 6091097

Please sign in to comment.