Compare commits

..

3 Commits

Author SHA1 Message Date
5562d9f985 combine proto scripts 2023-09-25 19:43:44 +08:00
a6d7d230d9 remove hard-coded record types 2023-09-21 19:42:24 +08:00
c0ac805601 add missing proto files 2023-09-13 23:48:48 +08:00
40 changed files with 554 additions and 845 deletions

View File

@ -1,2 +0,0 @@
Dockerfile
node_modules

View File

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

View File

@ -25,39 +25,57 @@ jobs:
ref: main ref: main
- name: Environment - name: Environment
run: ls -tlh && env run: ls -tlh && env
- name: Start dockerd - name: Start dockerd
run: | run: |
dockerd -H $DOCKER_HOST --userland-proxy=false & dockerd -H $DOCKER_HOST --userland-proxy=false &
sleep 5 sleep 5
- name: build containers scripts
- name: Build laconicd container
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
run: ./build-laconicd-container.sh run: ./build-laconicd-container.sh
- name: Build laconic-sdk container - name: build test-container
run: ./scripts/build-sdk-test-container.sh run: docker build -t cerc-io/laconic-sdk-tester:local-test -f laconicd/tests/sdk_tests/Dockerfile-sdk .
- name: start containers
- name: Start containers
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
run: docker compose up -d run: docker compose up -d
- name: Run tests - name: run basic tests
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
run: ./run-tests.sh run: |
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
- name: Start containers (auctions enabled) cosmos_chain_id=laconic_9000-1
laconicd_rest_endpoint=http://laconicd:1317
laconicd_gql_endpoint=http://laconicd:9473/api
sleep 30s
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test"
- name: stop containers
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
env: run: docker compose down
TEST_AUCTION_ENABLED: true - name: start auction containers
run: docker compose up -d
- name: Run auction tests
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
run: ./run-tests.sh test:auctions run: docker compose -f docker-compose-auctions.yml up -d
- name: run auction tests
- name: Start containers (expiry enabled)
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
env: run: |
TEST_REGISTRY_EXPIRY: true laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
run: docker compose up -d cosmos_chain_id=laconic_9000-1
- name: Run nameservice expiry tests laconicd_rest_endpoint=http://laconicd:1317
laconicd_gql_endpoint=http://laconicd:9473/api
sleep 30s
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:auctions"
- name: start containers
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
run: ./run-tests.sh test:nameservice-expiry run: docker compose down
- name: start containers
working-directory: laconicd/tests/sdk_tests
run: docker compose -f docker-compose-nameservice.yml up -d
- name: run nameservice expiry tests
working-directory: laconicd/tests/sdk_tests
run: |
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
cosmos_chain_id=laconic_9000-1
laconicd_rest_endpoint=http://laconicd:1317
laconicd_gql_endpoint=http://laconicd:9473/api
sleep 30s
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:nameservice-expiry"
- name: stop nameservice containers
working-directory: laconicd/tests/sdk_tests
run: docker compose down

View File

@ -20,34 +20,53 @@ jobs:
ref: main ref: main
- name: Environment - name: Environment
run: ls -tlh && env run: ls -tlh && env
- name: build containers scripts
- name: Build laconicd container
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
run: ./build-laconicd-container.sh run: ./build-laconicd-container.sh
- name: Build laconic-sdk container - name: build test-container
run: ./scripts/build-sdk-test-container.sh run: docker build -t cerc-io/laconic-sdk-tester:local-test -f laconicd/tests/sdk_tests/Dockerfile-sdk .
- name: start containers
- name: Start containers
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
run: docker compose up -d run: docker compose up -d
- name: Run tests - name: run basic tests
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
run: ./run-tests.sh run: |
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
- name: Start containers (auctions enabled) cosmos_chain_id=laconic_9000-1
laconicd_rest_endpoint=http://laconicd:1317
laconicd_gql_endpoint=http://laconicd:9473/api
sleep 30s
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test"
- name: stop containers
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
env: run: docker compose down
TEST_AUCTION_ENABLED: true - name: start auction containers
run: docker compose up -d
- name: Run auction tests
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
run: ./run-tests.sh test:auctions run: docker compose -f docker-compose-auctions.yml up -d
- name: run auction tests
- name: Start containers (expiry enabled)
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
env: run: |
TEST_REGISTRY_EXPIRY: true laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
run: docker compose up -d cosmos_chain_id=laconic_9000-1
- name: Run nameservice expiry tests laconicd_rest_endpoint=http://laconicd:1317
laconicd_gql_endpoint=http://laconicd:9473/api
sleep 30s
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:auctions"
- name: start containers
working-directory: laconicd/tests/sdk_tests working-directory: laconicd/tests/sdk_tests
run: ./run-tests.sh test:nameservice-expiry run: docker compose down
- name: start containers
working-directory: laconicd/tests/sdk_tests
run: docker compose -f docker-compose-nameservice.yml up -d
- name: run nameservice expiry tests
working-directory: laconicd/tests/sdk_tests
run: |
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
cosmos_chain_id=laconic_9000-1
laconicd_rest_endpoint=http://laconicd:1317
laconicd_gql_endpoint=http://laconicd:9473/api
sleep 30s
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:nameservice-expiry"
- name: stop nameservice containers
working-directory: laconicd/tests/sdk_tests
run: docker compose down

View File

@ -12,5 +12,13 @@ Run following scripts when [proto files](./proto/) are updated.
2. Generate typescript code for the proto files 2. Generate typescript code for the proto files
```bash ```bash
./scripts/proto-gen.sh ./scripts/create-proto-files.sh
``` ```
3. Remove GRPC code from generated code
```bash
./scripts/remove-grpc.sh
```
Reference: https://github.com/tharsis/evmosjs/tree/main/packages/proto#note

View File

@ -21,18 +21,34 @@ RUN \
&& npm config -g set prefix ${NPM_GLOBAL} \ && npm config -g set prefix ${NPM_GLOBAL} \
&& su ${USERNAME} -c "npm config -g set prefix ${NPM_GLOBAL}" \ && su ${USERNAME} -c "npm config -g set prefix ${NPM_GLOBAL}" \
# Install eslint # Install eslint
&& su ${USERNAME} -c "umask 0002 && npm install -g eslint" \ && su ${USERNAME} -c "umask 0002 && npm install -g eslint lerna jest" \
&& npm cache clean --force > /dev/null 2>&1 && npm cache clean --force > /dev/null 2>&1
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>"
WORKDIR / WORKDIR /
RUN mkdir node_modules && mkdir proto && mkdir scripts && mkdir src
COPY node_modules ./node_modules/
COPY proto . ./proto/
COPY scripts ./scripts/
COPY src ./src/
COPY entrypoint.sh . COPY entrypoint.sh .
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
# Placeholder CMD : generally this will be overridden at run time like :
# docker run -it -v /home/builder/cerc/laconic-sdk:/workspace cerc/builder-js sh -c 'cd /workspace && yarn && yarn build'
CMD node --version CMD node --version
WORKDIR /app/laconic-sdk # Temp hack, clone the laconic-sdk repo here
WORKDIR /app
COPY package*.json .
RUN yarn install RUN yarn install
COPY . .
WORKDIR /app/laconic-sdk WORKDIR /app/laconic-sdk

View File

@ -34,12 +34,6 @@ Follow these steps to run the tests:
- Run the tests with auctions enabled - Run the tests with auctions enabled
- Remove laconicd data from previous run
```bash
rm -rf ~/.laconicd
```
- In laconicd repo run: - In laconicd repo run:
```bash ```bash
@ -60,12 +54,6 @@ Follow these steps to run the tests:
- Run the tests for record and authority expiry - Run the tests for record and authority expiry
- Remove laconicd data from previous run
```bash
rm -rf ~/.laconicd
```
- In laconicd repo run: - In laconicd repo run:
```bash ```bash

View File

@ -1,6 +1,6 @@
{ {
"name": "@cerc-io/laconic-sdk", "name": "@cerc-io/laconic-sdk",
"version": "0.1.16", "version": "0.1.6",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"repository": "git@github.com:cerc-io/laconic-sdk.git", "repository": "git@github.com:cerc-io/laconic-sdk.git",
@ -14,7 +14,7 @@
"dotenv": "^16.0.0", "dotenv": "^16.0.0",
"google-protobuf": "^3.21.0", "google-protobuf": "^3.21.0",
"jest": "29.0.0", "jest": "29.0.0",
"protoc-gen-ts": "^0.8.7", "protoc-gen-ts": "^0.8.5",
"ts-jest": "^29.0.2", "ts-jest": "^29.0.2",
"typescript": "^4.6.2" "typescript": "^4.6.2"
}, },
@ -48,7 +48,7 @@
"tiny-secp256k1": "^1.1.6" "tiny-secp256k1": "^1.1.6"
}, },
"scripts": { "scripts": {
"test": "jest --runInBand --verbose --testPathPattern=src", "test": "jest --runInBand --verbose",
"test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts", "test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts",
"test:nameservice-expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts", "test:nameservice-expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts",
"build": "tsc" "build": "tsc"

View File

@ -67,25 +67,17 @@ message QueryParamsResponse {
// QueryListRecordsRequest is request type for registry records list // QueryListRecordsRequest is request type for registry records list
message QueryListRecordsRequest { message QueryListRecordsRequest {
message LinkInput { message ReferenceInput {
string id = 1; string id = 1;
} }
message ArrayInput {
repeated ValueInput values = 1;
}
message MapInput {
map<string, ValueInput> values = 1;
}
message ValueInput { message ValueInput {
oneof value { string type = 1;
string string = 1; string string = 2;
int64 int = 2; int64 int = 3;
double float = 3; double float = 4;
bool boolean = 4; bool boolean = 5;
string link = 5; ReferenceInput reference = 6;
ArrayInput array = 6; repeated ValueInput values = 7;
MapInput map = 7;
}
} }
message KeyValueInput { message KeyValueInput {
string key = 1; string key = 1;

View File

@ -1,2 +0,0 @@
#!/usr/bin/env bash
docker build -t cerc/laconic-sdk-tester:local -f Dockerfile .

View File

@ -23,7 +23,6 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
fi fi
echo "Removing gRPC references..." echo "Removing gRPC references..."
# https://github.com/tharsis/evmosjs/tree/main/packages/proto#note
for file in $(find $REPO_ROOT/src/proto -type f) for file in $(find $REPO_ROOT/src/proto -type f)
do do

View File

@ -12,10 +12,20 @@ jest.setTimeout(90 * 1000);
const bondTests = () => { const bondTests = () => {
let registry: Registry; let registry: Registry;
let watcher: any;
let version1: string;
let version2: string;
let bondId1: string;
let bondId2: string;
let bondOwner: string;
const publishNewWatcherVersion = async (bondId: string) => { const publishNewWatcherVersion = async (bondId: string) => {
let watcher = await ensureUpdatedConfig(WATCHER_YML_PATH); watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, fee); await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, fee);
return watcher; return watcher.record.version;
}; };
beforeAll(async () => { beforeAll(async () => {
@ -23,119 +33,93 @@ const bondTests = () => {
}); });
test('Create bond.', async () => { test('Create bond.', async () => {
let bondId = await registry.getNextBondId(privateKey); bondId1 = await registry.getNextBondId(privateKey);
expect(bondId).toBeDefined(); expect(bondId1).toBeDefined();
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee); await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
})
test('Get bond by ID.', async () => {
const [bond] = await registry.getBondsByIds([bondId1]);
expect(bond).toBeDefined();
expect(bond.id).toBe(bondId1);
expect(bond.balance).toHaveLength(1);
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
bondOwner = bond.owner;
}); });
describe('With bond created', () => { test('Query bonds.', async () => {
let bond1: any const bonds = await registry.queryBonds();
expect(bonds).toBeDefined();
const bond = bonds.filter((bond: any) => bond.id === bondId1);
expect(bond).toBeDefined();
});
beforeAll(async () => { test('Query bonds by owner.', async () => {
let bondId1 = await registry.getNextBondId(privateKey); const bonds = await registry.queryBonds({ owner: bondOwner });
expect(bondId1).toBeDefined(); expect(bonds).toBeDefined();
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee); const bond = bonds.filter((bond: any) => bond.id === bondId1);
expect(bond).toBeDefined();
});
[bond1] = await registry.getBondsByIds([bondId1]); test('Refill bond.', async () => {
expect(bond1).toBeDefined(); await registry.refillBond({ id: bondId1, denom: 'aphoton', amount: '500' }, privateKey, fee);
expect(bond1.id).toEqual(bondId1);
});
test('Get bond by ID.', async () => { const [bond] = await registry.getBondsByIds([bondId1]);
const [bond] = await registry.getBondsByIds([bond1.id]); expect(bond).toBeDefined();
expect(bond).toBeDefined(); expect(bond.id).toBe(bondId1);
expect(bond.id).toBe(bond1.id); expect(bond.balance).toHaveLength(1);
expect(bond.balance).toHaveLength(1); expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000500' });
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' }); });
});
test('Query bonds.', async () => { test('Withdraw bond.', async () => {
const bonds = await registry.queryBonds(); await registry.withdrawBond({ id: bondId1, denom: 'aphoton', amount: '500' }, privateKey, fee);
expect(bonds).toBeDefined();
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
expect(bond).toBeDefined();
});
test('Query bonds by owner.', async () => { const [bond] = await registry.getBondsByIds([bondId1]);
const bonds = await registry.queryBonds({ owner: bond1.owner }); expect(bond).toBeDefined();
expect(bonds).toBeDefined(); expect(bond.id).toBe(bondId1);
const bond = bonds.filter((bond: any) => bond.id === bond1.id); expect(bond.balance).toHaveLength(1);
expect(bond).toBeDefined(); expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
}); });
test('Refill bond.', async () => { test('Cancel bond.', async () => {
await registry.refillBond({ id: bond1.id, denom: 'aphoton', amount: '500' }, privateKey, fee); await registry.cancelBond({ id: bondId1 }, privateKey, fee);
const [bond] = await registry.getBondsByIds([bond1.id]);
expect(bond).toBeDefined();
expect(bond.id).toBe(bond1.id);
expect(bond.balance).toHaveLength(1);
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000500' });
});
test('Withdraw bond.', async () => {
await registry.withdrawBond({ id: bond1.id, denom: 'aphoton', amount: '500' }, privateKey, fee);
const [bond] = await registry.getBondsByIds([bond1.id]);
expect(bond).toBeDefined();
expect(bond.id).toBe(bond1.id);
expect(bond.balance).toHaveLength(1);
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
});
test('Cancel bond.', async () => {
await registry.cancelBond({ id: bond1.id }, privateKey, fee);
const [bond] = await registry.getBondsByIds([bond1.id]);
expect(bond.id).toBe("");
expect(bond.owner).toBe("");
expect(bond.balance).toHaveLength(0);
});
const [bond] = await registry.getBondsByIds([bondId1]);
expect(bond.id).toBe("");
expect(bond.owner).toBe("");
expect(bond.balance).toHaveLength(0);
}); });
test('Associate/Dissociate bond.', async () => { test('Associate/Dissociate bond.', async () => {
let bondId1: string;
bondId1 = await registry.getNextBondId(privateKey); bondId1 = await registry.getNextBondId(privateKey);
expect(bondId1).toBeDefined(); expect(bondId1).toBeDefined();
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee); await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
// Create a new record. // Create a new record.
let watcher = await publishNewWatcherVersion(bondId1); version1 = await publishNewWatcherVersion(bondId1);
let query = { type: watcher.record.type, url: watcher.record.url, version: watcher.record.version }; let [record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
let [record1] = await registry.queryRecords(query, true);
expect(record1.bondId).toBe(bondId1); expect(record1.bondId).toBe(bondId1);
// Dissociate record, query and confirm. // Dissociate record, query and confirm.
await registry.dissociateBond({ recordId: record1.id }, privateKey, fee); await registry.dissociateBond({ recordId: record1.id }, privateKey, fee);
[record1] = await registry.queryRecords(query, true); [record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(record1.bondId).toBe(''); expect(record1.bondId).toBe('');
// Associate record with bond, query and confirm. // Associate record with bond, query and confirm.
await registry.associateBond({ recordId: record1.id, bondId: bondId1 }, privateKey, fee); await registry.associateBond({ recordId: record1.id, bondId: bondId1 }, privateKey, fee);
[record1] = await registry.queryRecords(query, true); [record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(record1.bondId).toBe(bondId1); expect(record1.bondId).toBe(bondId1);
}); });
test('Reassociate/Dissociate records.', async () => { test('Reassociate/Dissociate records.', async () => {
let bondId1: string;
let bondId2: string;
bondId1 = await registry.getNextBondId(privateKey);
expect(bondId1).toBeDefined();
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
// Create a new record version. // Create a new record version.
let watcher = await publishNewWatcherVersion(bondId1); version2 = await publishNewWatcherVersion(bondId1);
let queryv1 = { type: watcher.record.type, url: watcher.record.url, version: watcher.record.version };
let queryv2 = { type: watcher.record.type, url: watcher.record.url, version: watcher.record.version };
// Check version1, version2 as associated with bondId1. // Check version1, version2 as associated with bondId1.
let records; let records;
records = await registry.queryRecords(queryv1, true); records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(records[0].bondId).toBe(bondId1); expect(records[0].bondId).toBe(bondId1);
records = await registry.queryRecords(queryv2, true); records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
expect(records[0].bondId).toBe(bondId1); expect(records[0].bondId).toBe(bondId1);
// Create another bond. // Create another bond.
@ -147,16 +131,16 @@ const bondTests = () => {
// Reassociate records from bondId1 to bondId2, verify change. // Reassociate records from bondId1 to bondId2, verify change.
await registry.reassociateRecords({ oldBondId: bondId1, newBondId: bondId2 }, privateKey, fee); await registry.reassociateRecords({ oldBondId: bondId1, newBondId: bondId2 }, privateKey, fee);
records = await registry.queryRecords(queryv1, true); records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(records[0].bondId).toBe(bondId2); expect(records[0].bondId).toBe(bondId2);
records = await registry.queryRecords(queryv2, true); records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
expect(records[0].bondId).toBe(bondId2); expect(records[0].bondId).toBe(bondId2);
// Dissociate all records from bond, verify change. // Dissociate all records from bond, verify change.
await registry.dissociateRecords({ bondId: bondId2 }, privateKey, fee); await registry.dissociateRecords({ bondId: bondId2 }, privateKey, fee);
records = await registry.queryRecords(queryv1, true); records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(records[0].bondId).toBe(''); expect(records[0].bondId).toBe('');
records = await registry.queryRecords(queryv2, true); records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
expect(records[0].bondId).toBe(''); expect(records[0].bondId).toBe('');
}); });
}; };

View File

@ -54,7 +54,7 @@ import {
export const DEFAULT_CHAIN_ID = 'laconic_9000-1'; export const DEFAULT_CHAIN_ID = 'laconic_9000-1';
const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd'; const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd.';
// Parse Tx response from cosmos-sdk. // Parse Tx response from cosmos-sdk.
export const parseTxResponse = (result: any, parseResponse?: (data: string) => any) => { export const parseTxResponse = (result: any, parseResponse?: (data: string) => any) => {
@ -117,8 +117,7 @@ export class Registry {
console.error(error) console.error(error)
} }
const [lastErrorLine] = error.split("\n").slice(-1); return errorMessage || DEFAULT_WRITE_ERROR;
return `${errorMessage || DEFAULT_WRITE_ERROR}: ${lastErrorLine}`;
} }
constructor(gqlUrl: string, restUrl: string = "", chainId: string = DEFAULT_CHAIN_ID) { constructor(gqlUrl: string, restUrl: string = "", chainId: string = DEFAULT_CHAIN_ID) {
@ -181,9 +180,9 @@ export class Registry {
} }
/** /**
* Publish record. * Publish record.
* @param transactionPrivateKey - private key in HEX to sign transaction. * @param transactionPrivateKey - private key in HEX to sign transaction.
*/ */
async setRecord( async setRecord(
params: { privateKey: string, record: any, bondId: string }, params: { privateKey: string, record: any, bondId: string },
transactionPrivateKey: string, transactionPrivateKey: string,

View File

@ -81,10 +81,10 @@ export const parseMsgSetRecordResponse = (data: string) => {
} }
export const NAMESERVICE_ERRORS = [ export const NAMESERVICE_ERRORS = [
'Name already reserved', 'Name already reserved.',
'Authority bond not found', 'Authority bond not found.',
'Name authority not found', 'Name authority not found.',
'Access denied', 'Access denied.',
] ]
export interface MessageMsgReserveAuthority { export interface MessageMsgReserveAuthority {

View File

@ -7,7 +7,7 @@ import { ensureUpdatedConfig, getConfig } from './testing/helper';
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml'); const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
jest.setTimeout(5 * 60 * 1000); jest.setTimeout(120 * 1000);
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig(); const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
@ -18,6 +18,12 @@ const namingTests = () => {
let watcher: any; let watcher: any;
let watcherId: string; let watcherId: string;
let authorityName: string;
let otherAuthorityName: string;
let otherPrivateKey: string;
let crn: string;
beforeAll(async () => { beforeAll(async () => {
registry = new Registry(gqlEndpoint, restEndpoint, chainId); registry = new Registry(gqlEndpoint, restEndpoint, chainId);
@ -40,272 +46,221 @@ const namingTests = () => {
watcherId = result.data.id; watcherId = result.data.id;
}); });
describe('Authority tests', () => { test('Reserve authority.', async () => {
test('Reserve authority.', async () => { authorityName = `laconic-${Date.now()}`;
const authorityName = `laconic-${Date.now()}`; await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
});
describe('With authority reserved', () => {
let authorityName: string;
let crn: string;
beforeAll(async () => {
authorityName = `laconic-${Date.now()}`;
crn = `crn://${authorityName}/app/test`;
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
})
test('Lookup authority.', async () => {
const [record] = await registry.lookupAuthorities([authorityName]);
expect(record).toBeDefined();
expect(record.ownerAddress).not.toBe('');
expect(record.ownerPublicKey).not.toBe('');
expect(Number(record.height)).toBeGreaterThan(0);
});
test('Lookup non existing authority', async () => {
const [record] = await registry.lookupAuthorities(['does-not-exist']);
expect(record.ownerAddress).toBe('');
expect(record.ownerPublicKey).toBe('');
expect(Number(record.height)).toBe(0);
});
test('Reserve already reserved authority', async () => {
await expect(registry.reserveAuthority({ name: authorityName }, privateKey, fee)).
rejects.toThrow('Name already reserved.');
});
test('Reserve sub-authority.', async () => {
const subAuthority = `echo.${authorityName}`;
await registry.reserveAuthority({ name: subAuthority }, privateKey, fee);
const [record] = await registry.lookupAuthorities([subAuthority]);
expect(record).toBeDefined();
expect(record.ownerAddress).not.toBe('');
expect(record.ownerPublicKey).not.toBe('');
expect(Number(record.height)).toBeGreaterThan(0);
});
test('Reserve sub-authority with different owner.', async () => {
// Create another account, send tx to set public key on the account.
const mnenonic1 = Account.generateMnemonic();
const otherAccount1 = await Account.generateFromMnemonic(mnenonic1);
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount1.formattedCosmosAddress }, privateKey, fee);
const mnenonic2 = Account.generateMnemonic();
const otherAccount2 = await Account.generateFromMnemonic(mnenonic2);
await registry.sendCoins({ denom: 'aphoton', amount: '10', destinationAddress: otherAccount2.formattedCosmosAddress }, otherAccount1.getPrivateKey(), fee);
const subAuthority = `halo.${authorityName}`;
await registry.reserveAuthority({ name: subAuthority, owner: otherAccount1.formattedCosmosAddress }, privateKey, fee);
const [record] = await registry.lookupAuthorities([subAuthority]);
expect(record).toBeDefined();
expect(record.ownerAddress).toBeDefined();
expect(record.ownerAddress).toBe(otherAccount1.getCosmosAddress());
expect(record.ownerPublicKey).toBeDefined();
expect(Number(record.height)).toBeGreaterThan(0);
});
test('Set name for unbonded authority', async () => {
assert(watcherId)
await expect(registry.setName({ crn, cid: watcherId }, privateKey, fee)).
rejects.toThrow('Authority bond not found.');
});
test('Set authority bond', async () => {
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
});
});
}); });
describe('Naming tests', () => { test('Lookup authority.', async () => {
let authorityName: string; const [record] = await registry.lookupAuthorities([authorityName]);
let otherAuthorityName: string;
let otherPrivateKey: string;
let otherAccount: Account;
beforeAll(async () => { expect(record).toBeDefined();
authorityName = `laconic-${Date.now()}`; expect(record.ownerAddress).not.toBe('');
expect(record.ownerPublicKey).not.toBe('');
expect(Number(record.height)).toBeGreaterThan(0);
});
await registry.reserveAuthority({ name: authorityName }, privateKey, fee); test('Lookup non existing authority', async () => {
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee); const [record] = await registry.lookupAuthorities(['does-not-exist']);
// Create another account. expect(record.ownerAddress).toBe('');
const mnenonic = Account.generateMnemonic(); expect(record.ownerPublicKey).toBe('');
otherAccount = await Account.generateFromMnemonic(mnenonic); expect(Number(record.height)).toBe(0);
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee); });
otherAuthorityName = `other-${Date.now()}`; test('Reserve already reserved authority', async () => {
otherPrivateKey = otherAccount.privateKey.toString('hex'); await expect(registry.reserveAuthority({ name: authorityName }, privateKey, fee)).rejects.toThrow('Name already reserved.');
}); });
test('Set name', async () => { test('Reserve sub-authority.', async () => {
const crn = `crn://${authorityName}/app/test1`; const subAuthority = `echo.${authorityName}`;
await registry.reserveAuthority({ name: subAuthority }, privateKey, fee);
await registry.setName({ crn, cid: watcherId }, privateKey, fee); const [record] = await registry.lookupAuthorities([subAuthority]);
expect(record).toBeDefined();
expect(record.ownerAddress).not.toBe('');
expect(record.ownerPublicKey).not.toBe('');
expect(Number(record.height)).toBeGreaterThan(0);
});
// Query records should return it (some CRN points to it). test('Reserve sub-authority with different owner.', async () => {
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }); // Create another account, send tx to set public key on the account.
expect(record).toBeDefined(); const mnenonic1 = Account.generateMnemonic();
expect(record.names).toHaveLength(1); const otherAccount1 = await Account.generateFromMnemonic(mnenonic1);
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount1.formattedCosmosAddress }, privateKey, fee);
await registry.deleteName({ crn }, privateKey, fee); const mnenonic2 = Account.generateMnemonic();
}); const otherAccount2 = await Account.generateFromMnemonic(mnenonic2);
await registry.sendCoins({ denom: 'aphoton', amount: '10', destinationAddress: otherAccount2.formattedCosmosAddress }, otherAccount1.getPrivateKey(), fee);
describe('With name set', () => { const subAuthority = `halo.${authorityName}`;
let crn: string; await registry.reserveAuthority({ name: subAuthority, owner: otherAccount1.formattedCosmosAddress }, privateKey, fee);
beforeAll(async () => { const [record] = await registry.lookupAuthorities([subAuthority]);
crn = `crn://${authorityName}/app/test2`; expect(record).toBeDefined();
await registry.setName({ crn, cid: watcherId }, privateKey, fee); expect(record.ownerAddress).toBeDefined();
}); expect(record.ownerAddress).toBe(otherAccount1.getCosmosAddress());
expect(record.ownerPublicKey).toBeDefined();
expect(Number(record.height)).toBeGreaterThan(0);
});
afterAll(async () => { test('Set name for unbonded authority', async () => {
await registry.deleteName({ crn }, privateKey, fee); crn = `crn://${authorityName}/app/test`;
}); assert(watcherId)
await expect(registry.setName({ crn, cid: watcherId }, privateKey, fee)).rejects.toThrow('Authority bond not found.');
});
test('Lookup name', async () => { test('Set authority bond', async () => {
const records = await registry.lookupNames([crn]); await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
expect(records).toBeDefined(); });
expect(records).toHaveLength(1);
const [{ latest, history }] = records; test('Set name', async () => {
expect(latest).toBeDefined(); crn = `crn://${authorityName}/app/test`;
expect(latest.id).toBeDefined(); await registry.setName({ crn, cid: watcherId }, privateKey, fee);
expect(latest.id).toBe(watcherId);
expect(latest.height).toBeDefined();
expect(history).toBeUndefined();
});
test('Resolve name', async () => { // Query records should return it (some CRN points to it).
const records = await registry.resolveNames([crn]); const records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
expect(records).toBeDefined(); expect(records).toBeDefined();
expect(records).toHaveLength(1); expect(records).toHaveLength(1);
});
const [{ attributes }] = records; test('Lookup name', async () => {
expect(attributes).toEqual(watcher.record); const records = await registry.lookupNames([crn]);
}); expect(records).toBeDefined();
expect(records).toHaveLength(1);
test('Lookup name with history', async () => { const [{ latest, history }] = records;
const updatedWatcher = await ensureUpdatedConfig(WATCHER_YML_PATH); expect(latest).toBeDefined();
const result = await registry.setRecord( expect(latest.id).toBeDefined();
{ expect(latest.id).toBe(watcherId);
privateKey, expect(latest.height).toBeDefined();
bondId, expect(history).toBeUndefined();
record: updatedWatcher.record });
},
privateKey,
fee
)
const updatedWatcherId = result.data.id; test('Resolve name', async () => {
await registry.setName({ crn, cid: updatedWatcherId }, privateKey, fee); const records = await registry.resolveNames([crn]);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
const records = await registry.lookupNames([crn], true); const [{ attributes }] = records;
expect(records).toHaveLength(1); expect(attributes).toEqual(watcher.record);
});
const [{ latest, history }] = records; test('Lookup name with history', async () => {
expect(latest).toBeDefined(); const updatedWatcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
expect(latest.id).toBeDefined(); const result = await registry.setRecord(
expect(latest.id).toBe(updatedWatcherId); {
expect(latest.height).toBeDefined(); privateKey,
expect(history).toBeDefined(); bondId,
expect(history).toHaveLength(1); record: updatedWatcher.record
},
privateKey,
fee
)
const [oldRecord] = history; const updatedWatcherId = result.data.id;
expect(oldRecord).toBeDefined(); await registry.setName({ crn, cid: updatedWatcherId }, privateKey, fee);
expect(oldRecord.id).toBeDefined();
expect(oldRecord.id).toBe(watcherId);
expect(oldRecord.height).toBeDefined();
});
test('Delete name', async () => { const records = await registry.lookupNames([crn], true);
await registry.deleteName({ crn }, privateKey, fee); expect(records).toHaveLength(1);
let records = await registry.lookupNames([crn], true); const [{ latest, history }] = records;
expect(records).toBeDefined(); expect(latest).toBeDefined();
expect(records).toHaveLength(1); expect(latest.id).toBeDefined();
expect(latest.id).toBe(updatedWatcherId);
expect(latest.height).toBeDefined();
expect(history).toBeDefined();
expect(history).toHaveLength(1);
const [{ latest }] = records; const [oldRecord] = history;
expect(latest).toBeDefined(); expect(oldRecord).toBeDefined();
expect(latest.id).toBeDefined(); expect(oldRecord.id).toBeDefined();
expect(latest.id).toBe(''); expect(oldRecord.id).toBe(watcherId);
expect(latest.height).toBeDefined(); expect(oldRecord.height).toBeDefined();
});
// Query records should NOT return it (no CRN points to it). test('Set name without reserving authority', async () => {
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }); await expect(registry.setName({ crn: 'crn://not-reserved/app/test', cid: watcherId }, privateKey, fee))
expect(records).toBeDefined(); .rejects.toThrow('Name authority not found.');
expect(records).toHaveLength(0); });
// Query all records should return it (all: true). test('Set name for non-owned authority', async () => {
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true); // Create another account.
expect(records).toBeDefined(); const mnenonic = Account.generateMnemonic();
expect(records).toHaveLength(1); const otherAccount = await Account.generateFromMnemonic(mnenonic);
}); await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
test('Delete already deleted name', async () => { // Other account reserves an authority.
await registry.deleteName({ crn }, privateKey, fee); otherAuthorityName = `other-${Date.now()}`;
await registry.deleteName({ crn }, privateKey, fee); otherPrivateKey = otherAccount.privateKey.toString('hex');
await registry.reserveAuthority({ name: otherAuthorityName }, otherPrivateKey, fee);
const records = await registry.lookupNames([crn], true); // Try setting name under other authority.
expect(records).toBeDefined(); await expect(registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, privateKey, fee)).rejects.toThrow('Access denied.');
expect(records).toHaveLength(1); });
const [{ latest }] = records; test('Lookup non existing name', async () => {
expect(latest).toBeDefined(); const records = await registry.lookupNames(['crn://not-reserved/app/test']);
expect(latest.id).toBeDefined(); expect(records).toBeDefined();
expect(latest.id).toBe(''); expect(records).toHaveLength(1);
expect(latest.height).toBeDefined(); const [record] = records;
}); expect(record).toBeNull();
}); });
test('Set name without reserving authority', async () => { test('Resolve non existing name', async () => {
await expect(registry.setName({ crn: 'crn://not-reserved/app/test', cid: watcherId }, privateKey, fee)) const records = await registry.resolveNames(['crn://not-reserved/app/test']);
.rejects.toThrow('Name authority not found.'); expect(records).toBeDefined();
}); expect(records).toHaveLength(1);
const [record] = records;
expect(record).toBeNull();
});
test('Set name for non-owned authority', async () => { test('Delete name', async () => {
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee); await registry.deleteName({ crn }, privateKey, fee);
// Other account reserves an authority. let records = await registry.lookupNames([crn], true);
await registry.reserveAuthority({ name: otherAuthorityName }, otherPrivateKey, fee); expect(records).toBeDefined();
expect(records).toHaveLength(1);
// Try setting name under other authority. const [{ latest }] = records;
await expect(registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, privateKey, fee)).rejects.toThrow('Access denied.'); expect(latest).toBeDefined();
}); expect(latest.id).toBeDefined();
expect(latest.id).toBe('');
expect(latest.height).toBeDefined();
test('Delete name for non-owned authority.', async () => { // Query records should NOT return it (no CRN points to it).
const otherBondId = await registry.getNextBondId(otherPrivateKey); records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
await registry.createBond({ denom: 'aphoton', amount: '10000' }, otherPrivateKey, fee); expect(records).toBeDefined();
await registry.setAuthorityBond({ name: otherAuthorityName, bondId: otherBondId }, otherPrivateKey, fee); expect(records).toHaveLength(0);
await registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, otherPrivateKey, fee);
// Try deleting name under other authority. // Query all records should return it (all: true).
await expect(registry.deleteName({ crn: `crn://${otherAuthorityName}/app/test` }, privateKey, fee)).rejects.toThrow('Access denied.'); records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
}); expect(records).toBeDefined();
expect(records).toHaveLength(1);
});
test('Lookup non existing name', async () => { test('Delete already deleted name', async () => {
const records = await registry.lookupNames(['crn://not-reserved/app/test']); await registry.deleteName({ crn }, privateKey, fee);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
const [record] = records;
expect(record).toBeNull();
});
test('Resolve non existing name', async () => { const records = await registry.lookupNames([crn], true);
const records = await registry.resolveNames(['crn://not-reserved/app/test']); expect(records).toBeDefined();
expect(records).toBeDefined(); expect(records).toHaveLength(1);
expect(records).toHaveLength(1);
const [record] = records; const [{ latest }] = records;
expect(record).toBeNull(); expect(latest).toBeDefined();
}); expect(latest.id).toBeDefined();
expect(latest.id).toBe('');
expect(latest.height).toBeDefined();
});
test('Delete name for non-owned authority.', async () => {
const otherBondId = await registry.getNextBondId(otherPrivateKey);
await registry.createBond({ denom: 'aphoton', amount: '10000' }, otherPrivateKey, fee);
await registry.setAuthorityBond({ name: otherAuthorityName, bondId: otherBondId }, otherPrivateKey, fee);
await registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, otherPrivateKey, fee);
// Try deleting name under other authority.
await expect(registry.deleteName({ crn: `crn://${otherAuthorityName}/app/test` }, privateKey, fee)).rejects.toThrow('Access denied.');
}); });
}; };

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: cosmos/base/query/v1beta1/pagination.proto * source: cosmos/base/query/v1beta1/pagination.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as pb_1 from "google-protobuf"; import * as pb_1 from "google-protobuf";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: cosmos/base/v1beta1/coin.proto * source: cosmos/base/v1beta1/coin.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: gogoproto/gogo.proto * source: gogoproto/gogo.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../google/protobuf/descriptor"; import * as dependency_1 from "./../google/protobuf/descriptor";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: google/api/annotations.proto * source: google/api/annotations.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./http"; import * as dependency_1 from "./http";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: google/api/http.proto * source: google/api/http.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as pb_1 from "google-protobuf"; import * as pb_1 from "google-protobuf";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: google/protobuf/descriptor.proto * source: google/protobuf/descriptor.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as pb_1 from "google-protobuf"; import * as pb_1 from "google-protobuf";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: google/protobuf/duration.proto * source: google/protobuf/duration.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as pb_1 from "google-protobuf"; import * as pb_1 from "google-protobuf";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: google/protobuf/timestamp.proto * source: google/protobuf/timestamp.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as pb_1 from "google-protobuf"; import * as pb_1 from "google-protobuf";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/auction/v1beta1/genesis.proto * source: vulcanize/auction/v1beta1/genesis.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/auction/v1beta1/query.proto * source: vulcanize/auction/v1beta1/query.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/auction/v1beta1/tx.proto * source: vulcanize/auction/v1beta1/tx.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/auction/v1beta1/types.proto * source: vulcanize/auction/v1beta1/types.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/bond/v1beta1/bond.proto * source: vulcanize/bond/v1beta1/bond.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/bond/v1beta1/genesis.proto * source: vulcanize/bond/v1beta1/genesis.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/bond/v1beta1/query.proto * source: vulcanize/bond/v1beta1/query.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/bond/v1beta1/tx.proto * source: vulcanize/bond/v1beta1/tx.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/registry/v1beta1/genesis.proto * source: vulcanize/registry/v1beta1/genesis.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/registry/v1beta1/query.proto * source: vulcanize/registry/v1beta1/query.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./registry"; import * as dependency_1 from "./registry";
@ -239,7 +239,7 @@ export namespace vulcanize.registry.v1beta1 {
} }
} }
export namespace QueryListRecordsRequest { export namespace QueryListRecordsRequest {
export class LinkInput extends pb_1.Message { export class ReferenceInput extends pb_1.Message {
#one_of_decls: number[][] = []; #one_of_decls: number[][] = [];
constructor(data?: any[] | { constructor(data?: any[] | {
id?: string; id?: string;
@ -260,8 +260,8 @@ export namespace vulcanize.registry.v1beta1 {
} }
static fromObject(data: { static fromObject(data: {
id?: string; id?: string;
}): LinkInput { }): ReferenceInput {
const message = new LinkInput({}); const message = new ReferenceInput({});
if (data.id != null) { if (data.id != null) {
message.id = data.id; message.id = data.id;
} }
@ -285,8 +285,8 @@ export namespace vulcanize.registry.v1beta1 {
if (!w) if (!w)
return writer.getResultBuffer(); return writer.getResultBuffer();
} }
static deserialize(bytes: Uint8Array | pb_1.BinaryReader): LinkInput { static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ReferenceInput {
const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new LinkInput(); const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ReferenceInput();
while (reader.nextField()) { while (reader.nextField()) {
if (reader.isEndGroup()) if (reader.isEndGroup())
break; break;
@ -302,220 +302,27 @@ export namespace vulcanize.registry.v1beta1 {
serializeBinary(): Uint8Array { serializeBinary(): Uint8Array {
return this.serialize(); return this.serialize();
} }
static deserializeBinary(bytes: Uint8Array): LinkInput { static deserializeBinary(bytes: Uint8Array): ReferenceInput {
return LinkInput.deserialize(bytes); return ReferenceInput.deserialize(bytes);
}
}
export class ArrayInput extends pb_1.Message {
#one_of_decls: number[][] = [];
constructor(data?: any[] | {
values?: QueryListRecordsRequest.ValueInput[];
}) {
super();
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls);
if (!Array.isArray(data) && typeof data == "object") {
if ("values" in data && data.values != undefined) {
this.values = data.values;
}
}
}
get values() {
return pb_1.Message.getRepeatedWrapperField(this, QueryListRecordsRequest.ValueInput, 1) as QueryListRecordsRequest.ValueInput[];
}
set values(value: QueryListRecordsRequest.ValueInput[]) {
pb_1.Message.setRepeatedWrapperField(this, 1, value);
}
static fromObject(data: {
values?: ReturnType<typeof QueryListRecordsRequest.ValueInput.prototype.toObject>[];
}): ArrayInput {
const message = new ArrayInput({});
if (data.values != null) {
message.values = data.values.map(item => QueryListRecordsRequest.ValueInput.fromObject(item));
}
return message;
}
toObject() {
const data: {
values?: ReturnType<typeof QueryListRecordsRequest.ValueInput.prototype.toObject>[];
} = {};
if (this.values != null) {
data.values = this.values.map((item: QueryListRecordsRequest.ValueInput) => item.toObject());
}
return data;
}
serialize(): Uint8Array;
serialize(w: pb_1.BinaryWriter): void;
serialize(w?: pb_1.BinaryWriter): Uint8Array | void {
const writer = w || new pb_1.BinaryWriter();
if (this.values.length)
writer.writeRepeatedMessage(1, this.values, (item: QueryListRecordsRequest.ValueInput) => item.serialize(writer));
if (!w)
return writer.getResultBuffer();
}
static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ArrayInput {
const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ArrayInput();
while (reader.nextField()) {
if (reader.isEndGroup())
break;
switch (reader.getFieldNumber()) {
case 1:
reader.readMessage(message.values, () => pb_1.Message.addToRepeatedWrapperField(message, 1, QueryListRecordsRequest.ValueInput.deserialize(reader), QueryListRecordsRequest.ValueInput));
break;
default: reader.skipField();
}
}
return message;
}
serializeBinary(): Uint8Array {
return this.serialize();
}
static deserializeBinary(bytes: Uint8Array): ArrayInput {
return ArrayInput.deserialize(bytes);
}
}
export class MapInput extends pb_1.Message {
#one_of_decls: number[][] = [];
constructor(data?: any[] | {
values?: Map<string, QueryListRecordsRequest.ValueInput>;
}) {
super();
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls);
if (!Array.isArray(data) && typeof data == "object") {
if ("values" in data && data.values != undefined) {
this.values = data.values;
}
}
if (!this.values)
this.values = new Map();
}
get values() {
return pb_1.Message.getField(this, 1) as any as Map<string, QueryListRecordsRequest.ValueInput>;
}
set values(value: Map<string, QueryListRecordsRequest.ValueInput>) {
pb_1.Message.setField(this, 1, value as any);
}
static fromObject(data: {
values?: {
[key: string]: ReturnType<typeof QueryListRecordsRequest.ValueInput.prototype.toObject>;
};
}): MapInput {
const message = new MapInput({});
if (typeof data.values == "object") {
message.values = new Map(Object.entries(data.values).map(([key, value]) => [key, QueryListRecordsRequest.ValueInput.fromObject(value)]));
}
return message;
}
toObject() {
const data: {
values?: {
[key: string]: ReturnType<typeof QueryListRecordsRequest.ValueInput.prototype.toObject>;
};
} = {};
if (this.values != null) {
data.values = (Object.fromEntries)((Array.from)(this.values).map(([key, value]) => [key, value.toObject()]));
}
return data;
}
serialize(): Uint8Array;
serialize(w: pb_1.BinaryWriter): void;
serialize(w?: pb_1.BinaryWriter): Uint8Array | void {
const writer = w || new pb_1.BinaryWriter();
for (const [key, value] of this.values) {
writer.writeMessage(1, this.values, () => {
writer.writeString(1, key);
writer.writeMessage(2, value, () => value.serialize(writer));
});
}
if (!w)
return writer.getResultBuffer();
}
static deserialize(bytes: Uint8Array | pb_1.BinaryReader): MapInput {
const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new MapInput();
while (reader.nextField()) {
if (reader.isEndGroup())
break;
switch (reader.getFieldNumber()) {
case 1:
reader.readMessage(message, () => pb_1.Map.deserializeBinary(message.values as any, reader, reader.readString, () => {
let value;
reader.readMessage(message, () => value = QueryListRecordsRequest.ValueInput.deserialize(reader));
return value;
}));
break;
default: reader.skipField();
}
}
return message;
}
serializeBinary(): Uint8Array {
return this.serialize();
}
static deserializeBinary(bytes: Uint8Array): MapInput {
return MapInput.deserialize(bytes);
} }
} }
export class ValueInput extends pb_1.Message { export class ValueInput extends pb_1.Message {
#one_of_decls: number[][] = [[1, 2, 3, 4, 5, 6, 7]]; #one_of_decls: number[][] = [];
constructor(data?: any[] | ({} & (({ constructor(data?: any[] | {
type?: string;
string?: string; string?: string;
int?: never;
float?: never;
boolean?: never;
link?: never;
array?: never;
map?: never;
} | {
string?: never;
int?: number; int?: number;
float?: never;
boolean?: never;
link?: never;
array?: never;
map?: never;
} | {
string?: never;
int?: never;
float?: number; float?: number;
boolean?: never;
link?: never;
array?: never;
map?: never;
} | {
string?: never;
int?: never;
float?: never;
boolean?: boolean; boolean?: boolean;
link?: never; reference?: QueryListRecordsRequest.ReferenceInput;
array?: never; values?: QueryListRecordsRequest.ValueInput[];
map?: never; }) {
} | {
string?: never;
int?: never;
float?: never;
boolean?: never;
link?: string;
array?: never;
map?: never;
} | {
string?: never;
int?: never;
float?: never;
boolean?: never;
link?: never;
array?: QueryListRecordsRequest.ArrayInput;
map?: never;
} | {
string?: never;
int?: never;
float?: never;
boolean?: never;
link?: never;
array?: never;
map?: QueryListRecordsRequest.MapInput;
})))) {
super(); super();
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [7], this.#one_of_decls);
if (!Array.isArray(data) && typeof data == "object") { if (!Array.isArray(data) && typeof data == "object") {
if ("type" in data && data.type != undefined) {
this.type = data.type;
}
if ("string" in data && data.string != undefined) { if ("string" in data && data.string != undefined) {
this.string = data.string; this.string = data.string;
} }
@ -528,105 +335,72 @@ export namespace vulcanize.registry.v1beta1 {
if ("boolean" in data && data.boolean != undefined) { if ("boolean" in data && data.boolean != undefined) {
this.boolean = data.boolean; this.boolean = data.boolean;
} }
if ("link" in data && data.link != undefined) { if ("reference" in data && data.reference != undefined) {
this.link = data.link; this.reference = data.reference;
} }
if ("array" in data && data.array != undefined) { if ("values" in data && data.values != undefined) {
this.array = data.array; this.values = data.values;
}
if ("map" in data && data.map != undefined) {
this.map = data.map;
} }
} }
} }
get string() { get type() {
return pb_1.Message.getFieldWithDefault(this, 1, "") as string; return pb_1.Message.getFieldWithDefault(this, 1, "") as string;
} }
set string(value: string) { set type(value: string) {
pb_1.Message.setOneofField(this, 1, this.#one_of_decls[0], value); pb_1.Message.setField(this, 1, value);
} }
get has_string() { get string() {
return pb_1.Message.getField(this, 1) != null; return pb_1.Message.getFieldWithDefault(this, 2, "") as string;
}
set string(value: string) {
pb_1.Message.setField(this, 2, value);
} }
get int() { get int() {
return pb_1.Message.getFieldWithDefault(this, 2, 0) as number;
}
set int(value: number) {
pb_1.Message.setOneofField(this, 2, this.#one_of_decls[0], value);
}
get has_int() {
return pb_1.Message.getField(this, 2) != null;
}
get float() {
return pb_1.Message.getFieldWithDefault(this, 3, 0) as number; return pb_1.Message.getFieldWithDefault(this, 3, 0) as number;
} }
set float(value: number) { set int(value: number) {
pb_1.Message.setOneofField(this, 3, this.#one_of_decls[0], value); pb_1.Message.setField(this, 3, value);
} }
get has_float() { get float() {
return pb_1.Message.getField(this, 3) != null; return pb_1.Message.getFieldWithDefault(this, 4, 0) as number;
}
set float(value: number) {
pb_1.Message.setField(this, 4, value);
} }
get boolean() { get boolean() {
return pb_1.Message.getFieldWithDefault(this, 4, false) as boolean; return pb_1.Message.getFieldWithDefault(this, 5, false) as boolean;
} }
set boolean(value: boolean) { set boolean(value: boolean) {
pb_1.Message.setOneofField(this, 4, this.#one_of_decls[0], value); pb_1.Message.setField(this, 5, value);
} }
get has_boolean() { get reference() {
return pb_1.Message.getField(this, 4) != null; return pb_1.Message.getWrapperField(this, QueryListRecordsRequest.ReferenceInput, 6) as QueryListRecordsRequest.ReferenceInput;
} }
get link() { set reference(value: QueryListRecordsRequest.ReferenceInput) {
return pb_1.Message.getFieldWithDefault(this, 5, "") as string; pb_1.Message.setWrapperField(this, 6, value);
} }
set link(value: string) { get has_reference() {
pb_1.Message.setOneofField(this, 5, this.#one_of_decls[0], value);
}
get has_link() {
return pb_1.Message.getField(this, 5) != null;
}
get array() {
return pb_1.Message.getWrapperField(this, QueryListRecordsRequest.ArrayInput, 6) as QueryListRecordsRequest.ArrayInput;
}
set array(value: QueryListRecordsRequest.ArrayInput) {
pb_1.Message.setOneofWrapperField(this, 6, this.#one_of_decls[0], value);
}
get has_array() {
return pb_1.Message.getField(this, 6) != null; return pb_1.Message.getField(this, 6) != null;
} }
get map() { get values() {
return pb_1.Message.getWrapperField(this, QueryListRecordsRequest.MapInput, 7) as QueryListRecordsRequest.MapInput; return pb_1.Message.getRepeatedWrapperField(this, QueryListRecordsRequest.ValueInput, 7) as QueryListRecordsRequest.ValueInput[];
} }
set map(value: QueryListRecordsRequest.MapInput) { set values(value: QueryListRecordsRequest.ValueInput[]) {
pb_1.Message.setOneofWrapperField(this, 7, this.#one_of_decls[0], value); pb_1.Message.setRepeatedWrapperField(this, 7, value);
}
get has_map() {
return pb_1.Message.getField(this, 7) != null;
}
get value() {
const cases: {
[index: number]: "none" | "string" | "int" | "float" | "boolean" | "link" | "array" | "map";
} = {
0: "none",
1: "string",
2: "int",
3: "float",
4: "boolean",
5: "link",
6: "array",
7: "map"
};
return cases[pb_1.Message.computeOneofCase(this, [1, 2, 3, 4, 5, 6, 7])];
} }
static fromObject(data: { static fromObject(data: {
type?: string;
string?: string; string?: string;
int?: number; int?: number;
float?: number; float?: number;
boolean?: boolean; boolean?: boolean;
link?: string; reference?: ReturnType<typeof QueryListRecordsRequest.ReferenceInput.prototype.toObject>;
array?: ReturnType<typeof QueryListRecordsRequest.ArrayInput.prototype.toObject>; values?: ReturnType<typeof QueryListRecordsRequest.ValueInput.prototype.toObject>[];
map?: ReturnType<typeof QueryListRecordsRequest.MapInput.prototype.toObject>;
}): ValueInput { }): ValueInput {
const message = new ValueInput({}); const message = new ValueInput({});
if (data.type != null) {
message.type = data.type;
}
if (data.string != null) { if (data.string != null) {
message.string = data.string; message.string = data.string;
} }
@ -639,27 +413,27 @@ export namespace vulcanize.registry.v1beta1 {
if (data.boolean != null) { if (data.boolean != null) {
message.boolean = data.boolean; message.boolean = data.boolean;
} }
if (data.link != null) { if (data.reference != null) {
message.link = data.link; message.reference = QueryListRecordsRequest.ReferenceInput.fromObject(data.reference);
} }
if (data.array != null) { if (data.values != null) {
message.array = QueryListRecordsRequest.ArrayInput.fromObject(data.array); message.values = data.values.map(item => QueryListRecordsRequest.ValueInput.fromObject(item));
}
if (data.map != null) {
message.map = QueryListRecordsRequest.MapInput.fromObject(data.map);
} }
return message; return message;
} }
toObject() { toObject() {
const data: { const data: {
type?: string;
string?: string; string?: string;
int?: number; int?: number;
float?: number; float?: number;
boolean?: boolean; boolean?: boolean;
link?: string; reference?: ReturnType<typeof QueryListRecordsRequest.ReferenceInput.prototype.toObject>;
array?: ReturnType<typeof QueryListRecordsRequest.ArrayInput.prototype.toObject>; values?: ReturnType<typeof QueryListRecordsRequest.ValueInput.prototype.toObject>[];
map?: ReturnType<typeof QueryListRecordsRequest.MapInput.prototype.toObject>;
} = {}; } = {};
if (this.type != null) {
data.type = this.type;
}
if (this.string != null) { if (this.string != null) {
data.string = this.string; data.string = this.string;
} }
@ -672,14 +446,11 @@ export namespace vulcanize.registry.v1beta1 {
if (this.boolean != null) { if (this.boolean != null) {
data.boolean = this.boolean; data.boolean = this.boolean;
} }
if (this.link != null) { if (this.reference != null) {
data.link = this.link; data.reference = this.reference.toObject();
} }
if (this.array != null) { if (this.values != null) {
data.array = this.array.toObject(); data.values = this.values.map((item: QueryListRecordsRequest.ValueInput) => item.toObject());
}
if (this.map != null) {
data.map = this.map.toObject();
} }
return data; return data;
} }
@ -687,20 +458,20 @@ export namespace vulcanize.registry.v1beta1 {
serialize(w: pb_1.BinaryWriter): void; serialize(w: pb_1.BinaryWriter): void;
serialize(w?: pb_1.BinaryWriter): Uint8Array | void { serialize(w?: pb_1.BinaryWriter): Uint8Array | void {
const writer = w || new pb_1.BinaryWriter(); const writer = w || new pb_1.BinaryWriter();
if (this.has_string) if (this.type.length)
writer.writeString(1, this.string); writer.writeString(1, this.type);
if (this.has_int) if (this.string.length)
writer.writeInt64(2, this.int); writer.writeString(2, this.string);
if (this.has_float) if (this.int != 0)
writer.writeDouble(3, this.float); writer.writeInt64(3, this.int);
if (this.has_boolean) if (this.float != 0)
writer.writeBool(4, this.boolean); writer.writeDouble(4, this.float);
if (this.has_link) if (this.boolean != false)
writer.writeString(5, this.link); writer.writeBool(5, this.boolean);
if (this.has_array) if (this.has_reference)
writer.writeMessage(6, this.array, () => this.array.serialize(writer)); writer.writeMessage(6, this.reference, () => this.reference.serialize(writer));
if (this.has_map) if (this.values.length)
writer.writeMessage(7, this.map, () => this.map.serialize(writer)); writer.writeRepeatedMessage(7, this.values, (item: QueryListRecordsRequest.ValueInput) => item.serialize(writer));
if (!w) if (!w)
return writer.getResultBuffer(); return writer.getResultBuffer();
} }
@ -711,25 +482,25 @@ export namespace vulcanize.registry.v1beta1 {
break; break;
switch (reader.getFieldNumber()) { switch (reader.getFieldNumber()) {
case 1: case 1:
message.string = reader.readString(); message.type = reader.readString();
break; break;
case 2: case 2:
message.int = reader.readInt64(); message.string = reader.readString();
break; break;
case 3: case 3:
message.float = reader.readDouble(); message.int = reader.readInt64();
break; break;
case 4: case 4:
message.boolean = reader.readBool(); message.float = reader.readDouble();
break; break;
case 5: case 5:
message.link = reader.readString(); message.boolean = reader.readBool();
break; break;
case 6: case 6:
reader.readMessage(message.array, () => message.array = QueryListRecordsRequest.ArrayInput.deserialize(reader)); reader.readMessage(message.reference, () => message.reference = QueryListRecordsRequest.ReferenceInput.deserialize(reader));
break; break;
case 7: case 7:
reader.readMessage(message.map, () => message.map = QueryListRecordsRequest.MapInput.deserialize(reader)); reader.readMessage(message.values, () => pb_1.Message.addToRepeatedWrapperField(message, 7, QueryListRecordsRequest.ValueInput.deserialize(reader), QueryListRecordsRequest.ValueInput));
break; break;
default: reader.skipField(); default: reader.skipField();
} }

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/registry/v1beta1/registry.proto * source: vulcanize/registry/v1beta1/registry.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../google/protobuf/duration"; import * as dependency_1 from "./../../../google/protobuf/duration";

View File

@ -2,7 +2,7 @@
/* eslint-disable */ /* eslint-disable */
/** /**
* Generated by the protoc-gen-ts. DO NOT EDIT! * Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1 * compiler version: 3.12.4
* source: vulcanize/registry/v1beta1/tx.proto * source: vulcanize/registry/v1beta1/tx.proto
* git: https://github.com/thesayyn/protoc-gen-ts */ * git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo"; import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -10,23 +10,15 @@ const attributeField = `
attributes { attributes {
key key
value { value {
... on BooleanValue { bool: value } null
... on IntValue { int: value } int
... on FloatValue { float: value } float
... on StringValue { string: value } string
... on BytesValue { bytes: value } boolean
... on LinkValue { link: value } json
... on ArrayValue { reference {
array: value { id
... on BooleanValue { bool: value }
... on IntValue { int: value }
... on FloatValue { float: value }
... on StringValue { string: value }
... on BytesValue { bytes: value }
... on LinkValue { link: value }
}
} }
... on MapValue { map: value { key mapping: value { __typename } } }
} }
} }
`; `;

View File

@ -50,18 +50,18 @@ describe('Querying', () => {
expect(records.length).toBeGreaterThanOrEqual(1); expect(records.length).toBeGreaterThanOrEqual(1);
const { attributes: { repo_registration_record_cid: record_repo_registration_record_cid } } = records[0]; const { attributes: { repo_registration_record_cid: record_repo_registration_record_cid } } = records[0];
expect(repo_registration_record_cid).toStrictEqual(record_repo_registration_record_cid); expect(repo_registration_record_cid).toBe(record_repo_registration_record_cid);
}); });
test('Query records by attributes.', async () => { test('Query records by attributes.', async () => {
const { version, url } = watcher.record; const { version, name } = watcher.record;
const records = await registry.queryRecords({ version, url, type: undefined }, true); const records = await registry.queryRecords({ version, name }, true);
expect(records.length).toBe(1); expect(records.length).toBe(1);
[ watcher ] = records; [ watcher ] = records;
const { attributes: { version: recordVersion, url: recordName } } = watcher; const { attributes: { version: recordVersion, name: recordName } } = watcher;
expect(recordVersion).toBe(version); expect(recordVersion).toBe(version);
expect(recordName).toBe(url); expect(recordName).toBe(name);
}); });
test('Query records by id.', async () => { test('Query records by id.', async () => {
@ -75,7 +75,6 @@ describe('Querying', () => {
expect(record.id).toBe(watcher.id); expect(record.id).toBe(watcher.id);
// temp fix // temp fix
expect(record.attributes.repo_registration_record_cid).toBeDefined(); expect(record.attributes.repo_registration_record_cid).toBeDefined();
expect(record.attributes.repo_registration_record_cid).toHaveProperty("/"); expect(record.attributes.repo_registration_record_cid).toHaveLength(46);
expect(record.attributes.repo_registration_record_cid["/"]).toHaveLength(46);
}); });
}); });

View File

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

View File

@ -10,21 +10,21 @@ export class Util {
/** /**
* Sorts JSON object. * Sorts JSON object.
*/ */
static sortJSON(obj: any) { static sortJSON(object: any) {
if (obj instanceof Array) { if (object instanceof Array) {
for (let i = 0; i < obj.length; i++) { for (let i = 0; i < object.length; i++) {
obj[i] = Util.sortJSON(obj[i]); object[i] = Util.sortJSON(object[i]);
} }
return obj; return object;
} }
if (typeof obj !== 'object' || obj === null) return obj; if (typeof object !== 'object' || object === null) return object;
let keys = Object.keys(obj); let keys = Object.keys(object);
keys = keys.sort(); keys = keys.sort();
const newObject: {[key: string]: any} = {}; const newObject: {[key: string]: any} = {};
for (let i = 0; i < keys.length; i++) { for (let i = 0; i < keys.length; i++) {
newObject[keys[i]] = Util.sortJSON(obj[keys[i]]); newObject[keys[i]] = Util.sortJSON(object[keys[i]]);
} }
return newObject; return newObject;
} }
@ -32,44 +32,29 @@ export class Util {
/** /**
* Marshal object into gql 'attributes' variable. * Marshal object into gql 'attributes' variable.
*/ */
static toGQLAttributes(obj: any) { static toGQLAttributes(object: any) {
const vars: any[] = []; const vars: any[] = [];
Object.keys(obj).forEach(key => {
const value = this.toGQLValue(obj[key]);
if (value !== undefined) { Object.keys(object).forEach(key => {
vars.push({ key, value }); let type: string = typeof object[key];
if (object[key] === null) {
vars.push({ key, value: { 'null': true } });
} else if (type === 'number') {
type = (object[key] % 1 === 0) ? 'int' : 'float';
vars.push({ key, value: { [type]: object[key] } });
} else if (type === 'string') {
vars.push({ key, value: { 'string': object[key] } });
} else if (type === 'boolean') {
vars.push({ key, value: { 'boolean': object[key] } });
} else if (type === 'object') {
const nestedObject = object[key];
if (nestedObject['/'] !== undefined) {
vars.push({ key, value: { 'reference': { id: nestedObject['/'] } } });
}
} }
}); });
return vars;
}
static toGQLValue(obj: any) { return vars;
if (obj === null) {
return null;
}
let type: string = typeof obj;
switch (type) {
case 'number':
type = (obj % 1 === 0) ? 'int' : 'float';
return { [type]: obj };
case 'string':
return { 'string': obj };
case 'boolean':
return { 'boolean': obj };
case 'object':
if (obj['/'] !== undefined) {
return { 'link': obj['/'] };
}
if (obj instanceof Array) {
return { 'array': obj };
}
return { 'map': obj };
case 'undefined':
return undefined;
default:
throw new Error(`Unknown object type '${type}': ${obj}`);
}
} }
/** /**
@ -79,29 +64,24 @@ export class Util {
const res: {[key: string]: any} = {}; const res: {[key: string]: any} = {};
attributes.forEach(attr => { attributes.forEach(attr => {
res[attr.key] = (attr.value === null) ? null : this.fromGQLValue(attr.value); if (attr.value.null) {
res[attr.key] = null;
} else if (attr.value.json) {
res[attr.key] = JSON.parse(attr.value.json);
} else if (attr.value.reference) {
// Convert GQL reference to IPLD style link.
const ref = attr.value.reference;
res[attr.key] = { '/': ref.id };
} else {
const { values, null: n, ...types } = attr.value;
const value = Object.values(types).find(v => v !== null);
res[attr.key] = value;
}
}); });
return res; return res;
} }
static fromGQLValue(obj: any) {
// Get first non-null key
const present = Object.keys(obj).find(k => obj[k] !== null);
if (present === undefined) {
throw new Error('Object has no non-null values');
}
// Create an array if array type attribute
if (present === 'array') {
return obj[present].map((e: any) => {
return this.fromGQLValue(e);
});
}
return obj[present];
}
/** /**
* Get record content ID. * Get record content ID.
*/ */

View File

@ -3093,10 +3093,10 @@ protobufjs@~6.11.2:
"@types/node" ">=13.7.0" "@types/node" ">=13.7.0"
long "^4.0.0" long "^4.0.0"
protoc-gen-ts@^0.8.7: protoc-gen-ts@^0.8.5:
version "0.8.7" version "0.8.6"
resolved "https://registry.yarnpkg.com/protoc-gen-ts/-/protoc-gen-ts-0.8.7.tgz#63e4d9af2ad30b753acf6f739323d01fc9f80b52" resolved "https://registry.yarnpkg.com/protoc-gen-ts/-/protoc-gen-ts-0.8.6.tgz#e789a6fc3fbe09bdc119acecc349b9554ec5940e"
integrity sha512-jr4VJey2J9LVYCV7EVyVe53g1VMw28cCmYJhBe5e3YX5wiyiDwgxWxeDf9oTqAe4P1bN/YGAkW2jhlH8LohwiQ== integrity sha512-66oeorGy4QBvYjQGd/gaeOYyFqKyRmRgTpofmnw8buMG0P7A0jQjoKSvKJz5h5tNUaVkIzvGBUTRVGakrhhwpA==
pure-rand@^6.0.0: pure-rand@^6.0.0:
version "6.0.3" version "6.0.3"