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

Move CodeID and ActorState to vm crate #271

Merged
merged 4 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ num-bigint = { path = "../math/bigint", package = "forest_bigint" }
address = { package = "forest_address", path = "./address" }
encoding = { package = "forest_encoding", path = "../encoding" }
serde = { version = "1.0", features = ["derive"] }
cid = { package = "forest_cid", path = "../ipld/cid" }

5 changes: 3 additions & 2 deletions vm/actor/src/builtin/init.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::{ActorID, CodeID};
use vm::{ExitCode, MethodNum, Serialized, METHOD_CONSTRUCTOR, METHOD_PLACEHOLDER};
use vm::{
ActorID, CodeID, ExitCode, MethodNum, Serialized, METHOD_CONSTRUCTOR, METHOD_PLACEHOLDER,
};

use address::Address;
use num_derive::FromPrimitive;
Expand Down
32 changes: 0 additions & 32 deletions vm/actor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,9 @@
// SPDX-License-Identifier: Apache-2.0, MIT

mod builtin;
mod code;

pub use self::builtin::*;
pub use self::code::*;
use cid::Cid;
use encoding::Cbor;
use num_bigint::BigUint;
use serde::{Deserialize, Serialize};

/// Identifier for Actors, includes builtin and initialized actors
#[derive(PartialEq, Eq, Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub struct ActorID(u64);

impl Cbor for ActorID {}

/// State of all actor implementations
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ActorState {
pub code_id: CodeID,
pub state: Cid,
pub balance: BigUint,
pub sequence: u64,
}

impl ActorState {
/// Constructor for actor state
pub fn new(code_id: CodeID, state: Cid, balance: BigUint, sequence: u64) -> Self {
Self {
code_id,
state,
balance,
sequence,
}
}
}

// TODO implement Actor for builtin actors on finished spec
/// Actor trait which defines the common functionality of system Actors
Expand Down
1 change: 1 addition & 0 deletions vm/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ cid = { package = "forest_cid", path = "../../ipld/cid" }
ipld_blockstore = { path = "../../ipld/blockstore" }
clock = { path = "../../node/clock" }
forest_encoding = { path = "../../encoding"}
state_tree = { path = "../state_tree" }
35 changes: 35 additions & 0 deletions vm/src/actor_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::CodeID;
use cid::Cid;
use encoding::Cbor;
use num_bigint::BigUint;
use serde::{Deserialize, Serialize};

/// Identifier for Actors, includes builtin and initialized actors
#[derive(PartialEq, Eq, Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub struct ActorID(pub u64);

impl Cbor for ActorID {}

/// State of all actor implementations
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ActorState {
pub code_id: CodeID,
pub state: Cid,
pub balance: BigUint,
pub sequence: u64,
}

impl ActorState {
/// Constructor for actor state
pub fn new(code_id: CodeID, state: Cid, balance: BigUint, sequence: u64) -> Self {
Self {
code_id,
state,
balance,
sequence,
}
}
}
File renamed without changes.
4 changes: 4 additions & 0 deletions vm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

mod actor_state;
mod code;
mod exit_code;
mod invoc;
mod method;
mod token;

pub use self::actor_state::*;
pub use self::code::*;
pub use self::exit_code::*;
pub use self::invoc::*;
pub use self::method::*;
Expand Down
1 change: 0 additions & 1 deletion vm/state_tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2018"

[dependencies]
actor = { path = "../actor" }
address = { package = "forest_address", path = "../address" }
vm = { path = "../../vm" }
cid = { package = "forest_cid", path = "../../ipld/cid" }
Expand Down
4 changes: 2 additions & 2 deletions vm/state_tree/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use actor::ActorState;
use address::Address;
use std::collections::HashMap;
use vm::ActorState;

pub trait StateTree {
fn get_actor(&self, addr: &Address) -> Option<ActorState>;
Expand Down Expand Up @@ -66,9 +66,9 @@ impl StateTree for HamtStateTree {
#[cfg(test)]
mod tests {
use super::*;
use actor::{ActorState, CodeID};
use cid::Cid;
use num_bigint::BigUint;
use vm::{ActorState, CodeID};

#[test]
fn get_set_cache() {
Expand Down