Update registry SDK record methods to use cosmjs #2

Merged
nabarun merged 7 commits from nv-check-remaining-tests into main 2024-03-11 08:51:01 +00:00
4 changed files with 79 additions and 18 deletions
Showing only changes of commit 562fa4c235 - Show all commits

View File

@ -200,7 +200,7 @@ export class Registry {
fee fee
); );
return response; return laconicClient.registry.decode(response.msgResponses[0]);
} }
/** /**
@ -474,15 +474,20 @@ export class Registry {
/** /**
* Set name (CRN) to record ID (CID). * Set name (CRN) to record ID (CID).
*/ */
async setName (params: MessageMsgSetName, privateKey: string, fee: Fee) { async setName ({ cid, crn }: MessageMsgSetName, privateKey: string, fee: StdFee) {
let result;
const account = new Account(Buffer.from(privateKey, 'hex')); 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); const response: DeliverTxResponse = await laconicClient.setName(
result = await this._submitTx(msg, privateKey, sender); 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. * Delete name (CRN) mapping.
*/ */
async deleteName (params: MessageMsgDeleteName, privateKey: string, fee: Fee) { async deleteName ({ crn }: MessageMsgDeleteName, privateKey: string, fee: StdFee) {
let result;
const account = new Account(Buffer.from(privateKey, 'hex')); 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); // TODO: Parse error response form delete name
result = await this._submitTx(msg, privateKey, sender); return response;
return parseTxResponse(result);
} }
/** /**

View File

@ -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 { MsgCancelBondEncodeObject, MsgCreateBondEncodeObject, MsgRefillBondEncodeObject, MsgWithdrawBondEncodeObject, bondTypes, typeUrlMsgCancelBond, typeUrlMsgCreateBond, typeUrlMsgRefillBond, typeUrlMsgWithdrawBond } from './types/cerc/bond/message';
import { Coin } from './proto2/cosmos/base/v1beta1/coin'; 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 { MsgCommitBidEncodeObject, MsgRevealBidEncodeObject, auctionTypes, typeUrlMsgCommitBid, typeUrlMsgRevealBid } from './types/cerc/auction/message';
import { Payload } from './proto2/cerc/registry/v1/tx'; import { Payload } from './proto2/cerc/registry/v1/tx';
import { Record, Signature } from './proto2/cerc/registry/v1/registry'; 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); 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);
}
} }

View File

@ -22,7 +22,6 @@ describe('Querying', () => {
bondId = await registry.getNextBondId(privateKey); bondId = await registry.getNextBondId(privateKey);
await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, laconic2Fee); await registry.createBond({ denom: DENOM, amount: '1000000000' }, privateKey, laconic2Fee);
// TODO: Implement set record
const publishNewWatcherVersion = async () => { const publishNewWatcherVersion = async () => {
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH); watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, laconic2Fee); await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, laconic2Fee);

View File

@ -1,6 +1,6 @@
import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing'; 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 typeUrlMsgReserveAuthority = '/cerc.registry.v1.MsgReserveAuthority';
export const typeUrlMsgSetRecord = '/cerc.registry.v1.MsgSetRecord'; 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 typeUrlMsgReserveAuthorityResponse = '/cerc.registry.v1.MsgReserveAuthorityResponse';
export const typeUrlMsgSetRecordResponse = '/cerc.registry.v1.MsgSetRecordResponse'; export const typeUrlMsgSetRecordResponse = '/cerc.registry.v1.MsgSetRecordResponse';
export const typeUrlMsgSetAuthorityBondResponse = '/cerc.registry.v1.MsgSetAuthorityBondResponse'; 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]> = [ export const registryTypes: ReadonlyArray<[string, GeneratedType]> = [
[typeUrlMsgReserveAuthority, MsgReserveAuthority], [typeUrlMsgReserveAuthority, MsgReserveAuthority],
@ -15,7 +19,11 @@ export const registryTypes: ReadonlyArray<[string, GeneratedType]> = [
[typeUrlMsgSetRecord, MsgSetRecord], [typeUrlMsgSetRecord, MsgSetRecord],
[typeUrlMsgSetRecordResponse, MsgSetRecordResponse], [typeUrlMsgSetRecordResponse, MsgSetRecordResponse],
[typeUrlMsgSetAuthorityBond, MsgSetAuthorityBond], [typeUrlMsgSetAuthorityBond, MsgSetAuthorityBond],
[typeUrlMsgSetAuthorityBondResponse, MsgSetAuthorityBondResponse] [typeUrlMsgSetAuthorityBondResponse, MsgSetAuthorityBondResponse],
[typeUrlMsgSetName, MsgSetName],
[typeUrlMsgSetNameResponse, MsgSetNameResponse],
[typeUrlMsgDeleteNameAuthority, MsgDeleteNameAuthority],
[typeUrlMsgDeleteNameAuthorityResponse, MsgDeleteNameAuthorityResponse]
]; ];
export interface MsgReserveAuthorityEncodeObject extends EncodeObject { export interface MsgReserveAuthorityEncodeObject extends EncodeObject {
@ -32,3 +40,13 @@ export interface MsgSetAuthorityBondEncodeObject extends EncodeObject {
readonly typeUrl: '/cerc.registry.v1.MsgSetAuthorityBond'; readonly typeUrl: '/cerc.registry.v1.MsgSetAuthorityBond';
readonly value: Partial<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>;
}