diff --git a/.env.example b/.env.example index d27f846..9354a4b 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ PRIVATE_KEY=75f719e613d05efab06a3f1dde5250b497723b13d4afa4f8ed80145764e40cf7 +COSMOS_CHAIN_ID=laconic_9000-1 diff --git a/src/account.ts b/src/account.ts index 93b3d35..070f4f2 100644 --- a/src/account.ts +++ b/src/account.ts @@ -1,6 +1,5 @@ import assert from 'assert'; import BIP32Factory from 'bip32'; -// TODO: Upgrade tiny-secp256k1 and use in react laconic-console app. import * as ecc from 'tiny-secp256k1'; import * as bip39 from 'bip39'; import canonicalStringify from 'canonical-json'; diff --git a/src/auction.test.ts b/src/auction.test.ts index 111484c..06637c3 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -16,7 +16,7 @@ const auctionTests = (numBidders = 3) => { beforeAll(async () => { 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 () => { diff --git a/src/bond.test.ts b/src/bond.test.ts index 77369c4..2b7f93c 100644 --- a/src/bond.test.ts +++ b/src/bond.test.ts @@ -29,7 +29,7 @@ const bondTests = () => { }; beforeAll(async () => { - registry = new Registry(restEndpoint, gqlEndpoint, chainId); + registry = new Registry(gqlEndpoint, restEndpoint, chainId); }); test('Create bond.', async () => { diff --git a/src/index.test.ts b/src/index.test.ts index b1ee44a..fc96f80 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -10,7 +10,7 @@ const registryTests = () => { let registry: Registry; beforeAll(async () => { - registry = new Registry(restEndpoint, gqlEndpoint, chainId); + registry = new Registry(gqlEndpoint, restEndpoint, chainId); }); diff --git a/src/index.ts b/src/index.ts index ae06546..c83797d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,6 +53,8 @@ import { MessageMsgRevealBid } from './messages/auction'; +export const DEFAULT_CHAIN_ID = 'laconic_9000-1'; + const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd.'; // Parse Tx response from cosmos-sdk. @@ -119,21 +121,21 @@ export class Registry { return errorMessage || DEFAULT_WRITE_ERROR; } - constructor(restUrl: string, gqlUrl: string, chainId: string) { - if (!isUrl(restUrl)) { - throw new Error('Path to a REST endpoint should be provided.'); - } - + constructor(gqlUrl: string, restUrl: string = "", chainId: string = DEFAULT_CHAIN_ID) { if (!isUrl(gqlUrl)) { 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 = { rest: restUrl, gql: gqlUrl }; - this._client = new RegistryClient(restUrl, gqlUrl); + this._client = new RegistryClient(gqlUrl, restUrl); this._chainID = chainId; this._chain = { diff --git a/src/nameservice-expiry.test.ts b/src/nameservice-expiry.test.ts index afa49ed..a52ab3b 100644 --- a/src/nameservice-expiry.test.ts +++ b/src/nameservice-expiry.test.ts @@ -20,7 +20,7 @@ const nameserviceExpiryTests = () => { let recordExpiryTime: Date; beforeAll(async () => { - registry = new Registry(restEndpoint, gqlEndpoint, chainId); + registry = new Registry(gqlEndpoint, restEndpoint, chainId); // Create bond. bondId = await registry.getNextBondId(privateKey); diff --git a/src/naming.test.ts b/src/naming.test.ts index 943d122..7445e41 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -25,7 +25,7 @@ const namingTests = () => { let crn: string; beforeAll(async () => { - registry = new Registry(restEndpoint, gqlEndpoint, chainId); + registry = new Registry(gqlEndpoint, restEndpoint, chainId); // Create bond. bondId = await registry.getNextBondId(privateKey); diff --git a/src/registry-client.ts b/src/registry-client.ts index 79cc5f7..ec49994 100644 --- a/src/registry-client.ts +++ b/src/registry-client.ts @@ -122,15 +122,14 @@ export class RegistryClient { /** * New Client. */ - constructor(restEndpoint: string, gqlEndpoint: string) { - assert(restEndpoint); - - this._restEndpoint = restEndpoint; - + constructor(gqlEndpoint: string, restEndpoint: string) { + assert(gqlEndpoint); this._graph = graphqlClient(gqlEndpoint, { method: 'POST', asJSON: true }); + + this._restEndpoint = restEndpoint; } /** diff --git a/src/sdk.test.ts b/src/sdk.test.ts index 0380d86..80038cf 100644 --- a/src/sdk.test.ts +++ b/src/sdk.test.ts @@ -15,7 +15,7 @@ describe('Querying', () => { let bondId: string; beforeAll(async () => { - registry = new Registry(restEndpoint, gqlEndpoint, chainId); + registry = new Registry(gqlEndpoint, restEndpoint, chainId); bondId = await provisionBondId(registry, privateKey, fee); const publishNewWatcherVersion = async () => { diff --git a/src/testing/helper.ts b/src/testing/helper.ts index be127b1..86cde9f 100644 --- a/src/testing/helper.ts +++ b/src/testing/helper.ts @@ -3,7 +3,7 @@ import yaml from 'node-yaml'; import semver from 'semver'; import { Fee } from '@tharsis/transactions'; -import { Registry } from '../index'; +import { DEFAULT_CHAIN_ID, Registry } from '../index'; export const ensureUpdatedConfig = async (path: string) => { const conf = await yaml.read(path); @@ -37,7 +37,7 @@ export const getConfig = () => { assert(process.env.PRIVATE_KEY); return { - chainId: process.env.COSMOS_CHAIN_ID || 'laconic_9000-1', + chainId: process.env.COSMOS_CHAIN_ID || DEFAULT_CHAIN_ID, privateKey: process.env.PRIVATE_KEY, restEndpoint: process.env.LACONICD_REST_ENDPOINT || 'http://localhost:1317', gqlEndpoint: process.env.LACONICD_GQL_ENDPOINT || 'http://localhost:9473/api', diff --git a/src/util.test.ts b/src/util.test.ts index c0103c6..df58da1 100644 --- a/src/util.test.ts +++ b/src/util.test.ts @@ -18,7 +18,7 @@ const utilTests = () => { let watcherId: string; beforeAll(async () => { - registry = new Registry(restEndpoint, gqlEndpoint, chainId); + registry = new Registry(gqlEndpoint, restEndpoint, chainId); // Create bond. bondId = await registry.getNextBondId(privateKey);