introduce NodeWasmService trait

This commit is contained in:
vms 2020-06-12 01:59:50 +03:00
parent 06de91968e
commit 9da7cc0957
7 changed files with 55 additions and 12 deletions

4
Cargo.lock generated
View File

@ -517,8 +517,8 @@ dependencies = [
] ]
[[package]] [[package]]
name = "ipfs_node" name = "ipfs_node_service"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"cmd_lib", "cmd_lib",
"fce", "fce",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "ipfs_node" name = "ipfs_node_service"
version = "0.1.0" version = "0.2.0"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
edition = "2018" edition = "2018"

View File

@ -13,10 +13,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#![feature(pattern)]
mod node; mod node;
mod node_wasm_service;
pub use fce::IValue; pub use fce::IValue;
pub use node::*; pub use node::IpfsNode;
pub use node::NodeError;
pub use node::NodePublicInterface;
pub use node::NodeModulePublicInterface;
pub use node_wasm_service::NodeWasmService;

View File

@ -15,9 +15,15 @@
*/ */
mod node; mod node;
mod node_wasm_service;
pub use node::IpfsNode;
pub use node::NodeError;
pub use node::NodePublicInterface;
pub use node::NodeModulePublicInterface;
pub use node_wasm_service::NodeWasmService;
use fce::IValue; use fce::IValue;
use node::IpfsNode;
use std::path::PathBuf; use std::path::PathBuf;

View File

@ -46,7 +46,7 @@ impl IpfsNode {
for entry in fs::read_dir(core_modules_dir.into())? { for entry in fs::read_dir(core_modules_dir.into())? {
let path = entry?.path(); let path = entry?.path();
if path.is_dir() { if path.is_dir() {
// just pass directories // just skip directories
continue; continue;
} }
@ -74,8 +74,10 @@ impl IpfsNode {
rpc_module_config, rpc_module_config,
}) })
} }
}
pub fn rpc_call( impl crate::node_wasm_service::NodeWasmService for IpfsNode {
fn rpc_call(
&mut self, &mut self,
wasm_rpc: &[u8], wasm_rpc: &[u8],
func_name: &str, func_name: &str,
@ -92,7 +94,7 @@ impl IpfsNode {
Ok(call_result) Ok(call_result)
} }
pub fn get_interface(&self) -> NodePublicInterface { fn get_interface(&self) -> NodePublicInterface {
let mut modules = Vec::with_capacity(self.module_names.len()); let mut modules = Vec::with_capacity(self.module_names.len());
for module_name in self.module_names.iter() { for module_name in self.module_names.iter() {

View File

@ -17,11 +17,11 @@
mod config; mod config;
mod errors; mod errors;
mod imports; mod imports;
mod node; mod ipfs_node;
mod node_public_interface; mod node_public_interface;
mod utils; mod utils;
pub use node::IpfsNode; pub use ipfs_node::IpfsNode;
pub use errors::NodeError; pub use errors::NodeError;
pub use node_public_interface::NodePublicInterface; pub use node_public_interface::NodePublicInterface;
pub use node_public_interface::NodeModulePublicInterface; pub use node_public_interface::NodeModulePublicInterface;

View File

@ -0,0 +1,31 @@
/*
* Copyright 2020 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::NodeError;
use crate::NodePublicInterface;
use fce::IValue;
pub trait NodeWasmService {
fn rpc_call(
&mut self,
wasm_rpc: &[u8],
func_name: &str,
args: &[IValue],
) -> Result<Vec<IValue>, NodeError>;
fn get_interface(&self) -> NodePublicInterface;
}