Accept fees optionally as gas estimation multiplier
This commit is contained in:
parent
bc3010f67b
commit
74d5631753
@ -1 +1,4 @@
|
|||||||
export const DENOM = 'alnt';
|
export const DENOM = 'alnt';
|
||||||
|
export const DEFAULT_CHAIN_ID = 'laconic_9000-1';
|
||||||
|
|
||||||
|
export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 1.5;
|
||||||
|
56
src/index.ts
56
src/index.ts
@ -31,8 +31,7 @@ import { Coin } from './proto/cosmos/base/v1beta1/coin';
|
|||||||
import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx';
|
import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx';
|
||||||
import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/tx';
|
import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/tx';
|
||||||
import { MsgSendResponse } from './proto/cosmos/bank/v1beta1/tx';
|
import { MsgSendResponse } from './proto/cosmos/bank/v1beta1/tx';
|
||||||
|
import { DEFAULT_CHAIN_ID, DEFAULT_GAS_ESTIMATION_MULTIPLIER } from './constants';
|
||||||
export const DEFAULT_CHAIN_ID = 'laconic_9000-1';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an auction bid.
|
* Create an auction bid.
|
||||||
@ -132,7 +131,7 @@ export class Registry {
|
|||||||
async setRecord (
|
async setRecord (
|
||||||
{ privateKey, record, bondId }: { privateKey: string, record: any, bondId: string },
|
{ privateKey, record, bondId }: { privateKey: string, record: any, bondId: string },
|
||||||
transactionPrivateKey: string,
|
transactionPrivateKey: string,
|
||||||
fee: StdFee
|
fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER
|
||||||
) {
|
) {
|
||||||
const account = new Account(Buffer.from(transactionPrivateKey, 'hex'));
|
const account = new Account(Buffer.from(transactionPrivateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
@ -147,7 +146,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Send coins.
|
* Send coins.
|
||||||
*/
|
*/
|
||||||
async sendCoins ({ amount, denom, destinationAddress }: MessageMsgSendCoins, privateKey: string, fee: StdFee) {
|
async sendCoins ({ amount, denom, destinationAddress }: MessageMsgSendCoins, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -202,7 +201,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Create bond.
|
* Create bond.
|
||||||
*/
|
*/
|
||||||
async createBond ({ denom, amount }: MessageMsgCreateBond, privateKey: string, fee: StdFee): Promise<MsgCreateBondResponse> {
|
async createBond ({ denom, amount }: MessageMsgCreateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgCreateBondResponse> {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -218,7 +217,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Refill bond.
|
* Refill bond.
|
||||||
*/
|
*/
|
||||||
async refillBond ({ denom, amount, id }: MessageMsgRefillBond, privateKey: string, fee: StdFee): Promise<MsgRefillBondResponse> {
|
async refillBond ({ denom, amount, id }: MessageMsgRefillBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgRefillBondResponse> {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -235,7 +234,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Withdraw (from) bond.
|
* Withdraw (from) bond.
|
||||||
*/
|
*/
|
||||||
async withdrawBond ({ denom, amount, id }: MessageMsgWithdrawBond, privateKey: string, fee: StdFee): Promise<MsgWithdrawBondResponse> {
|
async withdrawBond ({ denom, amount, id }: MessageMsgWithdrawBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgWithdrawBondResponse> {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -252,7 +251,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Cancel bond.
|
* Cancel bond.
|
||||||
*/
|
*/
|
||||||
async cancelBond ({ id }: MessageMsgCancelBond, privateKey: string, fee: StdFee): Promise<MsgCancelBondResponse> {
|
async cancelBond ({ id }: MessageMsgCancelBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgCancelBondResponse> {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -267,7 +266,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Associate record with bond.
|
* Associate record with bond.
|
||||||
*/
|
*/
|
||||||
async associateBond ({ bondId, recordId }: MessageMsgAssociateBond, privateKey: string, fee: StdFee) {
|
async associateBond ({ bondId, recordId }: MessageMsgAssociateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -283,7 +282,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Dissociate record from bond.
|
* Dissociate record from bond.
|
||||||
*/
|
*/
|
||||||
async dissociateBond ({ recordId }: MessageMsgDissociateBond, privateKey: string, fee: StdFee) {
|
async dissociateBond ({ recordId }: MessageMsgDissociateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -298,7 +297,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Dissociate all records from bond.
|
* Dissociate all records from bond.
|
||||||
*/
|
*/
|
||||||
async dissociateRecords ({ bondId }: MessageMsgDissociateRecords, privateKey: string, fee: StdFee) {
|
async dissociateRecords ({ bondId }: MessageMsgDissociateRecords, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -313,7 +312,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Reassociate records (switch bond).
|
* Reassociate records (switch bond).
|
||||||
*/
|
*/
|
||||||
async reassociateRecords ({ newBondId, oldBondId }: MessageMsgReAssociateRecords, privateKey: string, fee: StdFee) {
|
async reassociateRecords ({ newBondId, oldBondId }: MessageMsgReAssociateRecords, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -329,7 +328,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Reserve authority.
|
* Reserve authority.
|
||||||
*/
|
*/
|
||||||
async reserveAuthority ({ name, owner }: { name: string, owner?: string }, privateKey: string, fee: StdFee) {
|
async reserveAuthority ({ name, owner }: { name: string, owner?: string }, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -345,7 +344,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Set authority bond.
|
* Set authority bond.
|
||||||
*/
|
*/
|
||||||
async setAuthorityBond ({ bondId, name }: MessageMsgSetAuthorityBond, privateKey: string, fee: StdFee) {
|
async setAuthorityBond ({ bondId, name }: MessageMsgSetAuthorityBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -361,7 +360,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Commit auction bid.
|
* Commit auction bid.
|
||||||
*/
|
*/
|
||||||
async commitBid ({ auctionId, commitHash }: MessageMsgCommitBid, privateKey: string, fee: StdFee) {
|
async commitBid ({ auctionId, commitHash }: MessageMsgCommitBid, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -377,7 +376,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Reveal auction bid.
|
* Reveal auction bid.
|
||||||
*/
|
*/
|
||||||
async revealBid ({ auctionId, reveal }: MessageMsgRevealBid, privateKey: string, fee: StdFee) {
|
async revealBid ({ auctionId, reveal }: MessageMsgRevealBid, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -413,7 +412,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Set name (LRN) to record ID (CID).
|
* Set name (LRN) to record ID (CID).
|
||||||
*/
|
*/
|
||||||
async setName ({ cid, lrn }: MessageMsgSetName, privateKey: string, fee: StdFee) {
|
async setName ({ cid, lrn }: MessageMsgSetName, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -436,7 +435,7 @@ export class Registry {
|
|||||||
/**
|
/**
|
||||||
* Delete name (LRN) mapping.
|
* Delete name (LRN) mapping.
|
||||||
*/
|
*/
|
||||||
async deleteName ({ lrn }: MessageMsgDeleteName, privateKey: string, fee: StdFee) {
|
async deleteName ({ lrn }: MessageMsgDeleteName, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
|
||||||
const account = new Account(Buffer.from(privateKey, 'hex'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -447,20 +446,10 @@ export class Registry {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLaconicClient (account: Account) {
|
|
||||||
return LaconicClient.connectWithSigner(
|
|
||||||
this._endpoints.rpc,
|
|
||||||
account.wallet,
|
|
||||||
{
|
|
||||||
gasPrice: this._gasPrice
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Onboard participant.
|
* Onboard participant.
|
||||||
*/
|
*/
|
||||||
async onboardParticipant ({ ethPayload, ethSignature, role, kycId }: MessageMsgOnboardParticipant, privateKey: string, fee: StdFee): Promise<MsgOnboardParticipantResponse> {
|
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'));
|
const account = new Account(Buffer.from(privateKey, 'hex'));
|
||||||
await account.init();
|
await account.init();
|
||||||
const laconicClient = await this.getLaconicClient(account);
|
const laconicClient = await this.getLaconicClient(account);
|
||||||
@ -495,9 +484,18 @@ export class Registry {
|
|||||||
async getParticipantByNitroAddress (nitroAddress: string) {
|
async getParticipantByNitroAddress (nitroAddress: string) {
|
||||||
return this._client.getParticipantByNitroAddress(nitroAddress);
|
return this._client.getParticipantByNitroAddress(nitroAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getLaconicClient (account: Account) {
|
||||||
|
return LaconicClient.connectWithSigner(
|
||||||
|
this._endpoints.rpc,
|
||||||
|
account.wallet,
|
||||||
|
{ gasPrice: this._gasPrice }
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Account };
|
export { Account };
|
||||||
export { LaconicClient };
|
export { LaconicClient };
|
||||||
|
export * from './constants';
|
||||||
export * from './types/cerc/bond/message';
|
export * from './types/cerc/bond/message';
|
||||||
export * from './types/cerc/onboarding/message';
|
export * from './types/cerc/onboarding/message';
|
||||||
|
@ -2,7 +2,8 @@ import assert from 'assert';
|
|||||||
import yaml from 'node-yaml';
|
import yaml from 'node-yaml';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
|
||||||
import { Account, DEFAULT_CHAIN_ID } from '../index';
|
import { Account } from '../index';
|
||||||
|
import { DEFAULT_CHAIN_ID } from '../constants';
|
||||||
|
|
||||||
export const ensureUpdatedConfig = async (path: string) => {
|
export const ensureUpdatedConfig = async (path: string) => {
|
||||||
const conf = await yaml.read(path);
|
const conf = await yaml.read(path);
|
||||||
|
Loading…
Reference in New Issue
Block a user