-
Notifications
You must be signed in to change notification settings - Fork 85
Land Builtin actors API MVP into next #850
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
Changes from all commits
a45d19e
2cd742a
2993625
43569bb
e8a521f
cd678de
dcb9afa
6174e61
4ba05f3
76ac0a5
c39312b
efe7c3c
dc5c6d9
d3f02cc
a739ec7
52a38b4
8b7cbf2
d0097ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ use num_traits::{FromPrimitive, Zero}; | |
use fil_actors_runtime::cbor::serialize; | ||
use fil_actors_runtime::runtime::{ActorCode, Runtime}; | ||
use fil_actors_runtime::{ | ||
actor_error, cbor, ActorContext, ActorError, AsActorError, SYSTEM_ACTOR_ADDR, | ||
actor_error, cbor, restrict_internal_api, ActorContext, ActorError, AsActorError, | ||
SYSTEM_ACTOR_ADDR, | ||
}; | ||
|
||
pub use self::state::State; | ||
|
@@ -42,9 +43,10 @@ lazy_static! { | |
* BigInt::from(1_000_000_000_000_000_000_000_i128) | ||
); | ||
} | ||
/// Static method numbers for builtin-actor private dispatch. | ||
/// The methods are also expected to be exposed via FRC-XXXX standard calling convention, | ||
/// with numbers determined by name. | ||
|
||
/// Datacap actor methods available | ||
/// Some methods are available under 2 method nums -- a static number for "private" builtin actor usage, | ||
/// and via FRC-0042 calling convention, with number determined by method name. | ||
#[derive(FromPrimitive)] | ||
#[repr(u64)] | ||
pub enum Method { | ||
|
@@ -65,6 +67,19 @@ pub enum Method { | |
Burn = 19, | ||
BurnFrom = 20, | ||
Allowance = 21, | ||
// Method numbers derived from FRC-0042 standards | ||
NameExported = frc42_dispatch::method_hash!("Name"), | ||
SymbolExported = frc42_dispatch::method_hash!("Symbol"), | ||
TotalSupplyExported = frc42_dispatch::method_hash!("TotalSupply"), | ||
BalanceOfExported = frc42_dispatch::method_hash!("BalanceOf"), | ||
TransferExported = frc42_dispatch::method_hash!("Transfer"), | ||
TransferFromExported = frc42_dispatch::method_hash!("TransferFrom"), | ||
IncreaseAllowanceExported = frc42_dispatch::method_hash!("IncreaseAllowance"), | ||
DecreaseAllowanceExported = frc42_dispatch::method_hash!("DecreaseAllowance"), | ||
RevokeAllowanceExported = frc42_dispatch::method_hash!("RevokeAllowance"), | ||
BurnExported = frc42_dispatch::method_hash!("Burn"), | ||
BurnFromExported = frc42_dispatch::method_hash!("BurnFrom"), | ||
AllowanceExported = frc42_dispatch::method_hash!("Allowance"), | ||
} | ||
|
||
pub struct Actor; | ||
|
@@ -452,6 +467,7 @@ impl ActorCode for Actor { | |
where | ||
RT: Runtime, | ||
{ | ||
restrict_internal_api(rt, method)?; | ||
// I'm trying to find a fixed template for these blocks so we can macro it. | ||
// Current blockers: | ||
// - the serialize method maps () to CBOR null (we want no bytes instead) | ||
|
@@ -469,51 +485,51 @@ impl ActorCode for Actor { | |
let ret = Self::destroy(rt, cbor::deserialize_params(params)?)?; | ||
serialize(&ret, "destroy result") | ||
} | ||
Some(Method::Name) => { | ||
Some(Method::Name) | Some(Method::NameExported) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we keeping the non-exported method numbers active? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a policy decision that built-in actors only call other built-in actors through their internal method numbers? If that's the case, I think it makes sense for uniformity, as otherwise we would see calls to exported and internal method sprinkled over this codebase. However, it might be a usability nit for explorers and other tooling to have two method numbers associated with the same exact behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
let ret = Self::name(rt)?; | ||
serialize(&ret, "name result") | ||
} | ||
Some(Method::Symbol) => { | ||
Some(Method::Symbol) | Some(Method::SymbolExported) => { | ||
let ret = Self::symbol(rt)?; | ||
serialize(&ret, "symbol result") | ||
} | ||
Some(Method::TotalSupply) => { | ||
Some(Method::TotalSupply) | Some(Method::TotalSupplyExported) => { | ||
let ret = Self::total_supply(rt, cbor::deserialize_params(params)?)?; | ||
serialize(&ret, "total_supply result") | ||
} | ||
Some(Method::BalanceOf) => { | ||
Some(Method::BalanceOf) | Some(Method::BalanceOfExported) => { | ||
let ret = Self::balance_of(rt, cbor::deserialize_params(params)?)?; | ||
serialize(&ret, "balance_of result") | ||
} | ||
Some(Method::Transfer) => { | ||
Some(Method::Transfer) | Some(Method::TransferExported) => { | ||
let ret = Self::transfer(rt, cbor::deserialize_params(params)?)?; | ||
serialize(&ret, "transfer result") | ||
} | ||
Some(Method::TransferFrom) => { | ||
Some(Method::TransferFrom) | Some(Method::TransferFromExported) => { | ||
let ret = Self::transfer_from(rt, cbor::deserialize_params(params)?)?; | ||
serialize(&ret, "transfer_from result") | ||
} | ||
Some(Method::IncreaseAllowance) => { | ||
Some(Method::IncreaseAllowance) | Some(Method::IncreaseAllowanceExported) => { | ||
let ret = Self::increase_allowance(rt, cbor::deserialize_params(params)?)?; | ||
serialize(&ret, "increase_allowance result") | ||
} | ||
Some(Method::DecreaseAllowance) => { | ||
Some(Method::DecreaseAllowance) | Some(Method::DecreaseAllowanceExported) => { | ||
let ret = Self::decrease_allowance(rt, cbor::deserialize_params(params)?)?; | ||
serialize(&ret, "decrease_allowance result") | ||
} | ||
Some(Method::RevokeAllowance) => { | ||
Some(Method::RevokeAllowance) | Some(Method::RevokeAllowanceExported) => { | ||
Self::revoke_allowance(rt, cbor::deserialize_params(params)?)?; | ||
Ok(RawBytes::default()) | ||
} | ||
Some(Method::Burn) => { | ||
Some(Method::Burn) | Some(Method::BurnExported) => { | ||
let ret = Self::burn(rt, cbor::deserialize_params(params)?)?; | ||
serialize(&ret, "burn result") | ||
} | ||
Some(Method::BurnFrom) => { | ||
Some(Method::BurnFrom) | Some(Method::BurnFromExported) => { | ||
let ret = Self::burn_from(rt, cbor::deserialize_params(params)?)?; | ||
serialize(&ret, "burn_from result") | ||
} | ||
Some(Method::Allowance) => { | ||
Some(Method::Allowance) | Some(Method::AllowanceExported) => { | ||
let ret = Self::allowance(rt, cbor::deserialize_params(params)?)?; | ||
serialize(&ret, "allowance result") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks redundant with 113 and on now that we made that part of the test use the exported method