Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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.8",
|
||||||
"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",
|
||||||
|
|||||||
+11
-6
@@ -54,15 +54,20 @@ 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 [result] = await registry.queryBondsByOwner([bond1.owner]);
|
||||||
expect(bonds).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
|
expect(result.bonds).toBeDefined();
|
||||||
expect(bond).toBeDefined();
|
|
||||||
|
const filteredBonds = result.bonds.filter((bond: any) => bond.id === bond1.id);
|
||||||
|
expect(filteredBonds).toHaveLength(1);
|
||||||
|
expect(filteredBonds[0]).toMatchObject({ id: bond1.id, owner: bond1.owner });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Refill bond.', async () => {
|
test('Refill bond.', async () => {
|
||||||
|
|||||||
+12
-5
@@ -107,8 +107,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,10 +186,17 @@ 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 queryBondsByOwner (owners: string[]) {
|
||||||
|
return this._client.queryBondsByOwner(owners);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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';
|
||||||
|
|
||||||
@@ -80,7 +80,6 @@ const onboardingDisabledTests = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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 queryBondsByOwner (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');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user