Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
47f670bdde | |||
3be0c0aecf | |||
936ad73a89 | |||
c770d14bd9 | |||
03422548a4 | |||
86259b35a6 | |||
cf4bf5ed42 | |||
6055da62c7 | |||
aa46032bda | |||
c67961869b | |||
acd4791355 | |||
30654bb0ef | |||
70e63c74f1 | |||
901126d23f | |||
4f5de6ff38 | |||
aa2117e472 | |||
e6b747fb48 | |||
ed06cc05a6 | |||
aff309eaad | |||
b9d6804c17 | |||
6510c1b13f | |||
2e4dcf7e63 | |||
9c992ebe71 | |||
a33445aa4d | |||
cbff9646c7 | |||
c3f8d53f09 | |||
b01201ca50 | |||
5a0298dda5 | |||
97b74760d9 |
1
.env.example
Normal file
1
.env.example
Normal file
@ -0,0 +1 @@
|
|||||||
|
TEST_ACCOUNT=
|
5
.eslintignore
Normal file
5
.eslintignore
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Don't lint node_modules.
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Don't lint build output.
|
||||||
|
dist
|
21
.eslintrc.json
Normal file
21
.eslintrc.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"semistandard",
|
||||||
|
"plugin:@typescript-eslint/recommended"
|
||||||
|
],
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 12,
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"plugins": [
|
||||||
|
"@typescript-eslint"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"indent": ["error", 2, { "SwitchCase": 1 }],
|
||||||
|
"@typescript-eslint/no-explicit-any": "off"
|
||||||
|
}
|
||||||
|
}
|
28
.gitea/workflows/lint.yml
Normal file
28
.gitea/workflows/lint.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
name: Lint
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [18.x]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- 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: Linter check
|
||||||
|
run: yarn lint
|
@ -12,10 +12,29 @@ env:
|
|||||||
DOCKER_HOST: unix:///var/run/dind.sock
|
DOCKER_HOST: unix:///var/run/dind.sock
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sdk_tests:
|
cli_tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [18.x]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
- 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 }}
|
||||||
|
- name: Set registry
|
||||||
|
run: npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/
|
||||||
|
|
||||||
|
- name: Install dependencies and build
|
||||||
|
run: yarn && yarn build
|
||||||
|
- name: Install registry-cli
|
||||||
|
run: yarn global add file:$PWD
|
||||||
|
|
||||||
- name: Checkout laconicd
|
- name: Checkout laconicd
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
@ -23,23 +42,17 @@ jobs:
|
|||||||
repository: cerc-io/laconicd
|
repository: cerc-io/laconicd
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: main
|
ref: main
|
||||||
- name: Environment
|
|
||||||
run: ls -tlh && env
|
- name: Build laconicd container
|
||||||
- name: Start dockerd
|
working-directory: ./laconicd/tests/sdk_tests
|
||||||
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
|
run: ./build-laconicd-container.sh
|
||||||
- name: start laconicd container
|
- name: Start laconicd container
|
||||||
working-directory: laconicd/tests/sdk_tests
|
env:
|
||||||
|
TEST_AUCTION_ENABLED: true
|
||||||
run: docker compose up laconicd -d
|
run: docker compose up laconicd -d
|
||||||
|
|
||||||
- name: Run registry-cli demo commands in registry-cli container
|
- name: Run registry-cli tests
|
||||||
run : ls -tla
|
run: ./test/run-tests.sh
|
||||||
- name: stop containers
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
- name: Stop containers
|
||||||
run: docker compose down
|
run: docker compose down
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,6 +4,7 @@ dist/*
|
|||||||
out
|
out
|
||||||
|
|
||||||
config.yml
|
config.yml
|
||||||
|
.env
|
||||||
*~
|
*~
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
|
1
.husky/pre-commit
Normal file
1
.husky/pre-commit
Normal file
@ -0,0 +1 @@
|
|||||||
|
yarn lint
|
1
.npmrc
Normal file
1
.npmrc
Normal file
@ -0,0 +1 @@
|
|||||||
|
@cerc-io:registry=https://git.vdb.to/api/packages/cerc-io/npm/
|
429
README.md
429
README.md
@ -1,45 +1,149 @@
|
|||||||
# laconic-cns-client
|
# laconic-registry-client
|
||||||
|
|
||||||
CLI utility written in TS, used to interact with laconicd. Depends on [laconic-sdk](https://github.com/cerc-io/laconic-sdk).
|
CLI utility written in TS, used to interact with laconicd. Depends on [registry-sdk](https://git.vdb.to/cerc-io/registry-sdk).
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
* Add `.npmrc` file in desired project to resolve package
|
||||||
|
|
||||||
|
```bash
|
||||||
|
@cerc-io:registry=https://git.vdb.to/api/packages/cerc-io/npm/
|
||||||
|
```
|
||||||
|
|
||||||
|
This will set the registry for `cerc-io` scoped packages in the project
|
||||||
|
|
||||||
|
* Install the CLI using package manager
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn add @cerc-io/laconic-registry-cli
|
||||||
|
```
|
||||||
|
|
||||||
|
* For installing CLI globally add `.npmrc` file above in home directory and run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn global add @cerc-io/laconic-registry-cli
|
||||||
|
```
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
* Run `yarn` to install all dependencies.
|
* Run `yarn` to install all dependencies.
|
||||||
|
|
||||||
|
* Run `yarn build`.
|
||||||
|
|
||||||
* Create a `config.yml` file from [config.example.yml](./config.example.yml) file.
|
* Create a `config.yml` file from [config.example.yml](./config.example.yml) file.
|
||||||
|
|
||||||
|
* Add CLI cmd to path
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export PATH="$PWD/bin:$PATH"
|
||||||
|
```
|
||||||
|
|
||||||
## Account Setup
|
## Account Setup
|
||||||
|
|
||||||
Run the chain:
|
Run the chain:
|
||||||
|
|
||||||
- In laconicd repo run:
|
* In laconicd repo run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
TEST_AUCTION_ENABLED=true ./init.sh
|
TEST_AUCTION_ENABLED=true ./scripts/init.sh clean
|
||||||
```
|
```
|
||||||
|
|
||||||
Registering records in CNS requires an account. To get account private key run:
|
Registering records in registry requires an account. To get account private key run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconicd keys export mykey --unarmored-hex --unsafe
|
laconicd keys export alice --keyring-backend test --unarmored-hex --unsafe
|
||||||
```
|
```
|
||||||
|
|
||||||
In `config.yml` file assign the account private key to `userKey`.
|
In `config.yml` file assign the account private key to `userKey`:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
services:
|
||||||
|
registry:
|
||||||
|
..
|
||||||
|
userKey: "<user-key>"
|
||||||
|
..
|
||||||
|
```
|
||||||
|
|
||||||
## Gas and Fees
|
## Gas and Fees
|
||||||
|
|
||||||
https://docs.evmos.org/users/basics/gas.html
|
* Gas and fees in `cosmos-sdk`:
|
||||||
|
* <https://docs.cosmos.network/v0.50/learn/beginner/gas-fees>
|
||||||
|
* `gas` is a special unit that is used to track the consumption of resources during execution of a transaction
|
||||||
|
* The maximum value a tx is allowed to consume can be capped by setting `gas` in the config
|
||||||
|
* `fees` have to be paid by sender to allow the transaction into the mempool and is calculated using `gasPrice`:
|
||||||
|
|
||||||
* Transactions require `gas`, set to the maximum value the transaction is allowed to consume.
|
```bash
|
||||||
* Typically, validators also require transaction `fees` to be provided to allow the transaction into the mempool.
|
fees = gas * gasPrice
|
||||||
|
```
|
||||||
|
|
||||||
The `gas` and `fees` can be set to some default values in the config, and can be overriden for each command using the `--gas` and `--fees` arguments.
|
* Typically, validators / full nodes set `min-gas-prices` to only allow txs providing minimum amount of fees
|
||||||
|
* Using `cosmjs`, there are two ways max fees amount can be given for a tx:
|
||||||
|
* Either by specifying `fees` and `gas` (in which case `fees` should be >= `gas` * `min-gas-price`)
|
||||||
|
* Or by specifying a `gasPrice` (in which case `gasPrice` should be >= `min-gas-price` set by the node and fees is `auto` calculated by simulating the tx)
|
||||||
|
|
||||||
Example:
|
When using the `auto` fees calculation, the gas estimation by tx simulation is typically multiplied by a multiplier
|
||||||
|
* As such, following `gas`, `fees` and `gasPrice` combinations can be used in `laconic-registry-cli`:
|
||||||
|
* Gas set, fees set to `Xalnt`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond create --type aphoton --quantity 1000000000 --gas 200000 --fees 200000aphoton
|
# Example
|
||||||
```
|
gas: 500000
|
||||||
|
fees: 500000alnt
|
||||||
|
gasPrice:
|
||||||
|
```
|
||||||
|
|
||||||
|
* `gasPrice` config ignored
|
||||||
|
* tx rejected if given `fees` < `gas` * `min-gas-price` set by the node
|
||||||
|
* tx fails mid-execution if it runs out of given `gas`
|
||||||
|
* Fees not set, gas price set to `Xalnt`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Example
|
||||||
|
gas:
|
||||||
|
fees:
|
||||||
|
gasPrice: 1alnt
|
||||||
|
```
|
||||||
|
|
||||||
|
* `gas` config ignored
|
||||||
|
* uses `auto` fee calculation using gas estimation with [default multiplier](https://git.vdb.to/cerc-io/registry-sdk/src/branch/main/src/constants.ts) value from `registry-sdk`
|
||||||
|
* tx rejected if given `gasPrice` < `min-gas-price` set by the node
|
||||||
|
* tx fails mid-execution if it runs out of calculated gas
|
||||||
|
* Fees set to a `X` (without `alnt` suffix), gas price set to `Yalnt`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Example
|
||||||
|
gas:
|
||||||
|
fees: 1.8
|
||||||
|
gasPrice: 1alnt
|
||||||
|
```
|
||||||
|
|
||||||
|
* `gas` config ignored
|
||||||
|
* uses `auto` fee calculation using gas estimation with `fees` as the multiplier
|
||||||
|
* tx rejected if given `gasPrice` < `min-gas-price` set by the node
|
||||||
|
* tx fails mid-execution if it runs out of calculated gas, can be retried with a higher gas estimation multiplier (`fees`)
|
||||||
|
* Fees and gas price both not set:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Example
|
||||||
|
gas:
|
||||||
|
fees:
|
||||||
|
gasPrice:
|
||||||
|
```
|
||||||
|
|
||||||
|
* `gas` config ignored
|
||||||
|
* uses `auto` fee calculation using gas estimation
|
||||||
|
* throws error:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
Gas price must be set in the client options when auto gas is used.
|
||||||
|
```
|
||||||
|
|
||||||
|
* The `gas`, `fees` and `gasPrice` can be set to some default values in the config as shown above, and can be overriden for each command using the `--gas`, `--fees` and `--gasPrice` arguments:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Example:
|
||||||
|
laconic registry bond create --type alnt --quantity 100000000000 --gas 200000 --fees 200000alnt
|
||||||
|
```
|
||||||
|
|
||||||
## Operations
|
## Operations
|
||||||
|
|
||||||
@ -48,7 +152,7 @@ These commands require a `config.yml` file present in the current working direct
|
|||||||
Get node status:
|
Get node status:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns status
|
laconic registry status
|
||||||
{
|
{
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"node": {
|
"node": {
|
||||||
@ -82,16 +186,16 @@ $ laconic cns status
|
|||||||
Get account details:
|
Get account details:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns account get --address ethm133y09mveksh76uc99h4rl38nd033tk4e3y2z52
|
laconic registry account get --address laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"address": "ethm133y09mveksh76uc99h4rl38nd033tk4e3y2z52",
|
"address": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
"pubKey": "A2BeFMnq4h0v5/hP+trvQbCtVWwGGYNSHWRJ7Ae60biS",
|
"pubKey": "A2BeFMnq4h0v5/hP+trvQbCtVWwGGYNSHWRJ7Ae60biS",
|
||||||
"number": "0",
|
"number": "0",
|
||||||
"sequence": "37",
|
"sequence": "37",
|
||||||
"balance": [
|
"balance": [
|
||||||
{
|
{
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "89998999999999991999799300"
|
"quantity": "89998999999999991999799300"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -102,33 +206,62 @@ $ laconic cns account get --address ethm133y09mveksh76uc99h4rl38nd033tk4e3y2z52
|
|||||||
Send tokens:
|
Send tokens:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns tokens send --address ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu --type aphoton --quantity 1000000000
|
laconic registry tokens send --address laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k --type alnt --quantity 1000000000
|
||||||
[
|
{
|
||||||
{
|
"tx": {
|
||||||
"address": "ethm1lfekr7gvqtnhpp2kwdc6u2n569cqsp4ww0m4y8",
|
"hash": "977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC",
|
||||||
"pubKey": "A68/q7/xazFzNj+rrvE07ALxkMgqw1ugL35VECkWAYvt",
|
"height": 343369,
|
||||||
"number": "0",
|
"index": 0,
|
||||||
"sequence": "16",
|
"code": 0,
|
||||||
"balance": [
|
"log": "",
|
||||||
{
|
"sender": "laconic1pmuxrcnuhhf8qdllzuf2ctj2tnwwcg6yswqnyd",
|
||||||
"type": "aphoton",
|
"recipient": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
"quantity": "99998999999999997973999700"
|
"amount": "1000000000alnt"
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
"accounts": [
|
||||||
"address": "ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu",
|
{
|
||||||
"pubKey": null,
|
"address": "laconic1pmuxrcnuhhf8qdllzuf2ctj2tnwwcg6yswqnyd",
|
||||||
"number": "12",
|
"pubKey": "A68/q7/xazFzNj+rrvE07ALxkMgqw1ugL35VECkWAYvt",
|
||||||
"sequence": "0",
|
"number": "0",
|
||||||
"balance": [
|
"sequence": "16",
|
||||||
{
|
"balance": [
|
||||||
"type": "aphoton",
|
{
|
||||||
"quantity": "1000000000"
|
"type": "alnt",
|
||||||
}
|
"quantity": "99998999999999997973999700"
|
||||||
]
|
}
|
||||||
}
|
]
|
||||||
]
|
},
|
||||||
|
{
|
||||||
|
"address": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
|
"pubKey": null,
|
||||||
|
"number": "12",
|
||||||
|
"sequence": "0",
|
||||||
|
"balance": [
|
||||||
|
{
|
||||||
|
"type": "alnt",
|
||||||
|
"quantity": "1000000000"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Get token TX details:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic registry tokens gettx --hash 977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC
|
||||||
|
{
|
||||||
|
"hash": "977152CBE474613E1BBAFEF286F12134829FAF3C9E7C8349149DE3E687B816FC",
|
||||||
|
"height": 343369,
|
||||||
|
"index": 0,
|
||||||
|
"code": 0,
|
||||||
|
"log": "",
|
||||||
|
"sender": "laconic1pmuxrcnuhhf8qdllzuf2ctj2tnwwcg6yswqnyd",
|
||||||
|
"recipient": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
|
"amount": "1000000000alnt",
|
||||||
|
"raw": "0A91010A8E010A1C2F636F736D6F732E62616E6B2E763162657461312E4D736753656E64126E0A2E6C61636F6E696331347763303777613372377270707275343367396A786B7A68716E686D76666D34646765793673122E6C61636F6E6963317971706337637966657470676D71746B6B30756B657675676561617539703063776D6A6C73751A0C0A04616C6E7412043130303012680A500A460A1F2F636F736D6F732E63727970746F2E736563703235366B312E5075624B657912230A2102F3A1D077638F9FD828C4CF126FE82E0BE98388083F5BC1E1DD4D84132AEBFF8112040A020801185A12140A0E0A04616C6E7412063430303030301080B5181A4088DF7BA4B63EA68E185AB2887C9EC29EBC4158874BC037816B8494AD36D3B2433B5223CECC336D4624BB7FEF4DBB4A8B5F4707ACD8E55443312009E9473DF821"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Create record (generic):
|
Create record (generic):
|
||||||
@ -147,7 +280,7 @@ record:
|
|||||||
Publish record (see below for commands to create/query bonds):
|
Publish record (see below for commands to create/query bonds):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns record publish --filename watcher.yml --bond-id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785 --gas 250000
|
laconic registry record publish --filename watcher.yml --bond-id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785 --gas 250000 --fees 250000alnt
|
||||||
|
|
||||||
{ id: 'bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba' }
|
{ id: 'bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba' }
|
||||||
```
|
```
|
||||||
@ -155,7 +288,7 @@ $ laconic cns record publish --filename watcher.yml --bond-id 58508984500aa2ed18
|
|||||||
Get record:
|
Get record:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns record get --id bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba
|
laconic registry record get --id bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba",
|
"id": "bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba",
|
||||||
@ -196,19 +329,19 @@ $ laconic cns record get --id bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln
|
|||||||
List records:
|
List records:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns record list
|
laconic registry record list
|
||||||
```
|
```
|
||||||
|
|
||||||
Reserve authority:
|
Reserve authority:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns authority reserve laconic
|
laconic registry authority reserve laconic
|
||||||
```
|
```
|
||||||
|
|
||||||
Check authority information:
|
Check authority information:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns authority whois laconic
|
laconic registry authority whois laconic
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"ownerAddress": "",
|
"ownerAddress": "",
|
||||||
@ -220,20 +353,20 @@ $ laconic cns authority whois laconic
|
|||||||
"auction": {
|
"auction": {
|
||||||
"id": "0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48",
|
"id": "0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48",
|
||||||
"status": "commit",
|
"status": "commit",
|
||||||
"ownerAddress": "ethm1lfekr7gvqtnhpp2kwdc6u2n569cqsp4ww0m4y8",
|
"ownerAddress": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
"createTime": "2022-04-26T11:43:45.679728594",
|
"createTime": "2022-04-26T11:43:45.679728594",
|
||||||
"commitsEndTime": "2022-04-26T11:44:45.679728594",
|
"commitsEndTime": "2022-04-26T11:44:45.679728594",
|
||||||
"revealsEndTime": "2022-04-26T11:45:45.679728594",
|
"revealsEndTime": "2022-04-26T11:45:45.679728594",
|
||||||
"commitFee": {
|
"commitFee": {
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "1000000"
|
"quantity": "1000000"
|
||||||
},
|
},
|
||||||
"revealFee": {
|
"revealFee": {
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "1000000"
|
"quantity": "1000000"
|
||||||
},
|
},
|
||||||
"minimumBid": {
|
"minimumBid": {
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "5000000"
|
"quantity": "5000000"
|
||||||
},
|
},
|
||||||
"winnerAddress": "",
|
"winnerAddress": "",
|
||||||
@ -254,25 +387,25 @@ $ laconic cns authority whois laconic
|
|||||||
Get authority auction info:
|
Get authority auction info:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns auction get 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48
|
laconic registry auction get 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48",
|
"id": "0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48",
|
||||||
"status": "commit",
|
"status": "commit",
|
||||||
"ownerAddress": "ethm1lfekr7gvqtnhpp2kwdc6u2n569cqsp4ww0m4y8",
|
"ownerAddress": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
"createTime": "2022-04-26T11:42:05.256059269",
|
"createTime": "2022-04-26T11:42:05.256059269",
|
||||||
"commitsEndTime": "2022-04-26T11:44:45.679728594",
|
"commitsEndTime": "2022-04-26T11:44:45.679728594",
|
||||||
"revealsEndTime": "2022-04-26T11:45:45.679728594",
|
"revealsEndTime": "2022-04-26T11:45:45.679728594",
|
||||||
"commitFee": {
|
"commitFee": {
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "1000000"
|
"quantity": "1000000"
|
||||||
},
|
},
|
||||||
"revealFee": {
|
"revealFee": {
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "1000000"
|
"quantity": "1000000"
|
||||||
},
|
},
|
||||||
"minimumBid": {
|
"minimumBid": {
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "5000000"
|
"quantity": "5000000"
|
||||||
},
|
},
|
||||||
"winnerAddress": "",
|
"winnerAddress": "",
|
||||||
@ -292,7 +425,7 @@ $ laconic cns auction get 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5
|
|||||||
Commit an auction bid:
|
Commit an auction bid:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns auction bid commit 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48 25000000 aphoton
|
laconic registry auction bid commit 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48 25000000 alnt
|
||||||
|
|
||||||
Reveal file: ./out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.json
|
Reveal file: ./out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.json
|
||||||
```
|
```
|
||||||
@ -300,37 +433,49 @@ Reveal file: ./out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.j
|
|||||||
Reveal an auction bid:
|
Reveal an auction bid:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns auction bid reveal 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48 ./out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.json
|
laconic registry auction bid reveal 0294fb2e3659c347b53a6faf4bef041fd934f0f3ab13df6d2468d5d63abacd48 ./out/bafyreiay2rccax64yn4ljhvzvm3jkbebvzheyucuma5jlbpzpzd5i5gjuy.json
|
||||||
```
|
```
|
||||||
|
|
||||||
Set authority bond (after winning auction):
|
Set authority bond (after winning auction):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns authority bond set laconic 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785
|
laconic registry authority bond set laconic 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785
|
||||||
```
|
```
|
||||||
|
|
||||||
Create sub-authority (same owner as parent authority):
|
Create sub-authority (same owner as parent authority):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns authority reserve echo.laconic
|
laconic registry authority reserve echo.laconic
|
||||||
```
|
```
|
||||||
|
|
||||||
Create sub-authority (custom owner for sub-authority):
|
Create sub-authority (custom owner for sub-authority):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns authority reserve kube.laconic --owner ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu
|
laconic registry authority reserve kube.laconic --owner laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k
|
||||||
|
```
|
||||||
|
|
||||||
|
Get all the authorities:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic registry authority list
|
||||||
|
```
|
||||||
|
|
||||||
|
Get all the authorities by owner:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic registry authority list --owner laconic1zayjut6pd4xy9dguut56v55hktzmeq6r777hmd
|
||||||
```
|
```
|
||||||
|
|
||||||
Set name:
|
Set name:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns name set crn://laconic/watcher/erc20 bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba
|
laconic registry name set lrn://laconic/watcher/erc20 bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba
|
||||||
```
|
```
|
||||||
|
|
||||||
Lookup name information:
|
Lookup name information:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns name lookup crn://laconic/watcher/erc20
|
laconic registry name lookup lrn://laconic/watcher/erc20
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"latest": {
|
"latest": {
|
||||||
@ -344,7 +489,7 @@ $ laconic cns name lookup crn://laconic/watcher/erc20
|
|||||||
Resolve name:
|
Resolve name:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns name resolve crn://laconic/watcher/erc20
|
laconic registry name resolve lrn://laconic/watcher/erc20
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba",
|
"id": "bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba",
|
||||||
@ -385,9 +530,9 @@ $ laconic cns name resolve crn://laconic/watcher/erc20
|
|||||||
Delete name:
|
Delete name:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns name delete crn://laconic/watcher/erc20
|
laconic registry name delete lrn://laconic/watcher/erc20
|
||||||
|
|
||||||
$ laconic cns name resolve crn://laconic/watcher/erc20
|
laconic registry name resolve lrn://laconic/watcher/erc20
|
||||||
[
|
[
|
||||||
null
|
null
|
||||||
]
|
]
|
||||||
@ -396,30 +541,30 @@ $ laconic cns name resolve crn://laconic/watcher/erc20
|
|||||||
Create bond:
|
Create bond:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond create --type aphoton --quantity 1000
|
laconic registry bond create --type alnt --quantity 1000
|
||||||
```
|
```
|
||||||
|
|
||||||
List bonds:
|
List bonds:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond list
|
laconic registry bond list
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
||||||
"owner": "ethm1lfekr7gvqtnhpp2kwdc6u2n569cqsp4ww0m4y8",
|
"owner": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
"balance": [
|
"balance": [
|
||||||
{
|
{
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "698000000"
|
"quantity": "698000000"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0",
|
"id": "5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0",
|
||||||
"owner": "ethm1lfekr7gvqtnhpp2kwdc6u2n569cqsp4ww0m4y8",
|
"owner": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
"balance": [
|
"balance": [
|
||||||
{
|
{
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "1000"
|
"quantity": "1000"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -430,14 +575,14 @@ $ laconic cns bond list
|
|||||||
Get bond:
|
Get bond:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond get --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785
|
laconic registry bond get --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
||||||
"owner": "ethm1lfekr7gvqtnhpp2kwdc6u2n569cqsp4ww0m4y8",
|
"owner": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
"balance": [
|
"balance": [
|
||||||
{
|
{
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "691000000"
|
"quantity": "691000000"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -448,24 +593,24 @@ $ laconic cns bond get --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335
|
|||||||
Query bonds by owner:
|
Query bonds by owner:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond list --owner ethm1lfekr7gvqtnhpp2kwdc6u2n569cqsp4ww0m4y8
|
laconic registry bond list --owner laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
"id": "58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785",
|
||||||
"owner": "ethm1lfekr7gvqtnhpp2kwdc6u2n569cqsp4ww0m4y8",
|
"owner": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
"balance": [
|
"balance": [
|
||||||
{
|
{
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "684000000"
|
"quantity": "684000000"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0",
|
"id": "5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0",
|
||||||
"owner": "ethm1lfekr7gvqtnhpp2kwdc6u2n569cqsp4ww0m4y8",
|
"owner": "laconic15za32wly5exgcrt2zfr8php4ya49n5y7masu7k",
|
||||||
"balance": [
|
"balance": [
|
||||||
{
|
{
|
||||||
"type": "aphoton",
|
"type": "alnt",
|
||||||
"quantity": "1000"
|
"quantity": "1000"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -476,41 +621,145 @@ $ laconic cns bond list --owner ethm1lfekr7gvqtnhpp2kwdc6u2n569cqsp4ww0m4y8
|
|||||||
Refill bond:
|
Refill bond:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond refill --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785 --type aphoton --quantity 1000
|
laconic registry bond refill --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785 --type alnt --quantity 1000
|
||||||
```
|
```
|
||||||
|
|
||||||
Withdraw funds from bond:
|
Withdraw funds from bond:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond withdraw --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785 --type aphoton --quantity 500
|
laconic registry bond withdraw --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785 --type alnt --quantity 500
|
||||||
```
|
```
|
||||||
|
|
||||||
Cancel bond:
|
Cancel bond:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond cancel --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785
|
laconic registry bond cancel --id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785
|
||||||
```
|
```
|
||||||
|
|
||||||
Associate bond (with record):
|
Associate bond (with record):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond associate --id bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba --bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0
|
laconic registry bond associate --id bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba --bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0
|
||||||
```
|
```
|
||||||
|
|
||||||
Disassociate bond (from record):
|
Disassociate bond (from record):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond dissociate --id bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba
|
laconic registry bond dissociate --id bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba
|
||||||
```
|
```
|
||||||
|
|
||||||
Dissociate all records from bond:
|
Dissociate all records from bond:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond records dissociate --bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0
|
laconic registry bond records dissociate --bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0
|
||||||
```
|
```
|
||||||
|
|
||||||
Reassociate records (switch bond):
|
Reassociate records (switch bond):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ laconic cns bond records reassociate --old-bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0 --new-bond-id 3e11c61f179897e4b12e9b63de35d36f88ac146755e7a28ce0bcdd07cf3a03ae
|
laconic registry bond records reassociate --old-bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0 --new-bond-id 3e11c61f179897e4b12e9b63de35d36f88ac146755e7a28ce0bcdd07cf3a03ae
|
||||||
|
```
|
||||||
|
|
||||||
|
Create a `provider` auction:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic registry auction create --kind provider --commits-duration 60 --reveals-duration 60 --denom alnt --commit-fee 1000 --reveal-fee 1000 --max-price 100000 --num-providers 5
|
||||||
|
|
||||||
|
{"auctionId":"73c5fa4b91bb973641ccbb6901a8404745fb8793c95485b00d5a791e6b6c1630"}
|
||||||
|
|
||||||
|
# Set auction id in a variable
|
||||||
|
AUCTION=
|
||||||
|
```
|
||||||
|
|
||||||
|
Commit an auction bid:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic registry auction bid commit $AUCTION 25000 alnt
|
||||||
|
|
||||||
|
{"reveal_file":"/home/user/laconic-registry-cli/out/bafyreiai5upey4562ont54pe7m3buiphtd6n3q2vr5lxdcj3gpyklbbgvy.json"}
|
||||||
|
```
|
||||||
|
|
||||||
|
Reveal an auction bid:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic registry auction bid reveal $AUCTION /home/user/laconic-registry-cli/out/bafyreiai5upey4562ont54pe7m3buiphtd6n3q2vr5lxdcj3gpyklbbgvy.json
|
||||||
|
|
||||||
|
{"success": true}
|
||||||
|
```
|
||||||
|
|
||||||
|
Check the auction state on completion:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic registry auction get $AUCTION
|
||||||
|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "b66b74048fc360de6a926123b760e6485276d90ad2274b5386c02664cd04bace",
|
||||||
|
"kind": "provider",
|
||||||
|
"status": "completed",
|
||||||
|
"ownerAddress": "laconic1maqfgs93hnvzqh5mfj9kxt4e3n27vhd0w7emrx",
|
||||||
|
"createTime": "2024-09-17T09:51:48.605610628",
|
||||||
|
"commitsEndTime": "2024-09-17T09:52:48.605610628",
|
||||||
|
"revealsEndTime": "2024-09-17T09:53:48.605610628",
|
||||||
|
"commitFee": {
|
||||||
|
"type": "alnt",
|
||||||
|
"quantity": 1000
|
||||||
|
},
|
||||||
|
"revealFee": {
|
||||||
|
"type": "alnt",
|
||||||
|
"quantity": 1000
|
||||||
|
},
|
||||||
|
"minimumBid": {
|
||||||
|
"type": "",
|
||||||
|
"quantity": 0
|
||||||
|
},
|
||||||
|
"winnerAddresses": [
|
||||||
|
"laconic13qrlfkgl02wgwpw0n4j8kswygwnukphy92249r"
|
||||||
|
],
|
||||||
|
"winnerBids": [
|
||||||
|
{
|
||||||
|
"type": "alnt",
|
||||||
|
"quantity": 25000
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"winnerPrice": {
|
||||||
|
"type": "alnt",
|
||||||
|
"quantity": 25000
|
||||||
|
},
|
||||||
|
"maxPrice": {
|
||||||
|
"type": "alnt",
|
||||||
|
"quantity": 100000
|
||||||
|
},
|
||||||
|
"numProviders": 5,
|
||||||
|
"bids": [
|
||||||
|
{
|
||||||
|
"bidderAddress": "laconic13qrlfkgl02wgwpw0n4j8kswygwnukphy92249r",
|
||||||
|
"status": "reveal",
|
||||||
|
"commitHash": "bafyreifjkhiakayvvaasnsw7ufaax54ncow4xuycqnox7hxay34c6yod7a",
|
||||||
|
"commitTime": "2024-09-17T09:52:03.665761945",
|
||||||
|
"revealTime": "2024-09-17T09:53:00.904061323",
|
||||||
|
"commitFee": {
|
||||||
|
"type": "alnt",
|
||||||
|
"quantity": 1000
|
||||||
|
},
|
||||||
|
"revealFee": {
|
||||||
|
"type": "alnt",
|
||||||
|
"quantity": 1000
|
||||||
|
},
|
||||||
|
"bidAmount": {
|
||||||
|
"type": "alnt",
|
||||||
|
"quantity": 25000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Release provider winning funds:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic registry auction release-funds $AUCTION
|
||||||
|
|
||||||
|
{"success": true}
|
||||||
```
|
```
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
services:
|
services:
|
||||||
cns:
|
registry:
|
||||||
restEndpoint: 'http://localhost:1317'
|
rpcEndpoint: 'http://localhost:26657'
|
||||||
gqlEndpoint: 'http://localhost:9473/api'
|
gqlEndpoint: 'http://localhost:9473/api'
|
||||||
userKey:
|
userKey:
|
||||||
bondId:
|
bondId:
|
||||||
chainId: laconic_9000-1
|
chainId: laconic_9000-1
|
||||||
|
gas: 200000
|
||||||
|
fees: 200000alnt
|
||||||
|
gasPrice:
|
||||||
|
120
demo/README.md
Normal file
120
demo/README.md
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
# Registry Demo
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
* Install laconic CLI globally:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# In laconic-registry-cli repo root
|
||||||
|
yarn && yarn build
|
||||||
|
yarn global add file:$PWD
|
||||||
|
```
|
||||||
|
|
||||||
|
* Run the laconicd chain:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# In laconci2d repo
|
||||||
|
make install
|
||||||
|
./scripts/init.sh clean
|
||||||
|
```
|
||||||
|
|
||||||
|
* Create and populate `config.yml` following [config.example.yml](./config.example.yml):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# In laconic-registry-cli repo root
|
||||||
|
cp config.example.yml config.yml
|
||||||
|
|
||||||
|
# Update the gas value in config.yml
|
||||||
|
# gas: 500000
|
||||||
|
# fees: 500000alnt
|
||||||
|
|
||||||
|
# Get user private key
|
||||||
|
laconicd keys export alice --unarmored-hex --unsafe --keyring-backend test --home ~/.laconicd
|
||||||
|
|
||||||
|
# Set the output as 'userKey' in config.yml
|
||||||
|
# userKey: <ALICE_PRIVATE_KEY>
|
||||||
|
|
||||||
|
# Create a bond
|
||||||
|
laconic --config config.yml registry bond create --type alnt --quantity 100000000000
|
||||||
|
|
||||||
|
# Get the bond id
|
||||||
|
laconic --config config.yml registry bond list | jq -r '.[].id'
|
||||||
|
|
||||||
|
# Set the output as 'bondId' in config.yml
|
||||||
|
# bondId: <BOND_ID>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
* Publish records:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Publishes records and corresponding 'deployment' records from given directory
|
||||||
|
|
||||||
|
# In laconic-registry-cli repo root
|
||||||
|
# Use records dir path for '--records' as required
|
||||||
|
yarn ts-node demo/scripts/publish-records.ts --config config.yml --records <RECORDS_DIR>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
* Query for `azimuth-watcher` deployment(s):
|
||||||
|
|
||||||
|
* Find the `WatcherRecord` for `azimuth-watcher`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
WATCHER_RECORD_ID=$(laconic registry record list --all --type WatcherRecord --name azimuth-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'
|
||||||
|
|
||||||
|
# Expected output:
|
||||||
|
https://azimuth-watcher-endpoint.example.com
|
||||||
|
```
|
||||||
|
|
||||||
|
* Query for `sushiswap-v3-subgraph` deployment(s):
|
||||||
|
|
||||||
|
* Find the `SubgraphRecord` for `sushiswap-v3-subgraph`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
SUBGRAPH_RECORD_ID=$(laconic registry record list --all --type SubgraphRecord --name sushiswap-v3-subgraph | jq -r '.[].id')
|
||||||
|
```
|
||||||
|
|
||||||
|
* Find corresponding deployment(s):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic registry record list --all --type SubgraphDeploymentRecord subgraph $SUBGRAPH_RECORD_ID
|
||||||
|
|
||||||
|
# Get the deployment URL(s)
|
||||||
|
laconic registry record list --all --type SubgraphDeploymentRecord subgraph $SUBGRAPH_RECORD_ID | jq -r '.[].attributes.url'
|
||||||
|
|
||||||
|
# Expected output:
|
||||||
|
# https://sushiswap-v3-subgraph-endpoint.example.com
|
||||||
|
```
|
||||||
|
|
||||||
|
* Query for `geth` service deployment(s):
|
||||||
|
|
||||||
|
* Find the `ServiceRecord` for `geth`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
SERVICE_RECORD_ID=$(laconic registry record list --all --type ServiceRecord --name geth | jq -r '.[].id')
|
||||||
|
```
|
||||||
|
|
||||||
|
* Find corresponding deployment(s):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconic registry record list --all --type ServiceDeploymentRecord service $SERVICE_RECORD_ID
|
||||||
|
|
||||||
|
# Get the deployment URL(s)
|
||||||
|
laconic registry record list --all --type ServiceDeploymentRecord service $SERVICE_RECORD_ID | jq -r '.[].attributes.url'
|
||||||
|
|
||||||
|
# Expected output:
|
||||||
|
# https://geth-rpc-endpoint-1.example.com
|
||||||
|
# https://geth-rpc-endpoint-2.example.com
|
||||||
|
```
|
219
demo/scripts/publish-records.ts
Normal file
219
demo/scripts/publish-records.ts
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
import yargs from 'yargs';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { hideBin } from 'yargs/helpers';
|
||||||
|
|
||||||
|
import { StdFee } from '@cosmjs/stargate';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getGasAndFees, getConnectionInfo, txOutput } from '../../src/util';
|
||||||
|
|
||||||
|
enum RecordType {
|
||||||
|
RepositoryRecord = 'RepositoryRecord',
|
||||||
|
ServiceRecord = 'ServiceRecord',
|
||||||
|
StackRecord = 'StackRecord',
|
||||||
|
SubgraphRecord = 'SubgraphRecord',
|
||||||
|
WatcherRecord = 'WatcherRecord',
|
||||||
|
}
|
||||||
|
|
||||||
|
const recordTypeToRecordField = new Map<string, string>([
|
||||||
|
[RecordType.WatcherRecord, 'watcher'],
|
||||||
|
[RecordType.SubgraphRecord, 'subgraph'],
|
||||||
|
[RecordType.ServiceRecord, 'service']
|
||||||
|
]);
|
||||||
|
|
||||||
|
let registry: Registry;
|
||||||
|
let fee: any;
|
||||||
|
let userKey: string;
|
||||||
|
let bondId: string;
|
||||||
|
|
||||||
|
async function main () {
|
||||||
|
const argv = getArgs();
|
||||||
|
const { records: recordsDir, config } = argv;
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(config as string);
|
||||||
|
|
||||||
|
if (registryConfig.userKey == null) {
|
||||||
|
throw new Error('userKey not set in config');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (registryConfig.bondId == null) {
|
||||||
|
throw new Error('bondId not set in config');
|
||||||
|
}
|
||||||
|
|
||||||
|
let rpcEndpoint, gqlEndpoint, chainId: string;
|
||||||
|
({ rpcEndpoint, gqlEndpoint, userKey, bondId, chainId } = getConnectionInfo(argv, registryConfig));
|
||||||
|
|
||||||
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
fee = getGasAndFees(argv, registryConfig);
|
||||||
|
|
||||||
|
await processDir(path.resolve(recordsDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function processDir (directoryPath: string): Promise<void> {
|
||||||
|
const files = fs.readdirSync(directoryPath);
|
||||||
|
|
||||||
|
const dirHasRecords = await publishRecordsFromDir(directoryPath);
|
||||||
|
if (dirHasRecords) {
|
||||||
|
// Skip further recursion in the current dir
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recursively iterate through subdirectories
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
const file = files[i];
|
||||||
|
const filePath = path.join(directoryPath, file);
|
||||||
|
|
||||||
|
if (fs.statSync(filePath).isDirectory()) {
|
||||||
|
await processDir(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function publishRecordsFromDir (recordsDir: string): Promise<boolean> {
|
||||||
|
// List record files
|
||||||
|
const files = fs.readdirSync(recordsDir);
|
||||||
|
const recordFiles = files.filter(file => ['.json', '.yaml', '.yml'].includes(path.extname(file).toLowerCase()));
|
||||||
|
|
||||||
|
if (recordFiles.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read record from each JSON file
|
||||||
|
console.log('**************************************');
|
||||||
|
console.log(`Publishing records from ${recordsDir}`);
|
||||||
|
|
||||||
|
let recordType;
|
||||||
|
for (let i = 0; i < recordFiles.length; i++) {
|
||||||
|
const file = recordFiles[i];
|
||||||
|
|
||||||
|
const filePath = path.resolve(recordsDir, file);
|
||||||
|
const record = await readRecord(filePath);
|
||||||
|
|
||||||
|
// Publish record
|
||||||
|
const result = await publishRecord(userKey, bondId, fee, record);
|
||||||
|
|
||||||
|
console.log(`Published record ${file}`);
|
||||||
|
txOutput(result, JSON.stringify(result, undefined, 2), '', false);
|
||||||
|
|
||||||
|
recordType = record.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if deployment record files exist
|
||||||
|
const deploymentRecordsDir = path.resolve(recordsDir, 'deployments');
|
||||||
|
if (!fs.existsSync(deploymentRecordsDir) || !fs.statSync(deploymentRecordsDir).isDirectory()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log('--------------------------------------');
|
||||||
|
console.log(`Publishing deployment records from ${deploymentRecordsDir}`);
|
||||||
|
|
||||||
|
// List record files
|
||||||
|
const deploymentFiles = fs.readdirSync(deploymentRecordsDir);
|
||||||
|
const deploymentJsonFiles = deploymentFiles.filter(file => path.extname(file).toLowerCase() === '.json');
|
||||||
|
|
||||||
|
for (let i = 0; i < deploymentJsonFiles.length; i++) {
|
||||||
|
const file = deploymentJsonFiles[i];
|
||||||
|
|
||||||
|
const filePath = path.resolve(deploymentRecordsDir, file);
|
||||||
|
const deploymentRecord = await readRecord(filePath);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
deploymentRecord[recordTypeToRecordField.get(recordType)!] = recordId;
|
||||||
|
|
||||||
|
// Publish record
|
||||||
|
const deploymentResult = await registry.setRecord({ privateKey: userKey, record: deploymentRecord, bondId }, userKey, fee);
|
||||||
|
|
||||||
|
console.log(`Published record ${file}`);
|
||||||
|
txOutput(deploymentResult, JSON.stringify(deploymentResult, undefined, 2), '', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readRecord (filePath: string): Promise<any> {
|
||||||
|
let record;
|
||||||
|
try {
|
||||||
|
const fileExt = path.extname(filePath).toLowerCase();
|
||||||
|
const data = fs.readFileSync(filePath, 'utf8');
|
||||||
|
|
||||||
|
if (fileExt === '.json') {
|
||||||
|
// JSON file
|
||||||
|
record = JSON.parse(data);
|
||||||
|
} else {
|
||||||
|
// YAML file
|
||||||
|
({ record } = await yaml.load(data) 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error reading file ${filePath}:`, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function publishRecord (userKey: string, bondId: string, fee: StdFee, record: any): Promise<any> {
|
||||||
|
// Replace repository URL with record id (if type is one of RecordType)
|
||||||
|
if (record.repository && Object.values(RecordType).includes(record.type)) {
|
||||||
|
const repoUrl = record.repository;
|
||||||
|
|
||||||
|
const queryResult = await registry.queryRecords({ type: RecordType.RepositoryRecord, url: repoUrl }, true);
|
||||||
|
if (queryResult.length === 0) {
|
||||||
|
throw new Error(`Record not found, type: ${RecordType.RepositoryRecord}, url: ${repoUrl}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assume the first query result
|
||||||
|
const repoRecordId = queryResult[0].id;
|
||||||
|
|
||||||
|
// Replace repository URL with the repo record id
|
||||||
|
record.repository = repoRecordId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return registry.setRecord({ privateKey: userKey, record, bondId }, userKey, fee);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArgs (): any {
|
||||||
|
return yargs(hideBin(process.argv)).parserConfiguration({
|
||||||
|
'parse-numbers': false
|
||||||
|
}).usage('Usage: $0 [options]')
|
||||||
|
.option('config', {
|
||||||
|
alias: 'c',
|
||||||
|
describe: 'Config',
|
||||||
|
type: 'string',
|
||||||
|
demandOption: true
|
||||||
|
})
|
||||||
|
.option('records', {
|
||||||
|
alias: 'r',
|
||||||
|
describe: 'Records dir path',
|
||||||
|
type: 'string',
|
||||||
|
demandOption: true
|
||||||
|
})
|
||||||
|
.help().argv;
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
console.log('Done');
|
||||||
|
});
|
@ -1,28 +1,26 @@
|
|||||||
services:
|
services:
|
||||||
laconicd:
|
laconicd:
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
image: cerc-io/laconicd:local-test
|
image: cerc/laconicd:local
|
||||||
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
|
command: ["bash", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
|
||||||
|
environment:
|
||||||
|
- TEST_AUCTION_ENABLED
|
||||||
|
- TEST_REGISTRY_EXPIRY
|
||||||
|
- LOGLEVEL
|
||||||
volumes:
|
volumes:
|
||||||
- laconicd/init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
|
- ./laconicd/scripts/init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
|
test: ["CMD", "curl", "-v", "http://127.0.0.1", "6060"]
|
||||||
interval: 1s
|
interval: 1s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 30
|
retries: 30
|
||||||
ports:
|
ports:
|
||||||
- "6060"
|
- "9473:9473"
|
||||||
- "26657"
|
- "1317:1317"
|
||||||
- "26656"
|
- "26657:26657"
|
||||||
- "9473"
|
|
||||||
- "8545"
|
|
||||||
- "8546"
|
|
||||||
- "9090"
|
|
||||||
- "9091"
|
|
||||||
- "1317"
|
|
||||||
|
|
||||||
cli-test-runner:
|
cli-test-runner:
|
||||||
image: cerc/laconic-registry-cli:local-test
|
image: cerc/laconic-registry-cli:local
|
||||||
depends_on:
|
depends_on:
|
||||||
laconicd:
|
laconicd:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
6
jest.config.js
Normal file
6
jest.config.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||||
|
module.exports = {
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
setupFiles: ['dotenv/config']
|
||||||
|
};
|
24
package.json
24
package.json
@ -1,30 +1,48 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/laconic-registry-cli",
|
"name": "@cerc-io/laconic-registry-cli",
|
||||||
"version": "0.1.7",
|
"version": "0.2.10",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
|
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/fs-extra": "^9.0.13",
|
"@types/fs-extra": "^9.0.13",
|
||||||
|
"@types/jest": "^27.4.1",
|
||||||
"@types/js-yaml": "^4.0.5",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/lodash": "^4.14.182",
|
"@types/lodash": "^4.14.182",
|
||||||
"@types/node": "^17.0.25",
|
"@types/node": "^17.0.25",
|
||||||
"@types/yargs": "^17.0.10",
|
"@types/yargs": "^17.0.10",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||||
|
"@typescript-eslint/parser": "^5.47.1",
|
||||||
|
"dotenv": "^16.3.2",
|
||||||
|
"eslint": "^8.35.0",
|
||||||
|
"eslint-config-semistandard": "^15.0.1",
|
||||||
|
"eslint-config-standard": "^16.0.3",
|
||||||
|
"eslint-plugin-import": "^2.27.5",
|
||||||
|
"eslint-plugin-node": "^11.1.0",
|
||||||
|
"eslint-plugin-promise": "^5.1.0",
|
||||||
|
"eslint-plugin-standard": "^5.0.0",
|
||||||
|
"husky": "^9.0.2",
|
||||||
|
"jest": "29.0.0",
|
||||||
|
"ts-jest": "^29.0.2",
|
||||||
|
"ts-node": "^10.2.1",
|
||||||
"typescript": "^4.6.3"
|
"typescript": "^4.6.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@cerc-io/registry-sdk": "^0.2.11",
|
||||||
|
"@cosmjs/stargate": "^0.32.2",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"@cerc-io/laconic-sdk": "^0.1.13",
|
|
||||||
"js-yaml": "^3.14.1",
|
"js-yaml": "^3.14.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"lodash-clean": "^2.2.3",
|
"lodash-clean": "^2.2.3",
|
||||||
"yargs": "^17.4.1"
|
"yargs": "^17.4.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"test": "jest --runInBand --verbose test/cli.test.ts",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"clean": "rm -rf ./dist",
|
"clean": "rm -rf ./dist",
|
||||||
"build": "tsc"
|
"build": "tsc",
|
||||||
|
"prepare": "husky"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"laconic": "bin/laconic"
|
"laconic": "bin/laconic"
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Account, Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'get';
|
|
||||||
|
|
||||||
export const desc = 'Get account.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
let address = argv.address as string;
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
if (!address && privateKey) {
|
|
||||||
address = new Account(Buffer.from(privateKey, 'hex')).getCosmosAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const result = await registry.getAccounts([address]);
|
|
||||||
|
|
||||||
queryOutput(result,argv.output);
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import path from 'path';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
import fs from 'fs';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
|
|
||||||
|
|
||||||
export const command = 'reveal [auction-id] [file-path]';
|
|
||||||
|
|
||||||
export const desc = 'Reveal auction bid.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const auctionId = argv.auctionId as string;
|
|
||||||
const filePath = argv.filePath as string;
|
|
||||||
assert(auctionId, 'Invalid auction ID.');
|
|
||||||
assert(filePath, 'Invalid reveal file path.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
|
|
||||||
const reveal = fs.readFileSync(path.resolve(filePath));
|
|
||||||
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee);
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'get [id]';
|
|
||||||
|
|
||||||
export const desc = 'Get auction information.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const { id, config } = argv;
|
|
||||||
assert(id, 'Invalid auction ID.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const result = await registry.getAuctionsByIds([id as string]);
|
|
||||||
|
|
||||||
queryOutput(result,argv.output)
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
|
|
||||||
|
|
||||||
export const command = 'set [name] [bond-id]';
|
|
||||||
|
|
||||||
export const desc = 'Set bond for authority.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const name = argv.name as string;
|
|
||||||
const bondId = argv.bondId as string;
|
|
||||||
assert(name, 'Invalid authority name.');
|
|
||||||
assert(bondId, 'Invalid Bond ID.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee);
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'reserve [name]';
|
|
||||||
|
|
||||||
export const desc = 'Reserve authority/name.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
owner: {
|
|
||||||
type: 'string',
|
|
||||||
default: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const name = argv.name as string;
|
|
||||||
const owner = argv.owner as string;
|
|
||||||
assert(name, 'Invalid authority name.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.reserveAuthority({ name, owner }, privateKey, fee);
|
|
||||||
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'whois [name]';
|
|
||||||
|
|
||||||
export const desc = 'Lookup authority information.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const name = argv.name as string;
|
|
||||||
assert(name, 'Invalid authority name.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const result = await registry.lookupAuthorities([name], true);
|
|
||||||
|
|
||||||
queryOutput(result,argv.output)
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'associate';
|
|
||||||
|
|
||||||
export const desc = 'Associate record with bond.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
'bond-id': {
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const id = argv.id as string;
|
|
||||||
const bondId = argv.bondId as string;
|
|
||||||
assert(id, 'Invalid Record ID.');
|
|
||||||
assert(bondId, 'Invalid Bond ID.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee);
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'cancel';
|
|
||||||
|
|
||||||
export const desc = 'Cancel bond.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const id = argv.id as string
|
|
||||||
assert(id, 'Invalid Bond ID.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.cancelBond({ id }, privateKey, fee);
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'create';
|
|
||||||
|
|
||||||
export const desc = 'Create bond.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
type: {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
quantity: {
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const { config, verbose } = argv;
|
|
||||||
const denom = argv.type as string;
|
|
||||||
const amount = argv.quantity as string;
|
|
||||||
|
|
||||||
assert(denom, 'Invalid Type.');
|
|
||||||
assert(amount, 'Invalid Quantity.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
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);
|
|
||||||
const jsonString=`{"bondId":"${bondId}"}`
|
|
||||||
|
|
||||||
txOutput(result,jsonString,argv.output,argv.verbose)
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'dissociate';
|
|
||||||
|
|
||||||
export const desc = 'Dissociate record from bond.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const id = argv.id as string;
|
|
||||||
assert(id, 'Invalid Record ID.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.dissociateBond({ recordId: id }, privateKey, fee);
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'get';
|
|
||||||
|
|
||||||
export const desc = 'Get bond.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const { id, config } = argv;
|
|
||||||
console.assert(id, 'Bond Id is required.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
|
|
||||||
const result = await registry.getBondsByIds([id as string]);
|
|
||||||
|
|
||||||
queryOutput(result,argv.output)
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'list';
|
|
||||||
|
|
||||||
export const desc = 'List bonds.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
owner: {
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
|
|
||||||
const { owner } = argv;
|
|
||||||
const result = await registry.queryBonds({ owner });
|
|
||||||
|
|
||||||
queryOutput(result,argv.output)
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../../util';
|
|
||||||
|
|
||||||
export const command = 'dissociate';
|
|
||||||
|
|
||||||
export const desc = 'Dissociate all records from bond.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
'bond-id': {
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const bondId = argv.bondId as string;
|
|
||||||
assert(bondId, 'Invalid Bond ID.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.dissociateRecords({ bondId }, privateKey, fee);
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../../util';
|
|
||||||
|
|
||||||
export const command = 'reassociate';
|
|
||||||
|
|
||||||
export const desc = 'Reassociate records with new bond.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
'old-bond-id': {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
'new-bond-id': {
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const oldBondId = argv.oldBondId as string;
|
|
||||||
const newBondId = argv.newBondId as string;
|
|
||||||
assert(oldBondId, 'Invalid Old Bond ID.');
|
|
||||||
assert(newBondId, 'Invalid New Bond ID.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.reassociateRecords({ oldBondId, newBondId }, privateKey, fee);
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
|
|
||||||
import { isNil } from 'lodash';
|
|
||||||
|
|
||||||
export const command = 'refill';
|
|
||||||
|
|
||||||
export const desc = 'Refill bond.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
type: {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
quantity: {
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const denom = argv.type as string;
|
|
||||||
const amount = argv.quantity as string;
|
|
||||||
const id = argv.id as string
|
|
||||||
|
|
||||||
assert(id, 'Invalid Bond ID.');
|
|
||||||
assert(denom, 'Invalid Type.');
|
|
||||||
assert(amount, 'Invalid Quantity.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.refillBond({ id, denom, amount }, privateKey, fee);
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'withdraw';
|
|
||||||
|
|
||||||
export const desc = 'Withdraw funds from bond.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
type: {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
quantity: {
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const denom = argv.type as string;
|
|
||||||
const amount = argv.quantity as string;
|
|
||||||
const id = argv.id as string
|
|
||||||
|
|
||||||
assert(id, 'Invalid Bond ID.');
|
|
||||||
assert(denom, 'Invalid Type.');
|
|
||||||
assert(amount, 'Invalid Quantity.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee);
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'delete [name]';
|
|
||||||
|
|
||||||
export const desc = 'Delete name (remove name to record ID mapping).';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const name = argv.name as string;
|
|
||||||
assert(name, 'Invalid Name.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.deleteName({ crn: name }, privateKey, fee);
|
|
||||||
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'lookup [name]';
|
|
||||||
|
|
||||||
export const desc = 'Lookup name information.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
history: {
|
|
||||||
type: 'boolean'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const name = argv.name as string;
|
|
||||||
assert(name, 'Invalid Name.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const result = await registry.lookupNames([name], argv.history as boolean);
|
|
||||||
|
|
||||||
queryOutput(result,argv.output)
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'set [name] [id]';
|
|
||||||
|
|
||||||
export const desc = 'Set name (create name to record ID mapping).';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const name = argv.name as string;
|
|
||||||
const id = argv.id as string;
|
|
||||||
assert(name, 'Invalid Name.');
|
|
||||||
assert(id, 'Invalid Record ID.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
const result = await registry.setName({ crn: name, cid: id }, privateKey, fee);
|
|
||||||
|
|
||||||
const success = `{"success":${result.code==0}}`
|
|
||||||
txOutput(result,success,argv.output,argv.verbose)
|
|
||||||
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'get';
|
|
||||||
|
|
||||||
export const desc = 'Get record.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const { id, config } = argv;
|
|
||||||
assert(id, 'Invalid Record ID.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const result = await registry.getRecordsByIds([id as string]);
|
|
||||||
|
|
||||||
queryOutput(result,argv.output)
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'list';
|
|
||||||
|
|
||||||
export const desc = 'List records.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
'bond-id': {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
owner: {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
type: {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
all: {
|
|
||||||
type: 'boolean',
|
|
||||||
default: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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, 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.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import path from 'path';
|
|
||||||
import yaml from 'js-yaml';
|
|
||||||
import fs from 'fs';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getGasAndFees, getConnectionInfo, txOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'publish';
|
|
||||||
|
|
||||||
export const desc = 'Register record.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
'bond-id': {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const { txKey, filename, verbose, config } = argv;
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, userKey, bondId, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(userKey, 'Invalid User Key.');
|
|
||||||
assert(bondId, 'Invalid Bond ID.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
let file = null;
|
|
||||||
if (filename) {
|
|
||||||
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);
|
|
||||||
|
|
||||||
txOutput(result,JSON.stringify(result.data,undefined,2),argv.output,argv.verbose)
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo } from '../../util';
|
|
||||||
|
|
||||||
export const command = 'status';
|
|
||||||
|
|
||||||
export const desc = 'Get CNS status.';
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const { services: { cns } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cns);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
|
|
||||||
const result = await registry.getStatus();
|
|
||||||
console.log(JSON.stringify(result, undefined, 2));
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
import { Arguments } from 'yargs';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { Account, Registry } from '@cerc-io/laconic-sdk';
|
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, queryOutput } from '../../../util';
|
|
||||||
|
|
||||||
export const command = 'send';
|
|
||||||
|
|
||||||
export const desc = 'Send tokens.';
|
|
||||||
|
|
||||||
export const builder = {
|
|
||||||
type: {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
quantity: {
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
|
||||||
const destinationAddress = argv.address as string;
|
|
||||||
const denom = argv.type as string;
|
|
||||||
const amount = argv.quantity as string;
|
|
||||||
|
|
||||||
assert(destinationAddress, 'Invalid Address.');
|
|
||||||
assert(denom, 'Invalid Type.');
|
|
||||||
assert(amount, 'Invalid Quantity.');
|
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
|
||||||
|
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
|
||||||
const fromAddress = account.formattedCosmosAddress;
|
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
|
||||||
await registry.sendCoins({ denom, amount, destinationAddress }, privateKey, fee);
|
|
||||||
const result = await registry.getAccounts([fromAddress, destinationAddress]);
|
|
||||||
queryOutput(result,argv.output)
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
import yargs from 'yargs';
|
|
||||||
|
|
||||||
export const command = 'cns';
|
|
||||||
|
|
||||||
export const desc = 'CNS tools';
|
|
||||||
|
|
||||||
exports.builder = (yargs: yargs.Argv) => {
|
|
||||||
return yargs
|
|
||||||
.options({
|
|
||||||
'user-key': { type: 'string' },
|
|
||||||
'tx-key': { type: 'string' },
|
|
||||||
'bond-id': { type: 'string' },
|
|
||||||
'chain-id': { type: 'string' },
|
|
||||||
'filename': { alias: 'f' },
|
|
||||||
'id': { type: 'string' },
|
|
||||||
'address': { type: 'string' },
|
|
||||||
'gas': { type: 'string' },
|
|
||||||
'fees': { type: 'string' }
|
|
||||||
})
|
|
||||||
.commandDir('cns-cmds')
|
|
||||||
.demandCommand()
|
|
||||||
.help()
|
|
||||||
}
|
|
30
src/cmds/registry-cmds/account-cmds/get.ts
Normal file
30
src/cmds/registry-cmds/account-cmds/get.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Account, Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'get';
|
||||||
|
|
||||||
|
export const desc = 'Get account.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
let address = argv.address as string;
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
if (!address && privateKey) {
|
||||||
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
|
await account.init();
|
||||||
|
address = account.address;
|
||||||
|
}
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
const result = await registry.getAccounts([address]);
|
||||||
|
|
||||||
|
queryOutput(result, argv.output);
|
||||||
|
};
|
@ -7,4 +7,4 @@ export const desc = 'Account operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('account-cmds')
|
return yargs.commandDir('account-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
}
|
};
|
@ -1,11 +1,11 @@
|
|||||||
import { Arguments } from 'yargs';
|
import { Arguments } from 'yargs';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { Account, createBid, Registry } from '@cerc-io/laconic-sdk';
|
import { Account, createBid, Registry } from '@cerc-io/registry-sdk';
|
||||||
import { ensureDir } from 'fs-extra';
|
import { ensureDir } from 'fs-extra';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../../util';
|
||||||
|
|
||||||
const OUT_DIR = 'out';
|
const OUT_DIR = 'out';
|
||||||
|
|
||||||
@ -21,15 +21,16 @@ export const handler = async (argv: Arguments) => {
|
|||||||
assert(quantity, 'Invalid token quantity.');
|
assert(quantity, 'Invalid token quantity.');
|
||||||
assert(denom, 'Invalid token type.');
|
assert(denom, 'Invalid token type.');
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
assert(privateKey, 'Invalid Transaction Key.');
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
const bidderAddress = account.formattedCosmosAddress;
|
await account.init();
|
||||||
|
const bidderAddress = account.address;
|
||||||
const bidAmount = `${quantity}${denom}`;
|
const bidAmount = `${quantity}${denom}`;
|
||||||
const { reveal, commitHash } = await createBid(chainId, auctionId, bidderAddress, bidAmount);
|
const { reveal, commitHash } = await createBid(chainId, auctionId, bidderAddress, bidAmount);
|
||||||
|
|
||||||
@ -39,11 +40,12 @@ export const handler = async (argv: Arguments) => {
|
|||||||
await ensureDir(outDirPath);
|
await ensureDir(outDirPath);
|
||||||
fs.writeFileSync(revealFilePath, JSON.stringify(reveal, undefined, 2));
|
fs.writeFileSync(revealFilePath, JSON.stringify(reveal, undefined, 2));
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
|
||||||
const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee);
|
const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee);
|
||||||
const revealFile = `{"reveal_file":"${revealFilePath}"}`
|
const revealFile = `{"reveal_file":"${revealFilePath}"}`;
|
||||||
|
|
||||||
txOutput(result,revealFile,argv.output,argv.verbose)
|
txOutput(result, revealFile, argv.output, argv.verbose);
|
||||||
}
|
};
|
35
src/cmds/registry-cmds/auction-cmds/bid-cmds/reveal.ts
Normal file
35
src/cmds/registry-cmds/auction-cmds/bid-cmds/reveal.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import path from 'path';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../../util';
|
||||||
|
|
||||||
|
export const command = 'reveal [auction-id] [file-path]';
|
||||||
|
|
||||||
|
export const desc = 'Reveal auction bid.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const auctionId = argv.auctionId as string;
|
||||||
|
const filePath = argv.filePath as string;
|
||||||
|
assert(auctionId, 'Invalid auction ID.');
|
||||||
|
assert(filePath, 'Invalid reveal file path.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
|
||||||
|
const reveal = fs.readFileSync(path.resolve(filePath));
|
||||||
|
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee);
|
||||||
|
const success = '{"success": true}';
|
||||||
|
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
@ -6,10 +6,10 @@ export const desc = 'Auction bid operations.';
|
|||||||
|
|
||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.options({
|
return yargs.options({
|
||||||
'auction-id': { type: 'string' },
|
'auction-id': { type: 'string' },
|
||||||
'type': { type: 'string' },
|
type: { type: 'string' },
|
||||||
'quantity': { type: 'string' },
|
quantity: { type: 'string' },
|
||||||
'file-path': { type: 'string' }
|
'file-path': { type: 'string' }
|
||||||
}).commandDir('bid-cmds')
|
}).commandDir('bid-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
}
|
};
|
106
src/cmds/registry-cmds/auction-cmds/create.ts
Normal file
106
src/cmds/registry-cmds/auction-cmds/create.ts
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
|
import { AUCTION_KIND_PROVIDER, AUCTION_KIND_VICKREY, Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'create';
|
||||||
|
|
||||||
|
export const desc = 'Create auction.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
kind: {
|
||||||
|
type: 'string',
|
||||||
|
describe: 'Auction kind (vickrey | provider)'
|
||||||
|
},
|
||||||
|
'commits-duration': {
|
||||||
|
type: 'string',
|
||||||
|
describe: 'Duration for bid commit phase in seconds'
|
||||||
|
},
|
||||||
|
'reveals-duration': {
|
||||||
|
type: 'string',
|
||||||
|
describe: 'Duration for bid reveal phase in seconds'
|
||||||
|
},
|
||||||
|
denom: {
|
||||||
|
type: 'string',
|
||||||
|
describe: 'Denom to use'
|
||||||
|
},
|
||||||
|
'commit-fee': {
|
||||||
|
type: 'string',
|
||||||
|
describe: 'Fee for committing a bid to the auction'
|
||||||
|
},
|
||||||
|
'reveal-fee': {
|
||||||
|
type: 'string',
|
||||||
|
describe: 'Fee for revealing a bid in the auction'
|
||||||
|
},
|
||||||
|
'minimum-bid': {
|
||||||
|
type: 'string',
|
||||||
|
default: 0,
|
||||||
|
describe: 'Minimum bid amount (only for vickrey auction)'
|
||||||
|
},
|
||||||
|
'max-price': {
|
||||||
|
type: 'string',
|
||||||
|
default: 0,
|
||||||
|
describe: 'Max acceptable bid price (only for provider auction)'
|
||||||
|
},
|
||||||
|
'num-providers': {
|
||||||
|
type: 'number',
|
||||||
|
describe: 'Number ofdesired providers (only for provider auction)'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { config } = argv;
|
||||||
|
|
||||||
|
const kind = argv.kind as string;
|
||||||
|
const validAuctionKinds = [AUCTION_KIND_VICKREY, AUCTION_KIND_PROVIDER];
|
||||||
|
assert(validAuctionKinds.includes(kind), `Invalid auction kind, has to be one of ${validAuctionKinds}.`);
|
||||||
|
|
||||||
|
if (kind === AUCTION_KIND_VICKREY) {
|
||||||
|
assert(argv.minimumBid, 'Invalid minimum bid.');
|
||||||
|
assert(!argv.maxPrice, `Max price can only be used with ${AUCTION_KIND_PROVIDER} auction.`);
|
||||||
|
assert(!argv.numProviders, `Num providers can only be used with ${AUCTION_KIND_PROVIDER} auction.`);
|
||||||
|
} else if (kind === AUCTION_KIND_PROVIDER) {
|
||||||
|
assert(argv.maxPrice, 'Invalid max price.');
|
||||||
|
assert(argv.numProviders, 'Invalid num providers.');
|
||||||
|
assert(!argv.minimumBid, `Minimum bid can only be used with ${AUCTION_KIND_VICKREY} auction.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(argv.commitsDuration, 'Invalid commits duration.');
|
||||||
|
assert(argv.revealsDuration, 'Invalid reveals duration.');
|
||||||
|
assert(argv.commitFee, 'Invalid commit fee.');
|
||||||
|
assert(argv.revealFee, 'Invalid reveal fee.');
|
||||||
|
|
||||||
|
const commitsDuration = argv.commitsDuration as string;
|
||||||
|
const revealsDuration = argv.revealsDuration as string;
|
||||||
|
|
||||||
|
const denom = argv.denom as string;
|
||||||
|
const commitFee = argv.commitFee as string;
|
||||||
|
const revealFee = argv.revealFee as string;
|
||||||
|
const minimumBid = argv.minimumBid as string;
|
||||||
|
const maxPrice = argv.maxPrice as string;
|
||||||
|
const numProviders = argv.numProviders as number;
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
|
||||||
|
let result: any;
|
||||||
|
if (kind === AUCTION_KIND_VICKREY) {
|
||||||
|
result = await registry.createAuction({ commitsDuration, revealsDuration, denom, commitFee, revealFee, minimumBid }, privateKey, fee);
|
||||||
|
} else {
|
||||||
|
result = await registry.createProviderAuction({ commitsDuration, revealsDuration, denom, commitFee, revealFee, maxPrice, numProviders }, privateKey, fee);
|
||||||
|
}
|
||||||
|
|
||||||
|
const jsonString = `{"auctionId":"${result.auction?.id}"}`;
|
||||||
|
txOutput(result, jsonString, argv.output, argv.verbose);
|
||||||
|
};
|
25
src/cmds/registry-cmds/auction-cmds/get.ts
Normal file
25
src/cmds/registry-cmds/auction-cmds/get.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'get [id]';
|
||||||
|
|
||||||
|
export const desc = 'Get auction information.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { id, config } = argv;
|
||||||
|
assert(id, 'Invalid auction ID.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
const result = await registry.getAuctionsByIds([id as string]);
|
||||||
|
|
||||||
|
queryOutput(result, argv.output);
|
||||||
|
};
|
34
src/cmds/registry-cmds/auction-cmds/release-funds.ts
Normal file
34
src/cmds/registry-cmds/auction-cmds/release-funds.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
|
import { Account, Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'release-funds [auction-id]';
|
||||||
|
|
||||||
|
export const desc = 'Release funds of provider auction winners.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const auctionId = argv.auctionId as string;
|
||||||
|
assert(auctionId, 'Invalid auction ID.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
|
await account.init();
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
|
||||||
|
const result = await registry.releaseFunds({ auctionId }, privateKey, fee);
|
||||||
|
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
@ -7,4 +7,4 @@ export const desc = 'Auction operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('auction-cmds')
|
return yargs.commandDir('auction-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
}
|
};
|
31
src/cmds/registry-cmds/authority-cmds/bond-cmds/set.ts
Normal file
31
src/cmds/registry-cmds/authority-cmds/bond-cmds/set.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../../util';
|
||||||
|
|
||||||
|
export const command = 'set [name] [bond-id]';
|
||||||
|
|
||||||
|
export const desc = 'Set bond for authority.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const name = argv.name as string;
|
||||||
|
const bondId = argv.bondId as string;
|
||||||
|
assert(name, 'Invalid authority name.');
|
||||||
|
assert(bondId, 'Invalid Bond ID.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee);
|
||||||
|
const success = '{"success": true}';
|
||||||
|
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
@ -7,4 +7,4 @@ export const desc = 'Authority bond operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('bond-cmds')
|
return yargs.commandDir('bond-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
}
|
};
|
29
src/cmds/registry-cmds/authority-cmds/list.ts
Normal file
29
src/cmds/registry-cmds/authority-cmds/list.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'list';
|
||||||
|
|
||||||
|
export const desc = 'List authorities (optionally by owner).';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
owner: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
const result = await registry.getAuthorities(argv.owner as string);
|
||||||
|
|
||||||
|
queryOutput(result, argv.output);
|
||||||
|
};
|
37
src/cmds/registry-cmds/authority-cmds/reserve.ts
Normal file
37
src/cmds/registry-cmds/authority-cmds/reserve.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'reserve [name]';
|
||||||
|
|
||||||
|
export const desc = 'Reserve authority/name.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
owner: {
|
||||||
|
type: 'string',
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const name = argv.name as string;
|
||||||
|
const owner = argv.owner as string;
|
||||||
|
assert(name, 'Invalid authority name.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.reserveAuthority({ name, owner }, privateKey, fee);
|
||||||
|
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
25
src/cmds/registry-cmds/authority-cmds/whois.ts
Normal file
25
src/cmds/registry-cmds/authority-cmds/whois.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'whois [name]';
|
||||||
|
|
||||||
|
export const desc = 'Lookup authority information.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const name = argv.name as string;
|
||||||
|
assert(name, 'Invalid authority name.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
const result = await registry.lookupAuthorities([name], true);
|
||||||
|
|
||||||
|
queryOutput(result, argv.output);
|
||||||
|
};
|
@ -7,4 +7,4 @@ export const desc = 'Name authority operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('authority-cmds')
|
return yargs.commandDir('authority-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
}
|
};
|
36
src/cmds/registry-cmds/bond-cmds/associate.ts
Normal file
36
src/cmds/registry-cmds/bond-cmds/associate.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'associate';
|
||||||
|
|
||||||
|
export const desc = 'Associate record with bond.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
'bond-id': {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const id = argv.id as string;
|
||||||
|
const bondId = argv.bondId as string;
|
||||||
|
assert(id, 'Invalid Record ID.');
|
||||||
|
assert(bondId, 'Invalid Bond ID.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee);
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
28
src/cmds/registry-cmds/bond-cmds/cancel.ts
Normal file
28
src/cmds/registry-cmds/bond-cmds/cancel.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'cancel';
|
||||||
|
|
||||||
|
export const desc = 'Cancel bond.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const id = argv.id as string;
|
||||||
|
assert(id, 'Invalid Bond ID.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.cancelBond({ id }, privateKey, fee);
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
45
src/cmds/registry-cmds/bond-cmds/create.ts
Normal file
45
src/cmds/registry-cmds/bond-cmds/create.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'create';
|
||||||
|
|
||||||
|
export const desc = 'Create bond.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
type: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
quantity: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { config } = argv;
|
||||||
|
const denom = argv.type as string;
|
||||||
|
const amount = argv.quantity as string;
|
||||||
|
|
||||||
|
assert(denom, 'Invalid Type.');
|
||||||
|
assert(amount, 'Invalid Quantity.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const bondId = await registry.getNextBondId(privateKey);
|
||||||
|
const result = await registry.createBond({ denom, amount }, privateKey, fee);
|
||||||
|
const jsonString = `{"bondId":"${bondId}"}`;
|
||||||
|
|
||||||
|
txOutput(result, jsonString, argv.output, argv.verbose);
|
||||||
|
};
|
28
src/cmds/registry-cmds/bond-cmds/dissociate.ts
Normal file
28
src/cmds/registry-cmds/bond-cmds/dissociate.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'dissociate';
|
||||||
|
|
||||||
|
export const desc = 'Dissociate record from bond.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const id = argv.id as string;
|
||||||
|
assert(id, 'Invalid Record ID.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.dissociateBond({ recordId: id }, privateKey, fee);
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
26
src/cmds/registry-cmds/bond-cmds/get.ts
Normal file
26
src/cmds/registry-cmds/bond-cmds/get.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'get';
|
||||||
|
|
||||||
|
export const desc = 'Get bond.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { id, config } = argv;
|
||||||
|
console.assert(id, 'Bond Id is required.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
|
const result = await registry.getBondsByIds([id as string]);
|
||||||
|
|
||||||
|
queryOutput(result, argv.output);
|
||||||
|
};
|
37
src/cmds/registry-cmds/bond-cmds/list.ts
Normal file
37
src/cmds/registry-cmds/bond-cmds/list.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'list';
|
||||||
|
|
||||||
|
export const desc = 'List bonds.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
owner: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
|
let result: any;
|
||||||
|
|
||||||
|
const { owner } = argv;
|
||||||
|
if (owner) {
|
||||||
|
const [bondsByOwnerResult] = await registry.queryBondsByOwners([String(owner)]);
|
||||||
|
result = bondsByOwnerResult.bonds;
|
||||||
|
} else {
|
||||||
|
result = await registry.queryBonds();
|
||||||
|
}
|
||||||
|
|
||||||
|
queryOutput(result, argv.output);
|
||||||
|
};
|
34
src/cmds/registry-cmds/bond-cmds/records-cmds/dissociate.ts
Normal file
34
src/cmds/registry-cmds/bond-cmds/records-cmds/dissociate.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../../util';
|
||||||
|
|
||||||
|
export const command = 'dissociate';
|
||||||
|
|
||||||
|
export const desc = 'Dissociate all records from bond.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
'bond-id': {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const bondId = argv.bondId as string;
|
||||||
|
assert(bondId, 'Invalid Bond ID.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.dissociateRecords({ bondId }, privateKey, fee);
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
39
src/cmds/registry-cmds/bond-cmds/records-cmds/reassociate.ts
Normal file
39
src/cmds/registry-cmds/bond-cmds/records-cmds/reassociate.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../../util';
|
||||||
|
|
||||||
|
export const command = 'reassociate';
|
||||||
|
|
||||||
|
export const desc = 'Reassociate records with new bond.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
'old-bond-id': {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
'new-bond-id': {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const oldBondId = argv.oldBondId as string;
|
||||||
|
const newBondId = argv.newBondId as string;
|
||||||
|
assert(oldBondId, 'Invalid Old Bond ID.');
|
||||||
|
assert(newBondId, 'Invalid New Bond ID.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.reassociateRecords({ oldBondId, newBondId }, privateKey, fee);
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
@ -7,4 +7,4 @@ export const desc = 'Bond records operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('records-cmds')
|
return yargs.commandDir('records-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
}
|
};
|
42
src/cmds/registry-cmds/bond-cmds/refill.ts
Normal file
42
src/cmds/registry-cmds/bond-cmds/refill.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'refill';
|
||||||
|
|
||||||
|
export const desc = 'Refill bond.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
type: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
quantity: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const denom = argv.type as string;
|
||||||
|
const amount = argv.quantity as string;
|
||||||
|
const id = argv.id as string;
|
||||||
|
|
||||||
|
assert(id, 'Invalid Bond ID.');
|
||||||
|
assert(denom, 'Invalid Type.');
|
||||||
|
assert(amount, 'Invalid Quantity.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.refillBond({ id, denom, amount }, privateKey, fee);
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
42
src/cmds/registry-cmds/bond-cmds/withdraw.ts
Normal file
42
src/cmds/registry-cmds/bond-cmds/withdraw.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'withdraw';
|
||||||
|
|
||||||
|
export const desc = 'Withdraw funds from bond.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
type: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
quantity: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const denom = argv.type as string;
|
||||||
|
const amount = argv.quantity as string;
|
||||||
|
const id = argv.id as string;
|
||||||
|
|
||||||
|
assert(id, 'Invalid Bond ID.');
|
||||||
|
assert(denom, 'Invalid Type.');
|
||||||
|
assert(amount, 'Invalid Quantity.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee);
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
@ -7,4 +7,4 @@ export const desc = 'Bonds operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('bond-cmds')
|
return yargs.commandDir('bond-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
}
|
};
|
29
src/cmds/registry-cmds/name-cmds/delete.ts
Normal file
29
src/cmds/registry-cmds/name-cmds/delete.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'delete [name]';
|
||||||
|
|
||||||
|
export const desc = 'Delete name (remove name to record ID mapping).';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const name = argv.name as string;
|
||||||
|
assert(name, 'Invalid Name.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.deleteName({ lrn: name }, privateKey, fee);
|
||||||
|
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
31
src/cmds/registry-cmds/name-cmds/lookup.ts
Normal file
31
src/cmds/registry-cmds/name-cmds/lookup.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'lookup [name]';
|
||||||
|
|
||||||
|
export const desc = 'Lookup name information.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
history: {
|
||||||
|
type: 'boolean'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const name = argv.name as string;
|
||||||
|
assert(name, 'Invalid Name.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
const result = await registry.lookupNames([name], argv.history as boolean);
|
||||||
|
|
||||||
|
queryOutput(result, argv.output);
|
||||||
|
};
|
@ -1,6 +1,6 @@
|
|||||||
import { Arguments } from 'yargs';
|
import { Arguments } from 'yargs';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
|
||||||
@ -12,16 +12,16 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const name = argv.name as string;
|
const name = argv.name as string;
|
||||||
assert(name, 'Invalid Name.');
|
assert(name, 'Invalid Name.');
|
||||||
|
|
||||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
assert(chainId, 'Invalid CNS Chain ID.');
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
let result = await registry.resolveNames([name]);
|
let result = await registry.resolveNames([name]);
|
||||||
result = result.filter((v: any) => v);
|
result = result.filter((v: any) => v);
|
||||||
|
|
||||||
queryOutput(result, argv.output);
|
queryOutput(result, argv.output);
|
||||||
}
|
};
|
31
src/cmds/registry-cmds/name-cmds/set.ts
Normal file
31
src/cmds/registry-cmds/name-cmds/set.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'set [name] [id]';
|
||||||
|
|
||||||
|
export const desc = 'Set name (create name to record ID mapping).';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const name = argv.name as string;
|
||||||
|
const id = argv.id as string;
|
||||||
|
assert(name, 'Invalid Name.');
|
||||||
|
assert(id, 'Invalid Record ID.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.setName({ lrn: name, cid: id }, privateKey, fee);
|
||||||
|
|
||||||
|
const success = '{"success": true}';
|
||||||
|
txOutput(result, success, argv.output, argv.verbose);
|
||||||
|
};
|
@ -6,5 +6,5 @@ export const desc = 'Name operations.';
|
|||||||
|
|
||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('name-cmds')
|
return yargs.commandDir('name-cmds')
|
||||||
.demandCommand()
|
.demandCommand();
|
||||||
}
|
};
|
25
src/cmds/registry-cmds/record-cmds/get.ts
Normal file
25
src/cmds/registry-cmds/record-cmds/get.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'get';
|
||||||
|
|
||||||
|
export const desc = 'Get record.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { id, config } = argv;
|
||||||
|
assert(id, 'Invalid Record ID.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
const result = await registry.getRecordsByIds([id as string]);
|
||||||
|
|
||||||
|
queryOutput(result, argv.output);
|
||||||
|
};
|
69
src/cmds/registry-cmds/record-cmds/list.ts
Normal file
69
src/cmds/registry-cmds/record-cmds/list.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'list';
|
||||||
|
|
||||||
|
export const desc = 'List records.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
'bond-id': {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
owner: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
all: {
|
||||||
|
type: 'boolean',
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
refs: {
|
||||||
|
type: 'boolean',
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
limit: {
|
||||||
|
type: 'number'
|
||||||
|
},
|
||||||
|
offset: {
|
||||||
|
type: 'number'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
const { type, name, bondId, owner, all, refs, limit, offset } = 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(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
|
let result = await registry.queryRecords({ ...filters, type, name }, all as boolean, refs as boolean, limit as number, offset as number);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
};
|
53
src/cmds/registry-cmds/record-cmds/publish.ts
Normal file
53
src/cmds/registry-cmds/record-cmds/publish.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
|
import fs from 'fs';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getGasAndFees, getConnectionInfo, getGasPrice, txOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'publish';
|
||||||
|
|
||||||
|
export const desc = 'Register record.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
'bond-id': {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { txKey, filename, config } = argv;
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, userKey, bondId, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(userKey, 'Invalid User Key.');
|
||||||
|
assert(bondId, 'Invalid Bond ID.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
let file = null;
|
||||||
|
if (filename) {
|
||||||
|
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 gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey || userKey, fee);
|
||||||
|
|
||||||
|
txOutput(result, JSON.stringify(result, undefined, 2), argv.output, argv.verbose);
|
||||||
|
};
|
@ -6,6 +6,6 @@ export const desc = 'Record operations.';
|
|||||||
|
|
||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('record-cmds')
|
return yargs.commandDir('record-cmds')
|
||||||
.parserConfiguration({'unknown-options-as-args': true})
|
.parserConfiguration({ 'unknown-options-as-args': true })
|
||||||
.demandCommand()
|
.demandCommand();
|
||||||
}
|
};
|
22
src/cmds/registry-cmds/status.ts
Normal file
22
src/cmds/registry-cmds/status.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo } from '../../util';
|
||||||
|
|
||||||
|
export const command = 'status';
|
||||||
|
|
||||||
|
export const desc = 'Get registry status.';
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
|
const result = await registry.getStatus();
|
||||||
|
console.log(JSON.stringify(result, undefined, 2));
|
||||||
|
};
|
54
src/cmds/registry-cmds/tokens-cmds/gettx.ts
Normal file
54
src/cmds/registry-cmds/tokens-cmds/gettx.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { Account, Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||||
|
import { IndexedTx } from '@cosmjs/stargate/build/stargateclient';
|
||||||
|
|
||||||
|
export const command = 'gettx';
|
||||||
|
|
||||||
|
export const desc = 'Get token transfer tx info.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
hash: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const hash = argv.hash as string;
|
||||||
|
|
||||||
|
assert(hash, 'Invalid tx hash.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
|
await account.init();
|
||||||
|
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
const laconicClient = await registry.getLaconicClient(account);
|
||||||
|
|
||||||
|
const txResponse: IndexedTx | null = await laconicClient.getTx(hash);
|
||||||
|
if (txResponse) {
|
||||||
|
const transfer = txResponse.events.find(e => e.type === 'transfer' ? e.attributes.find(a => a.key === 'msg_index') : null);
|
||||||
|
const output = {
|
||||||
|
hash: txResponse.hash,
|
||||||
|
height: txResponse.height,
|
||||||
|
index: txResponse.txIndex,
|
||||||
|
code: txResponse.code,
|
||||||
|
log: txResponse.rawLog,
|
||||||
|
sender: transfer?.attributes.find(a => a.key === 'sender')?.value,
|
||||||
|
recipient: transfer?.attributes.find(a => a.key === 'recipient')?.value,
|
||||||
|
amount: transfer?.attributes.find(a => a.key === 'amount')?.value,
|
||||||
|
raw: Buffer.from(txResponse.tx).toString('hex').toUpperCase()
|
||||||
|
};
|
||||||
|
queryOutput(output, argv.output);
|
||||||
|
} else {
|
||||||
|
queryOutput(null, argv.output);
|
||||||
|
}
|
||||||
|
};
|
78
src/cmds/registry-cmds/tokens-cmds/send.ts
Normal file
78
src/cmds/registry-cmds/tokens-cmds/send.ts
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import { Arguments } from 'yargs';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
|
import { Account, Registry, DEFAULT_GAS_ESTIMATION_MULTIPLIER } from '@cerc-io/registry-sdk';
|
||||||
|
import { DeliverTxResponse } from '@cosmjs/stargate';
|
||||||
|
|
||||||
|
import { getConfig, getConnectionInfo, getGasAndFees, getGasPrice, queryOutput } from '../../../util';
|
||||||
|
|
||||||
|
export const command = 'send';
|
||||||
|
|
||||||
|
export const desc = 'Send tokens.';
|
||||||
|
|
||||||
|
export const builder = {
|
||||||
|
type: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
quantity: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handler = async (argv: Arguments) => {
|
||||||
|
const destinationAddress = argv.address as string;
|
||||||
|
const denom = argv.type as string;
|
||||||
|
const amount = argv.quantity as string;
|
||||||
|
|
||||||
|
assert(destinationAddress, 'Invalid Address.');
|
||||||
|
assert(denom, 'Invalid Type.');
|
||||||
|
assert(amount, 'Invalid Quantity.');
|
||||||
|
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
|
||||||
|
const { rpcEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, registryConfig);
|
||||||
|
assert(rpcEndpoint, 'Invalid registry RPC endpoint.');
|
||||||
|
assert(gqlEndpoint, 'Invalid registry GQL endpoint.');
|
||||||
|
assert(privateKey, 'Invalid Transaction Key.');
|
||||||
|
assert(chainId, 'Invalid registry Chain ID.');
|
||||||
|
|
||||||
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
|
await account.init();
|
||||||
|
const fromAddress = account.address;
|
||||||
|
|
||||||
|
const gasPrice = getGasPrice(argv, registryConfig);
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice });
|
||||||
|
const laconicClient = await registry.getLaconicClient(account);
|
||||||
|
const fee = getGasAndFees(argv, registryConfig);
|
||||||
|
|
||||||
|
const txResponse: DeliverTxResponse = await laconicClient.sendTokens(
|
||||||
|
account.address,
|
||||||
|
destinationAddress,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
denom,
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
],
|
||||||
|
fee || DEFAULT_GAS_ESTIMATION_MULTIPLIER);
|
||||||
|
|
||||||
|
assert(txResponse.code === 0, `TX Failed - Hash: ${txResponse.transactionHash}, Code: ${txResponse.code}, Message: ${txResponse.rawLog}`);
|
||||||
|
|
||||||
|
const transfer = txResponse.events.find(e => e.type === 'transfer' ? e.attributes.find(a => a.key === 'msg_index') : null);
|
||||||
|
const accountResponse = await registry.getAccounts([fromAddress, destinationAddress]);
|
||||||
|
|
||||||
|
const output = {
|
||||||
|
tx: {
|
||||||
|
hash: txResponse.transactionHash,
|
||||||
|
height: txResponse.height,
|
||||||
|
index: txResponse.txIndex,
|
||||||
|
code: txResponse.code,
|
||||||
|
log: txResponse.rawLog,
|
||||||
|
sender: transfer?.attributes.find(a => a.key === 'sender')?.value,
|
||||||
|
recipient: transfer?.attributes.find(a => a.key === 'recipient')?.value,
|
||||||
|
amount: transfer?.attributes.find(a => a.key === 'amount')?.value
|
||||||
|
},
|
||||||
|
accounts: accountResponse
|
||||||
|
};
|
||||||
|
|
||||||
|
queryOutput(output, argv.output);
|
||||||
|
};
|
@ -7,4 +7,4 @@ export const desc = 'Tokens operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('tokens-cmds')
|
return yargs.commandDir('tokens-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
}
|
};
|
24
src/cmds/registry.ts
Normal file
24
src/cmds/registry.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import yargs from 'yargs';
|
||||||
|
|
||||||
|
export const command = 'registry';
|
||||||
|
|
||||||
|
export const desc = 'Registry tools';
|
||||||
|
|
||||||
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
|
return yargs
|
||||||
|
.options({
|
||||||
|
'user-key': { type: 'string' },
|
||||||
|
'tx-key': { type: 'string' },
|
||||||
|
'bond-id': { type: 'string' },
|
||||||
|
'chain-id': { type: 'string' },
|
||||||
|
filename: { alias: 'f' },
|
||||||
|
id: { type: 'string' },
|
||||||
|
address: { type: 'string' },
|
||||||
|
gas: { type: 'string' },
|
||||||
|
fees: { type: 'string' },
|
||||||
|
gasPrice: { type: 'string' }
|
||||||
|
})
|
||||||
|
.commandDir('registry-cmds')
|
||||||
|
.demandCommand()
|
||||||
|
.help();
|
||||||
|
};
|
@ -1,6 +1,7 @@
|
|||||||
import yargs from 'yargs/yargs';
|
import yargs from 'yargs/yargs';
|
||||||
import { hideBin } from 'yargs/helpers';
|
import { hideBin } from 'yargs/helpers';
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-expressions
|
||||||
yargs(hideBin(process.argv))
|
yargs(hideBin(process.argv))
|
||||||
.options({
|
.options({
|
||||||
verbose: {
|
verbose: {
|
||||||
@ -25,4 +26,5 @@ yargs(hideBin(process.argv))
|
|||||||
.commandDir('cmds')
|
.commandDir('cmds')
|
||||||
.demandCommand()
|
.demandCommand()
|
||||||
.help()
|
.help()
|
||||||
|
.alias('h', 'help')
|
||||||
.argv;
|
.argv;
|
||||||
|
1
src/types/common/main.d.ts
vendored
Normal file
1
src/types/common/main.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
declare module 'lodash-clean';
|
6
src/types/common/package.json
Normal file
6
src/types/common/package.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "common",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"license": "AGPL-3.0",
|
||||||
|
"typings": "main.d.ts"
|
||||||
|
}
|
@ -1,16 +1,22 @@
|
|||||||
import { Arguments } from "yargs";
|
import { Arguments } from 'yargs';
|
||||||
import clean from 'lodash-clean';
|
import clean from 'lodash-clean';
|
||||||
|
|
||||||
export const getConnectionInfo = (argv: Arguments, config: any) => {
|
export const getConnectionInfo = (argv: Arguments, config: any) => {
|
||||||
const { server, userKey, bondId, txKey, chainId, fees, gas } = argv;
|
const { server, userKey, bondId, txKey, chainId, fees, gas, gasPrice } = argv;
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
...config,
|
...config,
|
||||||
|
userKey: stripHexPrefix(config.userKey),
|
||||||
...clean({ server, userKey, bondId, txKey, chainId }),
|
...clean({ server, userKey, bondId, txKey, chainId }),
|
||||||
privateKey: txKey || userKey || config.userKey,
|
privateKey: stripHexPrefix(txKey || userKey || config.userKey),
|
||||||
gas: String(gas || config.gas),
|
gas: String(gas || config.gas),
|
||||||
fees: String(fees || config.fees)
|
fees: String(fees || config.fees),
|
||||||
|
gasPrice: String(gasPrice || config.gasPrice)
|
||||||
};
|
};
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function stripHexPrefix (hex: string): string {
|
||||||
|
return hex && hex.startsWith('0x') ? hex.slice(2) : hex;
|
||||||
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import yaml from 'js-yaml'
|
import yaml from 'js-yaml';
|
||||||
import fs from 'fs'
|
import fs from 'fs';
|
||||||
import path from 'path'
|
import path from 'path';
|
||||||
|
|
||||||
export const getConfig = (configFilePath: string): any => {
|
export const getConfig = (configFilePath: string): any => {
|
||||||
const resolvedFilePath = path.resolve(process.cwd(), configFilePath);
|
const resolvedFilePath = path.resolve(process.cwd(), configFilePath);
|
||||||
const configFile = fs.readFileSync(resolvedFilePath, 'utf-8')
|
const configFile = fs.readFileSync(resolvedFilePath, 'utf-8');
|
||||||
return yaml.load(configFile);
|
return yaml.load(configFile);
|
||||||
};
|
};
|
||||||
|
@ -1,20 +1,17 @@
|
|||||||
import assert from 'assert';
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
import { Arguments } from 'yargs';
|
import { Arguments } from 'yargs';
|
||||||
|
|
||||||
export const parseGasAndFees = (gas: string, fees = '') => {
|
import { parseGasAndFees, getGasPrice as registryGetGasPrice } from '@cerc-io/registry-sdk';
|
||||||
assert(gas, 'Invalid gas.');
|
import { StdFee, GasPrice } from '@cosmjs/stargate';
|
||||||
|
|
||||||
const [{ amount, denom }] = fees.trim().split(',')
|
export const getGasAndFees = (argv: Arguments, config: any = {}): StdFee | number | undefined => {
|
||||||
.map(fee => fee.trim().split(/(\d+)/))
|
|
||||||
.filter(([_, amount, denom]) => (denom && amount))
|
|
||||||
.map(([_, amount, denom]) => ({ denom, amount }));
|
|
||||||
|
|
||||||
return { amount, denom, gas };
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getGasAndFees = (argv: Arguments, config: any = {}) => {
|
|
||||||
return parseGasAndFees(
|
return parseGasAndFees(
|
||||||
String(argv.gas || config.gas),
|
argv.gas || config.gas,
|
||||||
String(argv.fees || config.fees)
|
argv.fees || config.fees
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getGasPrice = (argv: Arguments, config: any = {}): GasPrice | undefined => {
|
||||||
|
const gasPriceString = argv.gasPrice || config.gasPrice;
|
||||||
|
return registryGetGasPrice(gasPriceString);
|
||||||
|
};
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
|
|
||||||
export const txOutput = (result:any,msg:string,output:unknown,verbose:unknown) => {
|
export const txOutput = (result:any, msg:string, output:unknown, verbose:unknown) => {
|
||||||
if (output=="json"){
|
if (output === 'json') {
|
||||||
console.log(verbose ? JSON.parse(JSON.stringify(result)) : JSON.parse(msg));
|
console.log(verbose ? JSON.parse(JSON.stringify(result)) : JSON.parse(msg));
|
||||||
} else {
|
} else {
|
||||||
console.log(verbose ? JSON.stringify(result,undefined,2) : msg);
|
console.log(verbose ? JSON.stringify(result, undefined, 2) : msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const queryOutput = (result: any, output: unknown) => {
|
export const queryOutput = (result: any, output: unknown) => {
|
||||||
if (output=="json"){
|
if (output === 'json') {
|
||||||
console.log(JSON.parse(JSON.stringify(result)));
|
console.log(JSON.parse(JSON.stringify(result)));
|
||||||
} else {
|
} else {
|
||||||
console.log(JSON.stringify(result, (key, value) => {
|
console.log(JSON.stringify(result, (key, value) => {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(value)
|
return JSON.parse(value);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}, 2));
|
}, 2));
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
34
test/README.md
Normal file
34
test/README.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Run CLI tests
|
||||||
|
|
||||||
|
* Follow the project `Setup` and `Account Setup` from root [README](./../README.md)
|
||||||
|
|
||||||
|
* Add laconic cmd to path
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export PATH="$PWD/bin:$PATH"
|
||||||
|
```
|
||||||
|
|
||||||
|
* Create a .env file using [.env.example](./.env.example):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
* Get account address of test account:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconicd keys list --keyring-backend test
|
||||||
|
|
||||||
|
# - address: laconic10er85pyd7ukw732e88fzv7k0jq205764hye2dx
|
||||||
|
# name: alice
|
||||||
|
# pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AsDoWlNIr3W013pOiwmopaB/SaWQj6r3g56xb2d9GxYK"}'
|
||||||
|
# type: local
|
||||||
|
```
|
||||||
|
|
||||||
|
Use the `address` field from the result and assign it in `TEST_ACCOUNT` field of `.env` file
|
||||||
|
|
||||||
|
* Run CLI tests:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn test
|
||||||
|
```
|
968
test/cli.test.ts
Normal file
968
test/cli.test.ts
Normal file
@ -0,0 +1,968 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import assert from 'assert';
|
||||||
|
import { spawnSync } from 'child_process';
|
||||||
|
|
||||||
|
import { AUCTION_KIND_PROVIDER, AUCTION_KIND_VICKREY } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
|
import {
|
||||||
|
CHAIN_ID,
|
||||||
|
TOKEN_TYPE,
|
||||||
|
AUCTION_COMMIT_DURATION,
|
||||||
|
AUCTION_REVEAL_DURATION,
|
||||||
|
delay,
|
||||||
|
checkResultAndRetrieveOutput,
|
||||||
|
createBond,
|
||||||
|
getBondObj,
|
||||||
|
getAccountObj,
|
||||||
|
getRecordObj,
|
||||||
|
getAuthorityObj,
|
||||||
|
getAuctionObj,
|
||||||
|
getBidObj,
|
||||||
|
updateGasAndFeesConfig,
|
||||||
|
AUCTION_STATUS,
|
||||||
|
getFeesConfig
|
||||||
|
} from './helpers';
|
||||||
|
|
||||||
|
describe('Test laconic CLI commands', () => {
|
||||||
|
test('laconic', async () => {
|
||||||
|
const result = spawnSync('laconic');
|
||||||
|
expect(result.status).toBe(1);
|
||||||
|
|
||||||
|
const output = result.stdout.toString().trim();
|
||||||
|
const errorOutput = result.stderr.toString().trim();
|
||||||
|
|
||||||
|
// Expect error with usage string
|
||||||
|
expect(output).toBe('');
|
||||||
|
expect(errorOutput).toContain('laconic <command>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry']);
|
||||||
|
expect(result.status).toBe(1);
|
||||||
|
|
||||||
|
const output = result.stdout.toString().trim();
|
||||||
|
const errorOutput = result.stderr.toString().trim();
|
||||||
|
|
||||||
|
// Expect error with usage string
|
||||||
|
expect(output).toBe('');
|
||||||
|
expect(errorOutput).toContain('laconic registry');
|
||||||
|
expect(errorOutput).toContain('Registry tools');
|
||||||
|
expect(errorOutput).toContain('Commands:');
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Break up tests into separate files
|
||||||
|
// TODO: Add tests for registry commands with all available flags
|
||||||
|
|
||||||
|
describe('laconic registry commands', () => {
|
||||||
|
const testAccount = process.env.TEST_ACCOUNT;
|
||||||
|
assert(testAccount, 'TEST_ACCOUNT not set in env');
|
||||||
|
const testAccount2 = 'laconic1pmuxrcnuhhf8qdllzuf2ctj2tnwwcg6yswqnyd';
|
||||||
|
const initialAccountBalance = Number('1000000000000000000000000000000');
|
||||||
|
|
||||||
|
const testAuthorityName = 'laconic';
|
||||||
|
const testRecordFilePath = 'test/data/watcher-record.yml';
|
||||||
|
let testAuctionId: string, testRecordId: string, testRecordBondId: string;
|
||||||
|
|
||||||
|
test('laconic registry status', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'status']);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expect output object to have registry status props
|
||||||
|
expect(outputObj).toHaveProperty('version');
|
||||||
|
expect(outputObj).toHaveProperty('node');
|
||||||
|
expect(outputObj).toHaveProperty('node.network', CHAIN_ID);
|
||||||
|
expect(outputObj).toHaveProperty('sync');
|
||||||
|
expect(Number(outputObj.sync.latestBlockHeight)).toBeGreaterThan(0);
|
||||||
|
expect(outputObj).toHaveProperty('validator');
|
||||||
|
expect(outputObj).toHaveProperty('validators');
|
||||||
|
expect(outputObj).toHaveProperty('numPeers');
|
||||||
|
expect(outputObj).toHaveProperty('peers');
|
||||||
|
expect(outputObj).toHaveProperty('diskUsage');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Bond operations', () => {
|
||||||
|
const bondOwner = testAccount;
|
||||||
|
let bondBalance = 1000000000;
|
||||||
|
let bondId: string;
|
||||||
|
|
||||||
|
test('laconic registry bond create --type <type> --quantity <quantity> --gas <gas> --fees <fees>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
|
||||||
|
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expect output object to have resultant bond id
|
||||||
|
expect(outputObj.bondId).toBeDefined();
|
||||||
|
|
||||||
|
bondId = outputObj.bondId;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry bond list', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'list']);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected bond
|
||||||
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toEqual(expectedBond);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry bond list --owner <owner_address>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'list', '--owner', bondOwner]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected bond
|
||||||
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toEqual(expectedBond);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry bond get --id <bond_id>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'get', '--id', bondId]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected bond
|
||||||
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toEqual(expectedBond);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry bond refill --id <bond_id> --type <type> --quantity <quantity>', async () => {
|
||||||
|
const bondRefillAmount = 1000;
|
||||||
|
bondBalance += bondRefillAmount;
|
||||||
|
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'refill', '--id', bondId, '--type', TOKEN_TYPE, '--quantity', bondRefillAmount.toString()]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
// Check updated bond
|
||||||
|
const bondResult = spawnSync('laconic', ['registry', 'bond', 'get', '--id', bondId]);
|
||||||
|
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
|
||||||
|
|
||||||
|
// Expected bond
|
||||||
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
||||||
|
|
||||||
|
expect(bondOutputObj.length).toEqual(1);
|
||||||
|
expect(bondOutputObj[0]).toEqual(expectedBond);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry bond withdraw --id <bond_id> --type <type> --quantity <quantity>', async () => {
|
||||||
|
const bondWithdrawAmount = 500;
|
||||||
|
bondBalance -= bondWithdrawAmount;
|
||||||
|
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'withdraw', '--id', bondId, '--type', TOKEN_TYPE, '--quantity', bondWithdrawAmount.toString()]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
// Check updated bond
|
||||||
|
const bondResult = spawnSync('laconic', ['registry', 'bond', 'get', '--id', bondId]);
|
||||||
|
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
|
||||||
|
|
||||||
|
// Expected bond
|
||||||
|
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
|
||||||
|
|
||||||
|
// Expect balance to be deducted
|
||||||
|
expect(bondOutputObj.length).toEqual(1);
|
||||||
|
expect(bondOutputObj[0]).toEqual(expectedBond);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry bond cancel --id <bond_id>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'cancel', '--id', bondId]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
// Check updated bond
|
||||||
|
const bondResult = spawnSync('laconic', ['registry', 'bond', 'get', '--id', bondId]);
|
||||||
|
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
|
||||||
|
|
||||||
|
// Expect empty object
|
||||||
|
expect(bondOutputObj.length).toEqual(1);
|
||||||
|
expect(bondOutputObj[0]).toEqual(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Account and tokens operations', () => {
|
||||||
|
let balanceBeforeSend: number;
|
||||||
|
|
||||||
|
test('laconic registry account get --address <account_address>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'account', 'get', '--address', testAccount]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected account
|
||||||
|
const expectedAccount = getAccountObj({ address: testAccount });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedAccount);
|
||||||
|
expect(outputObj[0].number).toBeDefined();
|
||||||
|
expect(outputObj[0].sequence).toBeDefined();
|
||||||
|
|
||||||
|
balanceBeforeSend = Number(outputObj[0].balance[0].quantity);
|
||||||
|
expect(balanceBeforeSend).toBeGreaterThan(0);
|
||||||
|
expect(balanceBeforeSend).toBeLessThan(initialAccountBalance);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry tokens send --address <account_address> --type <token_type> --quantity <quantity>', async () => {
|
||||||
|
const sendAmount = 1000000000;
|
||||||
|
const balanceAfterSend = balanceBeforeSend - sendAmount;
|
||||||
|
|
||||||
|
const result = spawnSync('laconic', ['registry', 'tokens', 'send', '--address', testAccount2, '--type', TOKEN_TYPE, '--quantity', sendAmount.toString()]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected acconts
|
||||||
|
const expectedAccounts = [
|
||||||
|
getAccountObj({ address: testAccount, balance: balanceAfterSend }),
|
||||||
|
getAccountObj({ address: testAccount2, balance: sendAmount })
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(outputObj.tx.code).toEqual(0);
|
||||||
|
expect(outputObj.tx.amount).toEqual(`${sendAmount}${TOKEN_TYPE}`);
|
||||||
|
expect(outputObj.tx.sender).toEqual(testAccount);
|
||||||
|
expect(outputObj.tx.recipient).toEqual(testAccount2);
|
||||||
|
expect(outputObj.accounts.length).toEqual(2);
|
||||||
|
expect(outputObj.accounts).toMatchObject(expectedAccounts);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry tokens gettx --hash <hash>', async () => {
|
||||||
|
const sendAmount = 1000000000;
|
||||||
|
|
||||||
|
const sendResult = spawnSync('laconic', ['registry', 'tokens', 'send', '--address', testAccount2, '--type', TOKEN_TYPE, '--quantity', sendAmount.toString()]);
|
||||||
|
const sendOutput = checkResultAndRetrieveOutput(sendResult);
|
||||||
|
expect(sendOutput.tx.code).toEqual(0);
|
||||||
|
|
||||||
|
const gettxResult = spawnSync('laconic', ['registry', 'tokens', 'gettx', '--hash', sendOutput.tx.hash]);
|
||||||
|
const gettxOutput = checkResultAndRetrieveOutput(gettxResult);
|
||||||
|
|
||||||
|
expect(gettxOutput.hash).toEqual(sendOutput.tx.hash);
|
||||||
|
expect(gettxOutput.code).toEqual(0);
|
||||||
|
expect(gettxOutput.amount).toEqual(`${sendAmount}${TOKEN_TYPE}`);
|
||||||
|
expect(gettxOutput.sender).toEqual(testAccount);
|
||||||
|
expect(gettxOutput.recipient).toEqual(testAccount2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Record operations', () => {
|
||||||
|
const gas = 250000;
|
||||||
|
const fees = `250000${TOKEN_TYPE}`;
|
||||||
|
const bondBalance = 1000000000;
|
||||||
|
|
||||||
|
test('laconic registry record publish --filename <record_file> --bond-id <bond_id> --gas <gas> --fees <fees>', async () => {
|
||||||
|
// Create a new bond to be associated with the record
|
||||||
|
({ bondId: testRecordBondId } = createBond(bondBalance));
|
||||||
|
const result = spawnSync('laconic', ['registry', 'record', 'publish', '--filename', testRecordFilePath, '--bond-id', testRecordBondId, '--gas', gas.toString(), '--fees', fees]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expect output object to resultant bond id
|
||||||
|
expect(outputObj.id).toBeDefined();
|
||||||
|
|
||||||
|
testRecordId = outputObj.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry record list', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'record', 'list']);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected record
|
||||||
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedRecord);
|
||||||
|
expect(outputObj[0].createTime).toBeDefined();
|
||||||
|
expect(outputObj[0].expiryTime).toBeDefined();
|
||||||
|
expect(outputObj[0].owners).toBeDefined();
|
||||||
|
expect(outputObj[0].owners.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry record get --id <record_id>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'record', 'get', '--id', testRecordId]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected record
|
||||||
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedRecord);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Bond records operations', () => {
|
||||||
|
let testRecordBondId2: string;
|
||||||
|
|
||||||
|
test('laconic registry bond dissociate --id <record_id>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'dissociate', '--id', testRecordId]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
const recordResult = spawnSync('laconic', ['registry', 'record', 'get', '--id', testRecordId]);
|
||||||
|
const recordOutputObj = checkResultAndRetrieveOutput(recordResult);
|
||||||
|
|
||||||
|
// Expected record
|
||||||
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: '', recordId: testRecordId, names: null });
|
||||||
|
|
||||||
|
expect(recordOutputObj.length).toEqual(1);
|
||||||
|
expect(recordOutputObj[0]).toMatchObject(expectedRecord);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry bond associate --id <record_id> --bond-id <bond_id>', async () => {
|
||||||
|
// Create a new bond to be associated with the record
|
||||||
|
({ bondId: testRecordBondId2 } = createBond(bondBalance));
|
||||||
|
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'associate', '--id', testRecordId, '--bond-id', testRecordBondId2]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
const recordResult = spawnSync('laconic', ['registry', 'record', 'get', '--id', testRecordId]);
|
||||||
|
const recordOutputObj = checkResultAndRetrieveOutput(recordResult);
|
||||||
|
|
||||||
|
// Expected record
|
||||||
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId2, recordId: testRecordId, names: null });
|
||||||
|
|
||||||
|
expect(recordOutputObj.length).toEqual(1);
|
||||||
|
expect(recordOutputObj[0]).toMatchObject(expectedRecord);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry bond records reassociate --old-bond-id <old_bond_id> --new-bond-id <new_bond_id>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'records', 'reassociate', '--old-bond-id', testRecordBondId2, '--new-bond-id', testRecordBondId]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
const recordResult = spawnSync('laconic', ['registry', 'record', 'get', '--id', testRecordId]);
|
||||||
|
const recordOutputObj = checkResultAndRetrieveOutput(recordResult);
|
||||||
|
|
||||||
|
// Expected record
|
||||||
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
|
||||||
|
|
||||||
|
expect(recordOutputObj.length).toEqual(1);
|
||||||
|
expect(recordOutputObj[0]).toMatchObject(expectedRecord);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Name authority operations (pre auction)', () => {
|
||||||
|
test('laconic registry authority reserve <authority_name>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'authority', 'reserve', testAuthorityName]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expect result
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry authority whois <authority_name>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'authority', 'whois', testAuthorityName]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
// Expected authority (still in auction)
|
||||||
|
const expectedAuthority = getAuthorityObj({ owner: '', status: 'auction', auction: getAuctionObj({ owner: testAccount }) });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedAuthority);
|
||||||
|
expect(outputObj[0].expiryTime).toBeDefined();
|
||||||
|
expect(outputObj[0].height).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
testAuctionId = outputObj[0].auction.id;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Authority auction operations', () => {
|
||||||
|
const bidAmount = 25000000;
|
||||||
|
let bidRevealFilePath: string;
|
||||||
|
|
||||||
|
test('laconic registry auction get <auction_id>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected auction (still in commit stage)
|
||||||
|
const expectedAuction = getAuctionObj({ owner: testAccount, status: 'commit' });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedAuction);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry auction bid commit <auction_id> <quantity> <type>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'commit', testAuctionId, bidAmount.toString(), TOKEN_TYPE]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj.reveal_file).toBeDefined();
|
||||||
|
|
||||||
|
bidRevealFilePath = outputObj.reveal_file;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry auction bid reveal <auction_id> <file_path>', async () => {
|
||||||
|
// Wait for auction commits duration (60s)
|
||||||
|
await delay(AUCTION_COMMIT_DURATION * 1000);
|
||||||
|
|
||||||
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedAuction = getAuctionObj({ owner: testAccount, status: 'reveal' });
|
||||||
|
const expectedBid = getBidObj({ bidder: testAccount });
|
||||||
|
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuction);
|
||||||
|
expect(auctionOutputObj[0].bids[0]).toMatchObject(expectedBid);
|
||||||
|
|
||||||
|
// Reveal bid
|
||||||
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'reveal', testAuctionId, bidRevealFilePath]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
const revealObject = JSON.parse(fs.readFileSync(bidRevealFilePath, 'utf8'));
|
||||||
|
expect(revealObject).toMatchObject({
|
||||||
|
chainId: CHAIN_ID,
|
||||||
|
auctionId: testAuctionId,
|
||||||
|
bidderAddress: testAccount,
|
||||||
|
bidAmount: `${bidAmount}alnt`
|
||||||
|
});
|
||||||
|
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Name authority operations (post auction)', () => {
|
||||||
|
const testSubAuthorityName = 'echo.laconic';
|
||||||
|
const testSubAuthorityName2 = 'kube.laconic';
|
||||||
|
|
||||||
|
test('laconic registry authority whois <authority_name>', async () => {
|
||||||
|
// Wait for auction reveals duration (60s)
|
||||||
|
await delay(AUCTION_REVEAL_DURATION * 1000);
|
||||||
|
|
||||||
|
const result = spawnSync('laconic', ['registry', 'authority', 'whois', testAuthorityName]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected authority (active)
|
||||||
|
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedAuthority);
|
||||||
|
}, (AUCTION_REVEAL_DURATION + 5) * 1000);
|
||||||
|
|
||||||
|
test('laconic registry authority bond set laconic <bond_id>', async () => {
|
||||||
|
// Create a new bond to be set on the authority
|
||||||
|
const bondBalance = 1000000000;
|
||||||
|
const { bondId } = createBond(bondBalance);
|
||||||
|
|
||||||
|
const result = spawnSync('laconic', ['registry', 'authority', 'bond', 'set', testAuthorityName, bondId]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
// Check updated authority
|
||||||
|
const authorityResult = spawnSync('laconic', ['registry', 'authority', 'whois', testAuthorityName]);
|
||||||
|
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
|
||||||
|
|
||||||
|
// Expected authority (active with bond)
|
||||||
|
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null, bondId: bondId });
|
||||||
|
|
||||||
|
expect(authorityOutputObj.length).toEqual(1);
|
||||||
|
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry authority reserve <sub_authority> (same owner)', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'authority', 'reserve', testSubAuthorityName]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
// Check updated authority
|
||||||
|
const authorityResult = spawnSync('laconic', ['registry', 'authority', 'whois', testSubAuthorityName]);
|
||||||
|
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
|
||||||
|
|
||||||
|
// Expected authority (active with bond)
|
||||||
|
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null });
|
||||||
|
|
||||||
|
expect(authorityOutputObj.length).toEqual(1);
|
||||||
|
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry authority reserve <sub_authority> --owner <owner_address> (different owner)', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'authority', 'reserve', testSubAuthorityName2, '--owner', testAccount2]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
// Check updated authority
|
||||||
|
const authorityResult = spawnSync('laconic', ['registry', 'authority', 'whois', testSubAuthorityName2]);
|
||||||
|
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
|
||||||
|
|
||||||
|
// Expected authority (active with bond)
|
||||||
|
const expectedAuthority = getAuthorityObj({ owner: testAccount2, status: 'active', auction: null });
|
||||||
|
|
||||||
|
expect(authorityOutputObj.length).toEqual(1);
|
||||||
|
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry authority list', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'authority', 'list']);
|
||||||
|
const authoritiesOutputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected authorities
|
||||||
|
const expectedAuthorities = [
|
||||||
|
{ name: 'echo.laconic', entry: { ownerAddress: testAccount, status: 'active' } },
|
||||||
|
{ name: 'kube.laconic', entry: { ownerAddress: testAccount2, status: 'active' } },
|
||||||
|
{ name: 'laconic', entry: { ownerAddress: testAccount, status: 'active' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(authoritiesOutputObj.length).toEqual(3);
|
||||||
|
expect(authoritiesOutputObj).toMatchObject(expectedAuthorities);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry authority list --owner <owner_address>', async () => {
|
||||||
|
let result = spawnSync('laconic', ['registry', 'authority', 'list', '--owner', testAccount]);
|
||||||
|
const authoritiesByOwner1 = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
const expectedAuthoritiesByOwner1 = [
|
||||||
|
{ name: 'echo.laconic', entry: { ownerAddress: testAccount, status: 'active' } },
|
||||||
|
{ name: 'laconic', entry: { ownerAddress: testAccount, status: 'active' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(authoritiesByOwner1.length).toEqual(2);
|
||||||
|
expect(authoritiesByOwner1).toMatchObject(expectedAuthoritiesByOwner1);
|
||||||
|
|
||||||
|
result = spawnSync('laconic', ['registry', 'authority', 'list', '--owner', testAccount2]);
|
||||||
|
const authoritiesByOwner2 = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
const expectedAuthoritiesByOwner2 = [
|
||||||
|
{ name: 'kube.laconic', entry: { ownerAddress: testAccount2, status: 'active' } }
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(authoritiesByOwner2.length).toEqual(1);
|
||||||
|
expect(authoritiesByOwner2).toMatchObject(expectedAuthoritiesByOwner2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Name operations', () => {
|
||||||
|
const testName = 'lrn://laconic/watcher/erc20';
|
||||||
|
|
||||||
|
test('laconic registry name set <name> <record_id>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'name', 'set', testName, testRecordId]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry name lookup <name>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'name', 'lookup', testName]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject({ latest: { id: testRecordId } });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry name resolve <name>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'name', 'resolve', testName]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected resolved record
|
||||||
|
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: [testName] });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedRecord);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry name delete <name>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'name', 'delete', testName]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
// Check that name doesn't resolve
|
||||||
|
const resolveResult = spawnSync('laconic', ['registry', 'name', 'resolve', testName]);
|
||||||
|
const resolveOutputObj = checkResultAndRetrieveOutput(resolveResult);
|
||||||
|
expect(resolveOutputObj.length).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Vickrey Auction operations', () => {
|
||||||
|
const commitFee = 1000;
|
||||||
|
const revealFee = 1000;
|
||||||
|
const minimumBid = 100000;
|
||||||
|
|
||||||
|
const bidAmount = 25000000;
|
||||||
|
let bidRevealFilePath: string;
|
||||||
|
|
||||||
|
test('laconic registry auction create --kind <kind> --commits-duration <commits_duration> --reveals-duration <reveals_duration> --denom <denom> --commit-fee <commit_fee> --reveal-fee <reveal_fee> --minimum-bid <minimum_bid>', async () => {
|
||||||
|
const createAuctionResult = spawnSync('laconic', [
|
||||||
|
'registry',
|
||||||
|
'auction',
|
||||||
|
'create',
|
||||||
|
'--kind', AUCTION_KIND_VICKREY,
|
||||||
|
'--commits-duration', AUCTION_COMMIT_DURATION.toString(),
|
||||||
|
'--reveals-duration', AUCTION_REVEAL_DURATION.toString(),
|
||||||
|
'--denom', TOKEN_TYPE,
|
||||||
|
'--commit-fee', commitFee.toString(),
|
||||||
|
'--reveal-fee', revealFee.toString(),
|
||||||
|
'--minimum-bid', minimumBid.toString()
|
||||||
|
]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(createAuctionResult);
|
||||||
|
|
||||||
|
expect(outputObj).toHaveProperty('auctionId');
|
||||||
|
|
||||||
|
testAuctionId = outputObj.auctionId;
|
||||||
|
const getAuctionResult = spawnSync('laconic', ['registry', 'auction', 'get', '--id', testAuctionId]);
|
||||||
|
const auctionOutputObj = checkResultAndRetrieveOutput(getAuctionResult);
|
||||||
|
|
||||||
|
const expectedAuctionObjPartial = {
|
||||||
|
kind: AUCTION_KIND_VICKREY,
|
||||||
|
status: AUCTION_STATUS.COMMIT,
|
||||||
|
ownerAddress: testAccount,
|
||||||
|
commitFee: { quantity: commitFee },
|
||||||
|
revealFee: { quantity: revealFee },
|
||||||
|
minimumBid: { quantity: minimumBid },
|
||||||
|
winnerAddresses: [],
|
||||||
|
winnerBids: [],
|
||||||
|
maxPrice: { quantity: 0 },
|
||||||
|
numProviders: 0,
|
||||||
|
bids: []
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry auction bid commit <auction_id> <quantity> <type>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'commit', testAuctionId, bidAmount.toString(), TOKEN_TYPE]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj.reveal_file).toBeDefined();
|
||||||
|
|
||||||
|
bidRevealFilePath = outputObj.reveal_file;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry auction bid reveal <auction_id> <file_path>', async () => {
|
||||||
|
// Wait for auction commits duration (60s)
|
||||||
|
await delay(AUCTION_COMMIT_DURATION * 1000);
|
||||||
|
|
||||||
|
let auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
let auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedAuctionObjPartial = {
|
||||||
|
status: AUCTION_STATUS.REVEAL,
|
||||||
|
ownerAddress: testAccount,
|
||||||
|
winnerAddresses: [],
|
||||||
|
winnerBids: [],
|
||||||
|
bids: [{
|
||||||
|
bidderAddress: testAccount,
|
||||||
|
status: AUCTION_STATUS.COMMIT,
|
||||||
|
bidAmount: { quantity: 0 }
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
||||||
|
|
||||||
|
// Reveal bid
|
||||||
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'reveal', testAuctionId, bidRevealFilePath]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
const revealObject = JSON.parse(fs.readFileSync(bidRevealFilePath, 'utf8'));
|
||||||
|
expect(revealObject).toMatchObject({
|
||||||
|
chainId: CHAIN_ID,
|
||||||
|
auctionId: testAuctionId,
|
||||||
|
bidderAddress: testAccount,
|
||||||
|
bidAmount: `${bidAmount}${TOKEN_TYPE}`
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get auction with revealed bid
|
||||||
|
auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedAuctionObjPartialOnBidReveal = {
|
||||||
|
status: AUCTION_STATUS.REVEAL,
|
||||||
|
winnerAddresses: [],
|
||||||
|
bids: [{
|
||||||
|
bidderAddress: testAccount,
|
||||||
|
status: AUCTION_STATUS.REVEAL,
|
||||||
|
bidAmount: { quantity: bidAmount }
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartialOnBidReveal);
|
||||||
|
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
||||||
|
|
||||||
|
test('laconic registry auction get <auction_id>', async () => {
|
||||||
|
// Wait for auction reveals duration (60s)
|
||||||
|
await delay(AUCTION_REVEAL_DURATION * 1000);
|
||||||
|
|
||||||
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedAuctionObjPartial = {
|
||||||
|
status: AUCTION_STATUS.COMPLETED,
|
||||||
|
ownerAddress: testAccount,
|
||||||
|
winnerAddresses: [testAccount],
|
||||||
|
winnerBids: [{ quantity: bidAmount }],
|
||||||
|
winnerPrice: { quantity: bidAmount }
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
||||||
|
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Provider Auction operations', () => {
|
||||||
|
const txFees = getFeesConfig();
|
||||||
|
|
||||||
|
const commitFee = 1000;
|
||||||
|
const revealFee = 1000;
|
||||||
|
const maxPrice = 1000000;
|
||||||
|
const numProviders = 2;
|
||||||
|
const bidderInitialBlanace = 1000000000;
|
||||||
|
testAuctionId = '5e9dd5501e965f25db4fa62635d0ce5f6c59d73ab1a2ea999f8c5bf2f6fb6350';
|
||||||
|
|
||||||
|
const bidderAccounts = [
|
||||||
|
{
|
||||||
|
privateKey: 'f40f8e2c9ba70595b6d1cf3bcc47ba539e7d6ad2bcdb16e26c1e369378fd5a55',
|
||||||
|
address: 'laconic13cd6ntlcf5y0zmafg6wf96y6vsnq46xagpmjtc',
|
||||||
|
bidAmount: 25000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
privateKey: '2c70e81c285e12f196837911aa258b11dff7e4189fc0f11e28cb228956807881',
|
||||||
|
address: 'laconic15x7sw49w3x2pahjlr48hunp5gpr7hm54eg3f8h',
|
||||||
|
bidAmount: 25300
|
||||||
|
},
|
||||||
|
{
|
||||||
|
privateKey: '1d3a47900e1a5980b171419ac700e779330bc0f85389a4113ff608ca314e25bb',
|
||||||
|
address: 'laconic1lkgay8ejvcwmngj3jua2ancdxxkukecz7hty89',
|
||||||
|
bidAmount: 25200
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const winnerAccounts = [bidderAccounts[0], bidderAccounts[2]];
|
||||||
|
const winnerPrice = bidderAccounts[2].bidAmount;
|
||||||
|
|
||||||
|
const bidRevealFilePaths: string[] = [];
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
// Fund all bidder accounts
|
||||||
|
bidderAccounts.forEach(account => {
|
||||||
|
spawnSync('laconic', ['registry', 'tokens', 'send', '--address', account.address, '--type', TOKEN_TYPE, '--quantity', bidderInitialBlanace.toString()]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry auction create --kind <kind> --commits-duration <commits_duration> --reveals-duration <reveals_duration> --denom <denom> --commit-fee <commit_fee> --reveal-fee <reveal_fee> --max-price <max_price> --num-providers <num_providers>', async () => {
|
||||||
|
const createAuctionResult = spawnSync('laconic', [
|
||||||
|
'registry',
|
||||||
|
'auction',
|
||||||
|
'create',
|
||||||
|
'--kind', AUCTION_KIND_PROVIDER,
|
||||||
|
'--commits-duration', AUCTION_COMMIT_DURATION.toString(),
|
||||||
|
'--reveals-duration', AUCTION_REVEAL_DURATION.toString(),
|
||||||
|
'--denom', TOKEN_TYPE,
|
||||||
|
'--commit-fee', commitFee.toString(),
|
||||||
|
'--reveal-fee', revealFee.toString(),
|
||||||
|
'--max-price', maxPrice.toString(),
|
||||||
|
'--num-providers', numProviders.toString()
|
||||||
|
]);
|
||||||
|
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(createAuctionResult);
|
||||||
|
|
||||||
|
expect(outputObj).toHaveProperty('auctionId');
|
||||||
|
|
||||||
|
testAuctionId = outputObj.auctionId;
|
||||||
|
const getAuctionResult = spawnSync('laconic', ['registry', 'auction', 'get', '--id', testAuctionId]);
|
||||||
|
const auctionOutputObj = checkResultAndRetrieveOutput(getAuctionResult);
|
||||||
|
|
||||||
|
const expectedAuctionObjPartial = {
|
||||||
|
kind: AUCTION_KIND_PROVIDER,
|
||||||
|
status: AUCTION_STATUS.COMMIT,
|
||||||
|
ownerAddress: testAccount,
|
||||||
|
commitFee: { quantity: commitFee },
|
||||||
|
revealFee: { quantity: revealFee },
|
||||||
|
minimumBid: { quantity: 0 },
|
||||||
|
winnerAddresses: [],
|
||||||
|
winnerBids: [],
|
||||||
|
maxPrice: { quantity: maxPrice },
|
||||||
|
numProviders: numProviders,
|
||||||
|
bids: []
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry auction bid commit <auction_id> <quantity> <type>', async () => {
|
||||||
|
for (const bidderAccount of bidderAccounts) {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'commit', testAuctionId, bidderAccount.bidAmount.toString(), TOKEN_TYPE, '--txKey', bidderAccount.privateKey]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj.reveal_file).toBeDefined();
|
||||||
|
|
||||||
|
bidRevealFilePaths.push(outputObj.reveal_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedBids = bidderAccounts.map(account => ({
|
||||||
|
bidderAddress: account.address,
|
||||||
|
status: AUCTION_STATUS.COMMIT,
|
||||||
|
bidAmount: { quantity: 0 }
|
||||||
|
}));
|
||||||
|
const expectedAuctionObjPartial = {
|
||||||
|
status: AUCTION_STATUS.COMMIT,
|
||||||
|
ownerAddress: testAccount,
|
||||||
|
winnerAddresses: [],
|
||||||
|
winnerBids: [],
|
||||||
|
bids: expectedBids
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('laconic registry auction bid reveal <auction_id> <file_path>', async () => {
|
||||||
|
// Wait for auction commits duration (60s)
|
||||||
|
await delay(AUCTION_COMMIT_DURATION * 1000);
|
||||||
|
|
||||||
|
// Reveal bid
|
||||||
|
for (let i = 0; i < bidderAccounts.length; i++) {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'auction', 'bid', 'reveal', testAuctionId, bidRevealFilePaths[i], '--txKey', bidderAccounts[i].privateKey]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
const revealObject = JSON.parse(fs.readFileSync(bidRevealFilePaths[i], 'utf8'));
|
||||||
|
expect(revealObject).toMatchObject({
|
||||||
|
chainId: CHAIN_ID,
|
||||||
|
auctionId: testAuctionId,
|
||||||
|
bidderAddress: bidderAccounts[i].address,
|
||||||
|
bidAmount: `${bidderAccounts[i].bidAmount}${TOKEN_TYPE}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get auction with revealed bid
|
||||||
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedBids = bidderAccounts.map(account => ({
|
||||||
|
bidderAddress: account.address,
|
||||||
|
status: AUCTION_STATUS.REVEAL,
|
||||||
|
bidAmount: { quantity: account.bidAmount }
|
||||||
|
}));
|
||||||
|
const expectedAuctionObjPartialOnBidReveal = {
|
||||||
|
status: AUCTION_STATUS.REVEAL,
|
||||||
|
winnerAddresses: [],
|
||||||
|
bids: expectedBids
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartialOnBidReveal);
|
||||||
|
}, (AUCTION_COMMIT_DURATION + 60) * 1000);
|
||||||
|
|
||||||
|
test('laconic registry auction get <auction_id>', async () => {
|
||||||
|
// Wait for auction reveals duration (60s)
|
||||||
|
await delay(AUCTION_REVEAL_DURATION * 1000);
|
||||||
|
|
||||||
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedWinnerAddresses = winnerAccounts.map(account => account.address);
|
||||||
|
const expectedWinnerBids = winnerAccounts.map(account => ({ quantity: account.bidAmount }));
|
||||||
|
|
||||||
|
const expectedAuctionObjPartial = {
|
||||||
|
status: AUCTION_STATUS.COMPLETED,
|
||||||
|
ownerAddress: testAccount,
|
||||||
|
winnerAddresses: expectedWinnerAddresses,
|
||||||
|
winnerBids: expectedWinnerBids,
|
||||||
|
winnerPrice: { quantity: winnerPrice },
|
||||||
|
fundsReleased: false
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
||||||
|
}, (AUCTION_REVEAL_DURATION + 5) * 1000);
|
||||||
|
|
||||||
|
test('laconic registry auction release-funds <auction_id>', async () => {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'auction', 'release-funds', testAuctionId]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
expect(outputObj).toEqual({ success: true });
|
||||||
|
|
||||||
|
const auctionResult = spawnSync('laconic', ['registry', 'auction', 'get', testAuctionId]);
|
||||||
|
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
|
||||||
|
|
||||||
|
const expectedAuctionObjPartial = {
|
||||||
|
status: AUCTION_STATUS.COMPLETED,
|
||||||
|
ownerAddress: testAccount,
|
||||||
|
fundsReleased: true
|
||||||
|
};
|
||||||
|
expect(auctionOutputObj[0]).toMatchObject(expectedAuctionObjPartial);
|
||||||
|
|
||||||
|
const expectedBalances = [
|
||||||
|
bidderInitialBlanace - (commitFee) - (2 * txFees) + winnerPrice,
|
||||||
|
bidderInitialBlanace - (commitFee) - (2 * txFees),
|
||||||
|
bidderInitialBlanace - (commitFee) - (2 * txFees) + winnerPrice
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let i = 0; i < bidderAccounts.length; i++) {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'account', 'get', '--address', bidderAccounts[i].address]);
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
|
||||||
|
// Expected account
|
||||||
|
const expectedAccount = getAccountObj({ address: bidderAccounts[i].address, balance: expectedBalances[i] });
|
||||||
|
|
||||||
|
expect(outputObj.length).toEqual(1);
|
||||||
|
expect(outputObj[0]).toMatchObject(expectedAccount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Gas and fees config', () => {
|
||||||
|
const bondAmount = 1000;
|
||||||
|
|
||||||
|
test('gas set, fees set to Xalnt', async () => {
|
||||||
|
// gasPrice not set
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
||||||
|
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
expect(outputObj.bondId).toBeDefined();
|
||||||
|
|
||||||
|
// gasPrice set (lower than min gas price)
|
||||||
|
updateGasAndFeesConfig(undefined, undefined, '0.00001alnt');
|
||||||
|
const result1 = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
||||||
|
|
||||||
|
const outputObj1 = checkResultAndRetrieveOutput(result1);
|
||||||
|
expect(outputObj1.bondId).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('gas not set, fees not set, gasPrice set', async () => {
|
||||||
|
updateGasAndFeesConfig(null, null, '1alnt');
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
||||||
|
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
expect(outputObj.bondId).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('gas not set, fees set without token suffix, gasPrice set', async () => {
|
||||||
|
updateGasAndFeesConfig(null, '1.8', '1alnt');
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
||||||
|
|
||||||
|
const outputObj = checkResultAndRetrieveOutput(result);
|
||||||
|
expect(outputObj.bondId).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('gas not set, fees not set, gasPrice not set', async () => {
|
||||||
|
updateGasAndFeesConfig(null, null, null);
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
||||||
|
|
||||||
|
expect(result.status).toBe(1);
|
||||||
|
|
||||||
|
const output = result.stdout.toString().trim();
|
||||||
|
const errorOutput = result.stderr.toString().trim();
|
||||||
|
|
||||||
|
expect(output).toBe('');
|
||||||
|
expect(errorOutput).toContain('Gas price must be set in the client options when auto gas is used.');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
7
test/data/watcher-record.yml
Normal file
7
test/data/watcher-record.yml
Normal 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.23
|
173
test/helpers.ts
Normal file
173
test/helpers.ts
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
|
import { SpawnSyncReturns, spawnSync } from 'child_process';
|
||||||
|
import { Arguments } from 'yargs';
|
||||||
|
|
||||||
|
import { StdFee } from '@cosmjs/stargate';
|
||||||
|
|
||||||
|
import { getConfig, getGasAndFees } from '../src/util';
|
||||||
|
|
||||||
|
export const CHAIN_ID = 'laconic_9000-1';
|
||||||
|
export const TOKEN_TYPE = 'alnt';
|
||||||
|
export const CONFIG_FILE = 'config.yml';
|
||||||
|
|
||||||
|
export enum AUCTION_STATUS {
|
||||||
|
COMMIT = 'commit',
|
||||||
|
REVEAL = 'reveal',
|
||||||
|
COMPLETED = 'completed'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AUCTION_FEES = {
|
||||||
|
commit: 1000000,
|
||||||
|
reveal: 1000000,
|
||||||
|
minimumBid: 5000000
|
||||||
|
};
|
||||||
|
export const AUCTION_COMMIT_DURATION = 60; // 60s
|
||||||
|
export const AUCTION_REVEAL_DURATION = 60; // 60s
|
||||||
|
|
||||||
|
export function checkResultAndRetrieveOutput (result: SpawnSyncReturns<Buffer>): any {
|
||||||
|
if (result.status !== 0) {
|
||||||
|
console.log('stderr', result.stderr.toString().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(result.status).toBe(0);
|
||||||
|
|
||||||
|
const errorOutput = result.stderr.toString().trim();
|
||||||
|
expect(errorOutput).toBe('');
|
||||||
|
|
||||||
|
const output = result.stdout.toString().trim();
|
||||||
|
expect(output.length).toBeGreaterThan(0);
|
||||||
|
return JSON.parse(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createBond (quantity: number): { bondId: string } {
|
||||||
|
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', quantity.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
|
||||||
|
const output = result.stdout.toString().trim();
|
||||||
|
|
||||||
|
return JSON.parse(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBondObj (params: { id: string, owner: string, balance: number}): any {
|
||||||
|
return {
|
||||||
|
id: params.id,
|
||||||
|
owner: params.owner,
|
||||||
|
balance: [
|
||||||
|
{
|
||||||
|
type: TOKEN_TYPE,
|
||||||
|
quantity: params.balance
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAccountObj (params: { address: string, balance?: number }): any {
|
||||||
|
const balanceObj: any = { type: TOKEN_TYPE };
|
||||||
|
if (params.balance) {
|
||||||
|
balanceObj.quantity = params.balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
address: params.address,
|
||||||
|
balance: [balanceObj]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRecordObj (recordFilePath: string, params: { bondId: string, recordId: string, names: any }): any {
|
||||||
|
const recordContent = yaml.load(fs.readFileSync(recordFilePath, 'utf8')) as any;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: params.recordId,
|
||||||
|
names: params.names,
|
||||||
|
bondId: params.bondId,
|
||||||
|
attributes: recordContent.record
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAuthorityObj (params: { owner: string, status: string, auction: any, bondId?: string }): any {
|
||||||
|
return {
|
||||||
|
ownerAddress: params.owner,
|
||||||
|
status: params.status,
|
||||||
|
bondId: params.bondId || '',
|
||||||
|
auction: params.auction
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAuctionObj (params: { owner: string, status?: string }): any {
|
||||||
|
return {
|
||||||
|
status: params.status || 'commit',
|
||||||
|
ownerAddress: params.owner,
|
||||||
|
commitFee: {
|
||||||
|
type: TOKEN_TYPE,
|
||||||
|
quantity: AUCTION_FEES.commit
|
||||||
|
},
|
||||||
|
revealFee: {
|
||||||
|
type: TOKEN_TYPE,
|
||||||
|
quantity: AUCTION_FEES.reveal
|
||||||
|
},
|
||||||
|
minimumBid: {
|
||||||
|
type: TOKEN_TYPE,
|
||||||
|
quantity: AUCTION_FEES.minimumBid
|
||||||
|
},
|
||||||
|
winnerAddresses: [],
|
||||||
|
winnerBids: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBidObj (params: { bidder: string, status?: string }): any {
|
||||||
|
return {
|
||||||
|
bidderAddress: params.bidder,
|
||||||
|
status: params.status || 'commit',
|
||||||
|
commitFee: {
|
||||||
|
type: TOKEN_TYPE,
|
||||||
|
quantity: AUCTION_FEES.commit
|
||||||
|
},
|
||||||
|
revealFee: {
|
||||||
|
type: TOKEN_TYPE,
|
||||||
|
quantity: AUCTION_FEES.reveal
|
||||||
|
},
|
||||||
|
bidAmount: {
|
||||||
|
type: '',
|
||||||
|
quantity: 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function delay (ms: number): Promise<any> {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFeesConfig (): number {
|
||||||
|
const { services: { registry: registryConfig } } = getConfig(CONFIG_FILE);
|
||||||
|
const fee = getGasAndFees({} as Arguments, registryConfig);
|
||||||
|
return Number((fee as StdFee).amount[0].amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateGasAndFeesConfig (gas?: string | null, fees?: string | null, gasPrice?: string | null): void {
|
||||||
|
const config = getConfig(path.resolve(CONFIG_FILE));
|
||||||
|
|
||||||
|
if (gas) {
|
||||||
|
config.services.registry.gas = gas;
|
||||||
|
} else if (gas === null) {
|
||||||
|
delete config.services.registry.gas;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fees) {
|
||||||
|
config.services.registry.fees = fees;
|
||||||
|
} else if (fees === null) {
|
||||||
|
delete config.services.registry.fees;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gasPrice) {
|
||||||
|
config.services.registry.gasPrice = gasPrice;
|
||||||
|
} else if (gasPrice === null) {
|
||||||
|
delete config.services.registry.gasPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(CONFIG_FILE, yaml.dump(config), 'utf8');
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error writing config file:', e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
37
test/run-tests.sh
Executable file
37
test/run-tests.sh
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
# Wait for the laconid endpoint to come up
|
||||||
|
docker compose exec laconicd sh -c "curl --retry 10 --retry-delay 3 --retry-connrefused http://127.0.0.1:9473/api"
|
||||||
|
|
||||||
|
# Get the key from laconicd
|
||||||
|
laconicd_key=$(yes | docker compose exec laconicd laconicd keys export alice --keyring-backend test --unarmored-hex --unsafe)
|
||||||
|
|
||||||
|
# Get the fixturenet account address
|
||||||
|
laconicd_account_address=$(docker compose exec laconicd laconicd keys list --keyring-backend test | awk '/- address:/ {print $3}')
|
||||||
|
|
||||||
|
# Set parameters for the test suite
|
||||||
|
cosmos_chain_id=laconic_9000-1
|
||||||
|
laconicd_rpc_endpoint=http://127.0.0.1:26657
|
||||||
|
laconicd_gql_endpoint=http://127.0.0.1:9473/api
|
||||||
|
|
||||||
|
# Create the required config
|
||||||
|
config_file="config.yml"
|
||||||
|
config=$(cat <<EOL
|
||||||
|
services:
|
||||||
|
registry:
|
||||||
|
rpcEndpoint: $laconicd_rpc_endpoint
|
||||||
|
gqlEndpoint: $laconicd_gql_endpoint
|
||||||
|
userKey: $laconicd_key
|
||||||
|
bondId:
|
||||||
|
chainId: $cosmos_chain_id
|
||||||
|
gas: 200000
|
||||||
|
fees: 200000alnt
|
||||||
|
EOL
|
||||||
|
)
|
||||||
|
echo "$config" > "$config_file"
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
TEST_ACCOUNT=$laconicd_account_address yarn test
|
@ -30,7 +30,10 @@
|
|||||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||||
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
|
"typeRoots": [
|
||||||
|
"node_modules/@types",
|
||||||
|
"src/types"
|
||||||
|
],
|
||||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
// "resolveJsonModule": true, /* Enable importing .json files */
|
// "resolveJsonModule": true, /* Enable importing .json files */
|
||||||
@ -97,5 +100,7 @@
|
|||||||
/* Completeness */
|
/* Completeness */
|
||||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||||
}
|
},
|
||||||
|
"include": ["src"],
|
||||||
|
"exclude": ["test"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user