Skip to content

Commit

Permalink
Modify Readme@
Browse files Browse the repository at this point in the history
  • Loading branch information
juanobligado committed Aug 23, 2021
1 parent 63678fe commit 9e083cd
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 2 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -46,4 +69,7 @@ ceramic commits <<SchemaId>>
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 <<schemaId>
```
```
#License
This project is licensed under the MIT license.
168 changes: 168 additions & 0 deletions web/src/_aqua/aggregator_service.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
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" "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;
}

0 comments on commit 9e083cd

Please sign in to comment.