diff --git a/demo/README.md b/demo/README.md new file mode 100644 index 0000000..63a0f55 --- /dev/null +++ b/demo/README.md @@ -0,0 +1,59 @@ +# Registry Demo + +## Setup + +* Run the laconicd chain: + + ```bash + # In laconcid + make install + ./scripts/init.sh clean + ``` + +* Create and populate `config.yml` following [config.example.yml](./config.example.yml): + + ```bash + # Get user key + laconicd keys export alice --unarmored-hex --unsafe --keyring-backend test --home ~/.laconicd + + # Create a bond + laconicd tx bond create 100000000000photon --fees 100photon --from alice + + # Get the bond id + laconicd query bond list + ``` + +* Install the CLI: + + ```bash + yarn && yarn build + yarn global add file:$PWD + ``` + +## Run + +* Publish watcher records from [`demo/records`](./demo/records): + + ```bash + # Publishes records and corresponding 'deployment' records from the given directory + yarn ts-node demo/scripts/publish-records.ts --config config.yml --records demo/records/watcher + ``` + +### Example + +* Query for `ajna-watcher` deployment(s): + + * Find the `WatcherRecord` for `ajna-watcher`: + + ```bash + WATCHER_RECORD_ID=$(laconic registry record list --all --type WatcherRecord --name ajna-watcher | jq -r '.[].id') + ``` + + * Find corresponding deployment(s): + + ```bash + laconic registry record list --all --type WatcherDeploymentRecord watcher $WATCHER_RECORD_ID + + # Get the deployment URL(s) + laconic registry record list --all --type WatcherDeploymentRecord watcher $WATCHER_RECORD_ID | jq -r '.[].attributes.url' + ``` diff --git a/demo/records/subgraph/SushiswapV2Subgraph.json b/demo/records/subgraph/SushiswapV2Subgraph.json new file mode 100644 index 0000000..0ffd07a --- /dev/null +++ b/demo/records/subgraph/SushiswapV2Subgraph.json @@ -0,0 +1,11 @@ +{ + "type": "SubgraphRecord", + "version": "0.1.0", + "schema": "", + "name": "sushiswap-v2-subgraph", + "subgraphName": "sushiswap/v2-filecoin", + "repository": "https://github.com/sushiswap/subgraphs", + "repository_ref": "8a465f0b583a916debdbe357e1bb99205d8709f4", + "network": "filecoin", + "chain": "314" +} diff --git a/demo/records/subgraph/deployments/SushiswapV2SubgraphDeployment.json b/demo/records/subgraph/deployments/SushiswapV2SubgraphDeployment.json new file mode 100644 index 0000000..0b93058 --- /dev/null +++ b/demo/records/subgraph/deployments/SushiswapV2SubgraphDeployment.json @@ -0,0 +1,11 @@ +{ + "type": "SubgraphDeploymentRecord", + "version": "0.1.0", + "schema": "", + "request": "", + "name": "sushiswap-v2-subgraph", + "subgraph": "", + "subgraph_id": "QmejnkeYZxJKxz6kV62V6mSmAKVDuyoiDsempRC6NMunYo", + "url": "https://sushiswap-v2-subgraph-endpoint.example.com", + "needs_auth": false +} diff --git a/records/watcher/AjnaWatcher.json b/demo/records/watcher/AjnaWatcher.json similarity index 92% rename from records/watcher/AjnaWatcher.json rename to demo/records/watcher/AjnaWatcher.json index 2bd84ff..f2ec2f8 100644 --- a/records/watcher/AjnaWatcher.json +++ b/demo/records/watcher/AjnaWatcher.json @@ -7,5 +7,5 @@ "repository_ref": "66b8d96308eacab1ef6a4f3cb74a0f28fb18dc67", "watcher_version": "0.1.3", "is_subgraph_watcher": true, - "chain": "filecoin" + "chain": "314" } diff --git a/records/watcher/AzimuthWatcher.json b/demo/records/watcher/AzimuthWatcher.json similarity index 92% rename from records/watcher/AzimuthWatcher.json rename to demo/records/watcher/AzimuthWatcher.json index a0193d0..7d4b4d0 100644 --- a/records/watcher/AzimuthWatcher.json +++ b/demo/records/watcher/AzimuthWatcher.json @@ -7,5 +7,5 @@ "repository_ref": "ffd8baa4bcdd0b0fff701d942de572b7ddf33191", "watcher_version": "0.1.3", "is_subgraph_watcher": false, - "chain": "ethereum" + "chain": "1" } diff --git a/records/watcher/MerklSushiswapWatcher.json b/demo/records/watcher/MerklSushiswapWatcher.json similarity index 93% rename from records/watcher/MerklSushiswapWatcher.json rename to demo/records/watcher/MerklSushiswapWatcher.json index ee64b65..13fecbd 100644 --- a/records/watcher/MerklSushiswapWatcher.json +++ b/demo/records/watcher/MerklSushiswapWatcher.json @@ -7,5 +7,5 @@ "repository_ref": "b7cf79883e73400ad064b0357208c167795ab521", "watcher_version": "0.1.9", "is_subgraph_watcher": true, - "chain": "filecoin" + "chain": "314" } diff --git a/records/watcher/SushiswapWatcher.json b/demo/records/watcher/SushiswapWatcher.json similarity index 93% rename from records/watcher/SushiswapWatcher.json rename to demo/records/watcher/SushiswapWatcher.json index e11cb80..4687af5 100644 --- a/records/watcher/SushiswapWatcher.json +++ b/demo/records/watcher/SushiswapWatcher.json @@ -7,5 +7,5 @@ "repository_ref": "2f9f4d1ca191805922a51d1e3b471c06314fbc64", "watcher_version": "0.1.9", "is_subgraph_watcher": true, - "chain": "filecoin" + "chain": "314" } diff --git a/records/watcher/deployments/AjnaWatcherDeployment.json b/demo/records/watcher/deployments/AjnaWatcherDeployment.json similarity index 88% rename from records/watcher/deployments/AjnaWatcherDeployment.json rename to demo/records/watcher/deployments/AjnaWatcherDeployment.json index f8a5335..834a356 100644 --- a/records/watcher/deployments/AjnaWatcherDeployment.json +++ b/demo/records/watcher/deployments/AjnaWatcherDeployment.json @@ -7,5 +7,5 @@ "watcher": "", "kind": "active", "url": "https://ajna-watcher-endpoint.example.com", - "requires_api_key": "true" + "needs_auth": true } diff --git a/records/watcher/deployments/AzimuthWatcherDeployment.json b/demo/records/watcher/deployments/AzimuthWatcherDeployment.json similarity index 88% rename from records/watcher/deployments/AzimuthWatcherDeployment.json rename to demo/records/watcher/deployments/AzimuthWatcherDeployment.json index 0c6e414..197b573 100644 --- a/records/watcher/deployments/AzimuthWatcherDeployment.json +++ b/demo/records/watcher/deployments/AzimuthWatcherDeployment.json @@ -7,5 +7,5 @@ "watcher": "", "kind": "active", "url": "https://azimuth-watcher-endpoint.example.com", - "requires_api_key": "false" + "needs_auth": false } diff --git a/records/watcher/deployments/MerklSushiswapWatcherDeployment.json b/demo/records/watcher/deployments/MerklSushiswapWatcherDeployment.json similarity index 89% rename from records/watcher/deployments/MerklSushiswapWatcherDeployment.json rename to demo/records/watcher/deployments/MerklSushiswapWatcherDeployment.json index 0c04aee..b3ad954 100644 --- a/records/watcher/deployments/MerklSushiswapWatcherDeployment.json +++ b/demo/records/watcher/deployments/MerklSushiswapWatcherDeployment.json @@ -7,5 +7,5 @@ "watcher": "", "kind": "active", "url": "https://merkl-sushiswap-v3-watcher-endpoint.example.com", - "requires_api_key": "false" + "needs_auth": true } diff --git a/records/watcher/deployments/SushiswapWatcherDeployment.json b/demo/records/watcher/deployments/SushiswapWatcherDeployment.json similarity index 89% rename from records/watcher/deployments/SushiswapWatcherDeployment.json rename to demo/records/watcher/deployments/SushiswapWatcherDeployment.json index ca2acf1..5a56139 100644 --- a/records/watcher/deployments/SushiswapWatcherDeployment.json +++ b/demo/records/watcher/deployments/SushiswapWatcherDeployment.json @@ -7,5 +7,5 @@ "watcher": "", "kind": "active", "url": "https://sushiswap-v3-watcher-endpoint.example.com", - "requires_api_key": "false" + "needs_auth": true } diff --git a/src/publish-endponit-records.ts b/demo/scripts/publish-records.ts similarity index 94% rename from src/publish-endponit-records.ts rename to demo/scripts/publish-records.ts index 571715d..152df51 100644 --- a/src/publish-endponit-records.ts +++ b/demo/scripts/publish-records.ts @@ -1,11 +1,12 @@ import yargs from 'yargs'; import fs from 'fs'; import path from 'path'; +import assert from 'assert'; import { hideBin } from 'yargs/helpers'; import { Registry } from '@cerc-io/registry-sdk'; -import { getConfig, getGasAndFees, getConnectionInfo, txOutput } from './util'; +import { getConfig, getGasAndFees, getConnectionInfo, txOutput } from '../../src/util'; const recordTypeToRecordField = new Map([ ['WatcherRecord', 'watcher'], @@ -15,7 +16,7 @@ const recordTypeToRecordField = new Map([ async function main () { const argv = getArgs(); - const { records: recordsDir, config, type: recordType } = argv; + const { records: recordsDir, config } = argv; const { services: { registry: registryConfig } } = getConfig(config as string); @@ -39,6 +40,8 @@ async function main () { // Read record from each JSON file console.log('**************************************'); console.log(`Publishing records from ${recordsDir}`); + + let recordType; for (let i = 0; i < jsonFiles.length; i++) { const file = jsonFiles[i]; @@ -50,6 +53,8 @@ async function main () { console.log(`Published record from ${file}`); txOutput(result, JSON.stringify(result, undefined, 2), argv.output, argv.verbose); + + recordType = record.type; } // Check if deployment record files exist @@ -73,10 +78,13 @@ async function main () { // Find record using name and given type const recordName = deploymentRecord.name; + assert(recordType, 'recordType could not be resolved'); const queryResult = await registry.queryRecords({ type: recordType, name: recordName }, true); if (queryResult.length === 0) { throw new Error(`Record not found, type: ${recordType}, name: ${recordName}`); } + + // Assume the first query result const recordId = queryResult[0].id; // Set record field to record id @@ -119,12 +127,6 @@ function getArgs (): any { type: 'string', demandOption: true }) - .option('type', { - alias: 't', - describe: 'Record type', - type: 'string', - demandOption: true - }) .help().argv; } diff --git a/records-demo.md b/records-demo.md deleted file mode 100644 index 2d182c0..0000000 --- a/records-demo.md +++ /dev/null @@ -1,141 +0,0 @@ -# Records Demo - -* Run the laconicd chain: - - ```bash - # In laconcid - make install - ./scripts/init.sh clean - ``` - -* Create and populate `config.yml` following [config.example.yml](./config.example.yml): - - ```bash - # Get user key - laconicd keys export alice --unarmored-hex --unsafe --keyring-backend test --home ~/.laconicd - - # Create a bond - laconicd tx bond create 100000000000photon --fees 100photon --from alice - - # Get the bond id - laconicd query bond list - ``` - -* Install the CLI: - - ```bash - yarn && yarn build - yarn global add file:$PWD - ``` - -* Publish watcher records from [`records/watcher`](./records/watcher): - - ```bash - # Publishes records and corresponding 'deployment' records from the given directory - yarn ts-node src/publish-endponit-records.ts -c config.yml -r records/watcher - ``` - -## Example - -* Query for `ajna-watcher` deployment: - - * Find the `WatcherRecord` for `ajna-watcher`: - - ```bash - WATCHER_RECORD_ID=$(laconic registry record list --all --type WatcherRecord --name ajna-watcher | jq -r '.[].id') - ``` - - * Find corresponding deployment(s): - - ```bash - laconic registry record list --all --type WatcherDeploymentRecord watcher $WATCHER_RECORD_ID - - # Get the deployment URL(s) - laconic registry record list --all --type WatcherDeploymentRecord watcher $WATCHER_RECORD_ID | jq -r '.[].attributes.url' - ``` - -## Query GQL - -* View the records at laconicd GQL endpoint : - - ```gql - { - queryRecords { - id - bondId - names - attributes { - key - value { - ... on BooleanValue { bool: value } - ... on IntValue { int: value } - ... on FloatValue { float: value } - ... on StringValue { string: value } - ... on BytesValue { bytes: value } - ... on LinkValue { link: value } - ... on ArrayValue { - array: value { - ... on BooleanValue { bool: value } - ... on IntValue { int: value } - ... on FloatValue { float: value } - ... on StringValue { string: value } - ... on BytesValue { bytes: value } - ... on LinkValue { link: value } - } - } - ... on MapValue { map: value { key mapping: value { __typename } } } - } - } - } - } - ``` - -* Query with filters, for example: query all `filecoin` `WatcherRecord`s: - - ```gql - { - queryRecords ( - attributes: [ - { - key: "type", - value: { - string: "WatcherRecord" - } - }, - { - key: "chain", - value: { - string: "filecoin" - } - } - ], - all: true - ) { - id - bondId - names - attributes { - key - value { - ... on BooleanValue { bool: value } - ... on IntValue { int: value } - ... on FloatValue { float: value } - ... on StringValue { string: value } - ... on BytesValue { bytes: value } - ... on LinkValue { link: value } - ... on ArrayValue { - array: value { - ... on BooleanValue { bool: value } - ... on IntValue { int: value } - ... on FloatValue { float: value } - ... on StringValue { string: value } - ... on BytesValue { bytes: value } - ... on LinkValue { link: value } - } - } - ... on MapValue { map: value { key mapping: value { __typename } } } - } - } - } - } - ```