Update methods for set name and delete name
This commit is contained in:
parent
cb6d4014ee
commit
562fa4c235
36
src/index.ts
36
src/index.ts
@ -200,7 +200,7 @@ export class Registry {
|
||||
fee
|
||||
);
|
||||
|
||||
return response;
|
||||
return laconicClient.registry.decode(response.msgResponses[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -474,15 +474,20 @@ export class Registry {
|
||||
/**
|
||||
* Set name (CRN) to record ID (CID).
|
||||
*/
|
||||
async setName (params: MessageMsgSetName, privateKey: string, fee: Fee) {
|
||||
let result;
|
||||
async setName ({ cid, crn }: MessageMsgSetName, 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 = createTxMsgSetName(this._chain, sender, fee, '', params);
|
||||
result = await this._submitTx(msg, privateKey, sender);
|
||||
const response: DeliverTxResponse = await laconicClient.setName(
|
||||
account.address,
|
||||
crn,
|
||||
cid,
|
||||
fee
|
||||
);
|
||||
|
||||
return parseTxResponse(result);
|
||||
// TODO: Parse error response
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -495,15 +500,18 @@ export class Registry {
|
||||
/**
|
||||
* Delete name (CRN) mapping.
|
||||
*/
|
||||
async deleteName (params: MessageMsgDeleteName, privateKey: string, fee: Fee) {
|
||||
let result;
|
||||
async deleteName ({ crn }: MessageMsgDeleteName, 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 response: DeliverTxResponse = await laconicClient.deleteName(
|
||||
account.address,
|
||||
crn,
|
||||
fee
|
||||
);
|
||||
|
||||
const msg = createTxMsgDeleteName(this._chain, sender, fee, '', params);
|
||||
result = await this._submitTx(msg, privateKey, sender);
|
||||
|
||||
return parseTxResponse(result);
|
||||
// TODO: Parse error response form delete name
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 { MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, MsgSetRecordEncodeObject, registryTypes, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond, typeUrlMsgSetRecord } from './types/cerc/registry/message';
|
||||
import { MsgDeleteNameAuthorityEncodeObject, MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, MsgSetNameEncodeObject, MsgSetRecordEncodeObject, registryTypes, typeUrlMsgDeleteNameAuthority, 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';
|
||||
@ -237,4 +237,40 @@ export class LaconicClient extends SigningStargateClient {
|
||||
|
||||
return this.signAndBroadcast(signer, [createMsg], fee, memo);
|
||||
}
|
||||
|
||||
public async setName (
|
||||
signer: string,
|
||||
lrn: string,
|
||||
cid: string,
|
||||
fee: StdFee | 'auto' | number,
|
||||
memo = ''
|
||||
): Promise<DeliverTxResponse> {
|
||||
const createMsg: MsgSetNameEncodeObject = {
|
||||
typeUrl: typeUrlMsgSetName,
|
||||
value: {
|
||||
signer,
|
||||
lrn,
|
||||
cid
|
||||
}
|
||||
};
|
||||
|
||||
return this.signAndBroadcast(signer, [createMsg], fee, memo);
|
||||
}
|
||||
|
||||
public async deleteName (
|
||||
signer: string,
|
||||
lrn: string,
|
||||
fee: StdFee | 'auto' | number,
|
||||
memo = ''
|
||||
): Promise<DeliverTxResponse> {
|
||||
const createMsg: MsgDeleteNameAuthorityEncodeObject = {
|
||||
typeUrl: typeUrlMsgDeleteNameAuthority,
|
||||
value: {
|
||||
signer,
|
||||
lrn
|
||||
}
|
||||
};
|
||||
|
||||
return this.signAndBroadcast(signer, [createMsg], fee, memo);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ describe('Querying', () => {
|
||||
bondId = await registry.getNextBondId(privateKey);
|
||||
await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, laconic2Fee);
|
||||
|
||||
// TODO: Implement set record
|
||||
const publishNewWatcherVersion = async () => {
|
||||
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
||||
await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, laconic2Fee);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing';
|
||||
|
||||
import { MsgReserveAuthority, MsgReserveAuthorityResponse, MsgSetAuthorityBond, MsgSetAuthorityBondResponse, MsgSetRecord, MsgSetRecordResponse } from '../../../proto2/cerc/registry/v1/tx';
|
||||
import { MsgReserveAuthority, MsgReserveAuthorityResponse, MsgSetAuthorityBond, MsgSetAuthorityBondResponse, MsgSetRecord, MsgSetRecordResponse, MsgSetName, MsgSetNameResponse, MsgDeleteNameAuthority, MsgDeleteNameAuthorityResponse } from '../../../proto2/cerc/registry/v1/tx';
|
||||
|
||||
export const typeUrlMsgReserveAuthority = '/cerc.registry.v1.MsgReserveAuthority';
|
||||
export const typeUrlMsgSetRecord = '/cerc.registry.v1.MsgSetRecord';
|
||||
@ -8,6 +8,10 @@ export const typeUrlMsgSetAuthorityBond = '/cerc.registry.v1.MsgSetAuthorityBond
|
||||
export const typeUrlMsgReserveAuthorityResponse = '/cerc.registry.v1.MsgReserveAuthorityResponse';
|
||||
export const typeUrlMsgSetRecordResponse = '/cerc.registry.v1.MsgSetRecordResponse';
|
||||
export const typeUrlMsgSetAuthorityBondResponse = '/cerc.registry.v1.MsgSetAuthorityBondResponse';
|
||||
export const typeUrlMsgSetName = '/cerc.registry.v1.MsgSetName';
|
||||
export const typeUrlMsgSetNameResponse = '/cerc.registry.v1.MsgSetNameResponse';
|
||||
export const typeUrlMsgDeleteNameAuthority = '/cerc.registry.v1.MsgDeleteNameAuthority';
|
||||
export const typeUrlMsgDeleteNameAuthorityResponse = '/cerc.registry.v1.MsgDeleteNameAuthorityResponse';
|
||||
|
||||
export const registryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
[typeUrlMsgReserveAuthority, MsgReserveAuthority],
|
||||
@ -15,7 +19,11 @@ export const registryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
[typeUrlMsgSetRecord, MsgSetRecord],
|
||||
[typeUrlMsgSetRecordResponse, MsgSetRecordResponse],
|
||||
[typeUrlMsgSetAuthorityBond, MsgSetAuthorityBond],
|
||||
[typeUrlMsgSetAuthorityBondResponse, MsgSetAuthorityBondResponse]
|
||||
[typeUrlMsgSetAuthorityBondResponse, MsgSetAuthorityBondResponse],
|
||||
[typeUrlMsgSetName, MsgSetName],
|
||||
[typeUrlMsgSetNameResponse, MsgSetNameResponse],
|
||||
[typeUrlMsgDeleteNameAuthority, MsgDeleteNameAuthority],
|
||||
[typeUrlMsgDeleteNameAuthorityResponse, MsgDeleteNameAuthorityResponse]
|
||||
];
|
||||
|
||||
export interface MsgReserveAuthorityEncodeObject extends EncodeObject {
|
||||
@ -32,3 +40,13 @@ export interface MsgSetAuthorityBondEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: '/cerc.registry.v1.MsgSetAuthorityBond';
|
||||
readonly value: Partial<MsgSetAuthorityBond>;
|
||||
}
|
||||
|
||||
export interface MsgSetNameEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: '/cerc.registry.v1.MsgSetName';
|
||||
readonly value: Partial<MsgSetName>;
|
||||
}
|
||||
|
||||
export interface MsgDeleteNameAuthorityEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: '/cerc.registry.v1.MsgDeleteNameAuthority';
|
||||
readonly value: Partial<MsgDeleteNameAuthority>;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user