Skip to content

Commit fdcf50b

Browse files
authored
feat: refactor blockstore into associated type (#803)
And use `impl Runtime` where possible. We don't use this in `invoke_method` so implementers can name the runtime if desired.
1 parent fa22fb5 commit fdcf50b

File tree

20 files changed

+434
-1047
lines changed

20 files changed

+434
-1047
lines changed

actors/account/src/lib.rs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2019-2022 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4-
use fvm_ipld_blockstore::Blockstore;
54
use fvm_ipld_encoding::RawBytes;
65
use fvm_shared::address::{Address, Protocol};
76
use fvm_shared::crypto::signature::SignatureType::{Secp256k1, BLS};
@@ -42,11 +41,7 @@ pub struct Actor;
4241

4342
impl Actor {
4443
/// Constructor for Account actor
45-
pub fn constructor<BS, RT>(rt: &mut RT, address: Address) -> Result<(), ActorError>
46-
where
47-
BS: Blockstore,
48-
RT: Runtime<BS>,
49-
{
44+
pub fn constructor(rt: &mut impl Runtime, address: Address) -> Result<(), ActorError> {
5045
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
5146
match address.protocol() {
5247
Protocol::Secp256k1 | Protocol::BLS => {}
@@ -60,11 +55,7 @@ impl Actor {
6055
}
6156

6257
/// Fetches the pubkey-type address from this actor.
63-
pub fn pubkey_address<BS, RT>(rt: &mut RT) -> Result<Address, ActorError>
64-
where
65-
BS: Blockstore,
66-
RT: Runtime<BS>,
67-
{
58+
pub fn pubkey_address(rt: &mut impl Runtime) -> Result<Address, ActorError> {
6859
rt.validate_immediate_caller_accept_any()?;
6960
let st: State = rt.state()?;
7061
Ok(st.address)
@@ -73,14 +64,10 @@ impl Actor {
7364
/// Authenticates whether the provided signature is valid for the provided message.
7465
/// Should be called with the raw bytes of a signature, NOT a serialized Signature object that includes a SignatureType.
7566
/// Errors with USR_ILLEGAL_ARGUMENT if the authentication is invalid.
76-
pub fn authenticate_message<BS, RT>(
77-
rt: &mut RT,
67+
pub fn authenticate_message(
68+
rt: &mut impl Runtime,
7869
params: AuthenticateMessageParams,
79-
) -> Result<(), ActorError>
80-
where
81-
BS: Blockstore,
82-
RT: Runtime<BS>,
83-
{
70+
) -> Result<(), ActorError> {
8471
rt.validate_immediate_caller_accept_any()?;
8572
let st: State = rt.state()?;
8673
let address = st.address;
@@ -104,28 +91,23 @@ impl Actor {
10491
}
10592

10693
// Always succeeds, accepting any transfers.
107-
pub fn universal_receiver_hook<BS, RT>(
108-
rt: &mut RT,
94+
pub fn universal_receiver_hook(
95+
rt: &mut impl Runtime,
10996
_params: &RawBytes,
110-
) -> Result<(), ActorError>
111-
where
112-
BS: Blockstore,
113-
RT: Runtime<BS>,
114-
{
97+
) -> Result<(), ActorError> {
11598
rt.validate_immediate_caller_accept_any()?;
11699
Ok(())
117100
}
118101
}
119102

120103
impl ActorCode for Actor {
121-
fn invoke_method<BS, RT>(
104+
fn invoke_method<RT>(
122105
rt: &mut RT,
123106
method: MethodNum,
124107
params: &RawBytes,
125108
) -> Result<RawBytes, ActorError>
126109
where
127-
BS: Blockstore,
128-
RT: Runtime<BS>,
110+
RT: Runtime,
129111
{
130112
match FromPrimitive::from_u64(method) {
131113
Some(Method::Constructor) => {

actors/cron/src/lib.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use fil_actors_runtime::runtime::{ActorCode, Runtime};
55
use fil_actors_runtime::{actor_error, cbor, ActorError, SYSTEM_ACTOR_ADDR};
6-
use fvm_ipld_blockstore::Blockstore;
6+
77
use fvm_ipld_encoding::tuple::*;
88
use fvm_ipld_encoding::RawBytes;
99
use fvm_shared::econ::TokenAmount;
@@ -42,23 +42,15 @@ pub struct ConstructorParams {
4242
pub struct Actor;
4343
impl Actor {
4444
/// Constructor for Cron actor
45-
fn constructor<BS, RT>(rt: &mut RT, params: ConstructorParams) -> Result<(), ActorError>
46-
where
47-
BS: Blockstore,
48-
RT: Runtime<BS>,
49-
{
45+
fn constructor(rt: &mut impl Runtime, params: ConstructorParams) -> Result<(), ActorError> {
5046
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
5147
rt.create(&State { entries: params.entries })?;
5248
Ok(())
5349
}
5450
/// Executes built-in periodic actions, run at every Epoch.
5551
/// epoch_tick(r) is called after all other messages in the epoch have been applied.
5652
/// This can be seen as an implicit last message.
57-
fn epoch_tick<BS, RT>(rt: &mut RT) -> Result<(), ActorError>
58-
where
59-
BS: Blockstore,
60-
RT: Runtime<BS>,
61-
{
53+
fn epoch_tick(rt: &mut impl Runtime) -> Result<(), ActorError> {
6254
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
6355

6456
let st: State = rt.state()?;
@@ -83,14 +75,13 @@ impl Actor {
8375
}
8476

8577
impl ActorCode for Actor {
86-
fn invoke_method<BS, RT>(
78+
fn invoke_method<RT>(
8779
rt: &mut RT,
8880
method: MethodNum,
8981
params: &RawBytes,
9082
) -> Result<RawBytes, ActorError>
9183
where
92-
BS: Blockstore,
93-
RT: Runtime<BS>,
84+
RT: Runtime,
9485
{
9586
match FromPrimitive::from_u64(method) {
9687
Some(Method::Constructor) => {

0 commit comments

Comments
 (0)