Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a17b1b175 | ||
|
|
1916386929 | ||
|
|
f14fb7d9bb |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/registry-sdk",
|
"name": "@cerc-io/registry-sdk",
|
||||||
"version": "0.2.6",
|
"version": "0.2.9",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"repository": "git@github.com:cerc-io/registry-sdk.git",
|
"repository": "git@github.com:cerc-io/registry-sdk.git",
|
||||||
|
|||||||
+1
-1
@@ -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(gqlEndpoint, rpcEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Setup bidder accounts', async () => {
|
test('Setup bidder accounts', async () => {
|
||||||
|
|||||||
+28
-9
@@ -1,6 +1,6 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import { Registry } from './index';
|
import { Account, Registry } from './index';
|
||||||
import { ensureUpdatedConfig, getConfig } from './testing/helper';
|
import { ensureUpdatedConfig, getConfig } from './testing/helper';
|
||||||
import { DENOM } from './constants';
|
import { DENOM } from './constants';
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ jest.setTimeout(90 * 1000);
|
|||||||
|
|
||||||
const bondTests = () => {
|
const bondTests = () => {
|
||||||
let registry: Registry;
|
let registry: Registry;
|
||||||
|
let bond0: { id: string, owner: string };
|
||||||
|
|
||||||
const publishNewWatcherVersion = async (bondId: string) => {
|
const publishNewWatcherVersion = async (bondId: string) => {
|
||||||
let watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
let watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
||||||
@@ -21,17 +22,19 @@ const bondTests = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Create bond.', async () => {
|
test('Create bond.', async () => {
|
||||||
let bondId = await registry.getNextBondId(privateKey);
|
let bondId = await registry.getNextBondId(privateKey);
|
||||||
expect(bondId).toBeDefined();
|
expect(bondId).toBeDefined();
|
||||||
await registry.createBond({ denom: DENOM, amount: BOND_AMOUNT }, privateKey, fee);
|
await registry.createBond({ denom: DENOM, amount: BOND_AMOUNT }, privateKey, fee);
|
||||||
|
|
||||||
|
[bond0] = await registry.getBondsByIds([bondId]);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('With bond created', () => {
|
describe('With bond created', () => {
|
||||||
let bond1: any;
|
let bond1: { id: string, owner: string };
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
let bondId1 = await registry.getNextBondId(privateKey);
|
let bondId1 = await registry.getNextBondId(privateKey);
|
||||||
@@ -54,15 +57,31 @@ const bondTests = () => {
|
|||||||
test('Query bonds.', async () => {
|
test('Query bonds.', async () => {
|
||||||
const bonds = await registry.queryBonds();
|
const bonds = await registry.queryBonds();
|
||||||
expect(bonds).toBeDefined();
|
expect(bonds).toBeDefined();
|
||||||
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
|
|
||||||
expect(bond).toBeDefined();
|
const filteredBonds = bonds.filter((bond: any) => bond.id === bond1.id);
|
||||||
|
expect(filteredBonds).toHaveLength(1);
|
||||||
|
expect(filteredBonds[0]).toMatchObject({ id: bond1.id, owner: bond1.owner });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Query bonds by owner.', async () => {
|
test('Query bonds by owner.', async () => {
|
||||||
const bonds = await registry.queryBonds({ owner: bond1.owner });
|
const mnenonic = Account.generateMnemonic();
|
||||||
expect(bonds).toBeDefined();
|
const otherAccount = await Account.generateFromMnemonic(mnenonic);
|
||||||
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
|
await otherAccount.init();
|
||||||
expect(bond).toBeDefined();
|
await registry.sendCoins({ denom: DENOM, amount: '1000000000000', destinationAddress: otherAccount.address }, privateKey, fee);
|
||||||
|
|
||||||
|
const { id: bondId2 } = await registry.createBond({ denom: DENOM, amount: BOND_AMOUNT }, otherAccount.getPrivateKey(), fee);
|
||||||
|
|
||||||
|
const [owner1Bonds] = await registry.queryBondsByOwners([bond0.owner]);
|
||||||
|
const owner1Bond1 = owner1Bonds.bonds.filter((b: any) => b.id === bond0.id);
|
||||||
|
const owner1Bond2 = owner1Bonds.bonds.filter((b: any) => b.id === bond1.id);
|
||||||
|
expect(owner1Bond1).toBeDefined();
|
||||||
|
expect(owner1Bond2).toBeDefined();
|
||||||
|
|
||||||
|
const [bond2] = await registry.getBondsByIds([bondId2]);
|
||||||
|
const [owner2Bonds] = await registry.queryBondsByOwners([bond2.owner]);
|
||||||
|
expect(owner2Bonds.bonds).toHaveLength(1);
|
||||||
|
const owner2Bond = owner2Bonds.bonds.filter((b: any) => b.id === bondId2);
|
||||||
|
expect(owner2Bond).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Refill bond.', async () => {
|
test('Refill bond.', async () => {
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import { GasPrice } from '@cosmjs/stargate';
|
||||||
|
|
||||||
|
import { Account } from './account';
|
||||||
|
import { DENOM } from './constants';
|
||||||
|
import { Registry } from './index';
|
||||||
|
import { createTestAccounts, getConfig } from './testing/helper';
|
||||||
|
|
||||||
|
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
||||||
|
|
||||||
|
jest.setTimeout(90 * 1000);
|
||||||
|
|
||||||
|
const configTests = () => {
|
||||||
|
let registry: Registry;
|
||||||
|
let testAccount: Account;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
|
// Fund a new account for the test
|
||||||
|
[testAccount] = await createTestAccounts(1);
|
||||||
|
await registry.sendCoins({ denom: DENOM, amount: '10000000', destinationAddress: testAccount.address }, privateKey, fee);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('StdFee fees with gas price not set', async () => {
|
||||||
|
const testFees = {
|
||||||
|
amount: [{ denom: 'alnt', amount: '400000' }],
|
||||||
|
gas: '400000'
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send a bond creation tx
|
||||||
|
await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey(), testFees);
|
||||||
|
|
||||||
|
// Check that bond gets created
|
||||||
|
const [result] = await registry.queryBondsByOwners([testAccount.address]);
|
||||||
|
expect(result.bonds).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('StdFee fees with gas price set', async () => {
|
||||||
|
const testFees = {
|
||||||
|
amount: [{ denom: 'alnt', amount: '400000' }],
|
||||||
|
gas: '400000'
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set gas price lower than min gas price
|
||||||
|
const testGasPrice = GasPrice.fromString(String('0.00001alnt'));
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice: testGasPrice });
|
||||||
|
|
||||||
|
// Send a bond creation tx
|
||||||
|
await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey(), testFees);
|
||||||
|
|
||||||
|
// Check that bond gets created (gas price ignored)
|
||||||
|
const [result] = await registry.queryBondsByOwners([testAccount.address]);
|
||||||
|
expect(result.bonds).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Gas price with fees not set (default gas estimation multiplier)', async () => {
|
||||||
|
// Set gas price
|
||||||
|
const testGasPrice = GasPrice.fromString('1alnt');
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice: testGasPrice });
|
||||||
|
|
||||||
|
// Send a bond creation tx
|
||||||
|
await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey());
|
||||||
|
|
||||||
|
// Check that bond gets created (gas price ignored)
|
||||||
|
const [result] = await registry.queryBondsByOwners([testAccount.address]);
|
||||||
|
expect(result.bonds).toHaveLength(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Gas price with fees set (fees as the gas estimation multiplier)', async () => {
|
||||||
|
const testFees = 2.1;
|
||||||
|
|
||||||
|
// Set gas price
|
||||||
|
const testGasPrice = GasPrice.fromString('1alnt');
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId, gasPrice: testGasPrice });
|
||||||
|
|
||||||
|
// Send a bond creation tx
|
||||||
|
await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey(), testFees);
|
||||||
|
|
||||||
|
// Check that bond gets created (gas price ignored)
|
||||||
|
const [result] = await registry.queryBondsByOwners([testAccount.address]);
|
||||||
|
expect(result.bonds).toHaveLength(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Error on fees and gas price both not set', async () => {
|
||||||
|
const errorMsg = 'Gas price must be set in the client options when auto gas is used';
|
||||||
|
|
||||||
|
// Create registry without gasPrice
|
||||||
|
const registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
|
// Send a bond creation tx
|
||||||
|
try {
|
||||||
|
await registry.createBond({ denom: DENOM, amount: '100000' }, testAccount.getPrivateKey());
|
||||||
|
} catch (error: any) {
|
||||||
|
expect(error.toString()).toContain(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that bond doesn't get created
|
||||||
|
const [result] = await registry.queryBondsByOwners([testAccount.address]);
|
||||||
|
expect(result.bonds).toHaveLength(4);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Config', configTests);
|
||||||
@@ -1 +1,2 @@
|
|||||||
export const DENOM = 'alnt';
|
export const DENOM = 'alnt';
|
||||||
|
export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 2;
|
||||||
|
|||||||
+36
-2
@@ -1,7 +1,7 @@
|
|||||||
import { Account } from './account';
|
import { Account } from './account';
|
||||||
import { DENOM } from './constants';
|
import { DENOM } from './constants';
|
||||||
import { Registry } from './index';
|
import { Registry } from './index';
|
||||||
import { getConfig } from './testing/helper';
|
import { createTestAccounts, getConfig } from './testing/helper';
|
||||||
|
|
||||||
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ const registryTests = () => {
|
|||||||
let registry: Registry;
|
let registry: Registry;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Get account info.', async () => {
|
test('Get account info.', async () => {
|
||||||
@@ -43,6 +43,40 @@ const registryTests = () => {
|
|||||||
expect(type).toBe(DENOM);
|
expect(type).toBe(DENOM);
|
||||||
expect(quantity).toBe('10000');
|
expect(quantity).toBe('10000');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Batch txs', () => {
|
||||||
|
let accounts: Account[];
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
// Fund 5 new accounts for the test
|
||||||
|
accounts = await createTestAccounts(5);
|
||||||
|
for (let i = 0; i < accounts.length; i++) {
|
||||||
|
await registry.sendCoins({ denom: DENOM, amount: '1000000', destinationAddress: accounts[i].address }, privateKey, fee);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Multiple txs get included in a block.', async () => {
|
||||||
|
// Send a bond creation tx from each account (send from different accounts to avoid sequence errors)
|
||||||
|
await Promise.all(accounts.map((account) =>
|
||||||
|
registry.createBond({ denom: DENOM, amount: '100000' }, account.getPrivateKey(), fee)
|
||||||
|
));
|
||||||
|
|
||||||
|
const laconicClient = await registry.getLaconicClient(accounts[0]);
|
||||||
|
const bondCreationTxHeights = await Promise.all(accounts.map(async (account) => {
|
||||||
|
// Get the bond creation tx for each account
|
||||||
|
const [tx] = await laconicClient.searchTx(`message.sender='${account.address}' AND message.action='/cerc.bond.v1.MsgCreateBond'`);
|
||||||
|
return tx.height;
|
||||||
|
}));
|
||||||
|
|
||||||
|
bondCreationTxHeights.forEach((txHeight, i) => {
|
||||||
|
console.log('tx', accounts[i].address, txHeight);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check that all txs are within two blocks
|
||||||
|
const expectedBlockHeight = bondCreationTxHeights.sort()[0];
|
||||||
|
expect(bondCreationTxHeights.every(txHeight => txHeight === expectedBlockHeight || txHeight === expectedBlockHeight + 1)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Registry', registryTests);
|
describe('Registry', registryTests);
|
||||||
|
|||||||
+49
-31
@@ -1,6 +1,6 @@
|
|||||||
import { sha256 } from 'js-sha256';
|
import { sha256 } from 'js-sha256';
|
||||||
|
|
||||||
import { DeliverTxResponse, StdFee } from '@cosmjs/stargate';
|
import { DeliverTxResponse, StdFee, GasPrice } from '@cosmjs/stargate';
|
||||||
|
|
||||||
import { RegistryClient } from './registry-client';
|
import { RegistryClient } from './registry-client';
|
||||||
import { Account } from './account';
|
import { Account } from './account';
|
||||||
@@ -31,8 +31,7 @@ import { Coin } from './proto/cosmos/base/v1beta1/coin';
|
|||||||
import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx';
|
import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx';
|
||||||
import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/tx';
|
import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/tx';
|
||||||
import { MsgSendResponse } from './proto/cosmos/bank/v1beta1/tx';
|
import { MsgSendResponse } from './proto/cosmos/bank/v1beta1/tx';
|
||||||
|
import { DEFAULT_GAS_ESTIMATION_MULTIPLIER } from './constants';
|
||||||
export const DEFAULT_CHAIN_ID = 'laconic_9000-1';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an auction bid.
|
* Create an auction bid.
|
||||||
@@ -60,19 +59,26 @@ export const createBid = async (chainId: string, auctionId: string, bidderAddres
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface RegistryOptions {
|
||||||
|
chainId: string
|
||||||
|
gasPrice?: GasPrice
|
||||||
|
}
|
||||||
|
|
||||||
export class Registry {
|
export class Registry {
|
||||||
_endpoints: { [key: string]: string };
|
_endpoints: { [key: string]: string };
|
||||||
_chainID: string;
|
_chainID: string;
|
||||||
_client: RegistryClient;
|
_client: RegistryClient;
|
||||||
|
_gasPrice?: GasPrice;
|
||||||
|
|
||||||
constructor (gqlUrl: string, rpcUrl = '', chainId: string = DEFAULT_CHAIN_ID) {
|
constructor (gqlUrl: string, rpcUrl = '', options: RegistryOptions) {
|
||||||
this._endpoints = {
|
this._endpoints = {
|
||||||
rpc: rpcUrl,
|
rpc: rpcUrl,
|
||||||
gql: gqlUrl
|
gql: gqlUrl
|
||||||
};
|
};
|
||||||
|
|
||||||
this._client = new RegistryClient(gqlUrl, rpcUrl);
|
this._client = new RegistryClient(gqlUrl, rpcUrl);
|
||||||
this._chainID = chainId;
|
this._chainID = options.chainId;
|
||||||
|
this._gasPrice = options.gasPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,8 +113,8 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Get records by attributes.
|
* Get records by attributes.
|
||||||
*/
|
*/
|
||||||
async queryRecords (attributes: { [key: string]: any }, all = false, refs = false) {
|
async queryRecords (attributes: { [key: string]: any }, all = false, refs = false, limit?: number, offset?: number) {
|
||||||
return this._client.queryRecords(attributes, all, refs);
|
return this._client.queryRecords(attributes, all, refs, limit, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,7 +131,7 @@ export class Registry {
|
|||||||
async setRecord (
|
async setRecord (
|
||||||
{ privateKey, record, bondId }: { privateKey: string, record: any, bondId: string },
|
{ privateKey, record, bondId }: { privateKey: string, record: any, bondId: string },
|
||||||
transactionPrivateKey: string,
|
transactionPrivateKey: string,
|
||||||
fee: StdFee
|
fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER
|
||||||
) {
|
) {
|
||||||
const account = new Account(Buffer.from(transactionPrivateKey, 'hex'));
|
const account = new Account(Buffer.from(transactionPrivateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
@@ -140,7 +146,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Send coins.
|
* Send coins.
|
||||||
*/
|
*/
|
||||||
async sendCoins ({ amount, denom, destinationAddress }: MessageMsgSendCoins, privateKey: string, fee: StdFee) {
|
async sendCoins ({ amount, denom, destinationAddress }: MessageMsgSendCoins, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -186,16 +192,23 @@ export class Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query bonds by attributes.
|
* Query bonds.
|
||||||
*/
|
*/
|
||||||
async queryBonds (attributes = {}) {
|
async queryBonds () {
|
||||||
return this._client.queryBonds(attributes);
|
return this._client.queryBonds();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query bonds by owner(s).
|
||||||
|
*/
|
||||||
|
async queryBondsByOwners (owners: string[]) {
|
||||||
|
return this._client.queryBondsByOwners(owners);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create bond.
|
* Create bond.
|
||||||
*/
|
*/
|
||||||
async createBond ({ denom, amount }: MessageMsgCreateBond, privateKey: string, fee: StdFee): Promise<MsgCreateBondResponse> {
|
async createBond ({ denom, amount }: MessageMsgCreateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgCreateBondResponse> {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -211,7 +224,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Refill bond.
|
* Refill bond.
|
||||||
*/
|
*/
|
||||||
async refillBond ({ denom, amount, id }: MessageMsgRefillBond, privateKey: string, fee: StdFee): Promise<MsgRefillBondResponse> {
|
async refillBond ({ denom, amount, id }: MessageMsgRefillBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgRefillBondResponse> {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -228,7 +241,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Withdraw (from) bond.
|
* Withdraw (from) bond.
|
||||||
*/
|
*/
|
||||||
async withdrawBond ({ denom, amount, id }: MessageMsgWithdrawBond, privateKey: string, fee: StdFee): Promise<MsgWithdrawBondResponse> {
|
async withdrawBond ({ denom, amount, id }: MessageMsgWithdrawBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgWithdrawBondResponse> {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -245,7 +258,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Cancel bond.
|
* Cancel bond.
|
||||||
*/
|
*/
|
||||||
async cancelBond ({ id }: MessageMsgCancelBond, privateKey: string, fee: StdFee): Promise<MsgCancelBondResponse> {
|
async cancelBond ({ id }: MessageMsgCancelBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgCancelBondResponse> {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -260,7 +273,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Associate record with bond.
|
* Associate record with bond.
|
||||||
*/
|
*/
|
||||||
async associateBond ({ bondId, recordId }: MessageMsgAssociateBond, privateKey: string, fee: StdFee) {
|
async associateBond ({ bondId, recordId }: MessageMsgAssociateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -276,7 +289,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Dissociate record from bond.
|
* Dissociate record from bond.
|
||||||
*/
|
*/
|
||||||
async dissociateBond ({ recordId }: MessageMsgDissociateBond, privateKey: string, fee: StdFee) {
|
async dissociateBond ({ recordId }: MessageMsgDissociateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -291,7 +304,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Dissociate all records from bond.
|
* Dissociate all records from bond.
|
||||||
*/
|
*/
|
||||||
async dissociateRecords ({ bondId }: MessageMsgDissociateRecords, privateKey: string, fee: StdFee) {
|
async dissociateRecords ({ bondId }: MessageMsgDissociateRecords, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -306,7 +319,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Reassociate records (switch bond).
|
* Reassociate records (switch bond).
|
||||||
*/
|
*/
|
||||||
async reassociateRecords ({ newBondId, oldBondId }: MessageMsgReAssociateRecords, privateKey: string, fee: StdFee) {
|
async reassociateRecords ({ newBondId, oldBondId }: MessageMsgReAssociateRecords, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -322,7 +335,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Reserve authority.
|
* Reserve authority.
|
||||||
*/
|
*/
|
||||||
async reserveAuthority ({ name, owner }: { name: string, owner?: string }, privateKey: string, fee: StdFee) {
|
async reserveAuthority ({ name, owner }: { name: string, owner?: string }, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -338,7 +351,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Set authority bond.
|
* Set authority bond.
|
||||||
*/
|
*/
|
||||||
async setAuthorityBond ({ bondId, name }: MessageMsgSetAuthorityBond, privateKey: string, fee: StdFee) {
|
async setAuthorityBond ({ bondId, name }: MessageMsgSetAuthorityBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -354,7 +367,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Commit auction bid.
|
* Commit auction bid.
|
||||||
*/
|
*/
|
||||||
async commitBid ({ auctionId, commitHash }: MessageMsgCommitBid, privateKey: string, fee: StdFee) {
|
async commitBid ({ auctionId, commitHash }: MessageMsgCommitBid, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -370,7 +383,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Reveal auction bid.
|
* Reveal auction bid.
|
||||||
*/
|
*/
|
||||||
async revealBid ({ auctionId, reveal }: MessageMsgRevealBid, privateKey: string, fee: StdFee) {
|
async revealBid ({ auctionId, reveal }: MessageMsgRevealBid, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -406,7 +419,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Set name (LRN) to record ID (CID).
|
* Set name (LRN) to record ID (CID).
|
||||||
*/
|
*/
|
||||||
async setName ({ cid, lrn }: MessageMsgSetName, privateKey: string, fee: StdFee) {
|
async setName ({ cid, lrn }: MessageMsgSetName, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -429,7 +442,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Delete name (LRN) mapping.
|
* Delete name (LRN) mapping.
|
||||||
*/
|
*/
|
||||||
async deleteName ({ lrn }: MessageMsgDeleteName, privateKey: string, fee: StdFee) {
|
async deleteName ({ lrn }: MessageMsgDeleteName, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -440,14 +453,10 @@ export class Registry {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLaconicClient (account: Account) {
|
|
||||||
return LaconicClient.connectWithSigner(this._endpoints.rpc, account.wallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Onboard participant.
|
* Onboard participant.
|
||||||
*/
|
*/
|
||||||
async onboardParticipant ({ ethPayload, ethSignature, role, kycId }: MessageMsgOnboardParticipant, privateKey: string, fee: StdFee): Promise<MsgOnboardParticipantResponse> {
|
async onboardParticipant ({ ethPayload, ethSignature, role, kycId }: MessageMsgOnboardParticipant, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgOnboardParticipantResponse> {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@@ -482,9 +491,18 @@ export class Registry {
|
|||||||
async getParticipantByNitroAddress (nitroAddress: string) {
|
async getParticipantByNitroAddress (nitroAddress: string) {
|
||||||
return this._client.getParticipantByNitroAddress(nitroAddress);
|
return this._client.getParticipantByNitroAddress(nitroAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getLaconicClient (account: Account) {
|
||||||
|
return LaconicClient.connectWithSigner(
|
||||||
|
this._endpoints.rpc,
|
||||||
|
account.wallet,
|
||||||
|
{ gasPrice: this._gasPrice }
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Account };
|
export { Account };
|
||||||
export { LaconicClient };
|
export { LaconicClient };
|
||||||
|
export * from './constants';
|
||||||
export * from './types/cerc/bond/message';
|
export * from './types/cerc/bond/message';
|
||||||
export * from './types/cerc/onboarding/message';
|
export * from './types/cerc/onboarding/message';
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { MsgCancelBondEncodeObject, MsgCreateBondEncodeObject, MsgRefillBondEnco
|
|||||||
import { Coin } from './proto/cosmos/base/v1beta1/coin';
|
import { Coin } from './proto/cosmos/base/v1beta1/coin';
|
||||||
import { MsgAssociateBondEncodeObject, MsgDeleteNameEncodeObject, MsgDissociateBondEncodeObject, MsgDissociateRecordsEncodeObject, MsgReassociateRecordsEncodeObject, MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, MsgSetNameEncodeObject, MsgSetRecordEncodeObject, registryTypes, typeUrlMsgAssociateBond, typeUrlMsgDeleteName, typeUrlMsgDissociateBond, typeUrlMsgDissociateRecords, typeUrlMsgReassociateRecords, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond, typeUrlMsgSetName, typeUrlMsgSetRecord, NAMESERVICE_ERRORS } from './types/cerc/registry/message';
|
import { MsgAssociateBondEncodeObject, MsgDeleteNameEncodeObject, MsgDissociateBondEncodeObject, MsgDissociateRecordsEncodeObject, MsgReassociateRecordsEncodeObject, MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, MsgSetNameEncodeObject, MsgSetRecordEncodeObject, registryTypes, typeUrlMsgAssociateBond, typeUrlMsgDeleteName, typeUrlMsgDissociateBond, typeUrlMsgDissociateRecords, typeUrlMsgReassociateRecords, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond, typeUrlMsgSetName, typeUrlMsgSetRecord, NAMESERVICE_ERRORS } from './types/cerc/registry/message';
|
||||||
import { MsgCommitBidEncodeObject, MsgRevealBidEncodeObject, auctionTypes, typeUrlMsgCommitBid, typeUrlMsgRevealBid } from './types/cerc/auction/message';
|
import { MsgCommitBidEncodeObject, MsgRevealBidEncodeObject, auctionTypes, typeUrlMsgCommitBid, typeUrlMsgRevealBid } from './types/cerc/auction/message';
|
||||||
import { MsgOnboardParticipantEncodeObject, onboardingTypes, typeUrlMsgOnboardParticipant } from './types/cerc/onboarding/message';
|
import { MsgOnboardParticipantEncodeObject, ONBOARDING_DISABLED_ERROR, onboardingTypes, typeUrlMsgOnboardParticipant } from './types/cerc/onboarding/message';
|
||||||
import { MsgAssociateBondResponse, MsgDeleteNameResponse, MsgDissociateBondResponse, MsgDissociateRecordsResponse, MsgReassociateRecordsResponse, MsgReserveAuthorityResponse, MsgSetAuthorityBondResponse, MsgSetNameResponse, MsgSetRecordResponse, Payload } from './proto/cerc/registry/v1/tx';
|
import { MsgAssociateBondResponse, MsgDeleteNameResponse, MsgDissociateBondResponse, MsgDissociateRecordsResponse, MsgReassociateRecordsResponse, MsgReserveAuthorityResponse, MsgSetAuthorityBondResponse, MsgSetNameResponse, MsgSetRecordResponse, Payload } from './proto/cerc/registry/v1/tx';
|
||||||
import { Record, Signature } from './proto/cerc/registry/v1/registry';
|
import { Record, Signature } from './proto/cerc/registry/v1/registry';
|
||||||
import { Account } from './account';
|
import { Account } from './account';
|
||||||
@@ -381,7 +381,7 @@ export class LaconicClient extends SigningStargateClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processWriteError (error: string) {
|
processWriteError (error: string) {
|
||||||
const errorMessage = NAMESERVICE_ERRORS.find(message => error.includes(message));
|
const errorMessage = [...NAMESERVICE_ERRORS, ONBOARDING_DISABLED_ERROR].find(message => error.includes(message));
|
||||||
|
|
||||||
if (!errorMessage) {
|
if (!errorMessage) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const nameserviceExpiryTests = () => {
|
|||||||
let recordExpiryTime: Date;
|
let recordExpiryTime: Date;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
// Create bond.
|
// Create bond.
|
||||||
bondId = await registry.getNextBondId(privateKey);
|
bondId = await registry.getNextBondId(privateKey);
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ const namingTests = () => {
|
|||||||
let account: CosmosAccount;
|
let account: CosmosAccount;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
// Create bond.
|
// Create bond.
|
||||||
bondId = await registry.getNextBondId(privateKey);
|
bondId = await registry.getNextBondId(privateKey);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Wallet } from 'ethers';
|
|||||||
|
|
||||||
import { DirectSecp256k1Wallet, AccountData as CosmosAccount } from '@cosmjs/proto-signing';
|
import { DirectSecp256k1Wallet, AccountData as CosmosAccount } from '@cosmjs/proto-signing';
|
||||||
|
|
||||||
import { Registry, Account } from './index';
|
import { Registry, Account, ONBOARDING_DISABLED_ERROR } from './index';
|
||||||
import { getConfig } from './testing/helper';
|
import { getConfig } from './testing/helper';
|
||||||
import { Participant } from './proto/cerc/onboarding/v1/onboarding';
|
import { Participant } from './proto/cerc/onboarding/v1/onboarding';
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ const onboardingEnabledTests = () => {
|
|||||||
let expectedParticipants: Participant[] = [];
|
let expectedParticipants: Participant[] = [];
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
const mnemonic = Account.generateMnemonic();
|
const mnemonic = Account.generateMnemonic();
|
||||||
ethWallet = Wallet.fromMnemonic(mnemonic);
|
ethWallet = Wallet.fromMnemonic(mnemonic);
|
||||||
@@ -76,11 +76,10 @@ const onboardingDisabledTests = () => {
|
|||||||
let ethWallet: Wallet;
|
let ethWallet: Wallet;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Error on onboarding attempt.', async () => {
|
test('Error on onboarding attempt.', async () => {
|
||||||
const errorMsg = 'Validator onboarding is disabled: invalid request';
|
|
||||||
const mnemonic = Account.generateMnemonic();
|
const mnemonic = Account.generateMnemonic();
|
||||||
ethWallet = Wallet.fromMnemonic(mnemonic);
|
ethWallet = Wallet.fromMnemonic(mnemonic);
|
||||||
|
|
||||||
@@ -100,7 +99,7 @@ const onboardingDisabledTests = () => {
|
|||||||
kycId: DUMMY_KYC_ID
|
kycId: DUMMY_KYC_ID
|
||||||
}, privateKey, fee);
|
}, privateKey, fee);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
expect(error.toString()).toContain(errorMsg);
|
expect(error.toString()).toContain(ONBOARDING_DISABLED_ERROR);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1162,7 +1162,7 @@ export const RecordsList = {
|
|||||||
declare var self: any | undefined;
|
declare var self: any | undefined;
|
||||||
declare var window: any | undefined;
|
declare var window: any | undefined;
|
||||||
declare var global: any | undefined;
|
declare var global: any | undefined;
|
||||||
var globalThis: any = (() => {
|
var _globalThis: any = (() => {
|
||||||
if (typeof globalThis !== "undefined") return globalThis;
|
if (typeof globalThis !== "undefined") return globalThis;
|
||||||
if (typeof self !== "undefined") return self;
|
if (typeof self !== "undefined") return self;
|
||||||
if (typeof window !== "undefined") return window;
|
if (typeof window !== "undefined") return window;
|
||||||
@@ -1171,10 +1171,10 @@ var globalThis: any = (() => {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
function bytesFromBase64(b64: string): Uint8Array {
|
function bytesFromBase64(b64: string): Uint8Array {
|
||||||
if (globalThis.Buffer) {
|
if (_globalThis.Buffer) {
|
||||||
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
|
return Uint8Array.from(_globalThis.Buffer.from(b64, "base64"));
|
||||||
} else {
|
} else {
|
||||||
const bin = globalThis.atob(b64);
|
const bin = _globalThis.atob(b64);
|
||||||
const arr = new Uint8Array(bin.length);
|
const arr = new Uint8Array(bin.length);
|
||||||
for (let i = 0; i < bin.length; ++i) {
|
for (let i = 0; i < bin.length; ++i) {
|
||||||
arr[i] = bin.charCodeAt(i);
|
arr[i] = bin.charCodeAt(i);
|
||||||
@@ -1184,14 +1184,14 @@ function bytesFromBase64(b64: string): Uint8Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function base64FromBytes(arr: Uint8Array): string {
|
function base64FromBytes(arr: Uint8Array): string {
|
||||||
if (globalThis.Buffer) {
|
if (_globalThis.Buffer) {
|
||||||
return globalThis.Buffer.from(arr).toString("base64");
|
return _globalThis.Buffer.from(arr).toString("base64");
|
||||||
} else {
|
} else {
|
||||||
const bin: string[] = [];
|
const bin: string[] = [];
|
||||||
arr.forEach((byte) => {
|
arr.forEach((byte) => {
|
||||||
bin.push(String.fromCharCode(byte));
|
bin.push(String.fromCharCode(byte));
|
||||||
});
|
});
|
||||||
return globalThis.btoa(bin.join(""));
|
return _globalThis.btoa(bin.join(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ export const PageResponse = {
|
|||||||
declare var self: any | undefined;
|
declare var self: any | undefined;
|
||||||
declare var window: any | undefined;
|
declare var window: any | undefined;
|
||||||
declare var global: any | undefined;
|
declare var global: any | undefined;
|
||||||
var globalThis: any = (() => {
|
var _globalThis: any = (() => {
|
||||||
if (typeof globalThis !== "undefined") return globalThis;
|
if (typeof globalThis !== "undefined") return globalThis;
|
||||||
if (typeof self !== "undefined") return self;
|
if (typeof self !== "undefined") return self;
|
||||||
if (typeof window !== "undefined") return window;
|
if (typeof window !== "undefined") return window;
|
||||||
@@ -260,10 +260,10 @@ var globalThis: any = (() => {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
function bytesFromBase64(b64: string): Uint8Array {
|
function bytesFromBase64(b64: string): Uint8Array {
|
||||||
if (globalThis.Buffer) {
|
if (_globalThis.Buffer) {
|
||||||
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
|
return Uint8Array.from(_globalThis.Buffer.from(b64, "base64"));
|
||||||
} else {
|
} else {
|
||||||
const bin = globalThis.atob(b64);
|
const bin = _globalThis.atob(b64);
|
||||||
const arr = new Uint8Array(bin.length);
|
const arr = new Uint8Array(bin.length);
|
||||||
for (let i = 0; i < bin.length; ++i) {
|
for (let i = 0; i < bin.length; ++i) {
|
||||||
arr[i] = bin.charCodeAt(i);
|
arr[i] = bin.charCodeAt(i);
|
||||||
@@ -273,14 +273,14 @@ function bytesFromBase64(b64: string): Uint8Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function base64FromBytes(arr: Uint8Array): string {
|
function base64FromBytes(arr: Uint8Array): string {
|
||||||
if (globalThis.Buffer) {
|
if (_globalThis.Buffer) {
|
||||||
return globalThis.Buffer.from(arr).toString("base64");
|
return _globalThis.Buffer.from(arr).toString("base64");
|
||||||
} else {
|
} else {
|
||||||
const bin: string[] = [];
|
const bin: string[] = [];
|
||||||
arr.forEach((byte) => {
|
arr.forEach((byte) => {
|
||||||
bin.push(String.fromCharCode(byte));
|
bin.push(String.fromCharCode(byte));
|
||||||
});
|
});
|
||||||
return globalThis.btoa(bin.join(""));
|
return _globalThis.btoa(bin.join(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4324,7 +4324,7 @@ export const GeneratedCodeInfo_Annotation = {
|
|||||||
declare var self: any | undefined;
|
declare var self: any | undefined;
|
||||||
declare var window: any | undefined;
|
declare var window: any | undefined;
|
||||||
declare var global: any | undefined;
|
declare var global: any | undefined;
|
||||||
var globalThis: any = (() => {
|
var _globalThis: any = (() => {
|
||||||
if (typeof globalThis !== "undefined") return globalThis;
|
if (typeof globalThis !== "undefined") return globalThis;
|
||||||
if (typeof self !== "undefined") return self;
|
if (typeof self !== "undefined") return self;
|
||||||
if (typeof window !== "undefined") return window;
|
if (typeof window !== "undefined") return window;
|
||||||
@@ -4333,10 +4333,10 @@ var globalThis: any = (() => {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
function bytesFromBase64(b64: string): Uint8Array {
|
function bytesFromBase64(b64: string): Uint8Array {
|
||||||
if (globalThis.Buffer) {
|
if (_globalThis.Buffer) {
|
||||||
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
|
return Uint8Array.from(_globalThis.Buffer.from(b64, "base64"));
|
||||||
} else {
|
} else {
|
||||||
const bin = globalThis.atob(b64);
|
const bin = _globalThis.atob(b64);
|
||||||
const arr = new Uint8Array(bin.length);
|
const arr = new Uint8Array(bin.length);
|
||||||
for (let i = 0; i < bin.length; ++i) {
|
for (let i = 0; i < bin.length; ++i) {
|
||||||
arr[i] = bin.charCodeAt(i);
|
arr[i] = bin.charCodeAt(i);
|
||||||
@@ -4346,14 +4346,14 @@ function bytesFromBase64(b64: string): Uint8Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function base64FromBytes(arr: Uint8Array): string {
|
function base64FromBytes(arr: Uint8Array): string {
|
||||||
if (globalThis.Buffer) {
|
if (_globalThis.Buffer) {
|
||||||
return globalThis.Buffer.from(arr).toString("base64");
|
return _globalThis.Buffer.from(arr).toString("base64");
|
||||||
} else {
|
} else {
|
||||||
const bin: string[] = [];
|
const bin: string[] = [];
|
||||||
arr.forEach((byte) => {
|
arr.forEach((byte) => {
|
||||||
bin.push(String.fromCharCode(byte));
|
bin.push(String.fromCharCode(byte));
|
||||||
});
|
});
|
||||||
return globalThis.btoa(bin.join(""));
|
return _globalThis.btoa(bin.join(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+33
-10
@@ -241,13 +241,13 @@ export class RegistryClient {
|
|||||||
/**
|
/**
|
||||||
* Get records by attributes.
|
* Get records by attributes.
|
||||||
*/
|
*/
|
||||||
async queryRecords (attributes: { [key: string]: any }, all = false, refs = false) {
|
async queryRecords (attributes: { [key: string]: any }, all = false, refs = false, limit?: number, offset?: number) {
|
||||||
if (!attributes) {
|
if (!attributes) {
|
||||||
attributes = {};
|
attributes = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = `query ($attributes: [KeyValueInput!], $all: Boolean) {
|
const query = `query ($attributes: [KeyValueInput!], $all: Boolean, $limit: Int, $offset: Int) {
|
||||||
queryRecords(attributes: $attributes, all: $all) {
|
queryRecords(attributes: $attributes, all: $all, limit: $limit, offset: $offset) {
|
||||||
id
|
id
|
||||||
names
|
names
|
||||||
owners
|
owners
|
||||||
@@ -261,7 +261,9 @@ export class RegistryClient {
|
|||||||
|
|
||||||
const variables = {
|
const variables = {
|
||||||
attributes: Util.toGQLAttributes(attributes),
|
attributes: Util.toGQLAttributes(attributes),
|
||||||
all
|
all,
|
||||||
|
limit,
|
||||||
|
offset
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = (await this._graph(query)(variables)).queryRecords;
|
let result = (await this._graph(query)(variables)).queryRecords;
|
||||||
@@ -425,11 +427,11 @@ export class RegistryClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get bonds by attributes.
|
* Get bonds.
|
||||||
*/
|
*/
|
||||||
async queryBonds (attributes = {}) {
|
async queryBonds () {
|
||||||
const query = `query ($attributes: [KeyValueInput!]) {
|
const query = `query {
|
||||||
queryBonds(attributes: $attributes) {
|
queryBonds {
|
||||||
id
|
id
|
||||||
owner
|
owner
|
||||||
balance {
|
balance {
|
||||||
@@ -439,11 +441,32 @@ export class RegistryClient {
|
|||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
return RegistryClient.getResult(this._graph(query)({}), 'queryBonds');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get bonds by owner(s).
|
||||||
|
*/
|
||||||
|
async queryBondsByOwners (ownerAddresses: string[]) {
|
||||||
|
const query = `query ($ownerAddresses: [String!]) {
|
||||||
|
queryBondsByOwner(ownerAddresses: $ownerAddresses) {
|
||||||
|
owner
|
||||||
|
bonds {
|
||||||
|
id
|
||||||
|
owner
|
||||||
|
balance {
|
||||||
|
type
|
||||||
|
quantity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|
||||||
const variables = {
|
const variables = {
|
||||||
attributes: Util.toGQLAttributes(attributes)
|
ownerAddresses
|
||||||
};
|
};
|
||||||
|
|
||||||
return RegistryClient.getResult(this._graph(query)(variables), 'queryBonds');
|
return RegistryClient.getResult(this._graph(query)(variables), 'queryBondsByOwner');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ describe('Querying', () => {
|
|||||||
let bondId: string;
|
let bondId: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
bondId = await registry.getNextBondId(privateKey);
|
bondId = await registry.getNextBondId(privateKey);
|
||||||
await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, fee);
|
await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, fee);
|
||||||
|
|||||||
+16
-1
@@ -2,7 +2,9 @@ import assert from 'assert';
|
|||||||
import yaml from 'node-yaml';
|
import yaml from 'node-yaml';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
|
||||||
import { DEFAULT_CHAIN_ID } from '../index';
|
import { Account } from '../index';
|
||||||
|
|
||||||
|
const DEFAULT_CHAIN_ID = 'laconic_9000-1';
|
||||||
|
|
||||||
export const ensureUpdatedConfig = async (path: string) => {
|
export const ensureUpdatedConfig = async (path: string) => {
|
||||||
const conf = await yaml.read(path);
|
const conf = await yaml.read(path);
|
||||||
@@ -33,3 +35,16 @@ export const getConfig = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const createTestAccounts = async (numAccounts: number): Promise<Account[]> => {
|
||||||
|
const accounts: Account[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < numAccounts; i++) {
|
||||||
|
const mnemonic = Account.generateMnemonic();
|
||||||
|
const account = await Account.generateFromMnemonic(mnemonic);
|
||||||
|
await account.init();
|
||||||
|
accounts.push(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
return accounts;
|
||||||
|
};
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ export interface MsgOnboardParticipantEncodeObject extends EncodeObject {
|
|||||||
readonly value: MsgOnboardParticipant;
|
readonly value: MsgOnboardParticipant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ONBOARDING_DISABLED_ERROR = 'Onboarding is disabled';
|
||||||
|
|
||||||
interface ethPayload {
|
interface ethPayload {
|
||||||
address: string
|
address: string
|
||||||
msg: string
|
msg: string
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ const utilTests = () => {
|
|||||||
let watcherId: string;
|
let watcherId: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
||||||
|
|
||||||
// Create bond.
|
// Create bond.
|
||||||
bondId = await registry.getNextBondId(privateKey);
|
bondId = await registry.getNextBondId(privateKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user