Update methods to reassociate and dissociate record
This commit is contained in:
parent
cc2debc4a5
commit
bbccc2c2e3
@ -95,13 +95,12 @@ const bondTests = () => {
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Implement set record
|
||||
xtest('Associate/Dissociate bond.', async () => {
|
||||
test('Associate/Dissociate bond.', async () => {
|
||||
let bondId1: string;
|
||||
|
||||
bondId1 = await registry.getNextBondId(privateKey);
|
||||
expect(bondId1).toBeDefined();
|
||||
await registry.createBond({ denom: DENOM, amount: BOND_AMOUNT }, privateKey, laconic2Fee);
|
||||
await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, laconic2Fee);
|
||||
|
||||
// Create a new record.
|
||||
let watcher = await publishNewWatcherVersion(bondId1);
|
||||
@ -110,24 +109,23 @@ const bondTests = () => {
|
||||
expect(record1.bondId).toBe(bondId1);
|
||||
|
||||
// Dissociate record, query and confirm.
|
||||
await registry.dissociateBond({ recordId: record1.id }, privateKey, fee);
|
||||
await registry.dissociateBond({ recordId: record1.id }, privateKey, laconic2Fee);
|
||||
[record1] = await registry.queryRecords(query, true);
|
||||
expect(record1.bondId).toBe('');
|
||||
|
||||
// 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, laconic2Fee);
|
||||
[record1] = await registry.queryRecords(query, true);
|
||||
expect(record1.bondId).toBe(bondId1);
|
||||
});
|
||||
|
||||
// TODO: Implement set record
|
||||
xtest('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: DENOM, amount: BOND_AMOUNT }, privateKey, laconic2Fee);
|
||||
await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, laconic2Fee);
|
||||
|
||||
// Create a new record version.
|
||||
let watcher = await publishNewWatcherVersion(bondId1);
|
||||
@ -144,19 +142,19 @@ const bondTests = () => {
|
||||
// Create another bond.
|
||||
bondId2 = await registry.getNextBondId(privateKey);
|
||||
expect(bondId2).toBeDefined();
|
||||
await registry.createBond({ denom: DENOM, amount: BOND_AMOUNT }, privateKey, laconic2Fee);
|
||||
await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, laconic2Fee);
|
||||
const [bond] = await registry.getBondsByIds([bondId2]);
|
||||
expect(bond.id).toBe(bondId2);
|
||||
|
||||
// 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, laconic2Fee);
|
||||
records = await registry.queryRecords(queryv1, true);
|
||||
expect(records[0].bondId).toBe(bondId2);
|
||||
records = await registry.queryRecords(queryv2, true);
|
||||
expect(records[0].bondId).toBe(bondId2);
|
||||
|
||||
// Dissociate all records from bond, verify change.
|
||||
await registry.dissociateRecords({ bondId: bondId2 }, privateKey, fee);
|
||||
await registry.dissociateRecords({ bondId: bondId2 }, privateKey, laconic2Fee);
|
||||
records = await registry.queryRecords(queryv1, true);
|
||||
expect(records[0].bondId).toBe('');
|
||||
records = await registry.queryRecords(queryv2, true);
|
||||
|
31
src/index.ts
31
src/index.ts
@ -354,29 +354,36 @@ export class Registry {
|
||||
/**
|
||||
* Dissociate all records from bond.
|
||||
*/
|
||||
async dissociateRecords (params: MessageMsgDissociateRecords, privateKey: string, fee: Fee) {
|
||||
let result;
|
||||
async dissociateRecords ({ bondId }: MessageMsgDissociateRecords, privateKey: string, fee: StdFee) {
|
||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||
const sender = await this._getSender(account);
|
||||
await account.init();
|
||||
const laconicClient = await this.getLaconicClient(account);
|
||||
|
||||
const msg = createTxMsgDissociateRecords(this._chain, sender, fee, '', params);
|
||||
result = await this._submitTx(msg, privateKey, sender);
|
||||
const response: DeliverTxResponse = await laconicClient.dissociateRecords(
|
||||
account.address,
|
||||
bondId,
|
||||
fee
|
||||
);
|
||||
|
||||
return parseTxResponse(result);
|
||||
return laconicClient.registry.decode(response.msgResponses[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reassociate records (switch bond).
|
||||
*/
|
||||
async reassociateRecords (params: MessageMsgReAssociateRecords, privateKey: string, fee: Fee) {
|
||||
let result;
|
||||
async reassociateRecords ({ newBondId, oldBondId }: MessageMsgReAssociateRecords, privateKey: string, fee: StdFee) {
|
||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||
const sender = await this._getSender(account);
|
||||
await account.init();
|
||||
const laconicClient = await this.getLaconicClient(account);
|
||||
|
||||
const msg = createTxMsgReAssociateRecords(this._chain, sender, fee, '', params);
|
||||
result = await this._submitTx(msg, privateKey, sender);
|
||||
const response: DeliverTxResponse = await laconicClient.reassociateRecords(
|
||||
account.address,
|
||||
oldBondId,
|
||||
newBondId,
|
||||
fee
|
||||
);
|
||||
|
||||
return parseTxResponse(result);
|
||||
return laconicClient.registry.decode(response.msgResponses[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ import { Comet38Client } from '@cosmjs/tendermint-rpc';
|
||||
|
||||
import { MsgCancelBondEncodeObject, MsgCreateBondEncodeObject, MsgRefillBondEncodeObject, MsgWithdrawBondEncodeObject, bondTypes, typeUrlMsgCancelBond, typeUrlMsgCreateBond, typeUrlMsgRefillBond, typeUrlMsgWithdrawBond } from './types/cerc/bond/message';
|
||||
import { Coin } from './proto2/cosmos/base/v1beta1/coin';
|
||||
import { MsgDeleteNameAuthorityEncodeObject, MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, MsgSetNameEncodeObject, MsgSetRecordEncodeObject, registryTypes, typeUrlMsgDeleteNameAuthority, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond, typeUrlMsgSetName, typeUrlMsgSetRecord } from './types/cerc/registry/message';
|
||||
import { MsgAssociateBondEncodeObject, MsgDeleteNameAuthorityEncodeObject, MsgDissociateBondEncodeObject, MsgDissociateRecordsEncodeObject, MsgReassociateRecordsEncodeObject, MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, MsgSetNameEncodeObject, MsgSetRecordEncodeObject, registryTypes, typeUrlMsgAssociateBond, typeUrlMsgDeleteNameAuthority, typeUrlMsgDissociateBond, typeUrlMsgDissociateRecords, typeUrlMsgReassociateRecords, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond, typeUrlMsgSetName, typeUrlMsgSetRecord } from './types/cerc/registry/message';
|
||||
import { MsgCommitBidEncodeObject, MsgRevealBidEncodeObject, auctionTypes, typeUrlMsgCommitBid, typeUrlMsgRevealBid } from './types/cerc/auction/message';
|
||||
import { Payload } from './proto2/cerc/registry/v1/tx';
|
||||
import { Record, Signature } from './proto2/cerc/registry/v1/registry';
|
||||
@ -168,6 +168,42 @@ export class LaconicClient extends SigningStargateClient {
|
||||
return this.signAndBroadcast(signer, [createMsg], fee, memo);
|
||||
}
|
||||
|
||||
public async dissociateRecords (
|
||||
signer: string,
|
||||
bondId: string,
|
||||
fee: StdFee | 'auto' | number,
|
||||
memo = ''
|
||||
): Promise<DeliverTxResponse> {
|
||||
const createMsg: MsgDissociateRecordsEncodeObject = {
|
||||
typeUrl: typeUrlMsgDissociateRecords,
|
||||
value: {
|
||||
signer,
|
||||
bondId
|
||||
}
|
||||
};
|
||||
|
||||
return this.signAndBroadcast(signer, [createMsg], fee, memo);
|
||||
}
|
||||
|
||||
public async reassociateRecords (
|
||||
signer: string,
|
||||
oldBondId: string,
|
||||
newBondId: string,
|
||||
fee: StdFee | 'auto' | number,
|
||||
memo = ''
|
||||
): Promise<DeliverTxResponse> {
|
||||
const createMsg: MsgReassociateRecordsEncodeObject = {
|
||||
typeUrl: typeUrlMsgReassociateRecords,
|
||||
value: {
|
||||
signer,
|
||||
oldBondId,
|
||||
newBondId
|
||||
}
|
||||
};
|
||||
|
||||
return this.signAndBroadcast(signer, [createMsg], fee, memo);
|
||||
}
|
||||
|
||||
public async reserveAuthority (
|
||||
signer: string,
|
||||
name: string,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing';
|
||||
|
||||
import { MsgReserveAuthority, MsgReserveAuthorityResponse, MsgSetAuthorityBond, MsgSetAuthorityBondResponse, MsgSetRecord, MsgSetRecordResponse, MsgSetName, MsgSetNameResponse, MsgDeleteNameAuthority, MsgDeleteNameAuthorityResponse } from '../../../proto2/cerc/registry/v1/tx';
|
||||
import { MsgReserveAuthority, MsgReserveAuthorityResponse, MsgSetAuthorityBond, MsgSetAuthorityBondResponse, MsgSetRecord, MsgSetRecordResponse, MsgSetName, MsgSetNameResponse, MsgDeleteNameAuthority, MsgDeleteNameAuthorityResponse, MsgAssociateBond, MsgAssociateBondResponse, MsgDissociateBond, MsgDissociateBondResponse, MsgDissociateRecords, MsgReassociateRecords, MsgDissociateRecordsResponse, MsgReassociateRecordsResponse } from '../../../proto2/cerc/registry/v1/tx';
|
||||
|
||||
export const typeUrlMsgReserveAuthority = '/cerc.registry.v1.MsgReserveAuthority';
|
||||
export const typeUrlMsgSetRecord = '/cerc.registry.v1.MsgSetRecord';
|
||||
@ -16,6 +16,10 @@ export const typeUrlMsgAssociateBond = '/cerc.registry.v1.MsgAssociateBond';
|
||||
export const typeUrlMsgDissociateBond = '/cerc.registry.v1.MsgDissociateBond';
|
||||
export const typeUrlMsgAssociateBondResponse = '/cerc.registry.v1.MsgAssociateBondResponse';
|
||||
export const typeUrlMsgDissociateBondResponse = '/cerc.registry.v1.MsgDissociateBondResponse';
|
||||
export const typeUrlMsgDissociateRecords = '/cerc.registry.v1.MsgDissociateRecords';
|
||||
export const typeUrlMsgReassociateRecords = '/cerc.registry.v1.MsgReassociateRecords';
|
||||
export const typeUrlMsgDissociateRecordsResponse = '/cerc.registry.v1.MsgDissociateRecordsResponse';
|
||||
export const typeUrlMsgReassociateRecordsResponse = '/cerc.registry.v1.MsgReassociateRecordsResponse';
|
||||
|
||||
export const registryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
[typeUrlMsgReserveAuthority, MsgReserveAuthority],
|
||||
@ -32,6 +36,10 @@ export const registryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
[typeUrlMsgAssociateBondResponse, MsgAssociateBondResponse],
|
||||
[typeUrlMsgDissociateBond, MsgDissociateBond],
|
||||
[typeUrlMsgDissociateBondResponse, MsgDissociateBondResponse],
|
||||
[typeUrlMsgDissociateRecords, MsgDissociateRecords],
|
||||
[typeUrlMsgReassociateRecords, MsgReassociateRecords],
|
||||
[typeUrlMsgDissociateRecordsResponse, MsgDissociateRecordsResponse],
|
||||
[typeUrlMsgReassociateRecordsResponse, MsgReassociateRecordsResponse]
|
||||
];
|
||||
|
||||
export interface MsgReserveAuthorityEncodeObject extends EncodeObject {
|
||||
@ -68,3 +76,13 @@ export interface MsgDissociateBondEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: '/cerc.registry.v1.MsgDissociateBond';
|
||||
readonly value: Partial<MsgDissociateBond>;
|
||||
}
|
||||
|
||||
export interface MsgDissociateRecordsEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: '/cerc.registry.v1.MsgDissociateRecords';
|
||||
readonly value: Partial<MsgDissociateRecords>;
|
||||
}
|
||||
|
||||
export interface MsgReassociateRecordsEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: '/cerc.registry.v1.MsgReassociateRecords';
|
||||
readonly value: Partial<MsgReassociateRecords>;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user