fix(hdnode):add default gasLimit and gasPrice

dev
neeboo 5 years ago
parent 1a0a5300c7
commit d9fa1c5875
  1. 41
      packages/harmony-account/src/hdnode.ts
  2. 17
      packages/harmony-core/src/truffleProvider.ts

@ -58,6 +58,8 @@ export class HDNode {
private addressCount: number;
private addresses: string[];
private wallets: WalletsInterfaces;
private gasLimit: string;
private gasPrice: string;
constructor(
provider: string | HttpProvider | WSProvider = 'http://localhost:9500',
@ -66,6 +68,8 @@ export class HDNode {
addressCount: number = 1,
chainType: ChainType = ChainType.Harmony,
chainId: ChainID = ChainID.Default,
gasLimit = '1000000',
gasPrice = '2000000000',
) {
this.provider = this.setProvider(provider);
this.messenger = new Messenger(this.provider, chainType, chainId);
@ -76,6 +80,8 @@ export class HDNode {
this.index = index;
this.addressCount = addressCount;
this.getHdWallet(menmonic || HDNode.generateMnemonic());
this.gasLimit = gasLimit;
this.gasPrice = gasPrice;
}
normalizePrivateKeys(mnemonic: string | string[]) {
@ -155,16 +161,31 @@ export class HDNode {
);
const to: string = txParams.to ? getAddress(txParams.to).checksum : '0x';
const gasLimit =
txParams.gas !== undefined && isHex(txParams.gas)
? // ? new Unit(hexToNumber(txParams.gas)).asWei().toWei()
new Unit('1000000').asWei().toWei()
: new Unit('0').asWei().toWei();
const gasPrice =
txParams.gasPrice !== undefined && isHex(txParams.gasPrice)
? // ? new Unit(txParams.gasPrice).asWei().toWei()
new Unit('2').asGwei().toWei()
: new Unit('0').asWei().toWei();
let gasLimit = new Unit('0').asWei().toWei();
if (txParams.gas !== undefined && isHex(txParams.gas)) {
gasLimit = new BN(hexToNumber(txParams.gas)).lt(new BN(this.gasLimit))
? new Unit(hexToNumber(txParams.gas)).asWei().toWei()
: new Unit(this.gasLimit).asWei().toWei();
}
if (txParams.gasLimit !== undefined && isHex(txParams.gasLimit)) {
gasLimit = new BN(hexToNumber(txParams.gasLimit)).lt(
new BN(this.gasLimit),
)
? new Unit(hexToNumber(txParams.gasLimit)).asWei().toWei()
: new Unit(this.gasLimit).asWei().toWei();
}
let gasPrice = new Unit('0').asWei().toWei();
if (txParams.gasPrice !== undefined && isHex(txParams.gasPrice)) {
gasPrice = new BN(hexToNumber(txParams.gasPrice)).lt(
new BN(this.gasPrice),
)
? new Unit(hexToNumber(txParams.gasPrice)).asWei().toWei()
: new Unit(this.gasPrice).asWei().toWei();
}
const value =
txParams.value !== undefined && isHex(txParams.value)
? txParams.value

@ -20,8 +20,23 @@ export class TruffleProvider extends HDNode {
constructor(
provider: string | HttpProvider | WSProvider = 'http://localhost:9500',
menmonic?: string,
index: number = 0,
addressCount: number = 1,
chainType: ChainType = ChainType.Harmony,
chainId: ChainID = ChainID.Default,
gasLimit = '1000000',
gasPrice = '2000000000',
) {
super(provider, menmonic, 0, 1, ChainType.Harmony, ChainID.Default);
super(
provider,
menmonic,
index,
addressCount,
chainType,
chainId,
gasLimit,
gasPrice,
);
}
async send(...args: [RPCRequestPayload<any>, any]) {
const {newArgs, id, params, newMethod, callback} = this.resolveArgs(

Loading…
Cancel
Save