Update bond-record association methods to use cosmjs #3
31
src/index.ts
31
src/index.ts
@ -319,29 +319,36 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Associate record with bond.
|
* Associate record with bond.
|
||||||
*/
|
*/
|
||||||
async associateBond (params: MessageMsgAssociateBond, privateKey: string, fee: Fee) {
|
async associateBond ({ bondId, recordId }: MessageMsgAssociateBond, 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 = createTxMsgAssociateBond(this._chain, sender, fee, '', params);
|
const response: DeliverTxResponse = await laconicClient.associateBond(
|
||||||
result = await this._submitTx(msg, privateKey, sender);
|
account.address,
|
||||||
|
recordId,
|
||||||
|
bondId,
|
||||||
|
fee
|
||||||
|
);
|
||||||
|
|
||||||
return parseTxResponse(result);
|
return laconicClient.registry.decode(response.msgResponses[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dissociate record from bond.
|
* Dissociate record from bond.
|
||||||
*/
|
*/
|
||||||
async dissociateBond (params: MessageMsgDissociateBond, privateKey: string, fee: Fee) {
|
async dissociateBond ({ recordId }: MessageMsgDissociateBond, 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 = createTxMsgDissociateBond(this._chain, sender, fee, '', params);
|
const response: DeliverTxResponse = await laconicClient.dissociateBond(
|
||||||
result = await this._submitTx(msg, privateKey, sender);
|
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);
|
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 (
|
public async reserveAuthority (
|
||||||
signer: string,
|
signer: string,
|
||||||
name: string,
|
name: string,
|
||||||
|
@ -12,6 +12,10 @@ export const typeUrlMsgSetName = '/cerc.registry.v1.MsgSetName';
|
|||||||
export const typeUrlMsgSetNameResponse = '/cerc.registry.v1.MsgSetNameResponse';
|
export const typeUrlMsgSetNameResponse = '/cerc.registry.v1.MsgSetNameResponse';
|
||||||
export const typeUrlMsgDeleteNameAuthority = '/cerc.registry.v1.MsgDeleteNameAuthority';
|
export const typeUrlMsgDeleteNameAuthority = '/cerc.registry.v1.MsgDeleteNameAuthority';
|
||||||
export const typeUrlMsgDeleteNameAuthorityResponse = '/cerc.registry.v1.MsgDeleteNameAuthorityResponse';
|
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]> = [
|
export const registryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||||
[typeUrlMsgReserveAuthority, MsgReserveAuthority],
|
[typeUrlMsgReserveAuthority, MsgReserveAuthority],
|
||||||
@ -23,7 +27,11 @@ export const registryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
|||||||
[typeUrlMsgSetName, MsgSetName],
|
[typeUrlMsgSetName, MsgSetName],
|
||||||
[typeUrlMsgSetNameResponse, MsgSetNameResponse],
|
[typeUrlMsgSetNameResponse, MsgSetNameResponse],
|
||||||
[typeUrlMsgDeleteNameAuthority, MsgDeleteNameAuthority],
|
[typeUrlMsgDeleteNameAuthority, MsgDeleteNameAuthority],
|
||||||
[typeUrlMsgDeleteNameAuthorityResponse, MsgDeleteNameAuthorityResponse]
|
[typeUrlMsgDeleteNameAuthorityResponse, MsgDeleteNameAuthorityResponse],
|
||||||
|
[typeUrlMsgAssociateBond, MsgAssociateBond],
|
||||||
|
[typeUrlMsgAssociateBondResponse, MsgAssociateBondResponse],
|
||||||
|
[typeUrlMsgDissociateBond, MsgDissociateBond],
|
||||||
|
[typeUrlMsgDissociateBondResponse, MsgDissociateBondResponse],
|
||||||
];
|
];
|
||||||
|
|
||||||
export interface MsgReserveAuthorityEncodeObject extends EncodeObject {
|
export interface MsgReserveAuthorityEncodeObject extends EncodeObject {
|
||||||
@ -50,3 +58,13 @@ export interface MsgDeleteNameAuthorityEncodeObject extends EncodeObject {
|
|||||||
readonly typeUrl: '/cerc.registry.v1.MsgDeleteNameAuthority';
|
readonly typeUrl: '/cerc.registry.v1.MsgDeleteNameAuthority';
|
||||||
readonly value: Partial<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