add get_addresses export

This commit is contained in:
vms 2020-06-12 16:54:21 +03:00
parent 761a636bee
commit c98e577150
5 changed files with 61 additions and 4 deletions

View File

@ -45,12 +45,22 @@ fn main() {
println!("ipfs node interface is\n{}", ipfs_node.get_interface());
let node_addresses = ipfs_node
.core_call(
"ipfs_node.wasm",
"get_addresses",
&[],
)
.unwrap();
println!("ipfs node addresses are:\n{:?}", node_addresses);
let result = ipfs_node
.rpc_call(
&ipfs_rpc,
"put",
"get",
&[IValue::String(
"QmdHsYnAvbrvXg3iwr6bLaqooVT31E8CMpZRWc9wX2Fbt8".to_string(),
"Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD".to_string(),
)],
)
.unwrap();

View File

@ -47,7 +47,7 @@ pub unsafe fn put(file_path_ptr: *mut u8, file_path_size: usize) {
"host ipfs call failed".to_string()
};
let msg = format!("ipfs_node.put: file add wtih hash is {} \n", hash);
let msg = format!("ipfs_node.put: file add with hash is {} \n", hash);
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
*RESULT_PTR.get_mut() = hash.as_ptr() as _;
@ -82,6 +82,32 @@ pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) {
std::mem::forget(file_path);
}
#[no_mangle]
pub unsafe fn get_addresses() {
let msg = "ipfs_node.get_addresses".to_string();
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
let cmd = "id -f'<addrs>'";
let result = ipfs(cmd.as_ptr() as _, cmd.len() as _);
let multiaddrs = if result == 0 {
String::from_raw_parts(
*RESULT_PTR.get_mut() as _,
*RESULT_SIZE.get_mut(),
*RESULT_SIZE.get_mut(),
)
} else {
"host ipfs call failed".to_string()
};
let msg = format!("ipfs_node.get_addresses: node addresses are {} \n", multiaddrs);
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
*RESULT_PTR.get_mut() = multiaddrs.as_ptr() as _;
*RESULT_SIZE.get_mut() = multiaddrs.len();
std::mem::forget(multiaddrs);
}
#[link(wasm_import_module = "host")]
extern "C" {
/// Writes a byte string of size bytes that starts from ptr to a logger.

View File

@ -25,6 +25,12 @@
;; import ipfs put/get function
(@interface type (func (param string) (result string))) ;; 8
;; export ipfs.get_addresses function
(@interface type (func (result string))) ;; 9
;; export ipfs.get_addresses function
(@interface type (func )) ;; 10
(@interface export "allocate" (func 0)) ;; 0
(@interface export "deallocate" (func 1)) ;; 1
(@interface export "get_result_size" (func 3)) ;; 2
@ -34,6 +40,7 @@
(@interface export "put" (func 5)) ;; 6
(@interface export "get" (func 6)) ;; 7
(@interface export "get_addresses" (func 10)) ;; 8
;; adapter for export function put
(@interface func (type 7)
@ -67,6 +74,18 @@
call-core 1 ;; call deallocate
)
;; adapter for export function get_addresses
(@interface func (type 9)
call-core 8 ;; call self.get
call-core 3 ;; call get_result_ptr
call-core 2 ;; call get_result_size
string.lift_memory
call-core 3 ;; call get_result_ptr
call-core 2 ;; call get_result_size
call-core 1 ;; call deallocate
)
;; Implementations
(@interface implement (func 5) (func 7))
(@interface implement (func 6) (func 8))
(@interface implement (func 10) (func 9))

View File

@ -20,6 +20,7 @@
(@interface export "get_result_size" (func 4))
(@interface export "get_result_ptr" (func 4))
;; greeting export adapter
(@interface func (type 2)
arg.get 0
string.size
@ -35,6 +36,7 @@
call-core 1 ;; call deallocate
)
;; strlen export adapter
(@interface func (type 3)
arg.get 0
string.size

View File

@ -15,9 +15,9 @@
*/
use wasmer_wasi::WasiVersion;
use wasmer_runtime::ImportObject;
use std::path::PathBuf;
use wasmer_runtime::ImportObject;
#[derive(Clone)]
pub struct FCEModuleConfig {