UNPKG

@aeternity/aepp-sdk

Version:

SDK for the æternity blockchain

31 lines 1.09 kB
import { IllegalArgumentError } from '../../../utils/errors.js'; import { Tag, MAX_AUTH_FUN_GAS } from '../constants.js'; import shortUInt from './short-u-int.js'; import { buildGas } from './fee.js'; function calculateGasLimitMax(gasMax, rebuildTx, unpackTx, buildTx) { return gasMax - +buildGas(rebuildTx(gasMax), unpackTx, buildTx); } export default { ...shortUInt, serialize(_value, { tag, rebuildTx, unpackTx, buildTx, _computingGasLimit }, { gasMax = 6e6 }) { if (_computingGasLimit != null) return shortUInt.serialize(_computingGasLimit); const gasLimitMax = tag === Tag.GaMetaTx ? MAX_AUTH_FUN_GAS : calculateGasLimitMax(gasMax, gasLimit => rebuildTx({ _computingGasLimit: gasLimit, _canIncreaseFee: true }), unpackTx, buildTx); const value = _value !== null && _value !== void 0 ? _value : gasLimitMax; if (value > gasLimitMax) { throw new IllegalArgumentError(`Gas limit ${value} must be less or equal to ${gasLimitMax}`); } return shortUInt.serialize(value); } }; //# sourceMappingURL=gas-limit.js.map