Refactor to demo dir
This commit is contained in:
parent
f32a0d1cf1
commit
7bdeab22f8
59
demo/README.md
Normal file
59
demo/README.md
Normal file
@ -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'
|
||||
```
|
11
demo/records/subgraph/SushiswapV2Subgraph.json
Normal file
11
demo/records/subgraph/SushiswapV2Subgraph.json
Normal file
@ -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"
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"type": "SubgraphDeploymentRecord",
|
||||
"version": "0.1.0",
|
||||
"schema": "",
|
||||
"request": "",
|
||||
"name": "sushiswap-v2-subgraph",
|
||||
"subgraph": "<subgraph-record-id>",
|
||||
"subgraph_id": "QmejnkeYZxJKxz6kV62V6mSmAKVDuyoiDsempRC6NMunYo",
|
||||
"url": "https://sushiswap-v2-subgraph-endpoint.example.com",
|
||||
"needs_auth": false
|
||||
}
|
@ -7,5 +7,5 @@
|
||||
"repository_ref": "66b8d96308eacab1ef6a4f3cb74a0f28fb18dc67",
|
||||
"watcher_version": "0.1.3",
|
||||
"is_subgraph_watcher": true,
|
||||
"chain": "filecoin"
|
||||
"chain": "314"
|
||||
}
|
@ -7,5 +7,5 @@
|
||||
"repository_ref": "ffd8baa4bcdd0b0fff701d942de572b7ddf33191",
|
||||
"watcher_version": "0.1.3",
|
||||
"is_subgraph_watcher": false,
|
||||
"chain": "ethereum"
|
||||
"chain": "1"
|
||||
}
|
@ -7,5 +7,5 @@
|
||||
"repository_ref": "b7cf79883e73400ad064b0357208c167795ab521",
|
||||
"watcher_version": "0.1.9",
|
||||
"is_subgraph_watcher": true,
|
||||
"chain": "filecoin"
|
||||
"chain": "314"
|
||||
}
|
@ -7,5 +7,5 @@
|
||||
"repository_ref": "2f9f4d1ca191805922a51d1e3b471c06314fbc64",
|
||||
"watcher_version": "0.1.9",
|
||||
"is_subgraph_watcher": true,
|
||||
"chain": "filecoin"
|
||||
"chain": "314"
|
||||
}
|
@ -7,5 +7,5 @@
|
||||
"watcher": "<watcher-record-id>",
|
||||
"kind": "active",
|
||||
"url": "https://ajna-watcher-endpoint.example.com",
|
||||
"requires_api_key": "true"
|
||||
"needs_auth": true
|
||||
}
|
@ -7,5 +7,5 @@
|
||||
"watcher": "<watcher-record-id>",
|
||||
"kind": "active",
|
||||
"url": "https://azimuth-watcher-endpoint.example.com",
|
||||
"requires_api_key": "false"
|
||||
"needs_auth": false
|
||||
}
|
@ -7,5 +7,5 @@
|
||||
"watcher": "<watcher-record-id>",
|
||||
"kind": "active",
|
||||
"url": "https://merkl-sushiswap-v3-watcher-endpoint.example.com",
|
||||
"requires_api_key": "false"
|
||||
"needs_auth": true
|
||||
}
|
@ -7,5 +7,5 @@
|
||||
"watcher": "<watcher-record-id>",
|
||||
"kind": "active",
|
||||
"url": "https://sushiswap-v3-watcher-endpoint.example.com",
|
||||
"requires_api_key": "false"
|
||||
"needs_auth": true
|
||||
}
|
@ -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<string, string>([
|
||||
['WatcherRecord', 'watcher'],
|
||||
@ -15,7 +16,7 @@ const recordTypeToRecordField = new Map<string, string>([
|
||||
|
||||
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;
|
||||
}
|
||||
|
141
records-demo.md
141
records-demo.md
@ -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 <http://localhost:9473>:
|
||||
|
||||
```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 } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user