Update registry SDK auction methods to use cosmjs #1
@ -3,9 +3,8 @@ import { getConfig, getLaconic2Config } from './testing/helper';
|
|||||||
import { DENOM } from './constants';
|
import { DENOM } from './constants';
|
||||||
|
|
||||||
jest.setTimeout(30 * 60 * 1000);
|
jest.setTimeout(30 * 60 * 1000);
|
||||||
const { fee: laconic2Fee } = getLaconic2Config();
|
|
||||||
|
|
||||||
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
||||||
|
const { fee: laconic2Fee } = getLaconic2Config();
|
||||||
|
|
||||||
const auctionTests = (numBidders = 3) => {
|
const auctionTests = (numBidders = 3) => {
|
||||||
let registry: Registry;
|
let registry: Registry;
|
||||||
@ -26,7 +25,7 @@ const auctionTests = (numBidders = 3) => {
|
|||||||
const mnenonic = Account.generateMnemonic();
|
const mnenonic = Account.generateMnemonic();
|
||||||
const account = await Account.generateFromMnemonic(mnenonic);
|
const account = await Account.generateFromMnemonic(mnenonic);
|
||||||
await account.init();
|
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') });
|
accounts.push({ address: account.address, privateKey: account.privateKey.toString('hex') });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -50,8 +49,8 @@ const auctionTests = (numBidders = 3) => {
|
|||||||
|
|
||||||
test('Commit bids.', async () => {
|
test('Commit bids.', async () => {
|
||||||
for (let i = 0; i < numBidders; i++) {
|
for (let i = 0; i < numBidders; i++) {
|
||||||
accounts[i].bid = await createBid(chainId, auctionId, accounts[i].address, `${10000000 + (i * 500)}aphoton`);
|
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, fee);
|
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');
|
expect(auction.status).toEqual('reveal');
|
||||||
|
|
||||||
for (let i = 0; i < numBidders; i++) {
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
37
src/index.ts
37
src/index.ts
@ -216,7 +216,8 @@ export class Registry {
|
|||||||
],
|
],
|
||||||
fee);
|
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.
|
* Commit auction bid.
|
||||||
*/
|
*/
|
||||||
async commitBid (params: MessageMsgCommitBid, privateKey: string, fee: Fee) {
|
async commitBid ({ auctionId, commitHash }: MessageMsgCommitBid, 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 response: DeliverTxResponse = await laconicClient.commitBid(
|
||||||
|
account.address,
|
||||||
|
auctionId,
|
||||||
|
commitHash,
|
||||||
|
fee
|
||||||
|
);
|
||||||
|
|
||||||
const msg = createTxMsgCommitBid(this._chain, sender, fee, '', params);
|
return laconicClient.registry.decode(response.msgResponses[0]);
|
||||||
result = await this._submitTx(msg, privateKey, sender);
|
|
||||||
|
|
||||||
return parseTxResponse(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reveal auction bid.
|
* Reveal auction bid.
|
||||||
*/
|
*/
|
||||||
async revealBid (params: MessageMsgRevealBid, privateKey: string, fee: Fee) {
|
async revealBid ({ auctionId, reveal }: MessageMsgRevealBid, 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 response: DeliverTxResponse = await laconicClient.revealBid(
|
||||||
|
account.address,
|
||||||
|
auctionId,
|
||||||
|
reveal,
|
||||||
|
fee
|
||||||
|
);
|
||||||
|
|
||||||
const msg = createTxMsgRevealBid(this._chain, sender, fee, '', params);
|
return laconicClient.registry.decode(response.msgResponses[0]);
|
||||||
result = await this._submitTx(msg, privateKey, sender);
|
|
||||||
|
|
||||||
return parseTxResponse(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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 { MsgCancelBondEncodeObject, MsgCreateBondEncodeObject, MsgRefillBondEncodeObject, MsgWithdrawBondEncodeObject, bondTypes, typeUrlMsgCancelBond, typeUrlMsgCreateBond, typeUrlMsgRefillBond, typeUrlMsgWithdrawBond } from './types/cerc/bond/message';
|
||||||
import { Coin } from './proto2/cosmos/base/v1beta1/coin';
|
import { Coin } from './proto2/cosmos/base/v1beta1/coin';
|
||||||
import { MsgReserveAuthorityEncodeObject, MsgSetAuthorityBondEncodeObject, registryTypes, typeUrlMsgReserveAuthority, typeUrlMsgSetAuthorityBond } from './types/cerc/registry/message';
|
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]> = [
|
export const laconicDefaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||||
...defaultRegistryTypes,
|
...defaultRegistryTypes,
|
||||||
...bondTypes,
|
...bondTypes,
|
||||||
...registryTypes
|
...registryTypes,
|
||||||
|
...auctionTypes
|
||||||
];
|
];
|
||||||
|
|
||||||
function createDefaultRegistry (): Registry {
|
function createDefaultRegistry (): Registry {
|
||||||
@ -145,6 +147,44 @@ export class LaconicClient extends SigningStargateClient {
|
|||||||
return this.signAndBroadcast(signer, [createMsg], fee, memo);
|
return this.signAndBroadcast(signer, [createMsg], fee, memo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async commitBid (
|
||||||
|
signer: string,
|
||||||
|
auctionId: string,
|
||||||
|
commitHash: string,
|
||||||
|
fee: StdFee | 'auto' | number,
|
||||||
|
memo = ''
|
||||||
|
): Promise<DeliverTxResponse> {
|
||||||
|
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<DeliverTxResponse> {
|
||||||
|
const createMsg: MsgRevealBidEncodeObject = {
|
||||||
|
typeUrl: typeUrlMsgRevealBid,
|
||||||
|
value: {
|
||||||
|
signer,
|
||||||
|
auctionId,
|
||||||
|
reveal
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.signAndBroadcast(signer, [createMsg], fee, memo);
|
||||||
|
}
|
||||||
|
|
||||||
public async setAuthorityBond (
|
public async setAuthorityBond (
|
||||||
signer: string,
|
signer: string,
|
||||||
bondId: string,
|
bondId: string,
|
||||||
|
25
src/types/cerc/auction/message.ts
Normal file
25
src/types/cerc/auction/message.ts
Normal file
@ -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<MsgCommitBid>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MsgRevealBidEncodeObject extends EncodeObject {
|
||||||
|
readonly typeUrl: '/cerc.auction.v1.MsgRevealBid';
|
||||||
|
readonly value: Partial<MsgRevealBid>;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user