Compare commits

...

34 Commits

Author SHA1 Message Date
6814707752 Update SDK version. (#48)
Reviewed-on: cerc-io/laconic-registry-cli#48
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-21 21:38:11 +00:00
e1da44bae7 Bump version (#47)
Reviewed-on: cerc-io/laconic-registry-cli#47
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-13 21:13:39 +00:00
51fd81a082 Decode JSON strings automatically. 2023-12-13 15:10:09 -06:00
3cdd930b82 0.1.5 (#46)
Reviewed-on: cerc-io/laconic-registry-cli#46
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-08 04:55:27 +00:00
80d1b01713 SDK 0.1.11 (#45)
Reviewed-on: cerc-io/laconic-registry-cli#45
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-08 04:53:08 +00:00
f3c0ae8c34 Use SDK 0.1.10 (#44)
Reviewed-on: cerc-io/laconic-registry-cli#44
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-07 22:15:04 +00:00
f5625d0c87 Take the path as-is, not relative to the current dir. (#43)
Reviewed-on: cerc-io/laconic-registry-cli#43
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-05 03:53:15 +00:00
fb381c07f3 Fix cns name resolve (#42)
The `cns name resolve` does not return the result.  Obviously it should.

Reviewed-on: cerc-io/laconic-registry-cli#42
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-30 05:01:25 +00:00
145da8c453 v0.1.2 (#41)
Reviewed-on: cerc-io/laconic-registry-cli#41
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-29 17:39:18 +00:00
6e0829d91f Filter by arbitrary attributes (#40)
```
laconic cns record list \
  --type GeneralRecord \
  --value anything-goes-here \
  --category filter-by-this \
  --bond-id d0094c75e267abb709d631abd7bfaa8d610413f5766ddfc07db735822905d641 \
  --owner AB0A17A1EBF47DDCF6AB267CA8E07B7EA836E1AF \
  --all
```

Reviewed-on: cerc-io/laconic-registry-cli#40
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-28 23:22:57 +00:00
1fa32a3cc1 Add .gitea workflows (#39)
Reviewed-on: cerc-io/laconic-registry-cli#39
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-22 04:19:39 +00:00
129019105d Convert sub-objects (other than arrays) in YAML to JSON strings automatically. (#38)
This allows us to support attributes in YAML like this:

```
  meta:
    foo: bar
    bar:
      baz: boz
```

Which will automatically become:

```
"meta": "{\"foo\":\"bar\",\"bar\":{\"baz\":\"boz\"}}"
```

> Note: cosmos-sdk's protobuf code does not support maps (https://github.com/cosmos/cosmos-sdk/issues/15254), or else we would just use a map.

Reviewed-on: cerc-io/laconic-registry-cli#38
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-20 22:01:39 +00:00
Zach
37b69da3bb
Merge pull request #35 from cerc-io/dboreham/remove-lerna-file
Remove unnecessary lerna.json file
2023-04-04 09:14:47 -04:00
707b3049ef Remove unnecessary lerna.json file 2023-04-04 07:09:48 -06:00
Zach
a986e4cccb
Merge pull request #33 from cerc-io/murali/output
fix cmd outputs
2023-03-28 08:30:56 -04:00
0xmuralik
61a2aaab0f fix send output 2023-03-27 19:37:16 +05:30
0xmuralik
0c0eb79fa3 eliminate dry code 2023-03-27 18:14:42 +05:30
0xmuralik
8ebb80beed json format 2023-03-27 17:35:47 +05:30
0xmuralik
9b9e8829ec name outputs 2023-03-27 16:58:14 +05:30
0xmuralik
1de17a40ef authority and auction output 2023-03-27 13:58:41 +05:30
0xmuralik
d3020daf2e bond and records outputs 2023-03-27 13:14:02 +05:30
Zach
495bbfdb3c
Merge pull request #21 from cerc-io/integrated_testing
Integrated testing
2023-03-17 14:21:49 -04:00
Zach
64a796c421
Merge pull request #30 from cerc-io/murali/bond
get bond id
2023-03-15 21:26:47 -04:00
0xmuralik
3258e4cfe3 get bond id 2023-03-07 16:27:53 +05:30
Zach
cbcc31d6bd
Merge pull request #23 from cerc-io/0xmuralik-patch-1
Update README.md
2023-03-06 21:10:10 -05:00
Zach
a5e0a6dd22
Merge pull request #24 from cerc-io/0xmuralik-patch-2
Update README.md to fix null auction
2023-03-06 17:50:55 -05:00
Murali Krishna Komatireddy
5e0c6dd649
Update README.md 2023-03-01 14:51:15 +05:30
Murali Krishna Komatireddy
46c333985e
Update README.md 2023-03-01 11:48:50 +05:30
Michael Shaw
93e3f5c301 trying basic npm publish 2023-02-15 17:57:29 -05:00
Michael Shaw
723c2be857 private for workspaces 2023-02-15 17:24:44 -05:00
Michael Shaw
c0280b7352 add src workspace package 2023-02-15 17:21:09 -05:00
Michael Shaw
b7b77fb04e add lerna dependency for publishing 2023-02-15 17:07:45 -05:00
Michael Shaw
b05b550c43 use yarn lerna to publish 2023-02-15 16:56:53 -05:00
Michael Shaw
49c4c1f049 incomplete first pass of testing to get package.json updated on branch for publishing 2023-02-15 15:57:23 -05:00
40 changed files with 380 additions and 85 deletions

View File

@ -0,0 +1,36 @@
name: Publish npm package to gitea
on:
release:
types: [published]
jobs:
npm_publish:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 18.x ]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download yarn
run: |
curl -fsSL -o /usr/local/bin/yarn https://github.com/yarnpkg/yarn/releases/download/v1.22.21/yarn-1.22.21.js
chmod +x /usr/local/bin/yarn
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: yarn
- name: Run yarn build
run: |
yarn build
- name: Configure git.vdb.to npm registry
run: |
npm config set registry https://git.vdb.to/api/packages/cerc-io/npm/
- name: Authenticate to git.vdb.to registry
run: |
npm config set -- '//git.vdb.to/api/packages/cerc-io/npm/:_authToken' "${{ secrets.CICD_PUBLISH_TOKEN }}"
- name: npm publish
run: |
npm publish

45
.gitea/workflows/test.yml Normal file
View File

@ -0,0 +1,45 @@
name: Tests
on:
pull_request:
branches:
- '*'
push:
branches:
- main
- release/**
env:
DOCKER_HOST: unix:///var/run/dind.sock
jobs:
sdk_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout laconicd
uses: actions/checkout@v3
with:
path: "./laconicd/"
repository: cerc-io/laconicd
fetch-depth: 0
ref: main
- name: Environment
run: ls -tlh && env
- name: Start dockerd
run: |
dockerd -H $DOCKER_HOST --userland-proxy=false &
sleep 5
- name: build registry-cli container
run: docker build -t cerc/laconic-registry-cli:local-test --build-arg CERC_NPM_URL=https://git.vdb.to/api/packages/cerc-io/npm/ --build-arg CERC_NPM_AUTH_TOKEN="${{ secrets.CICD_PUBLISH_TOKEN }}" .
- name: build containers scripts
working-directory: laconicd/tests/sdk_tests
run: ./build-laconicd-container.sh
- name: start laconicd container
working-directory: laconicd/tests/sdk_tests
run: docker compose up laconicd -d
- name: Run registry-cli demo commands in registry-cli container
run : ls -tla
- name: stop containers
working-directory: laconicd/tests/sdk_tests
run: docker compose down

View File

@ -35,6 +35,6 @@ jobs:
- name: Authenticate to git.vdb.to registry
run: |
npm config set -- '//git.vdb.to/api/packages/cerc-io/npm/:_authToken' "${{ secrets.GITEA_PUBLISH_TOKEN }}"
- name: lerna publish
run: |
lerna publish from-package --no-git-tag-version --yes
- name: npm publish
run: npm publish

37
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,37 @@
name: Tests
on:
pull_request:
push:
branches:
- main
- release/**
jobs:
sdk_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout laconicd
uses: actions/checkout@v3
with:
path: "./laconicd/"
repository: cerc-io/laconicd
fetch-depth: 0
ref: main
- name: Environment
run: ls -tlh && env
- name: build registry-cli container
run: docker build -t cerc/laconic-registry-cli:local-test --build-arg CERC_NPM_URL=https://git.vdb.to/api/packages/cerc-io/npm/ --build-arg CERC_NPM_AUTH_TOKEN="${{ secrets.GITEA_PUBLISH_TOKEN }}" .
- name: build containers scripts
working-directory: laconicd/tests/sdk_tests
run: ./build-laconicd-container.sh
- name: start laconicd container
working-directory: laconicd/tests/sdk_tests
run: docker compose up laconicd -d
- name: Run registry-cli demo commands in registry-cli container
run : ls -tla
- name: stop containers
working-directory: laconicd/tests/sdk_tests
run: docker compose down

3
.gitignore vendored
View File

@ -4,3 +4,6 @@ dist/*
out
config.yml
*~
.idea

56
Dockerfile Normal file
View File

@ -0,0 +1,56 @@
# Originally from: https://github.com/devcontainers/images/blob/main/src/javascript-node/.devcontainer/Dockerfile
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
ARG VARIANT=16-bullseye
FROM node:${VARIANT}
ARG USERNAME=node
ARG NPM_GLOBAL=/usr/local/share/npm-global
# This container pulls npm packages from a local registry configured via these env vars
ARG CERC_NPM_URL
ARG CERC_NPM_AUTH_TOKEN
# Add NPM global to PATH.
ENV PATH=${NPM_GLOBAL}/bin:${PATH}
RUN \
# Configure global npm install location, use group to adapt to UID/GID changes
if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \
&& usermod -a -G npm ${USERNAME} \
&& umask 0002 \
&& mkdir -p ${NPM_GLOBAL} \
&& touch /usr/local/etc/npmrc \
&& chown ${USERNAME}:npm ${NPM_GLOBAL} /usr/local/etc/npmrc \
&& chmod g+s ${NPM_GLOBAL} \
&& npm config -g set prefix ${NPM_GLOBAL} \
&& su ${USERNAME} -c "npm config -g set prefix ${NPM_GLOBAL}" \
# Install eslint
&& su ${USERNAME} -c "umask 0002 && npm install -g eslint" \
&& npm cache clean --force > /dev/null 2>&1
# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends jq
# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>"
# Configure the local npm registry
RUN npm config set @lirewine:registry ${CERC_NPM_URL} \
&& npm config set @cerc-io:registry ${CERC_NPM_URL} \
&& npm config set -- ${CERC_NPM_URL}:_authToken ${CERC_NPM_AUTH_TOKEN}
# TODO: the image at this point could be made a base image for several different CLI images
# that install different Node-based CLI commands
# DEBUG, remove
RUN yarn info @cerc-io/laconic-registry-cli
# Globally install the cli package
RUN yarn global add @cerc-io/laconic-registry-cli
ENTRYPOINT ["laconic"]

View File

@ -10,6 +10,14 @@ CLI utility written in TS, used to interact with laconicd. Depends on [laconic-s
## Account Setup
Run the chain:
- In laconicd repo run:
```bash
TEST_AUCTION_ENABLED=true ./init.sh
```
Registering records in CNS requires an account. To get account private key run:
```bash
@ -128,26 +136,18 @@ Create record (generic):
```yaml
# watcher.yml
record:
name: ERC20 Watcher
type: watcher
version: 1.0.0
protocol:
/: QmbQiRpLX5djUsfc2yDswHvTkHTGd9uQEy6oUJfxkBYwRq
package:
linux:
x64:
/: QmVRmLrQeLZS8Xee7YVzYYAQANWmXqsNgNkaPMxM8MtPLA
arm:
/: QmX3DDmeFunX5aVmaTNnViwQUe15Wa4UbZYcC3AwFwoWcg
macos:
x64:
/: QmXogCVZZ867qZfS3CYjYdDEziPb4ARiDfgwqbd7urVKkr
type: WebsiteRegistrationRecord
url: 'https://cerc.io'
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
version: 1.0.23
```
Publish record (see below for commands to create/query bonds):
```bash
$ laconic cns record publish --filename watcher.yml --bond-id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785
$ laconic cns record publish --filename watcher.yml --bond-id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785 --gas 250000
{ id: 'bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba' }
```

29
docker-compose.yml Normal file
View File

@ -0,0 +1,29 @@
services:
laconicd:
restart: unless-stopped
image: cerc-io/laconicd:local-test
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
volumes:
- laconicd/init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
healthcheck:
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
interval: 1s
timeout: 5s
retries: 30
ports:
- "6060"
- "26657"
- "26656"
- "9473"
- "8545"
- "8546"
- "9090"
- "9091"
- "1317"
cli-test-runner:
image: cerc/laconic-registry-cli:local-test
depends_on:
laconicd:
condition: service_healthy
command: tail -F /dev/null

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/laconic-registry-cli",
"version": "0.1.0",
"version": "0.1.7",
"main": "index.js",
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
"author": "",
@ -15,7 +15,7 @@
},
"dependencies": {
"fs-extra": "^10.1.0",
"@cerc-io/laconic-sdk": "0.1.6",
"@cerc-io/laconic-sdk": "^0.1.13",
"js-yaml": "^3.14.1",
"lodash": "^4.17.21",
"lodash-clean": "^2.2.3",

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Account, Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get';
@ -24,5 +24,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAccounts([address]);
console.log(JSON.stringify(result, undefined, 2));
queryOutput(result,argv.output);
}

View File

@ -5,7 +5,7 @@ import { Account, createBid, Registry } from '@cerc-io/laconic-sdk';
import { ensureDir } from 'fs-extra';
import fs from 'fs';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
const OUT_DIR = 'out';
@ -43,7 +43,7 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const revealFile = `{"reveal_file":"${revealFilePath}"}`
console.log(`\nReveal file: ${revealFilePath}`);
txOutput(result,revealFile,argv.output,argv.verbose)
}

View File

@ -4,7 +4,7 @@ import path from 'path';
import { Registry } from '@cerc-io/laconic-sdk';
import fs from 'fs';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
export const command = 'reveal [auction-id] [file-path]';
@ -28,5 +28,7 @@ export const handler = async (argv: Arguments) => {
const reveal = fs.readFileSync(path.resolve(filePath));
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get [id]';
@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAuctionsByIds([id as string]);
console.log(JSON.stringify(result, undefined, 2));
queryOutput(result,argv.output)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
export const command = 'set [name] [bond-id]';
@ -24,5 +24,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'reserve [name]';
@ -31,5 +31,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.reserveAuthority({ name, owner }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'whois [name]';
@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.lookupAuthorities([name], true);
console.log(JSON.stringify(result, undefined, 2));
queryOutput(result,argv.output)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
export const command = 'associate';
@ -30,5 +30,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
export const command = 'cancel';
@ -22,5 +22,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.cancelBond({ id }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
export const command = 'create';
@ -34,6 +34,10 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const bondId = await registry.getNextBondId(privateKey);
const result = await registry.createBond({ denom, amount }, privateKey, fee);
console.log(verbose ? JSON.stringify(result, undefined, 2) : result.data);
const jsonString=`{"bondId":"${bondId}"}`
txOutput(result,jsonString,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
export const command = 'dissociate';
@ -22,5 +22,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.dissociateBond({ recordId: id }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
export const command = 'get';
@ -21,5 +21,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getBondsByIds([id as string]);
console.log(JSON.stringify(result, undefined, 2));
queryOutput(result,argv.output)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
export const command = 'list';
@ -25,5 +25,6 @@ export const handler = async (argv: Arguments) => {
const { owner } = argv;
const result = await registry.queryBonds({ owner });
console.log(JSON.stringify(result, undefined, 2));
queryOutput(result,argv.output)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../../util';
export const command = 'dissociate';
@ -28,5 +28,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.dissociateRecords({ bondId }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../../util';
export const command = 'reassociate';
@ -33,5 +33,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.reassociateRecords({ oldBondId, newBondId }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,8 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
import { isNil } from 'lodash';
export const command = 'refill';
@ -36,5 +37,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.refillBond({ id, denom, amount }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
export const command = 'withdraw';
@ -36,5 +36,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
export const command = 'delete [name]';
@ -23,5 +23,7 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.deleteName({ crn: name }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
export const command = 'lookup [name]';
@ -27,5 +27,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.lookupNames([name], argv.history as boolean);
console.log(JSON.stringify(result, undefined, 2));
queryOutput(result,argv.output)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'resolve [name]';
@ -20,6 +20,8 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.resolveNames([name]);
console.log(JSON.stringify(result, undefined, 4));
let result = await registry.resolveNames([name]);
result = result.filter((v: any) => v);
queryOutput(result, argv.output);
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
export const command = 'set [name] [id]';
@ -25,5 +25,7 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setName({ crn: name, cid: id }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const success = `{"success":${result.code==0}}`
txOutput(result,success,argv.output,argv.verbose)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
export const command = 'get';
@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getRecordsByIds([id as string]);
console.log(JSON.stringify(result, undefined, 2));
queryOutput(result,argv.output)
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
export const command = 'list';
@ -12,6 +12,9 @@ export const builder = {
'bond-id': {
type: 'string'
},
owner: {
type: 'string'
},
type: {
type: 'string'
},
@ -27,7 +30,13 @@ export const builder = {
export const handler = async (argv: Arguments) => {
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
const { type, name, bondId, all } = argv;
const { type, name, bondId, owner, all } = argv;
const filters: any = {};
const filterArgs = argv._.slice(3);
for (let i = 0; i < filterArgs.length-1; i+=2) {
filters[String(filterArgs[i]).replace(/^-+/,"")] = filterArgs[i+1];
}
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@ -35,6 +44,16 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.queryRecords({ bondId, type, name }, all as boolean);
console.log(JSON.stringify(result, undefined, 2));
let result = await registry.queryRecords({...filters, type, name}, all as boolean);
// Apply ex post filters.
if (bondId) {
result = result.filter((v: any) => v.bondId === bondId);
}
if (owner) {
result = result.filter((v: any) => v.owners?.find((e: string) => e === owner));
}
queryOutput(result, argv.output)
}

View File

@ -5,7 +5,7 @@ import yaml from 'js-yaml';
import fs from 'fs';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getGasAndFees, getConnectionInfo } from '../../../util';
import { getConfig, getGasAndFees, getConnectionInfo, txOutput } from '../../../util';
export const command = 'publish';
@ -30,15 +30,23 @@ export const handler = async (argv: Arguments) => {
let file = null;
if (filename) {
file = path.join(process.cwd(), filename as string);
file = filename as string;
} else {
file = 0; // stdin
}
const { record } = await yaml.load(fs.readFileSync(file, 'utf-8')) as any;
// Convert sub-objects (other than arrays) to a JSON automatically.
for (const [k, v] of Object.entries(record)) {
if (v && typeof v === "object" && !Array.isArray(v)) {
record[k] = JSON.stringify(v);
}
}
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey as string, fee);
console.log(verbose ? JSON.stringify(result, undefined, 2) : result.data);
txOutput(result,JSON.stringify(result.data,undefined,2),argv.output,argv.verbose)
}

View File

@ -6,5 +6,6 @@ export const desc = 'Record operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('record-cmds')
.parserConfiguration({'unknown-options-as-args': true})
.demandCommand()
}

View File

@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Account, Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, queryOutput } from '../../../util';
export const command = 'send';
@ -40,5 +40,5 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
await registry.sendCoins({ denom, amount, destinationAddress }, privateKey, fee);
const result = await registry.getAccounts([fromAddress, destinationAddress]);
console.log(JSON.stringify(result, undefined, 2));
queryOutput(result,argv.output)
}

View File

@ -15,6 +15,11 @@ yargs(hideBin(process.argv))
default: 'config.yml',
describe: 'Config file path.',
type: 'string'
},
output: {
alias: 'o',
describe: 'Gives output in json format when specified.',
type: 'string'
}
})
.commandDir('cmds')

View File

@ -1,3 +1,4 @@
export * from './fees';
export * from './config';
export * from './common';
export * from './output';

22
src/util/output.ts Normal file
View File

@ -0,0 +1,22 @@
export const txOutput = (result:any,msg:string,output:unknown,verbose:unknown) => {
if (output=="json"){
console.log(verbose ? JSON.parse(JSON.stringify(result)) : JSON.parse(msg));
} else {
console.log(verbose ? JSON.stringify(result,undefined,2) : msg);
}
};
export const queryOutput = (result: any, output: unknown) => {
if (output=="json"){
console.log(JSON.parse(JSON.stringify(result)));
} else {
console.log(JSON.stringify(result, (key, value) => {
try {
return JSON.parse(value)
} catch (e) {
return value;
}
}, 2));
}
}

7
watcher.yml Normal file
View File

@ -0,0 +1,7 @@
record:
type: WebsiteRegistrationRecord
url: 'https://cerc.io'
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
version: 1.0.35

View File

@ -2,10 +2,10 @@
# yarn lockfile v1
"@cerc-io/laconic-sdk@0.1.4":
version "0.1.4"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Flaconic-sdk/-/0.1.4/laconic-sdk-0.1.4.tgz#06159cb3c9c48325b53eba9bd642cf63420351d9"
integrity sha512-IsXUnz5S14zF+VPWydKy52PkCdyFqRJiMs9FCv8YEJVtUasXkU9xJLBmGaz7Nuo2MyNyKy2NHM7LoB1A75ZHAQ==
"@cerc-io/laconic-sdk@^0.1.13":
version "0.1.13"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Flaconic-sdk/-/0.1.13/laconic-sdk-0.1.13.tgz#a51c601f50f3c96656556b7c3f28bc544aac8aef"
integrity sha512-P5dCEZjpQTGupSDz1mBfGl3SK/95KKHP0Yww6zlz9xva8l66P9t6juYcF//Os2vA4PzDujCTETPr15kJHSFcTQ==
dependencies:
"@cosmjs/amino" "^0.28.1"
"@cosmjs/crypto" "^0.28.1"
@ -25,7 +25,6 @@
ethers "^5.6.2"
evmosjs "^0.2.5"
graphql.js "^0.6.8"
is-url "^1.2.4"
js-sha256 "^0.9.0"
js-yaml "^3.14.1"
jsonschema "^1.4.0"
@ -1131,11 +1130,6 @@ is-hex-prefixed@1.0.0:
resolved "https://registry.yarnpkg.com/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz#7d8d37e6ad77e5d127148913c573e082d777f554"
integrity sha1-fY035q135dEnFIkTxXPggtd39VQ=
is-url@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/is-url/-/is-url-1.2.4.tgz#04a4df46d28c4cff3d73d01ff06abeb318a1aa52"
integrity sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==
js-sha256@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966"