Skip to content

Commit

Permalink
feat(js): use zero address in gas calculation if no account is provid…
Browse files Browse the repository at this point in the history
…ed (#473)
  • Loading branch information
osipov-mit authored Aug 16, 2024
1 parent 868cf04 commit f86c20e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
11 changes: 8 additions & 3 deletions js/src/transaction-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
/**
Expand Down Expand Up @@ -154,9 +155,9 @@ export class TransactionBuilder<ResponseType> {
* @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': {
Expand Down Expand Up @@ -292,6 +293,10 @@ export class TransactionBuilder<ResponseType> {
* ## Sign and send transaction
*/
public async signAndSend(): Promise<IMethodReturnType<ResponseType>> {
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);
Expand Down

0 comments on commit f86c20e

Please sign in to comment.