Make REST endpoint optional

This commit is contained in:
nabarun 2022-12-09 11:16:18 +05:30
parent 9e8d6d910e
commit 984d96b27b
12 changed files with 22 additions and 21 deletions

View File

@ -1 +1,2 @@
PRIVATE_KEY=75f719e613d05efab06a3f1dde5250b497723b13d4afa4f8ed80145764e40cf7 PRIVATE_KEY=75f719e613d05efab06a3f1dde5250b497723b13d4afa4f8ed80145764e40cf7
COSMOS_CHAIN_ID=laconic_9000-1

View File

@ -1,6 +1,5 @@
import assert from 'assert'; import assert from 'assert';
import BIP32Factory from 'bip32'; import BIP32Factory from 'bip32';
// TODO: Upgrade tiny-secp256k1 and use in react laconic-console app.
import * as ecc from 'tiny-secp256k1'; import * as ecc from 'tiny-secp256k1';
import * as bip39 from 'bip39'; import * as bip39 from 'bip39';
import canonicalStringify from 'canonical-json'; import canonicalStringify from 'canonical-json';

View File

@ -16,7 +16,7 @@ const auctionTests = (numBidders = 3) => {
beforeAll(async () => { beforeAll(async () => {
console.log('Running auction tests with num bidders', numBidders); console.log('Running auction tests with num bidders', numBidders);
registry = new Registry(restEndpoint, gqlEndpoint, chainId); registry = new Registry(gqlEndpoint, restEndpoint, chainId);
}); });
test('Setup bidder accounts', async () => { test('Setup bidder accounts', async () => {

View File

@ -29,7 +29,7 @@ const bondTests = () => {
}; };
beforeAll(async () => { beforeAll(async () => {
registry = new Registry(restEndpoint, gqlEndpoint, chainId); registry = new Registry(gqlEndpoint, restEndpoint, chainId);
}); });
test('Create bond.', async () => { test('Create bond.', async () => {

View File

@ -10,7 +10,7 @@ const registryTests = () => {
let registry: Registry; let registry: Registry;
beforeAll(async () => { beforeAll(async () => {
registry = new Registry(restEndpoint, gqlEndpoint, chainId); registry = new Registry(gqlEndpoint, restEndpoint, chainId);
}); });

View File

@ -53,6 +53,8 @@ import {
MessageMsgRevealBid MessageMsgRevealBid
} from './messages/auction'; } from './messages/auction';
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.
@ -119,21 +121,21 @@ export class Registry {
return errorMessage || DEFAULT_WRITE_ERROR; return errorMessage || DEFAULT_WRITE_ERROR;
} }
constructor(restUrl: string, gqlUrl: string, chainId: string) { constructor(gqlUrl: string, restUrl: string = "", chainId: string = DEFAULT_CHAIN_ID) {
if (!isUrl(restUrl)) {
throw new Error('Path to a REST endpoint should be provided.');
}
if (!isUrl(gqlUrl)) { if (!isUrl(gqlUrl)) {
throw new Error('Path to a GQL endpoint should be provided.'); throw new Error('Path to a GQL endpoint should be provided.');
} }
if (restUrl && !isUrl(restUrl)) {
throw new Error('REST endpoint is not a URL string.');
}
this._endpoints = { this._endpoints = {
rest: restUrl, rest: restUrl,
gql: gqlUrl gql: gqlUrl
}; };
this._client = new RegistryClient(restUrl, gqlUrl); this._client = new RegistryClient(gqlUrl, restUrl);
this._chainID = chainId; this._chainID = chainId;
this._chain = { this._chain = {

View File

@ -20,7 +20,7 @@ const nameserviceExpiryTests = () => {
let recordExpiryTime: Date; let recordExpiryTime: Date;
beforeAll(async () => { beforeAll(async () => {
registry = new Registry(restEndpoint, gqlEndpoint, chainId); registry = new Registry(gqlEndpoint, restEndpoint, chainId);
// Create bond. // Create bond.
bondId = await registry.getNextBondId(privateKey); bondId = await registry.getNextBondId(privateKey);

View File

@ -25,7 +25,7 @@ const namingTests = () => {
let crn: string; let crn: string;
beforeAll(async () => { beforeAll(async () => {
registry = new Registry(restEndpoint, gqlEndpoint, chainId); registry = new Registry(gqlEndpoint, restEndpoint, chainId);
// Create bond. // Create bond.
bondId = await registry.getNextBondId(privateKey); bondId = await registry.getNextBondId(privateKey);

View File

@ -122,15 +122,14 @@ export class RegistryClient {
/** /**
* New Client. * New Client.
*/ */
constructor(restEndpoint: string, gqlEndpoint: string) { constructor(gqlEndpoint: string, restEndpoint: string) {
assert(restEndpoint); assert(gqlEndpoint);
this._restEndpoint = restEndpoint;
this._graph = graphqlClient(gqlEndpoint, { this._graph = graphqlClient(gqlEndpoint, {
method: 'POST', method: 'POST',
asJSON: true asJSON: true
}); });
this._restEndpoint = restEndpoint;
} }
/** /**

View File

@ -15,7 +15,7 @@ describe('Querying', () => {
let bondId: string; let bondId: string;
beforeAll(async () => { beforeAll(async () => {
registry = new Registry(restEndpoint, gqlEndpoint, chainId); registry = new Registry(gqlEndpoint, restEndpoint, chainId);
bondId = await provisionBondId(registry, privateKey, fee); bondId = await provisionBondId(registry, privateKey, fee);
const publishNewWatcherVersion = async () => { const publishNewWatcherVersion = async () => {

View File

@ -3,7 +3,7 @@ import yaml from 'node-yaml';
import semver from 'semver'; import semver from 'semver';
import { Fee } from '@tharsis/transactions'; import { Fee } from '@tharsis/transactions';
import { Registry } from '../index'; import { DEFAULT_CHAIN_ID, Registry } from '../index';
export const ensureUpdatedConfig = async (path: string) => { export const ensureUpdatedConfig = async (path: string) => {
const conf = await yaml.read(path); const conf = await yaml.read(path);
@ -37,7 +37,7 @@ export const getConfig = () => {
assert(process.env.PRIVATE_KEY); assert(process.env.PRIVATE_KEY);
return { return {
chainId: process.env.COSMOS_CHAIN_ID || 'laconic_9000-1', chainId: process.env.COSMOS_CHAIN_ID || DEFAULT_CHAIN_ID,
privateKey: process.env.PRIVATE_KEY, privateKey: process.env.PRIVATE_KEY,
restEndpoint: process.env.LACONICD_REST_ENDPOINT || 'http://localhost:1317', restEndpoint: process.env.LACONICD_REST_ENDPOINT || 'http://localhost:1317',
gqlEndpoint: process.env.LACONICD_GQL_ENDPOINT || 'http://localhost:9473/api', gqlEndpoint: process.env.LACONICD_GQL_ENDPOINT || 'http://localhost:9473/api',

View File

@ -18,7 +18,7 @@ const utilTests = () => {
let watcherId: string; let watcherId: string;
beforeAll(async () => { beforeAll(async () => {
registry = new Registry(restEndpoint, gqlEndpoint, chainId); registry = new Registry(gqlEndpoint, restEndpoint, chainId);
// Create bond. // Create bond.
bondId = await registry.getNextBondId(privateKey); bondId = await registry.getNextBondId(privateKey);