From 9e083cd88cfbc3c0ac32cb72ec2e2f6f574727aa Mon Sep 17 00:00:00 2001 From: juanobligado Date: Mon, 23 Aug 2021 01:58:26 +0000 Subject: [PATCH] Modify Readme@ --- README.md | 30 ++++- web/src/_aqua/aggregator_service.ts | 168 ++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 web/src/_aqua/aggregator_service.ts diff --git a/README.md b/README.md index 0d21b90..fc04d8f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,29 @@ -# dxpriceaggregator +# DXPriceaggregator Decentralized Price Aggregation Service +#Tree Structure + +. +├── schema # Ceramic schema definition +├── services # Fluence Services +│ ├── ceramic_adapter # ceramic adapter service +│ ├── aggregator_service # price aggregator service +│ ├── artifacts # Web Assembly outputs +│ ├── configs # Configuration files to deploy services +│ ├── build.sh # Build script to create artifacts +│ ├── ... +│ └── deploy_service.sh # Script to deploy artifacts into a node using fldist +│ +├── service_interface # scripts to create service interface (Air and typescripts) +│ ├── aqua_scripts # Orchestrating scripts to de +│ ├── air-scripts # generated air and typescript +│ └── build.interface.sh +├── ... +├── web +│ └── src +│ └── _aqua # Here we copy aqua generated typescript file so we can +| # invoke fluence code from Web project +└── ... #Introduction The idea is to create a Composable price aggregation service which will allow devs to easily access / create and store historical data sets in a descentralized manner @@ -46,4 +69,7 @@ ceramic commits <> 4- Initialize stream with some mock data ```bash ceramic create tile --content '{"ticker":"Foo","duration":0,"start_time":0,"open":0.0,"high":0.0,"low":0.0,"close":0.0}' --schema < -``` \ No newline at end of file +``` + +#License +This project is licensed under the MIT license. \ No newline at end of file diff --git a/web/src/_aqua/aggregator_service.ts b/web/src/_aqua/aggregator_service.ts new file mode 100644 index 0000000..2248495 --- /dev/null +++ b/web/src/_aqua/aggregator_service.ts @@ -0,0 +1,168 @@ +/** + * + * 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.9-163 + * + */ +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 read_last_price(client: FluenceClient, node: string, aggregator_service_id: string, streamId: string, config?: {ttl?: number}): Promise<{close:number;error_msg:string;high:number;low:number;open:number;success:boolean;ticker:string}> { + let request: RequestFlow; + const promise = new Promise<{close:number;error_msg:string;high:number;low:number;open:number;success:boolean;ticker:string}>((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" "aggregator_service_id") [] aggregator_service_id) + ) + (call %init_peer_id% ("getDataSrv" "streamId") [] streamId) + ) + (call -relay- ("op" "noop") []) + ) + (xor + (seq + (call -relay- ("op" "noop") []) + (call node (aggregator_service_id "read_last_price") [streamId] last_price) + ) + (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") [last_price]) + (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', 'aggregator_service_id', () => {return aggregator_service_id;}); +h.on('getDataSrv', 'streamId', () => {return streamId;}); + 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 read_last_price'); + }) + if(config?.ttl) { + r.withTTL(config.ttl) + } + request = r.build(); + }); + await client.initiateFlow(request!); + return promise; +} + + + +export async function ping(client: FluenceClient, node: string, aggregator_service_id: string, config?: {ttl?: number}): Promise { + let request: RequestFlow; + const promise = new Promise((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" "aggregator_service_id") [] aggregator_service_id) + ) + (call -relay- ("op" "noop") []) + ) + (xor + (seq + (call -relay- ("op" "noop") []) + (call node (aggregator_service_id "ping") [] ping_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") [ping_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', 'aggregator_service_id', () => {return aggregator_service_id;}); + 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 ping'); + }) + if(config?.ttl) { + r.withTTL(config.ttl) + } + request = r.build(); + }); + await client.initiateFlow(request!); + return promise; +} + \ No newline at end of file