fix ipfs integration example

This commit is contained in:
Pavel Murygin 2021-09-10 20:44:16 +03:00
parent a88c04bfe1
commit a9a97e7e84
16 changed files with 33457 additions and 58387 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,10 +3,10 @@
* 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
* Aqua version: 0.3.0-226
*
*/
import { FluencePeer } from '@fluencelabs/fluence';
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
import {
ResultCodes,
RequestFlow,
@ -27,13 +27,13 @@ import {
let node: any;
let timeout_sec: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
timeout_sec = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
node = args[0];
timeout_sec = args[1];
config = args[2];
@ -75,7 +75,7 @@ config = args[2];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'timeout_sec', () => {return timeout_sec;});
@ -112,7 +112,7 @@ let cid: any;
let from: any;
let error: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
cid = args[2];
@ -120,7 +120,7 @@ from = args[3];
error = args[4];
config = args[5];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
node = args[0];
cid = args[1];
from = args[2];
@ -219,7 +219,7 @@ config = args[4];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'cid', () => {return cid;});
@ -278,14 +278,14 @@ h.on('getDataSrv', 'from', () => {return from;});
let cid: any;
let from: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
cid = args[2];
from = args[3];
config = args[4];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
node = args[0];
cid = args[1];
from = args[2];
@ -337,7 +337,7 @@ config = args[3];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'cid', () => {return cid;});
@ -373,12 +373,12 @@ h.on('getDataSrv', 'from', () => {return from;});
let peer: FluencePeer;
let node: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
node = args[0];
config = args[1];
}
@ -422,7 +422,7 @@ config = args[1];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'node', () => {return node;});
h.onEvent('callbackSrv', 'response', (args) => {
@ -456,12 +456,12 @@ config = args[1];
let peer: FluencePeer;
let node: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
node = args[0];
config = args[1];
}
@ -505,7 +505,7 @@ config = args[1];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'node', () => {return node;});
h.onEvent('callbackSrv', 'response', (args) => {
@ -540,13 +540,13 @@ config = args[1];
let node: any;
let path: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
path = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
node = args[0];
path = args[1];
config = args[2];
@ -594,7 +594,7 @@ config = args[2];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'path', () => {return path;});
@ -629,12 +629,12 @@ h.on('getDataSrv', 'path', () => {return path;});
let peer: FluencePeer;
let node: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
node = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
node = args[0];
config = args[1];
}
@ -678,7 +678,7 @@ config = args[1];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'node', () => {return node;});
h.onEvent('callbackSrv', 'response', (args) => {

View File

@ -3,10 +3,10 @@
* 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
* Aqua version: 0.3.0-226
*
*/
import { FluencePeer } from '@fluencelabs/fluence';
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
import {
ResultCodes,
RequestFlow,
@ -29,10 +29,10 @@ export function registerStringOp(peer: FluencePeer, serviceId: string, service:
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
@ -44,7 +44,12 @@ export function registerStringOp(peer: FluencePeer, serviceId: string, service:
serviceId = "op"
}
if (!(args[0] instanceof FluencePeer) && typeof args[0] === 'object') {
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// If the first argument is peer, we are checking further. The second argument might either be
// an object, that it must be the service object
// or a string, which is the service id. In that case the service is the third argument
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
@ -86,12 +91,12 @@ export function registerStringOp(peer: FluencePeer, serviceId: string, service:
let peer: FluencePeer;
let module_hash: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
module_hash = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
module_hash = args[0];
config = args[1];
}
@ -132,7 +137,7 @@ config = args[1];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'module_hash', () => {return module_hash;});
h.onEvent('callbackSrv', 'response', (args) => {
@ -171,7 +176,7 @@ let service_id: any;
let logSize: any;
let error: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
relay = args[1];
cid = args[2];
@ -181,7 +186,7 @@ logSize = args[5];
error = args[6];
config = args[7];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
relay = args[0];
cid = args[1];
ipfs = args[2];
@ -323,7 +328,7 @@ config = args[6];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'relay', () => {return relay;});
h.on('getDataSrv', 'cid', () => {return cid;});
@ -399,13 +404,13 @@ h.on('getDataSrv', 'service_id', () => {return service_id;});
let relay: any;
let service_id: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
relay = args[1];
service_id = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
relay = args[0];
service_id = args[1];
config = args[2];
@ -453,7 +458,7 @@ config = args[2];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'relay', () => {return relay;});
h.on('getDataSrv', 'service_id', () => {return service_id;});
@ -489,13 +494,13 @@ h.on('getDataSrv', 'service_id', () => {return service_id;});
let name: any;
let path: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
name = args[1];
path = args[2];
config = args[3];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
name = args[0];
path = args[1];
config = args[2];
@ -534,7 +539,7 @@ config = args[2];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'name', () => {return name;});
h.on('getDataSrv', 'path', () => {return path;});
@ -572,7 +577,7 @@ let cid: any;
let ipfs: any;
let error: any;
let config: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
relay = args[1];
cid = args[2];
@ -580,7 +585,7 @@ ipfs = args[3];
error = args[4];
config = args[5];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
relay = args[0];
cid = args[1];
ipfs = args[2];
@ -674,7 +679,7 @@ config = args[4];
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'relay', () => {return relay;});
h.on('getDataSrv', 'cid', () => {return cid;});

View File

@ -1,95 +0,0 @@
/**
*
* 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-224
*
*/
import { FluencePeer } from "@fluencelabs/fluence";
import {
ResultCodes,
RequestFlow,
RequestFlowBuilder,
CallParams,
} from "@fluencelabs/fluence/dist/internal/compilerSupport/v1";
// Services
export interface ProcessFilesDef {
file_size: (
file_path: string,
callParams: CallParams<"file_path">
) => { error: string; size: number; success: boolean };
write_file_size: (
size: number,
callParams: CallParams<"size">
) => { error: string; path: string; success: boolean };
}
export function registerProcessFiles(
serviceId: string,
service: ProcessFilesDef
): void;
export function registerProcessFiles(
peer: FluencePeer,
serviceId: string,
service: ProcessFilesDef
): void;
export function registerProcessFiles(...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];
}
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 === "file_size") {
const callParams = {
...req.particleContext,
tetraplets: {
file_path: req.tetraplets[0],
},
};
resp.retCode = ResultCodes.success;
resp.result = service.file_size(req.args[0], callParams);
}
if (req.fnName === "write_file_size") {
const callParams = {
...req.particleContext,
tetraplets: {
size: req.tetraplets[0],
},
};
resp.retCode = ResultCodes.success;
resp.result = service.write_file_size(req.args[0], callParams);
}
next();
});
}
// Functions

View File

@ -1,5 +0,0 @@
module Exports
import "@fluencelabs/aqua-ipfs/ipfs-api.aqua"
export set_timeout, get_external_swarm_multiaddr, get_external_api_multiaddr

View File

@ -1,78 +0,0 @@
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

View File

@ -1,15 +0,0 @@
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

View File

@ -1,706 +0,0 @@
/**
*
* 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;
}

View File

@ -1,725 +0,0 @@
/**
*
* 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;
}

File diff suppressed because it is too large Load Diff

View File

@ -4,12 +4,8 @@
"description": "An example of executing WASM code from IPFS over IPFS files",
"main": "dist/index.js",
"scripts": {
"compile-aqua": "aqua -i ./aqua -o ./generated",
"prebuild": "npm run compile-aqua",
"build": "tsc",
"prestart:local": "npm run build",
"start:local": "node dist/demo.js local",
"prestart:remote": "npm run build",
"start:remote": "node dist/demo.js krasnodar",
"start": "npm run start:remote"
},
@ -26,6 +22,7 @@
"author": "Fluence Labs",
"license": "MIT",
"dependencies": {
"@fluencelabs/ipfs-execution-aqua": "file:../aqua",
"@fluencelabs/aqua": "0.3.0-225",
"@fluencelabs/fluence": "0.12.0",
"@fluencelabs/fluence-network-environment": "1.0.10",

View File

@ -16,7 +16,7 @@
import { provideFile } from "./provider";
import { FluencePeer, setLogLevel } from "@fluencelabs/fluence";
import { Fluence, FluencePeer, setLogLevel } from "@fluencelabs/fluence";
import {
stage,
krasnodar,
@ -27,15 +27,16 @@ import {
deploy_service,
put_file_size,
remove_service,
} from "./generated/process";
import { set_timeout } from "./generated/exports";
set_timeout,
} from "@fluencelabs/ipfs-execution-aqua";
import { globSource, urlSource } from "ipfs-http-client";
async function main(environment: Node[]) {
// setLogLevel('DEBUG');
let providerHost = environment[0];
let providerClient = new FluencePeer();
await providerClient.init({ connectTo: providerHost });
await providerClient.start({ connectTo: providerHost });
console.log("📘 uploading .wasm to node %s", providerHost.multiaddr);
let path = globSource("../service/artifacts/process_files.wasm");
let { file, swarmAddr, rpcAddr } = await provideFile(path, providerClient);
@ -45,8 +46,8 @@ async function main(environment: Node[]) {
await Fluence.start({ connectTo: environment[1] });
console.log(
"📗 created a fluence client %s with relay %s",
FluencePeer.default.connectionInfo.selfPeerId,
FluencePeer.default.connectionInfo.connectedRelay
Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId
);
// default IPFS timeout is 1 sec, set to 10 secs to retrieve file from remote node

View File

@ -6,17 +6,17 @@ import { FluencePeer } from "@fluencelabs/fluence";
import {
get_external_api_multiaddr,
get_external_swarm_multiaddr,
} from "./generated/exports";
} from "@fluencelabs/ipfs-execution-aqua";
export async function provideFile(
source: any,
provider: FluencePeer
): Promise<{ file: AddResult; swarmAddr: string; rpcAddr: string }> {
const relayPeerId = provider.connectionInfo.connectedRelay!;
const relayPeerId = provider.getStatus().relayPeerId!;
let swarmAddr;
let result = await get_external_swarm_multiaddr(
provider,
provider.connectionInfo.connectedRelay!,
provider.getStatus().relayPeerId!,
{ ttl: 20000 }
);
if (result.success) {
@ -24,7 +24,7 @@ export async function provideFile(
} else {
console.error(
"Failed to retrieve external swarm multiaddr from %s: ",
provider.connectionInfo.connectedRelay!
provider.getStatus().relayPeerId!
);
throw result.error;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
import { FluencePeer } from "@fluencelabs/fluence";
import { Fluence } from "@fluencelabs/fluence";
import { krasnodar } from "@fluencelabs/fluence-network-environment";
import { useSetRecoilState, useRecoilValue, useRecoilState } from "recoil";
import {
@ -24,7 +24,7 @@ export const relayNodes = [krasnodar[0], krasnodar[1], krasnodar[2]];
const requestRpcAddr = async () => {
let result = await get_external_api_multiaddr(
FluencePeer.default.connectionInfo.connectedRelay!
Fluence.getStatus().relayPeerId!
);
console.log("getRpcAddr result", result);
let rpcAddr = result.multiaddr;
@ -41,8 +41,8 @@ export const useClientConnect = () => {
try {
await Fluence.start({ connectTo: relayPeerId });
setIsConnected(true);
setRelay(FluencePeer.default.connectionInfo.connectedRelay);
setSelfPeerId(FluencePeer.default.connectionInfo.selfPeerId);
setRelay(Fluence.getStatus().relayPeerId!);
setSelfPeerId(Fluence.getStatus().peerId!);
const addr = await requestRpcAddr();
setRpcAddr(addr!);
} catch (err) {