Update methods to associate and dissociate bond
This commit is contained in:
parent
227cd3d318
commit
cc2debc4a5
31
src/index.ts
31
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]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<DeliverTxResponse> {
|
||||
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<DeliverTxResponse> {
|
||||
const createMsg: MsgDissociateBondEncodeObject = {
|
||||
typeUrl: typeUrlMsgDissociateBond,
|
||||
value: {
|
||||
recordId,
|
||||
signer
|
||||
}
|
||||
};
|
||||
|
||||
return this.signAndBroadcast(signer, [createMsg], fee, memo);
|
||||
}
|
||||
|
||||
public async reserveAuthority (
|
||||
signer: string,
|
||||
name: string,
|
||||
|
@ -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<MsgDeleteNameAuthority>;
|
||||
}
|
||||
|
||||
export interface MsgAssociateBondEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: '/cerc.registry.v1.MsgAssociateBond';
|
||||
readonly value: Partial<MsgAssociateBond>;
|
||||
}
|
||||
|
||||
export interface MsgDissociateBondEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: '/cerc.registry.v1.MsgDissociateBond';
|
||||
readonly value: Partial<MsgDissociateBond>;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user