Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actor Name By Code #1218

Merged
merged 2 commits into from
Oct 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)),
}
}