Add release funds method

This commit is contained in:
IshaVenikar 2024-09-23 18:04:54 +05:30
parent ff9712f31d
commit d95736b0cf
3 changed files with 56 additions and 9 deletions

View File

@ -24,7 +24,8 @@ import {
MessageMsgCommitBid,
MessageMsgRevealBid,
MessageCreateVickreyAuction,
MessageCreateProviderAuction
MessageCreateProviderAuction,
MessageMsgReleaseFunds
} from './types/cerc/auction/message';
import { MessageMsgSendCoins } from './types/cosmos/bank/message';
import { MessageMsgOnboardParticipant } from './types/cerc/onboarding/message';
@ -458,7 +459,7 @@ export class Registry {
/**
* Onboard participant.
*/
*/
async onboardParticipant ({ ethPayload, ethSignature, role, kycId }: MessageMsgOnboardParticipant, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgOnboardParticipantResponse> {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
@ -476,21 +477,21 @@ export class Registry {
/**
* Query participants.
*/
*/
async getParticipants () {
return this._client.getParticipants();
}
/**
* Get participant by cosmos (laconic) address.
*/
*/
async getParticipantByAddress (address: string) {
return this._client.getParticipantByAddress(address);
}
/**
* Get participant by nitro address.
*/
*/
async getParticipantByNitroAddress (nitroAddress: string) {
return this._client.getParticipantByNitroAddress(nitroAddress);
}
@ -565,6 +566,21 @@ export class Registry {
fee
);
}
/**
* Release provider auction winner funds.
*/
async releaseFunds ({ auctionId }: MessageMsgReleaseFunds, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
return laconicClient.releaseFunds(
account.address,
auctionId,
fee
);
}
}
export { Account };

View File

@ -13,13 +13,13 @@ import { Comet38Client } from '@cosmjs/tendermint-rpc';
import { MsgCancelBondEncodeObject, MsgCreateBondEncodeObject, MsgRefillBondEncodeObject, MsgWithdrawBondEncodeObject, bondTypes, typeUrlMsgCancelBond, typeUrlMsgCreateBond, typeUrlMsgRefillBond, typeUrlMsgWithdrawBond } from './types/cerc/bond/message';
import { Coin } from './proto/cosmos/base/v1beta1/coin';
import { MsgAssociateBondEncodeObject, MsgDeleteNameEncodeObject, MsgDissociateBondEncodeObject, MsgDissociateRecordsEncodeObject, MsgReassociateRecordsEncodeObject, MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, MsgSetNameEncodeObject, MsgSetRecordEncodeObject, registryTypes, typeUrlMsgAssociateBond, typeUrlMsgDeleteName, typeUrlMsgDissociateBond, typeUrlMsgDissociateRecords, typeUrlMsgReassociateRecords, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond, typeUrlMsgSetName, typeUrlMsgSetRecord, NAMESERVICE_ERRORS } from './types/cerc/registry/message';
import { MsgCommitBidEncodeObject, MsgCreateAuctionEncodeObject, MsgRevealBidEncodeObject, auctionTypes, typeUrlMsgCommitBid, typeUrlMsgCreateAuction, typeUrlMsgRevealBid } from './types/cerc/auction/message';
import { MsgCommitBidEncodeObject, MsgCreateAuctionEncodeObject, MsgReleaseFundsEncodeObject, MsgRevealBidEncodeObject, auctionTypes, typeUrlMsgCommitBid, typeUrlMsgCreateAuction, typeUrlMsgReleaseFunds, typeUrlMsgRevealBid } from './types/cerc/auction/message';
import { MsgOnboardParticipantEncodeObject, ONBOARDING_DISABLED_ERROR, onboardingTypes, typeUrlMsgOnboardParticipant } from './types/cerc/onboarding/message';
import { MsgAssociateBondResponse, MsgDeleteNameResponse, MsgDissociateBondResponse, MsgDissociateRecordsResponse, MsgReassociateRecordsResponse, MsgReserveAuthorityResponse, MsgSetAuthorityBondResponse, MsgSetNameResponse, MsgSetRecordResponse, Payload } from './proto/cerc/registry/v1/tx';
import { Record, Signature } from './proto/cerc/registry/v1/registry';
import { Account } from './account';
import { Util } from './util';
import { MsgCommitBidResponse, MsgCreateAuction, MsgCreateAuctionResponse, MsgRevealBidResponse } from './proto/cerc/auction/v1/tx';
import { MsgCommitBidResponse, MsgCreateAuction, MsgCreateAuctionResponse, MsgReleaseFundsResponse, MsgRevealBidResponse } from './proto/cerc/auction/v1/tx';
import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx';
import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/tx';
import { bankTypes } from './types/cosmos/bank/message';
@ -448,4 +448,22 @@ export class LaconicClient extends SigningStargateClient {
const response = await this.signAndBroadcast(signer, [createAuctionMsg], fee, memo);
return this.parseResponse<MsgCreateAuctionResponse>(response);
}
public async releaseFunds (
signer: string,
auctionId: string,
fee: StdFee | 'auto' | number,
memo = ''
) {
const createMsg: MsgReleaseFundsEncodeObject = {
typeUrl: typeUrlMsgReleaseFunds,
value: {
signer,
auctionId
}
};
const response = await this.signAndBroadcast(signer, [createMsg], fee, memo);
return this.parseResponse<MsgReleaseFundsResponse>(response);
}
}

View File

@ -1,6 +1,6 @@
import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing';
import { MsgCommitBidResponse, MsgCommitBid, MsgRevealBid, MsgRevealBidResponse, MsgCreateAuction, MsgCreateAuctionResponse } from '../../../proto/cerc/auction/v1/tx';
import { MsgCommitBidResponse, MsgCommitBid, MsgRevealBid, MsgRevealBidResponse, MsgCreateAuction, MsgCreateAuctionResponse, MsgReleaseFunds, MsgReleaseFundsResponse } from '../../../proto/cerc/auction/v1/tx';
export const typeUrlMsgCreateAuction = '/cerc.auction.v1.MsgCreateAuction';
export const typeUrlMsgCommitBid = '/cerc.auction.v1.MsgCommitBid';
@ -8,6 +8,8 @@ export const typeUrlMsgCommitBidResponse = '/cerc.auction.v1.MsgCommitBidRespons
export const typeUrlMsgRevealBid = '/cerc.auction.v1.MsgRevealBid';
export const typeUrlMsgRevealBidResponse = '/cerc.auction.v1.MsgRevealBidResponse';
export const typeUrlMsgCreateAuctionResponse = '/cerc.auction.v1.MsgCreateAuctionResponse';
export const typeUrlMsgReleaseFunds = '/cerc.auction.v1.MsgReleaseFunds';
export const typeUrlMsgReleaseFundsResponse = '/cerc.auction.v1.MsgReleaseFundsResponse';
export const auctionTypes: ReadonlyArray<[string, GeneratedType]> = [
[typeUrlMsgCreateAuction, MsgCreateAuction],
@ -15,7 +17,9 @@ export const auctionTypes: ReadonlyArray<[string, GeneratedType]> = [
[typeUrlMsgCommitBidResponse, MsgCommitBidResponse],
[typeUrlMsgRevealBid, MsgRevealBid],
[typeUrlMsgRevealBidResponse, MsgRevealBidResponse],
[typeUrlMsgCreateAuctionResponse, MsgCreateAuctionResponse]
[typeUrlMsgCreateAuctionResponse, MsgCreateAuctionResponse],
[typeUrlMsgReleaseFunds, MsgReleaseFunds],
[typeUrlMsgReleaseFundsResponse, MsgReleaseFundsResponse]
];
export interface MsgCreateAuctionEncodeObject extends EncodeObject {
@ -33,6 +37,11 @@ export interface MsgRevealBidEncodeObject extends EncodeObject {
readonly value: Partial<MsgRevealBid>;
}
export interface MsgReleaseFundsEncodeObject extends EncodeObject {
readonly typeUrl: '/cerc.auction.v1.MsgReleaseFunds';
readonly value: Partial<MsgReleaseFunds>;
}
export interface MessageMsgCommitBid {
auctionId: string,
commitHash: string,
@ -61,3 +70,7 @@ export interface MessageCreateProviderAuction {
maxPrice: string;
numProviders: number;
}
export interface MessageMsgReleaseFunds {
auctionId: string
}