mirror of
https://github.com/fluencelabs/examples
synced 2025-05-28 18:21:20 +00:00
nodejs demo works
This commit is contained in:
parent
12b1860374
commit
7680fc7e05
@ -0,0 +1,5 @@
|
|||||||
|
module Exports
|
||||||
|
|
||||||
|
import "@fluencelabs/aqua-ipfs/ipfs-api.aqua"
|
||||||
|
|
||||||
|
export set_timeout, get_external_swarm_multiaddr, get_external_api_multiaddr
|
78
aqua-examples/aqua-ipfs-integration/nodejs/aqua/process.aqua
Normal file
78
aqua-examples/aqua-ipfs-integration/nodejs/aqua/process.aqua
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||||
|
import "@fluencelabs/aqua-ipfs/ipfs.aqua"
|
||||||
|
import "process_files.aqua"
|
||||||
|
|
||||||
|
alias PeerId : string
|
||||||
|
alias CID : string
|
||||||
|
alias Multiaddr : string
|
||||||
|
alias Hash : string
|
||||||
|
alias ServiceID : string
|
||||||
|
|
||||||
|
service StringOp("op"):
|
||||||
|
-- function that wraps string in array
|
||||||
|
array(s: string) -> []string
|
||||||
|
|
||||||
|
-- Add module to node
|
||||||
|
func add_module(name: string, path: string) -> Hash:
|
||||||
|
config <- Dist.default_module_config(name)
|
||||||
|
module_hash <- Dist.add_module_from_vault(path, config)
|
||||||
|
<- module_hash
|
||||||
|
|
||||||
|
-- Add service blueprint to node
|
||||||
|
func add_blueprint(module_hash: Hash) -> string:
|
||||||
|
prefixed_hash <- Op.concat_strings("hash:", module_hash)
|
||||||
|
dependencies <- StringOp.array(prefixed_hash)
|
||||||
|
blueprint <- Dist.make_blueprint("process_files", dependencies)
|
||||||
|
blueprint_id <- Dist.add_blueprint(blueprint)
|
||||||
|
<- blueprint_id
|
||||||
|
|
||||||
|
-- Download single .wasm module from IPFS and create a service from it
|
||||||
|
func deploy_service(relay: PeerId, cid: CID, ipfs: Multiaddr, error: string, string -> ()) -> ?ServiceID:
|
||||||
|
service_id: *ServiceID
|
||||||
|
on relay:
|
||||||
|
-- Download .wasm from IPFS to node
|
||||||
|
get_result <- Ipfs.get_from(cid, ipfs)
|
||||||
|
if get_result.success:
|
||||||
|
module_hash <- add_module("process_files", get_result.path)
|
||||||
|
blueprint_id <- add_blueprint(module_hash)
|
||||||
|
service_id <- Srv.create(blueprint_id)
|
||||||
|
else:
|
||||||
|
co error("Ipfs.get_from failed", get_result.error)
|
||||||
|
|
||||||
|
<- service_id
|
||||||
|
|
||||||
|
-- Download file from IPFS, and write it's size to file in IPFS
|
||||||
|
func put_file_size(
|
||||||
|
relay: PeerId,
|
||||||
|
cid: CID,
|
||||||
|
ipfs: Multiaddr,
|
||||||
|
service_id: ServiceID,
|
||||||
|
logSize: u32 -> (),
|
||||||
|
error: string, string -> ()
|
||||||
|
) -> ?IpfsPutResult:
|
||||||
|
result: *IpfsPutResult
|
||||||
|
ProcessFiles service_id
|
||||||
|
on relay:
|
||||||
|
get <- Ipfs.get_from(cid, ipfs)
|
||||||
|
if get.success:
|
||||||
|
size <- ProcessFiles.file_size(get.path)
|
||||||
|
if size.success:
|
||||||
|
-- report file size in background
|
||||||
|
co logSize(size.size)
|
||||||
|
-- write file size to disk
|
||||||
|
write <- ProcessFiles.write_file_size(size.size)
|
||||||
|
if write.success:
|
||||||
|
-- upload file to ipfs
|
||||||
|
result <- Ipfs.put(write.path)
|
||||||
|
else:
|
||||||
|
co error("ProcessFiles.write_file_size failed", write.error)
|
||||||
|
else:
|
||||||
|
co error("ProcessFiles.file_size failed", size.error)
|
||||||
|
else:
|
||||||
|
co error("Ipfs.get_from failed", get.error)
|
||||||
|
<- result
|
||||||
|
|
||||||
|
func remove_service(relay: PeerId, service_id: ServiceID) -> bool:
|
||||||
|
on relay:
|
||||||
|
Srv.remove(service_id)
|
||||||
|
<- true
|
@ -0,0 +1,15 @@
|
|||||||
|
module ProcessFiles declares *
|
||||||
|
|
||||||
|
data SizeResult:
|
||||||
|
size: u32
|
||||||
|
success: bool
|
||||||
|
error: string
|
||||||
|
|
||||||
|
data WriteResult:
|
||||||
|
path: string
|
||||||
|
success: bool
|
||||||
|
error: string
|
||||||
|
|
||||||
|
service ProcessFiles:
|
||||||
|
file_size(file_path: string) -> SizeResult
|
||||||
|
write_file_size(size: u32) -> WriteResult
|
@ -27,8 +27,8 @@ import {
|
|||||||
deploy_service,
|
deploy_service,
|
||||||
put_file_size,
|
put_file_size,
|
||||||
remove_service,
|
remove_service,
|
||||||
set_timeout,
|
} from "./generated/process";
|
||||||
} from "@fluencelabs/ipfs-execution-aqua";
|
import { set_timeout } from "./generated/exports";
|
||||||
import { globSource, urlSource } from "ipfs-http-client";
|
import { globSource, urlSource } from "ipfs-http-client";
|
||||||
|
|
||||||
async function main(environment: Node[]) {
|
async function main(environment: Node[]) {
|
||||||
|
706
aqua-examples/aqua-ipfs-integration/nodejs/generated/exports.ts
Normal file
706
aqua-examples/aqua-ipfs-integration/nodejs/generated/exports.ts
Normal file
@ -0,0 +1,706 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||||
|
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||||
|
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
|
||||||
|
* Aqua version: 0.3.0-225
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
import { FluencePeer } from '@fluencelabs/fluence';
|
||||||
|
import {
|
||||||
|
ResultCodes,
|
||||||
|
RequestFlow,
|
||||||
|
RequestFlowBuilder,
|
||||||
|
CallParams,
|
||||||
|
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
|
||||||
|
|
||||||
|
|
||||||
|
// Services
|
||||||
|
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
|
||||||
|
export function set_timeout(node: string, timeout_sec: number, config?: {ttl?: number}) : Promise<void>;
|
||||||
|
export function set_timeout(peer: FluencePeer, node: string, timeout_sec: number, config?: {ttl?: number}) : Promise<void>;
|
||||||
|
export function set_timeout(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let node: any;
|
||||||
|
let timeout_sec: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
node = args[1];
|
||||||
|
timeout_sec = args[2];
|
||||||
|
config = args[3];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
node = args[0];
|
||||||
|
timeout_sec = args[1];
|
||||||
|
config = args[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<void>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "timeout_sec") [] timeout_sec)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call node ("aqua-ipfs" "set_timeout") [timeout_sec])
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'node', () => {return node;});
|
||||||
|
h.on('getDataSrv', 'timeout_sec', () => {return timeout_sec;});
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for set_timeout');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return Promise.race([promise, Promise.resolve()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function get_and_cache(node: string, cid: string, from: string, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<string | null>;
|
||||||
|
export function get_and_cache(peer: FluencePeer, node: string, cid: string, from: string, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<string | null>;
|
||||||
|
export function get_and_cache(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let node: any;
|
||||||
|
let cid: any;
|
||||||
|
let from: any;
|
||||||
|
let error: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
node = args[1];
|
||||||
|
cid = args[2];
|
||||||
|
from = args[3];
|
||||||
|
error = args[4];
|
||||||
|
config = args[5];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
node = args[0];
|
||||||
|
cid = args[1];
|
||||||
|
from = args[2];
|
||||||
|
error = args[3];
|
||||||
|
config = args[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<string | null>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "cid") [] cid)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "from") [] from)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(call node ("aqua-ipfs" "get_from") [cid from] get)
|
||||||
|
(xor
|
||||||
|
(match get.$.success! true
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(call node ("aqua-ipfs" "put") [get.$.path!] put)
|
||||||
|
(xor
|
||||||
|
(match put.$.success! true
|
||||||
|
(xor
|
||||||
|
(ap put.$.hash! $localCid)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(par
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "error") ["Ipfs.put failed" put.$.error!])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(null)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(par
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "error") ["Ipfs.get failed" get.$.error!])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(null)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [$localCid])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'node', () => {return node;});
|
||||||
|
h.on('getDataSrv', 'cid', () => {return cid;});
|
||||||
|
h.on('getDataSrv', 'from', () => {return from;});
|
||||||
|
|
||||||
|
h.use((req, resp, next) => {
|
||||||
|
if(req.serviceId === 'callbackSrv' && req.fnName === 'error') {
|
||||||
|
|
||||||
|
const callParams = {
|
||||||
|
...req.particleContext,
|
||||||
|
tetraplets: {
|
||||||
|
arg0: req.tetraplets[0],arg1: req.tetraplets[1]
|
||||||
|
},
|
||||||
|
};
|
||||||
|
resp.retCode = ResultCodes.success;
|
||||||
|
error(req.args[0], req.args[1], callParams); resp.result = {}
|
||||||
|
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
let [opt] = args;
|
||||||
|
if (Array.isArray(opt)) {
|
||||||
|
if (opt.length === 0) { resolve(null); }
|
||||||
|
opt = opt[0];
|
||||||
|
}
|
||||||
|
return resolve(opt);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for get_and_cache');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function get_from(node: string, cid: string, from: string, config?: {ttl?: number}) : Promise<{error:string;path:string;success:boolean}>;
|
||||||
|
export function get_from(peer: FluencePeer, node: string, cid: string, from: string, config?: {ttl?: number}) : Promise<{error:string;path:string;success:boolean}>;
|
||||||
|
export function get_from(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let node: any;
|
||||||
|
let cid: any;
|
||||||
|
let from: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
node = args[1];
|
||||||
|
cid = args[2];
|
||||||
|
from = args[3];
|
||||||
|
config = args[4];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
node = args[0];
|
||||||
|
cid = args[1];
|
||||||
|
from = args[2];
|
||||||
|
config = args[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<{error:string;path:string;success:boolean}>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "cid") [] cid)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "from") [] from)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call node ("aqua-ipfs" "get_from") [cid from] result)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'node', () => {return node;});
|
||||||
|
h.on('getDataSrv', 'cid', () => {return cid;});
|
||||||
|
h.on('getDataSrv', 'from', () => {return from;});
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
const [res] = args;
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for get_from');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function get_local_api_multiaddr(node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
|
||||||
|
export function get_local_api_multiaddr(peer: FluencePeer, node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
|
||||||
|
export function get_local_api_multiaddr(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let node: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
node = args[1];
|
||||||
|
config = args[2];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
node = args[0];
|
||||||
|
config = args[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<{error:string;multiaddr:string;success:boolean}>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call node ("aqua-ipfs" "get_local_api_multiaddr") [] result)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'node', () => {return node;});
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
const [res] = args;
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for get_local_api_multiaddr');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function get_external_swarm_multiaddr(node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
|
||||||
|
export function get_external_swarm_multiaddr(peer: FluencePeer, node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
|
||||||
|
export function get_external_swarm_multiaddr(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let node: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
node = args[1];
|
||||||
|
config = args[2];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
node = args[0];
|
||||||
|
config = args[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<{error:string;multiaddr:string;success:boolean}>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call node ("aqua-ipfs" "get_external_swarm_multiaddr") [] result)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'node', () => {return node;});
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
const [res] = args;
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for get_external_swarm_multiaddr');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function put(node: string, path: string, config?: {ttl?: number}) : Promise<{error:string;hash:string;success:boolean}>;
|
||||||
|
export function put(peer: FluencePeer, node: string, path: string, config?: {ttl?: number}) : Promise<{error:string;hash:string;success:boolean}>;
|
||||||
|
export function put(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let node: any;
|
||||||
|
let path: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
node = args[1];
|
||||||
|
path = args[2];
|
||||||
|
config = args[3];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
node = args[0];
|
||||||
|
path = args[1];
|
||||||
|
config = args[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<{error:string;hash:string;success:boolean}>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "path") [] path)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call node ("aqua-ipfs" "put") [path] result)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'node', () => {return node;});
|
||||||
|
h.on('getDataSrv', 'path', () => {return path;});
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
const [res] = args;
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for put');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function get_external_api_multiaddr(node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
|
||||||
|
export function get_external_api_multiaddr(peer: FluencePeer, node: string, config?: {ttl?: number}) : Promise<{error:string;multiaddr:string;success:boolean}>;
|
||||||
|
export function get_external_api_multiaddr(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let node: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
node = args[1];
|
||||||
|
config = args[2];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
node = args[0];
|
||||||
|
config = args[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<{error:string;multiaddr:string;success:boolean}>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call node ("aqua-ipfs" "get_external_api_multiaddr") [] result)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [result])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'node', () => {return node;});
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
const [res] = args;
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for get_external_api_multiaddr');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
725
aqua-examples/aqua-ipfs-integration/nodejs/generated/process.ts
Normal file
725
aqua-examples/aqua-ipfs-integration/nodejs/generated/process.ts
Normal file
@ -0,0 +1,725 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||||
|
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||||
|
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
|
||||||
|
* Aqua version: 0.3.0-225
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
import { FluencePeer } from '@fluencelabs/fluence';
|
||||||
|
import {
|
||||||
|
ResultCodes,
|
||||||
|
RequestFlow,
|
||||||
|
RequestFlowBuilder,
|
||||||
|
CallParams,
|
||||||
|
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
|
||||||
|
|
||||||
|
|
||||||
|
// Services
|
||||||
|
|
||||||
|
export interface StringOpDef {
|
||||||
|
array: (s: string, callParams: CallParams<'s'>) => string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerStringOp(service: StringOpDef): void;
|
||||||
|
export function registerStringOp(serviceId: string, service: StringOpDef): void;
|
||||||
|
export function registerStringOp(peer: FluencePeer, service: StringOpDef): void;
|
||||||
|
export function registerStringOp(peer: FluencePeer, serviceId: string, service: StringOpDef): void;
|
||||||
|
export function registerStringOp(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let serviceId: any;
|
||||||
|
let service: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof args[0] === 'string') {
|
||||||
|
serviceId = args[0];
|
||||||
|
} else if (typeof args[1] === 'string') {
|
||||||
|
serviceId = args[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
serviceId = "op"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(args[0] instanceof FluencePeer) && typeof args[0] === 'object') {
|
||||||
|
service = args[0];
|
||||||
|
} else if (typeof args[1] === 'object') {
|
||||||
|
service = args[1];
|
||||||
|
} else {
|
||||||
|
service = args[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
peer.internals.callServiceHandler.use((req, resp, next) => {
|
||||||
|
if (req.serviceId !== serviceId) {
|
||||||
|
next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (req.fnName === 'array') {
|
||||||
|
|
||||||
|
const callParams = {
|
||||||
|
...req.particleContext,
|
||||||
|
tetraplets: {
|
||||||
|
s: req.tetraplets[0]
|
||||||
|
},
|
||||||
|
};
|
||||||
|
resp.retCode = ResultCodes.success;
|
||||||
|
resp.result = service.array(req.args[0], callParams)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
|
||||||
|
export function add_blueprint(module_hash: string, config?: {ttl?: number}) : Promise<string>;
|
||||||
|
export function add_blueprint(peer: FluencePeer, module_hash: string, config?: {ttl?: number}) : Promise<string>;
|
||||||
|
export function add_blueprint(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let module_hash: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
module_hash = args[1];
|
||||||
|
config = args[2];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
module_hash = args[0];
|
||||||
|
config = args[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<string>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "module_hash") [] module_hash)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("op" "concat_strings") ["hash:" module_hash] prefixed_hash)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("op" "array") [prefixed_hash] dependencies)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("dist" "make_blueprint") ["process_files" dependencies] blueprint)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("dist" "add_blueprint") [blueprint] blueprint_id)
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [blueprint_id])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'module_hash', () => {return module_hash;});
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
const [res] = args;
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for add_blueprint');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function put_file_size(relay: string, cid: string, ipfs: string, service_id: string, logSize: (arg0: number, callParams: CallParams<'arg0'>) => void, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<{error:string;hash:string;success:boolean} | null>;
|
||||||
|
export function put_file_size(peer: FluencePeer, relay: string, cid: string, ipfs: string, service_id: string, logSize: (arg0: number, callParams: CallParams<'arg0'>) => void, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<{error:string;hash:string;success:boolean} | null>;
|
||||||
|
export function put_file_size(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let relay: any;
|
||||||
|
let cid: any;
|
||||||
|
let ipfs: any;
|
||||||
|
let service_id: any;
|
||||||
|
let logSize: any;
|
||||||
|
let error: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
relay = args[1];
|
||||||
|
cid = args[2];
|
||||||
|
ipfs = args[3];
|
||||||
|
service_id = args[4];
|
||||||
|
logSize = args[5];
|
||||||
|
error = args[6];
|
||||||
|
config = args[7];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
relay = args[0];
|
||||||
|
cid = args[1];
|
||||||
|
ipfs = args[2];
|
||||||
|
service_id = args[3];
|
||||||
|
logSize = args[4];
|
||||||
|
error = args[5];
|
||||||
|
config = args[6];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<{error:string;hash:string;success:boolean} | null>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "cid") [] cid)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "ipfs") [] ipfs)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "service_id") [] service_id)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(call relay ("aqua-ipfs" "get_from") [cid ipfs] get)
|
||||||
|
(xor
|
||||||
|
(match get.$.success! true
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(call relay (service_id "file_size") [get.$.path!] size)
|
||||||
|
(xor
|
||||||
|
(match size.$.success! true
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(par
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "logSize") [size.$.size!])
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(null)
|
||||||
|
)
|
||||||
|
(call relay (service_id "write_file_size") [size.$.size!] write)
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(match write.$.success! true
|
||||||
|
(xor
|
||||||
|
(call relay ("aqua-ipfs" "put") [write.$.path!] $result)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(par
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "error") ["ProcessFiles.write_file_size failed" write.$.error!])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(null)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(par
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "error") ["ProcessFiles.file_size failed" size.$.error!])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(null)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 6])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(par
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "error") ["Ipfs.get_from failed" get.$.error!])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 7])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(null)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 8])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [$result])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 9])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 10])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'relay', () => {return relay;});
|
||||||
|
h.on('getDataSrv', 'cid', () => {return cid;});
|
||||||
|
h.on('getDataSrv', 'ipfs', () => {return ipfs;});
|
||||||
|
h.on('getDataSrv', 'service_id', () => {return service_id;});
|
||||||
|
|
||||||
|
h.use((req, resp, next) => {
|
||||||
|
if(req.serviceId === 'callbackSrv' && req.fnName === 'logSize') {
|
||||||
|
|
||||||
|
const callParams = {
|
||||||
|
...req.particleContext,
|
||||||
|
tetraplets: {
|
||||||
|
arg0: req.tetraplets[0]
|
||||||
|
},
|
||||||
|
};
|
||||||
|
resp.retCode = ResultCodes.success;
|
||||||
|
logSize(req.args[0], callParams); resp.result = {}
|
||||||
|
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
h.use((req, resp, next) => {
|
||||||
|
if(req.serviceId === 'callbackSrv' && req.fnName === 'error') {
|
||||||
|
|
||||||
|
const callParams = {
|
||||||
|
...req.particleContext,
|
||||||
|
tetraplets: {
|
||||||
|
arg0: req.tetraplets[0],arg1: req.tetraplets[1]
|
||||||
|
},
|
||||||
|
};
|
||||||
|
resp.retCode = ResultCodes.success;
|
||||||
|
error(req.args[0], req.args[1], callParams); resp.result = {}
|
||||||
|
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
let [opt] = args;
|
||||||
|
if (Array.isArray(opt)) {
|
||||||
|
if (opt.length === 0) { resolve(null); }
|
||||||
|
opt = opt[0];
|
||||||
|
}
|
||||||
|
return resolve(opt);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for put_file_size');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function remove_service(relay: string, service_id: string, config?: {ttl?: number}) : Promise<boolean>;
|
||||||
|
export function remove_service(peer: FluencePeer, relay: string, service_id: string, config?: {ttl?: number}) : Promise<boolean>;
|
||||||
|
export function remove_service(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let relay: any;
|
||||||
|
let service_id: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
relay = args[1];
|
||||||
|
service_id = args[2];
|
||||||
|
config = args[3];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
relay = args[0];
|
||||||
|
service_id = args[1];
|
||||||
|
config = args[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<boolean>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "service_id") [] service_id)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call relay ("srv" "remove") [service_id])
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [true])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'relay', () => {return relay;});
|
||||||
|
h.on('getDataSrv', 'service_id', () => {return service_id;});
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
const [res] = args;
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for remove_service');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function add_module(name: string, path: string, config?: {ttl?: number}) : Promise<string>;
|
||||||
|
export function add_module(peer: FluencePeer, name: string, path: string, config?: {ttl?: number}) : Promise<string>;
|
||||||
|
export function add_module(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let name: any;
|
||||||
|
let path: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
name = args[1];
|
||||||
|
path = args[2];
|
||||||
|
config = args[3];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
name = args[0];
|
||||||
|
path = args[1];
|
||||||
|
config = args[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<string>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "name") [] name)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "path") [] path)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("dist" "default_module_config") [name] config)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("dist" "add_module_from_vault") [path config] module_hash)
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [module_hash])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'name', () => {return name;});
|
||||||
|
h.on('getDataSrv', 'path', () => {return path;});
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
const [res] = args;
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for add_module');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function deploy_service(relay: string, cid: string, ipfs: string, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<string | null>;
|
||||||
|
export function deploy_service(peer: FluencePeer, relay: string, cid: string, ipfs: string, error: (arg0: string, arg1: string, callParams: CallParams<'arg0' | 'arg1'>) => void, config?: {ttl?: number}) : Promise<string | null>;
|
||||||
|
export function deploy_service(...args: any) {
|
||||||
|
let peer: FluencePeer;
|
||||||
|
let relay: any;
|
||||||
|
let cid: any;
|
||||||
|
let ipfs: any;
|
||||||
|
let error: any;
|
||||||
|
let config: any;
|
||||||
|
if (args[0] instanceof FluencePeer) {
|
||||||
|
peer = args[0];
|
||||||
|
relay = args[1];
|
||||||
|
cid = args[2];
|
||||||
|
ipfs = args[3];
|
||||||
|
error = args[4];
|
||||||
|
config = args[5];
|
||||||
|
} else {
|
||||||
|
peer = FluencePeer.default;
|
||||||
|
relay = args[0];
|
||||||
|
cid = args[1];
|
||||||
|
ipfs = args[2];
|
||||||
|
error = args[3];
|
||||||
|
config = args[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
let request: RequestFlow;
|
||||||
|
const promise = new Promise<string | null>((resolve, reject) => {
|
||||||
|
const r = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "cid") [] cid)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "ipfs") [] ipfs)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(call relay ("aqua-ipfs" "get_from") [cid ipfs] get_result)
|
||||||
|
(xor
|
||||||
|
(match get_result.$.success! true
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call relay ("dist" "default_module_config") ["process_files"] config)
|
||||||
|
(call relay ("dist" "add_module_from_vault") [get_result.$.path! config] module_hash)
|
||||||
|
)
|
||||||
|
(call relay ("op" "concat_strings") ["hash:" module_hash] prefixed_hash)
|
||||||
|
)
|
||||||
|
(call relay ("op" "array") [prefixed_hash] dependencies)
|
||||||
|
)
|
||||||
|
(call relay ("dist" "make_blueprint") ["process_files" dependencies] blueprint)
|
||||||
|
)
|
||||||
|
(call relay ("dist" "add_blueprint") [blueprint] blueprint_id)
|
||||||
|
)
|
||||||
|
(call relay ("srv" "create") [blueprint_id] $service_id)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(par
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "error") ["Ipfs.get_from failed" get_result.$.error!])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(null)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [$service_id])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', '-relay-', () => {
|
||||||
|
return peer.connectionInfo.connectedRelay ;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'relay', () => {return relay;});
|
||||||
|
h.on('getDataSrv', 'cid', () => {return cid;});
|
||||||
|
h.on('getDataSrv', 'ipfs', () => {return ipfs;});
|
||||||
|
|
||||||
|
h.use((req, resp, next) => {
|
||||||
|
if(req.serviceId === 'callbackSrv' && req.fnName === 'error') {
|
||||||
|
|
||||||
|
const callParams = {
|
||||||
|
...req.particleContext,
|
||||||
|
tetraplets: {
|
||||||
|
arg0: req.tetraplets[0],arg1: req.tetraplets[1]
|
||||||
|
},
|
||||||
|
};
|
||||||
|
resp.retCode = ResultCodes.success;
|
||||||
|
error(req.args[0], req.args[1], callParams); resp.result = {}
|
||||||
|
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||||||
|
let [opt] = args;
|
||||||
|
if (Array.isArray(opt)) {
|
||||||
|
if (opt.length === 0) { resolve(null); }
|
||||||
|
opt = opt[0];
|
||||||
|
}
|
||||||
|
return resolve(opt);
|
||||||
|
});
|
||||||
|
|
||||||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||||
|
const [err] = args;
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.handleScriptError(reject)
|
||||||
|
.handleTimeout(() => {
|
||||||
|
reject('Request timed out for deploy_service');
|
||||||
|
})
|
||||||
|
if(config && config.ttl) {
|
||||||
|
r.withTTL(config.ttl)
|
||||||
|
}
|
||||||
|
request = r.build();
|
||||||
|
});
|
||||||
|
peer.internals.initiateFlow(request!);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
3074
aqua-examples/aqua-ipfs-integration/nodejs/package-lock.json
generated
3074
aqua-examples/aqua-ipfs-integration/nodejs/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,8 @@
|
|||||||
"description": "An example of executing WASM code from IPFS over IPFS files",
|
"description": "An example of executing WASM code from IPFS over IPFS files",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"compile-aqua": "aqua -i ./aqua -o ./generated",
|
||||||
|
"prebuild": "npm run compile-aqua",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"prestart:local": "npm run build",
|
"prestart:local": "npm run build",
|
||||||
"start:local": "node dist/demo.js local",
|
"start:local": "node dist/demo.js local",
|
||||||
@ -24,10 +26,11 @@
|
|||||||
"author": "Fluence Labs",
|
"author": "Fluence Labs",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fluencelabs/ipfs-execution-aqua": "file:../aqua",
|
"@fluencelabs/aqua": "0.3.0-225",
|
||||||
"@fluencelabs/fluence": "0.11.0",
|
"@fluencelabs/fluence": "0.11.0",
|
||||||
"@fluencelabs/fluence-network-environment": "1.0.10",
|
"@fluencelabs/fluence-network-environment": "1.0.10",
|
||||||
"@fluencelabs/aqua-lib": "0.1.14",
|
"@fluencelabs/aqua-lib": "0.1.14",
|
||||||
|
"@fluencelabs/aqua-ipfs": "0.4.2",
|
||||||
"ipfs-http-client": "^50.1.2",
|
"ipfs-http-client": "^50.1.2",
|
||||||
"it-all": "^1.0.5",
|
"it-all": "^1.0.5",
|
||||||
"uint8arrays": "^2.1.5",
|
"uint8arrays": "^2.1.5",
|
||||||
|
@ -6,7 +6,7 @@ import { FluencePeer } from "@fluencelabs/fluence";
|
|||||||
import {
|
import {
|
||||||
get_external_api_multiaddr,
|
get_external_api_multiaddr,
|
||||||
get_external_swarm_multiaddr,
|
get_external_swarm_multiaddr,
|
||||||
} from "@fluencelabs/ipfs-execution-aqua";
|
} from "./generated/exports";
|
||||||
|
|
||||||
export async function provideFile(
|
export async function provideFile(
|
||||||
source: any,
|
source: any,
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
module Exports
|
||||||
|
|
||||||
|
import "@fluencelabs/aqua-ipfs/ipfs-api.aqua"
|
||||||
|
|
||||||
|
export set_timeout, get_external_swarm_multiaddr, get_external_api_multiaddr
|
78
aqua-examples/aqua-ipfs-integration/web/aqua/process.aqua
Normal file
78
aqua-examples/aqua-ipfs-integration/web/aqua/process.aqua
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||||
|
import "@fluencelabs/aqua-ipfs/ipfs.aqua"
|
||||||
|
import "process_files.aqua"
|
||||||
|
|
||||||
|
alias PeerId : string
|
||||||
|
alias CID : string
|
||||||
|
alias Multiaddr : string
|
||||||
|
alias Hash : string
|
||||||
|
alias ServiceID : string
|
||||||
|
|
||||||
|
service StringOp("op"):
|
||||||
|
-- function that wraps string in array
|
||||||
|
array(s: string) -> []string
|
||||||
|
|
||||||
|
-- Add module to node
|
||||||
|
func add_module(name: string, path: string) -> Hash:
|
||||||
|
config <- Dist.default_module_config(name)
|
||||||
|
module_hash <- Dist.add_module_from_vault(path, config)
|
||||||
|
<- module_hash
|
||||||
|
|
||||||
|
-- Add service blueprint to node
|
||||||
|
func add_blueprint(module_hash: Hash) -> string:
|
||||||
|
prefixed_hash <- Op.concat_strings("hash:", module_hash)
|
||||||
|
dependencies <- StringOp.array(prefixed_hash)
|
||||||
|
blueprint <- Dist.make_blueprint("process_files", dependencies)
|
||||||
|
blueprint_id <- Dist.add_blueprint(blueprint)
|
||||||
|
<- blueprint_id
|
||||||
|
|
||||||
|
-- Download single .wasm module from IPFS and create a service from it
|
||||||
|
func deploy_service(relay: PeerId, cid: CID, ipfs: Multiaddr, error: string, string -> ()) -> ?ServiceID:
|
||||||
|
service_id: *ServiceID
|
||||||
|
on relay:
|
||||||
|
-- Download .wasm from IPFS to node
|
||||||
|
get_result <- Ipfs.get_from(cid, ipfs)
|
||||||
|
if get_result.success:
|
||||||
|
module_hash <- add_module("process_files", get_result.path)
|
||||||
|
blueprint_id <- add_blueprint(module_hash)
|
||||||
|
service_id <- Srv.create(blueprint_id)
|
||||||
|
else:
|
||||||
|
co error("Ipfs.get_from failed", get_result.error)
|
||||||
|
|
||||||
|
<- service_id
|
||||||
|
|
||||||
|
-- Download file from IPFS, and write it's size to file in IPFS
|
||||||
|
func put_file_size(
|
||||||
|
relay: PeerId,
|
||||||
|
cid: CID,
|
||||||
|
ipfs: Multiaddr,
|
||||||
|
service_id: ServiceID,
|
||||||
|
logSize: u32 -> (),
|
||||||
|
error: string, string -> ()
|
||||||
|
) -> ?IpfsPutResult:
|
||||||
|
result: *IpfsPutResult
|
||||||
|
ProcessFiles service_id
|
||||||
|
on relay:
|
||||||
|
get <- Ipfs.get_from(cid, ipfs)
|
||||||
|
if get.success:
|
||||||
|
size <- ProcessFiles.file_size(get.path)
|
||||||
|
if size.success:
|
||||||
|
-- report file size in background
|
||||||
|
co logSize(size.size)
|
||||||
|
-- write file size to disk
|
||||||
|
write <- ProcessFiles.write_file_size(size.size)
|
||||||
|
if write.success:
|
||||||
|
-- upload file to ipfs
|
||||||
|
result <- Ipfs.put(write.path)
|
||||||
|
else:
|
||||||
|
co error("ProcessFiles.write_file_size failed", write.error)
|
||||||
|
else:
|
||||||
|
co error("ProcessFiles.file_size failed", size.error)
|
||||||
|
else:
|
||||||
|
co error("Ipfs.get_from failed", get.error)
|
||||||
|
<- result
|
||||||
|
|
||||||
|
func remove_service(relay: PeerId, service_id: ServiceID) -> bool:
|
||||||
|
on relay:
|
||||||
|
Srv.remove(service_id)
|
||||||
|
<- true
|
@ -0,0 +1,15 @@
|
|||||||
|
module ProcessFiles declares *
|
||||||
|
|
||||||
|
data SizeResult:
|
||||||
|
size: u32
|
||||||
|
success: bool
|
||||||
|
error: string
|
||||||
|
|
||||||
|
data WriteResult:
|
||||||
|
path: string
|
||||||
|
success: bool
|
||||||
|
error: string
|
||||||
|
|
||||||
|
service ProcessFiles:
|
||||||
|
file_size(file_path: string) -> SizeResult
|
||||||
|
write_file_size(size: u32) -> WriteResult
|
Loading…
x
Reference in New Issue
Block a user