diff --git a/src/auction.test.ts b/src/auction.test.ts index 0c13c87..4f8239a 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -3,9 +3,8 @@ import { getConfig, getLaconic2Config } from './testing/helper'; import { DENOM } from './constants'; jest.setTimeout(30 * 60 * 1000); -const { fee: laconic2Fee } = getLaconic2Config(); - const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig(); +const { fee: laconic2Fee } = getLaconic2Config(); const auctionTests = (numBidders = 3) => { let registry: Registry; @@ -26,7 +25,7 @@ const auctionTests = (numBidders = 3) => { const mnenonic = Account.generateMnemonic(); const account = await Account.generateFromMnemonic(mnenonic); await account.init(); - await registry.sendCoins({ denom: DENOM, amount: '100000', destinationAddress: account.address }, privateKey, laconic2Fee); + await registry.sendCoins({ denom: DENOM, amount: '20000000', destinationAddress: account.address }, privateKey, laconic2Fee); accounts.push({ address: account.address, privateKey: account.privateKey.toString('hex') }); } }); @@ -50,8 +49,8 @@ const auctionTests = (numBidders = 3) => { test('Commit bids.', async () => { for (let i = 0; i < numBidders; i++) { - accounts[i].bid = await createBid(chainId, auctionId, accounts[i].address, `${10000000 + (i * 500)}aphoton`); - await registry.commitBid({ auctionId, commitHash: accounts[i].bid.commitHash }, accounts[i].privateKey, fee); + accounts[i].bid = await createBid(chainId, auctionId, accounts[i].address, `${10000000 + (i * 500)}${DENOM}`); + await registry.commitBid({ auctionId, commitHash: accounts[i].bid.commitHash }, accounts[i].privateKey, laconic2Fee); } }); @@ -75,7 +74,7 @@ const auctionTests = (numBidders = 3) => { expect(auction.status).toEqual('reveal'); for (let i = 0; i < numBidders; i++) { - await registry.revealBid({ auctionId, reveal: accounts[i].bid.revealString }, accounts[i].privateKey, fee); + await registry.revealBid({ auctionId, reveal: accounts[i].bid.revealString }, accounts[i].privateKey, laconic2Fee); } }); diff --git a/src/index.ts b/src/index.ts index 889bff8..e7399ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -216,7 +216,8 @@ export class Registry { ], fee); - return laconicClient.registry.decode(response.msgResponses[0]); + // TODO: Register type /cosmos.bank.v1beta1.MsgSendResponse for decoding response + return response; } /** @@ -419,29 +420,35 @@ export class Registry { /** * Commit auction bid. */ - async commitBid (params: MessageMsgCommitBid, privateKey: string, fee: Fee) { - let result; + async commitBid ({ auctionId, commitHash }: MessageMsgCommitBid, 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 response: DeliverTxResponse = await laconicClient.commitBid( + account.address, + auctionId, + commitHash, + fee + ); - const msg = createTxMsgCommitBid(this._chain, sender, fee, '', params); - result = await this._submitTx(msg, privateKey, sender); - - return parseTxResponse(result); + return laconicClient.registry.decode(response.msgResponses[0]); } /** * Reveal auction bid. */ - async revealBid (params: MessageMsgRevealBid, privateKey: string, fee: Fee) { - let result; + async revealBid ({ auctionId, reveal }: MessageMsgRevealBid, 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 response: DeliverTxResponse = await laconicClient.revealBid( + account.address, + auctionId, + reveal, + fee + ); - const msg = createTxMsgRevealBid(this._chain, sender, fee, '', params); - result = await this._submitTx(msg, privateKey, sender); - - return parseTxResponse(result); + return laconicClient.registry.decode(response.msgResponses[0]); } /** diff --git a/src/laconic-client.ts b/src/laconic-client.ts index 6e8b343..1f2a854 100644 --- a/src/laconic-client.ts +++ b/src/laconic-client.ts @@ -12,11 +12,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 './proto2/cosmos/base/v1beta1/coin'; import { MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, registryTypes, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond } from './types/cerc/registry/message'; +import { MsgCommitBidEncodeObject, MsgRevealBidEncodeObject, auctionTypes, typeUrlMsgCommitBid, typeUrlMsgRevealBid } from './types/cerc/auction/message'; export const laconicDefaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ ...defaultRegistryTypes, ...bondTypes, - ...registryTypes + ...registryTypes, + ...auctionTypes ]; function createDefaultRegistry (): Registry { @@ -145,6 +147,44 @@ export class LaconicClient extends SigningStargateClient { return this.signAndBroadcast(signer, [createMsg], fee, memo); } + public async commitBid ( + signer: string, + auctionId: string, + commitHash: string, + fee: StdFee | 'auto' | number, + memo = '' + ): Promise { + const createMsg: MsgCommitBidEncodeObject = { + typeUrl: typeUrlMsgCommitBid, + value: { + signer, + auctionId, + commitHash + } + }; + + return this.signAndBroadcast(signer, [createMsg], fee, memo); + } + + public async revealBid ( + signer: string, + auctionId: string, + reveal: string, + fee: StdFee | 'auto' | number, + memo = '' + ): Promise { + const createMsg: MsgRevealBidEncodeObject = { + typeUrl: typeUrlMsgRevealBid, + value: { + signer, + auctionId, + reveal + } + }; + + return this.signAndBroadcast(signer, [createMsg], fee, memo); + } + public async setAuthorityBond ( signer: string, bondId: string, diff --git a/src/types/cerc/auction/message.ts b/src/types/cerc/auction/message.ts new file mode 100644 index 0000000..87c4abe --- /dev/null +++ b/src/types/cerc/auction/message.ts @@ -0,0 +1,25 @@ +import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing'; + +import { MsgCommitBidResponse, MsgCommitBid, MsgRevealBid, MsgRevealBidResponse } from '../../../proto2/cerc/auction/v1/tx'; + +export const typeUrlMsgCommitBid = '/cerc.auction.v1.MsgCommitBid'; +export const typeUrlMsgCommitBidResponse = '/cerc.auction.v1.MsgCommitBidResponse'; +export const typeUrlMsgRevealBid = '/cerc.auction.v1.MsgRevealBid'; +export const typeUrlMsgRevealBidResponse = '/cerc.auction.v1.MsgRevealBidResponse'; + +export const auctionTypes: ReadonlyArray<[string, GeneratedType]> = [ + [typeUrlMsgCommitBid, MsgCommitBid], + [typeUrlMsgCommitBidResponse, MsgCommitBidResponse], + [typeUrlMsgRevealBid, MsgRevealBid], + [typeUrlMsgRevealBidResponse, MsgRevealBidResponse] +]; + +export interface MsgCommitBidEncodeObject extends EncodeObject { + readonly typeUrl: '/cerc.auction.v1.MsgCommitBid'; + readonly value: Partial; +} + +export interface MsgRevealBidEncodeObject extends EncodeObject { + readonly typeUrl: '/cerc.auction.v1.MsgRevealBid'; + readonly value: Partial; +}