Skip to content

Commit

Permalink
feat(createGeneralizeAccount): estimate gas limit instead of using const
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jan 28, 2022
1 parent bb6977d commit da88852
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/contract/aci.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default async function getContractInstance ({
throw new NodeInvocationError(message)
}

const estimateGas = async (name, params, options) => {
instance._estimateGas = async (name, params, options) => {
const { result: { gasUsed } } =
await instance.call(name, params, { ...options, callStatic: true })
// taken from https://github.com/aeternity/aepp-sdk-js/issues/1286#issuecomment-977814771
Expand All @@ -190,7 +190,7 @@ export default async function getContractInstance ({
const ownerId = await this.address(opt)
const { tx, contractId } = await this.contractCreateTx({
...opt,
gas: opt.gas ?? await estimateGas('init', params, opt),
gas: opt.gas ?? await instance._estimateGas('init', params, opt),
callData: instance.calldata.encode(instance._name, 'init', params),
code: instance.bytecode,
ownerId
Expand Down Expand Up @@ -272,7 +272,7 @@ export default async function getContractInstance ({
} else {
const tx = await this.contractCallTx({
...opt,
gas: opt.gas ?? await estimateGas(fn, params, opt),
gas: opt.gas ?? await instance._estimateGas(fn, params, opt),
callerId,
contractId,
callData
Expand Down
4 changes: 2 additions & 2 deletions src/contract/ga/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @example import { GeneralizeAccount } from '@aeternity/aepp-sdk'
*/
import Contract from '../../ae/contract'
import { TX_TYPE, GAS_ABOVE_AVERAGE } from '../../tx/builder/schema'
import { TX_TYPE } from '../../tx/builder/schema'
import { buildTx, unpackTx } from '../../tx/builder'
import { prepareGaParams } from './helpers'
import { hash } from '../../utils/crypto'
Expand Down Expand Up @@ -91,8 +91,8 @@ async function createGeneralizeAccount (authFnName, source, args = [], options =
const contract = await this.getContractInstance({ source })
await contract.compile()
const { tx, contractId } = await this.gaAttachTx({
gas: GAS_ABOVE_AVERAGE,
...opt,
gas: opt.gas ?? await contract._estimateGas('init', args, opt),
ownerId,
code: contract.bytecode,
callData: contract.calldata.encode(contract._name, 'init', args),
Expand Down
1 change: 0 additions & 1 deletion src/tx/builder/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const RESPONSE_TTL = { type: 'delta', value: 10 }
// # CONTRACT
export const DEPOSIT = 0
export const AMOUNT = 0
export const GAS_ABOVE_AVERAGE = 25000 // TODO: don't use this
export const GAS_MAX = 1600000 - 21000
export const MIN_GAS_PRICE = 1e9
export const MAX_AUTH_FUN_GAS = 50000
Expand Down

0 comments on commit da88852

Please sign in to comment.