From f86c20e787352c6db051b20e7bfa2a93a7657b02 Mon Sep 17 00:00:00 2001 From: Dmitryii Osipov Date: Fri, 16 Aug 2024 19:27:05 +0300 Subject: [PATCH] feat(js): use zero address in gas calculation if no account is provided (#473) --- js/package.json | 2 +- js/src/transaction-builder.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/js/package.json b/js/package.json index 11848cd8..58266851 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "sails-js", - "version": "0.1.8", + "version": "0.1.9", "description": "Parser and typescript code generator from Sails IDL files", "main": "lib/index.js", "preferGlobal": true, diff --git a/js/src/transaction-builder.ts b/js/src/transaction-builder.ts index 6e203ad3..d688afba 100644 --- a/js/src/transaction-builder.ts +++ b/js/src/transaction-builder.ts @@ -3,6 +3,7 @@ import { SignerOptions, SubmittableExtrinsic } from '@polkadot/api/types'; import { IKeyringPair, ISubmittableResult } from '@polkadot/types/types'; import { TypeRegistry, u128, u64 } from '@polkadot/types'; import { getPayloadMethod } from './utils/index.js'; +import { ZERO_ADDRESS } from 'consts.js'; export interface IMethodReturnType { /** @@ -154,9 +155,9 @@ export class TransactionBuilder { * @returns */ public async calculateGas(allowOtherPanics = false, increaseGas = 0) { - if (!this._account) throw new Error('Account is required. Use withAccount() method to set account.'); - - const source = decodeAddress(typeof this._account === 'string' ? this._account : this._account.address); + const source = this._account + ? decodeAddress(typeof this._account === 'string' ? this._account : this._account.address) + : ZERO_ADDRESS; switch (this._tx.method.method) { case 'uploadProgram': { @@ -292,6 +293,10 @@ export class TransactionBuilder { * ## Sign and send transaction */ public async signAndSend(): Promise> { + if (!this._account) { + throw new Error('Account is required. Use withAccount() method to set account.'); + } + if (this._voucher) { const callParams: ICallOptions = { SendMessage: this._tx }; this._tx = this._api.voucher.call(this._voucher, callParams);