Files
marine/examples/ipfs_node/src/main.rs

49 lines
1.5 KiB
Rust
Raw Normal View History

2020-06-06 21:34:13 +03:00
/*
* 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 fluence_faas::FluenceFaaS;
use fluence_faas::IValue;
2020-06-06 21:34:13 +03:00
use std::path::PathBuf;
2020-06-16 11:15:56 +03:00
const IPFS_MODULES_DIR: &str = "wasm/artifacts/wasm_modules";
const IPFS_MODULES_CONFIG_PATH: &str = "Config.toml";
2020-06-16 11:15:56 +03:00
const IPFS_RPC: &str = "wasm/artifacts/wasm_ipfs_rpc_wit.wasi.wasm";
2020-06-06 21:34:13 +03:00
fn main() {
let ipfs_rpc = std::fs::read(IPFS_RPC).unwrap();
let mut ipfs_node = FluenceFaaS::new(
2020-06-06 21:34:13 +03:00
PathBuf::from(IPFS_MODULES_DIR),
PathBuf::from(IPFS_MODULES_CONFIG_PATH),
)
.unwrap();
2020-06-10 18:00:07 +03:00
println!("ipfs node interface is\n{}", ipfs_node.get_interface());
2020-06-10 16:55:18 +03:00
2020-06-12 16:54:21 +03:00
let node_addresses = ipfs_node
.call_module("ipfs_node.wasm", "get_addresses", &[])
2020-06-12 16:54:21 +03:00
.unwrap();
println!("ipfs node addresses are:\n{:?}", node_addresses);
2020-06-10 18:00:07 +03:00
let result = ipfs_node
2020-06-16 11:15:56 +03:00
.call_code(&ipfs_rpc, "put", &[IValue::String("Hello, world".to_string())])
2020-06-10 18:00:07 +03:00
.unwrap();
2020-06-06 21:34:13 +03:00
println!("execution result {:?}", result);
}