Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
improved resolve address and additional methods
Browse files Browse the repository at this point in the history
  • Loading branch information
adlrocha committed Jul 4, 2023
1 parent bdebcd3 commit 032feee
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions runtime/src/runtime/fvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_ipld_encoding::{to_vec, CborStore, DAG_CBOR};
use fvm_sdk as fvm;
use fvm_sdk::NO_DATA_BLOCK_ID;
use fvm_shared::address::Address;
use fvm_shared::address::{Address, Protocol};
use fvm_shared::clock::ChainEpoch;
use fvm_shared::crypto::signature::Signature;
use fvm_shared::econ::TokenAmount;
Expand Down Expand Up @@ -430,21 +430,46 @@ fn init_logging() {
}
}

/// Resolves the SECP or BLS public key of an account actor ID address.
pub fn resolve_secp_bls(rt: &mut impl Runtime, addr: &Address) -> Result<Address, ActorError> {
let resolved = match rt.resolve_address(addr) {
// return directly if it is already a public key
match addr.protocol() {
Protocol::Secp256k1 | Protocol::BLS => Ok(addr.clone()),
Protocol::ID => {
let ret = rt.send(
&addr,
PUBLIC_RESOLVE_ADDRESS_METHOD,
None,
TokenAmount::zero(),
)?;
deserialize_block(ret)
}
_ => Err(ActorError::illegal_argument(String::from(
"address type not compatible",
))),
}
}

pub fn equal_account_id(
rt: &mut impl Runtime,
a: &Address,
b: &Address,
) -> Result<bool, ActorError> {
let a_id = match rt.resolve_address(a) {
Some(id) => id,
None => {
return Err(ActorError::illegal_argument(String::from(
"couldn't resolve actor address",
)))
}
};
let b_id = match rt.resolve_address(b) {
Some(id) => id,
None => {
return Err(ActorError::illegal_argument(String::from(
"couldn't resolve actor address",
)))
}
};
let ret = rt.send(
&resolved,
PUBLIC_RESOLVE_ADDRESS_METHOD,
None,
TokenAmount::zero(),
)?;

deserialize_block(ret)
Ok(a_id == b_id)
}

0 comments on commit 032feee

Please sign in to comment.