Skip to content

Commit

Permalink
chore: restructure pallet part 2, workspace manifest file (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoks authored Mar 1, 2024
1 parent 440b53c commit f42e934
Show file tree
Hide file tree
Showing 76 changed files with 146 additions and 157 deletions.
93 changes: 31 additions & 62 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,74 +1,43 @@
[package]
name = "pallet-move"
version = "0.1.0"
authors = ["Eiger <[email protected]>"]
[workspace]
members = [
"pallet",
"rpc",
]
resolver = "2"

[workspace.package]
edition = "2021"
authors = ["Eiger <[email protected]>"]
readme = "README.md"

repository = "https://github.com/eigerco/substrate-movevm-pallet"
description = "MoveVM support pallet"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
[workspace.dependencies]
# crates.io
anyhow = { version = "1.0", default-features = false }
bcs = { git = "https://github.com/eigerco/bcs.git", default-features = false, branch = "master" }
blake2 = { version = "0.10", default-features = false }
codec = { package = "parity-scale-codec", version = "3.6", default-features = false, features = ["derive"] }
hashbrown = { version = "0.14" }
frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
frame-support = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
frame-system = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
hex = { version = "0.4", default-features = false }
jsonrpsee = { version = "0.16", features = ["server", "macros"] }
rand = { version = "0.8", default-features = false }
scale-info = { version = "2.10", default-features = false, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
sp-core = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
sp-std = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }

# MoveVM dependencies
move-core-types = { default-features = false, git = "https://github.com/eigerco/substrate-move.git", branch = "main", features = ["address32"] }

# MoveVM backend dependency
move-vm-backend = { default-features = false, git = "https://github.com/eigerco/substrate-move.git", branch = "main" }
move-vm-backend-common = { default-features = false, git = "https://github.com/eigerco/substrate-move.git", branch = "main" }

[dev-dependencies]
hex = "0.4"
rand = "0.8"
move-stdlib = { git = "https://github.com/eigerco/substrate-move.git", features = ["stdlib-bytecode"] }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }

[features]
default = ["std"]
std = [
"anyhow/std",
"blake2/std",
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"serde/std",
"sp-std/std",
"move-core-types/std",
"move-vm-backend/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]

# Builds move projects for test purposes.
#
# The move projects in `tests/assets/move-projects/` are not built by default without this flag
# since rebuilding those tests takes lots of time.
build-move-projects-for-test = []
# Polkadot crates
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }

# Eiger crates
move-core-types = { git = "https://github.com/eigerco/substrate-move.git", branch = "main", features = ["address32"], default-features = false }
move-stdlib = { git = "https://github.com/eigerco/substrate-move.git", features = ["stdlib-bytecode"], default-features = false }
move-vm-backend = { git = "https://github.com/eigerco/substrate-move.git", branch = "main", default-features = false }
move-vm-backend-common = { git = "https://github.com/eigerco/substrate-move.git", branch = "main", default-features = false }
5 changes: 2 additions & 3 deletions doc/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,8 @@ In order to keep things separated and easy to maintain, we propose to create a s

The package and repository structure will look like this:
- [`pallet-move`][pallet-move] - contains the pallet codebase, tests, and documentation.
- `pallet-move` - the main pallet crate.
- `pallet-move-rpc` - the RPC MoveVM pallet crate - placed under `src/rpc` directory. It contains the RPC codebase, tests, and documentation.
- `pallet-move-runtime-api` - the runtime API MoveVM pallet crate - placed under `src/rpc/runtime-api` directory.
- `pallet-move` - the main pallet crate with the runtime-api - placed under `pallet`.
- `pallet-move-rpc` - the RPC MoveVM pallet crate - placed under `rpc` directory. It contains the RPC codebase, tests, and documentation.
- [`substrate-move`][substrate-move] - Move language fork. Contains all the Move crates and the toolchain.
- [`substrate-node-template-move-vm-test`][substrate-node-template-move-vm-test] - testing node repository - contains the node codebase, tests, and documentation. Work is done in the `pallet-move` branch.
- [`bcs`][bcs] - Rust implementation of the Binary Canonical Serialization (BCS) format - a crate which is used by some Move crates.
Expand Down
70 changes: 70 additions & 0 deletions pallet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[package]
name = "pallet-move"
version = "0.1.0"
description = "MoveVM support pallet"
authors = { workspace = true }
edition = { workspace = true }
readme = { workspace = true }
repository = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
anyhow = { workspace = true }
bcs = { workspace = true }
blake2 = { workspace = true }
codec = { workspace = true }
hashbrown = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
move-core-types = { workspace = true }
move-vm-backend = { workspace = true }
move-vm-backend-common = { workspace = true }
scale-info = { workspace = true }
serde = { workspace = true }
sp-api = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

[dev-dependencies]
hex = { workspace = true }
rand = { workspace = true }
move-stdlib = { workspace = true }
sp-io = { workspace = true }
pallet-balances = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"anyhow/std",
"blake2/std",
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"serde/std",
"sp-std/std",
"move-core-types/std",
"move-vm-backend/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]

# Builds move projects for test purposes.
#
# The move projects in `tests/assets/move-projects/` are not built by default without this flag
# since rebuilding those tests takes lots of time.
build-move-projects-for-test = []
File renamed without changes.
23 changes: 15 additions & 8 deletions rpc/runtime-api/src/lib.rs → pallet/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

extern crate alloc;

pub mod types;

use alloc::{string::String, vec::Vec};

use codec::{Decode, Encode};
use frame_support::weights::Weight;
pub use pallet_move::pallet::ModuleAbi;
use sp_runtime::{scale_info::TypeInfo, DispatchError};

pub use crate::types::MoveApiEstimation;
pub use move_vm_backend_common::abi::ModuleAbi;

/// Gas estimation information.
#[derive(Clone, PartialEq, Debug, Encode, Decode, TypeInfo)]
pub struct MoveApiEstimation {
/// Gas used.
pub gas_used: u64,
/// Status code for the MoveVM execution.
pub vm_status_code: u64,
}

// Here we declare the runtime API. It is implemented it the `impl` block in
// runtime file (the `runtime/src/lib.rs` of the node)
Expand All @@ -24,13 +31,13 @@ sp_api::decl_runtime_apis! {
fn weight_to_gas(weight: Weight) -> u64;

// Estimate gas for publishing a module.
fn estimate_gas_publish_module(account: AccountId, bytecode: Vec<u8>) -> Result<MoveApiEstimation, sp_runtime::DispatchError>;
fn estimate_gas_publish_module(account: AccountId, bytecode: Vec<u8>) -> Result<MoveApiEstimation, DispatchError>;

// Estimate gas for publishing a bundle.
fn estimate_gas_publish_bundle(account: AccountId, bytecode: Vec<u8>) -> Result<MoveApiEstimation, sp_runtime::DispatchError>;
fn estimate_gas_publish_bundle(account: AccountId, bytecode: Vec<u8>) -> Result<MoveApiEstimation, DispatchError>;

// Estimate gas for script execution.
fn estimate_gas_execute_script(account: AccountId, transaction: Vec<u8>, cheque_limit: u128) -> Result<MoveApiEstimation, sp_runtime::DispatchError>;
fn estimate_gas_execute_script(account: AccountId, transaction: Vec<u8>, cheque_limit: u128) -> Result<MoveApiEstimation, DispatchError>;

// Get module binary by its address.
fn get_module(address: String, name: String) -> Result<Option<Vec<u8>>, Vec<u8>>;
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions src/lib.rs → pallet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod api;
pub mod balance;
#[cfg(all(test, feature = "runtime-benchmarks"))]
mod benchmarking;
Expand Down Expand Up @@ -39,9 +40,9 @@ pub mod pallet {
use move_vm_backend::{
balance::BalanceHandler, genesis::VmGenesisConfig, types::VmResult, Mvm,
};
use move_vm_backend_common::abi::ModuleAbi;
pub use move_vm_backend_common::{
abi::ModuleAbi, bytecode::verify_script_integrity_and_check_signers,
types::ScriptTransaction,
bytecode::verify_script_integrity_and_check_signers, types::ScriptTransaction,
};
use sp_core::crypto::AccountId32;
use sp_std::{vec, vec::Vec};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 14 additions & 15 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
[package]
name = "pallet-move-rpc"
version = "0.1.0"
authors = ["Eiger <[email protected]>"]
edition = "2021"
description = 'RPC methods for the Move pallet'
description = "RPC for the Move Pallet"
authors = { workspace = true }
edition = { workspace = true }
readme = { workspace = true }
repository = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6", default-features = false, features = ["derive"] }
serde = { version = "1.0", features = [ "derive" ], default-features = false }
jsonrpsee = { version = "0.16", features = ["server", "macros"] }
codec = { workspace = true }
serde = { workspace = true }
frame-support = { workspace = true }
jsonrpsee = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-runtime = { workspace = true }

# Substrate packages
frame-support = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
sp-api = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
sp-blockchain = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0" }

# local packages
pallet-move-runtime-api = { path = "./runtime-api", default-features = false }
pallet-move = { path = "../pallet" }

[features]
default = ["std"]
std = [
"sp-api/std",
"sp-runtime/std",
"pallet-move-runtime-api/std"
"pallet-move/std"
]
10 changes: 0 additions & 10 deletions rpc/runtime-api/.gitignore

This file was deleted.

28 changes: 0 additions & 28 deletions rpc/runtime-api/Cargo.toml

This file was deleted.

11 changes: 0 additions & 11 deletions rpc/runtime-api/src/types.rs

This file was deleted.

29 changes: 11 additions & 18 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use jsonrpsee::{
proc_macros::rpc,
types::error::{CallError, ErrorObject},
};
pub use pallet_move_runtime_api::MoveApi as MoveRuntimeApi;
use pallet_move_runtime_api::{ModuleAbi, MoveApiEstimation};
pub use pallet_move::api::{ModuleAbi, MoveApi as MoveRuntimeApi, MoveApiEstimation};
use serde::{Deserialize, Serialize};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
Expand Down Expand Up @@ -272,14 +271,11 @@ mod tests {
let err_str_tst = "\"\\\"test\\\"\"";
let res = runtime_error_into_rpc_err(err_str);
match res {
JsonRpseeError::Call(err) => match err {
CallError::Custom(err) => {
assert_eq!(err.code(), RUNTIME_ERROR);
assert_eq!(err.message(), "Runtime error");
assert_eq!(err.data().unwrap().get(), err_str_tst)
}
_ => panic!("Wrong error type"),
},
JsonRpseeError::Call(CallError::Custom(err)) => {
assert_eq!(err.code(), RUNTIME_ERROR);
assert_eq!(err.message(), "Runtime error");
assert_eq!(err.data().unwrap().get(), err_str_tst);
}
_ => panic!("Wrong error type"),
}
}
Expand All @@ -290,14 +286,11 @@ mod tests {
let err_str_tst = "\"\\\"\\\"\"";
let res = runtime_error_into_rpc_err(err_str);
match res {
JsonRpseeError::Call(err) => match err {
CallError::Custom(err) => {
assert_eq!(err.code(), RUNTIME_ERROR);
assert_eq!(err.message(), "Runtime error");
assert_eq!(err.data().unwrap().get(), err_str_tst)
}
_ => panic!("Wrong error type"),
},
JsonRpseeError::Call(CallError::Custom(err)) => {
assert_eq!(err.code(), RUNTIME_ERROR);
assert_eq!(err.message(), "Runtime error");
assert_eq!(err.data().unwrap().get(), err_str_tst);
}
_ => panic!("Wrong error type"),
}
}
Expand Down

0 comments on commit f42e934

Please sign in to comment.