diff --git a/src/index.ts b/src/index.ts index 0e1b0d1..a680b48 100644 --- a/src/index.ts +++ b/src/index.ts @@ -319,29 +319,36 @@ export class Registry { /** * Associate record with bond. */ - async associateBond (params: MessageMsgAssociateBond, privateKey: string, fee: Fee) { - let result; + async associateBond ({ bondId, recordId }: MessageMsgAssociateBond, 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 = createTxMsgAssociateBond(this._chain, sender, fee, '', params); - result = await this._submitTx(msg, privateKey, sender); + const response: DeliverTxResponse = await laconicClient.associateBond( + account.address, + recordId, + bondId, + fee + ); - return parseTxResponse(result); + return laconicClient.registry.decode(response.msgResponses[0]); } /** * Dissociate record from bond. */ - async dissociateBond (params: MessageMsgDissociateBond, privateKey: string, fee: Fee) { - let result; + async dissociateBond ({ recordId }: MessageMsgDissociateBond, 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 = createTxMsgDissociateBond(this._chain, sender, fee, '', params); - result = await this._submitTx(msg, privateKey, sender); + const response: DeliverTxResponse = await laconicClient.dissociateBond( + account.address, + recordId, + fee + ); - return parseTxResponse(result); + return laconicClient.registry.decode(response.msgResponses[0]); } /** diff --git a/src/laconic-client.ts b/src/laconic-client.ts index f62f69a..d0e7c81 100644 --- a/src/laconic-client.ts +++ b/src/laconic-client.ts @@ -132,6 +132,42 @@ export class LaconicClient extends SigningStargateClient { return this.signAndBroadcast(signer, [createMsg], fee, memo); } + public async associateBond ( + signer: string, + recordId: string, + bondId: string, + fee: StdFee | 'auto' | number, + memo = '' + ): Promise { + const createMsg: MsgAssociateBondEncodeObject = { + typeUrl: typeUrlMsgAssociateBond, + value: { + recordId, + bondId, + signer + } + }; + + return this.signAndBroadcast(signer, [createMsg], fee, memo); + } + + public async dissociateBond ( + signer: string, + recordId: string, + fee: StdFee | 'auto' | number, + memo = '' + ): Promise { + const createMsg: MsgDissociateBondEncodeObject = { + typeUrl: typeUrlMsgDissociateBond, + value: { + recordId, + signer + } + }; + + return this.signAndBroadcast(signer, [createMsg], fee, memo); + } + public async reserveAuthority ( signer: string, name: string, diff --git a/src/types/cerc/registry/message.ts b/src/types/cerc/registry/message.ts index 7bb81d4..3bdee6f 100644 --- a/src/types/cerc/registry/message.ts +++ b/src/types/cerc/registry/message.ts @@ -12,6 +12,10 @@ 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 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 registryTypes: ReadonlyArray<[string, GeneratedType]> = [ [typeUrlMsgReserveAuthority, MsgReserveAuthority], @@ -23,7 +27,11 @@ export const registryTypes: ReadonlyArray<[string, GeneratedType]> = [ [typeUrlMsgSetName, MsgSetName], [typeUrlMsgSetNameResponse, MsgSetNameResponse], [typeUrlMsgDeleteNameAuthority, MsgDeleteNameAuthority], - [typeUrlMsgDeleteNameAuthorityResponse, MsgDeleteNameAuthorityResponse] + [typeUrlMsgDeleteNameAuthorityResponse, MsgDeleteNameAuthorityResponse], + [typeUrlMsgAssociateBond, MsgAssociateBond], + [typeUrlMsgAssociateBondResponse, MsgAssociateBondResponse], + [typeUrlMsgDissociateBond, MsgDissociateBond], + [typeUrlMsgDissociateBondResponse, MsgDissociateBondResponse], ]; export interface MsgReserveAuthorityEncodeObject extends EncodeObject { @@ -50,3 +58,13 @@ export interface MsgDeleteNameAuthorityEncodeObject extends EncodeObject { readonly typeUrl: '/cerc.registry.v1.MsgDeleteNameAuthority'; readonly value: Partial; } + +export interface MsgAssociateBondEncodeObject extends EncodeObject { + readonly typeUrl: '/cerc.registry.v1.MsgAssociateBond'; + readonly value: Partial; +} + +export interface MsgDissociateBondEncodeObject extends EncodeObject { + readonly typeUrl: '/cerc.registry.v1.MsgDissociateBond'; + readonly value: Partial; +}