Add builtin on_start script (#8)

This commit is contained in:
Aleksey Proshutisnkiy 2021-07-09 15:52:41 +03:00 committed by GitHub
parent 7a05a39b5a
commit 1eb0e5ce09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 4709 additions and 170 deletions

View File

@ -4,12 +4,12 @@ import "ipfs.aqua"
alias Multiaddr: string alias Multiaddr: string
alias PeerId: string alias PeerId: string
func put(node: PeerId, path: string) -> IpfsResult: func put(node: PeerId, path: string) -> IpfsPutResult:
on node: on node:
result <- Ipfs.put(path) result <- Ipfs.put(path)
<- result <- result
func get_from(node: PeerId, hash: string, from: Multiaddr) -> IpfsResult: func get_from(node: PeerId, hash: string, from: Multiaddr) -> IpfsGetFromResult:
on node: on node:
result <- Ipfs.get_from(hash, from) result <- Ipfs.get_from(hash, from)
<- result <- result

4691
aqua/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -65,7 +65,7 @@ async function main() {
let getResult = await get_from(fluence, testNet[2].peerId, file.cid.toString(), ipfsMultiaddr, { ttl: 10000 }); let getResult = await get_from(fluence, testNet[2].peerId, file.cid.toString(), ipfsMultiaddr, { ttl: 10000 });
console.log("Ipfs.get", getResult); console.log("Ipfs.get", getResult);
let putResult = await put(fluence, testNet[2].peerId, getResult.result, { ttl: 10000 }); let putResult = await put(fluence, testNet[2].peerId, getResult.path, { ttl: 10000 });
console.log("Ipfs.put", putResult); console.log("Ipfs.put", putResult);
return; return;

View File

@ -1,158 +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.1.8-160
*
*/
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
export async function put(client: FluenceClient, node: string, path: string, config?: {ttl?: number}): Promise<{result:string;success:boolean}> {
let request: RequestFlow;
const promise = new Promise<{result:string;success:boolean}>((resolve, reject) => {
request = new RequestFlowBuilder()
.disableInjections()
.withTTL(config?.ttl || 5000)
.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 ("ipfs-adapter" "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 client.relayPeerId!;
});
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) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for put');
})
.build();
});
await client.initiateFlow(request!);
return promise;
}
export async function get_from(client: FluenceClient, node: string, hash: string, from: string, config?: {ttl?: number}): Promise<{result:string;success:boolean}> {
let request: RequestFlow;
const promise = new Promise<{result:string;success:boolean}>((resolve, reject) => {
request = new RequestFlowBuilder()
.disableInjections()
.withTTL(config?.ttl || 5000)
.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" "hash") [] hash)
)
(call %init_peer_id% ("getDataSrv" "from") [] from)
)
(call -relay- ("op" "noop") [])
)
(xor
(call node ("ipfs-adapter" "get_from") [hash 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 client.relayPeerId!;
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'hash', () => {return hash;});
h.on('getDataSrv', 'from', () => {return from;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for get_from');
})
.build();
});
await client.initiateFlow(request!);
return promise;
}

View File

@ -0,0 +1,19 @@
(seq
(seq
(xor
(call relay ("ipfs-adapter" "set_local_api_multiaddr") [local_api_multiaddr])
(call %init_peer_id% ("op" "return") [%last_error%.$.instruction])
)
(xor
(call relay ("ipfs-adapter" "set_external_api_multiaddr") [external_api_multiaddr])
(call %init_peer_id% ("op" "return") [%last_error%.$.instruction])
)
)
(xor
(seq
(call relay ("ipfs-adapter" "set_external_swarm_multiaddr") [external_swarm_multiaddr])
(call %init_peer_id% ("op" "return") ["ok"])
)
(call %init_peer_id% ("op" "return") [%last_error%.$.instruction])
)
)

View File

@ -0,0 +1,5 @@
{
"external_swarm_multiaddr": "$FLUENCE_ENV_IPFS_ADAPTER_EXTERNAL_SWARM_MULTIADDR",
"local_api_multiaddr": "$FLUENCE_ENV_IPFS_ADAPTER_LOCAL_API_MULTIADDR",
"external_api_multiaddr": "$FLUENCE_ENV_IPFS_ADAPTER_EXTERNAL_API_MULTIADDR"
}