genlayer-js 0.18.1 → 0.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
 
2
2
 
3
+ ## 0.18.3 (2025-11-03)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * default to zero address for read operations when account not provided ([#121](https://github.com/genlayerlabs/genlayer-js/issues/121)) ([6a1b47a](https://github.com/genlayerlabs/genlayer-js/commit/6a1b47aeafaeb807d5219abbb88e10041c03030e))
9
+
10
+ ## 0.18.2 (2025-09-18)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **transactions:** handle all DECIDED states in waitForTransactionReceipt ([#116](https://github.com/genlayerlabs/genlayer-js/issues/116)) ([78433d7](https://github.com/genlayerlabs/genlayer-js/commit/78433d7224298ab418ca16a87de497149b66b5f7))
16
+
3
17
  ## 0.18.1 (2025-09-11)
4
18
 
5
19
 
@@ -75,6 +75,19 @@ var transactionsStatusNameToNumber = {
75
75
  ["VALIDATORS_TIMEOUT" /* VALIDATORS_TIMEOUT */]: "12",
76
76
  ["LEADER_TIMEOUT" /* LEADER_TIMEOUT */]: "13"
77
77
  };
78
+ var DECIDED_STATES = [
79
+ "ACCEPTED" /* ACCEPTED */,
80
+ "UNDETERMINED" /* UNDETERMINED */,
81
+ "LEADER_TIMEOUT" /* LEADER_TIMEOUT */,
82
+ "VALIDATORS_TIMEOUT" /* VALIDATORS_TIMEOUT */,
83
+ "CANCELED" /* CANCELED */,
84
+ "FINALIZED" /* FINALIZED */
85
+ ];
86
+ function isDecidedState(status) {
87
+ return DECIDED_STATES.some(
88
+ (state) => transactionsStatusNameToNumber[state] === status
89
+ );
90
+ }
78
91
  var transactionResultNumberToName = {
79
92
  "0": "IDLE" /* IDLE */,
80
93
  "1": "AGREE" /* AGREE */,
@@ -129,6 +142,8 @@ export {
129
142
  TransactionResult,
130
143
  transactionsStatusNumberToName,
131
144
  transactionsStatusNameToNumber,
145
+ DECIDED_STATES,
146
+ isDecidedState,
132
147
  transactionResultNumberToName,
133
148
  TransactionResultNameToNumber,
134
149
  VoteType,
@@ -75,6 +75,19 @@ var transactionsStatusNameToNumber = {
75
75
  ["VALIDATORS_TIMEOUT" /* VALIDATORS_TIMEOUT */]: "12",
76
76
  ["LEADER_TIMEOUT" /* LEADER_TIMEOUT */]: "13"
77
77
  };
78
+ var DECIDED_STATES = [
79
+ "ACCEPTED" /* ACCEPTED */,
80
+ "UNDETERMINED" /* UNDETERMINED */,
81
+ "LEADER_TIMEOUT" /* LEADER_TIMEOUT */,
82
+ "VALIDATORS_TIMEOUT" /* VALIDATORS_TIMEOUT */,
83
+ "CANCELED" /* CANCELED */,
84
+ "FINALIZED" /* FINALIZED */
85
+ ];
86
+ function isDecidedState(status) {
87
+ return DECIDED_STATES.some(
88
+ (state) => transactionsStatusNameToNumber[state] === status
89
+ );
90
+ }
78
91
  var transactionResultNumberToName = {
79
92
  "0": "IDLE" /* IDLE */,
80
93
  "1": "AGREE" /* AGREE */,
@@ -135,4 +148,6 @@ var TransactionHashVariant = /* @__PURE__ */ ((TransactionHashVariant2) => {
135
148
 
136
149
 
137
150
 
138
- exports.CalldataAddress = CalldataAddress; exports.TransactionStatus = TransactionStatus; exports.TransactionResult = TransactionResult; exports.transactionsStatusNumberToName = transactionsStatusNumberToName; exports.transactionsStatusNameToNumber = transactionsStatusNameToNumber; exports.transactionResultNumberToName = transactionResultNumberToName; exports.TransactionResultNameToNumber = TransactionResultNameToNumber; exports.VoteType = VoteType; exports.voteTypeNumberToName = voteTypeNumberToName; exports.voteTypeNameToNumber = voteTypeNameToNumber; exports.TransactionHashVariant = TransactionHashVariant;
151
+
152
+
153
+ exports.CalldataAddress = CalldataAddress; exports.TransactionStatus = TransactionStatus; exports.TransactionResult = TransactionResult; exports.transactionsStatusNumberToName = transactionsStatusNumberToName; exports.transactionsStatusNameToNumber = transactionsStatusNameToNumber; exports.DECIDED_STATES = DECIDED_STATES; exports.isDecidedState = isDecidedState; exports.transactionResultNumberToName = transactionResultNumberToName; exports.TransactionResultNameToNumber = TransactionResultNameToNumber; exports.VoteType = VoteType; exports.voteTypeNumberToName = voteTypeNumberToName; exports.voteTypeNameToNumber = voteTypeNameToNumber; exports.TransactionHashVariant = TransactionHashVariant;
@@ -80,6 +80,8 @@ declare const transactionsStatusNameToNumber: {
80
80
  VALIDATORS_TIMEOUT: string;
81
81
  LEADER_TIMEOUT: string;
82
82
  };
83
+ declare const DECIDED_STATES: TransactionStatus[];
84
+ declare function isDecidedState(status: string): boolean;
83
85
  declare const transactionResultNumberToName: {
84
86
  "0": TransactionResult;
85
87
  "1": TransactionResult;
@@ -402,4 +404,4 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
402
404
  }) => Promise<any>;
403
405
  };
404
406
 
405
- export { type CalldataEncodable as C, type DecodedDeployData as D, type GenLayerClient as G, type Hash as H, type MethodDescription as M, type Network as N, type SnapSource as S, type TransactionDataElement as T, VoteType as V, type DecodedCallData as a, type GenLayerRawTransaction as b, type GenLayerTransaction as c, CalldataAddress as d, type GenLayerMethod as e, type ContractParamsArraySchemaElement as f, type ContractParamsSchema as g, type ContractMethodBase as h, type ContractMethod as i, type ContractSchema as j, type TransactionHash as k, TransactionStatus as l, TransactionResult as m, transactionsStatusNameToNumber as n, transactionResultNumberToName as o, TransactionResultNameToNumber as p, voteTypeNameToNumber as q, type TransactionType as r, TransactionHashVariant as s, transactionsStatusNumberToName as t, voteTypeNumberToName as v };
407
+ export { type CalldataEncodable as C, type DecodedDeployData as D, type GenLayerClient as G, type Hash as H, type MethodDescription as M, type Network as N, type SnapSource as S, type TransactionDataElement as T, VoteType as V, type DecodedCallData as a, type GenLayerRawTransaction as b, type GenLayerTransaction as c, CalldataAddress as d, type GenLayerMethod as e, type ContractParamsArraySchemaElement as f, type ContractParamsSchema as g, type ContractMethodBase as h, type ContractMethod as i, type ContractSchema as j, type TransactionHash as k, TransactionStatus as l, TransactionResult as m, transactionsStatusNameToNumber as n, DECIDED_STATES as o, isDecidedState as p, transactionResultNumberToName as q, TransactionResultNameToNumber as r, voteTypeNameToNumber as s, transactionsStatusNumberToName as t, type TransactionType as u, voteTypeNumberToName as v, TransactionHashVariant as w };
@@ -80,6 +80,8 @@ declare const transactionsStatusNameToNumber: {
80
80
  VALIDATORS_TIMEOUT: string;
81
81
  LEADER_TIMEOUT: string;
82
82
  };
83
+ declare const DECIDED_STATES: TransactionStatus[];
84
+ declare function isDecidedState(status: string): boolean;
83
85
  declare const transactionResultNumberToName: {
84
86
  "0": TransactionResult;
85
87
  "1": TransactionResult;
@@ -402,4 +404,4 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
402
404
  }) => Promise<any>;
403
405
  };
404
406
 
405
- export { type CalldataEncodable as C, type DecodedDeployData as D, type GenLayerClient as G, type Hash as H, type MethodDescription as M, type Network as N, type SnapSource as S, type TransactionDataElement as T, VoteType as V, type DecodedCallData as a, type GenLayerRawTransaction as b, type GenLayerTransaction as c, CalldataAddress as d, type GenLayerMethod as e, type ContractParamsArraySchemaElement as f, type ContractParamsSchema as g, type ContractMethodBase as h, type ContractMethod as i, type ContractSchema as j, type TransactionHash as k, TransactionStatus as l, TransactionResult as m, transactionsStatusNameToNumber as n, transactionResultNumberToName as o, TransactionResultNameToNumber as p, voteTypeNameToNumber as q, type TransactionType as r, TransactionHashVariant as s, transactionsStatusNumberToName as t, voteTypeNumberToName as v };
407
+ export { type CalldataEncodable as C, type DecodedDeployData as D, type GenLayerClient as G, type Hash as H, type MethodDescription as M, type Network as N, type SnapSource as S, type TransactionDataElement as T, VoteType as V, type DecodedCallData as a, type GenLayerRawTransaction as b, type GenLayerTransaction as c, CalldataAddress as d, type GenLayerMethod as e, type ContractParamsArraySchemaElement as f, type ContractParamsSchema as g, type ContractMethodBase as h, type ContractMethod as i, type ContractSchema as j, type TransactionHash as k, TransactionStatus as l, TransactionResult as m, transactionsStatusNameToNumber as n, DECIDED_STATES as o, isDecidedState as p, transactionResultNumberToName as q, TransactionResultNameToNumber as r, voteTypeNameToNumber as s, transactionsStatusNumberToName as t, type TransactionType as u, voteTypeNumberToName as v, TransactionHashVariant as w };
package/dist/index.cjs CHANGED
@@ -10,7 +10,8 @@ var _chunkZKBMABRAcjs = require('./chunk-ZKBMABRA.cjs');
10
10
 
11
11
 
12
12
 
13
- var _chunkH4ZYXVV2cjs = require('./chunk-H4ZYXVV2.cjs');
13
+
14
+ var _chunkFPZNF3JHcjs = require('./chunk-FPZNF3JH.cjs');
14
15
 
15
16
 
16
17
  var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
@@ -183,7 +184,7 @@ function encodeImpl(to, data) {
183
184
  }
184
185
  } else if (data instanceof Map) {
185
186
  encodeMap(to, data);
186
- } else if (data instanceof _chunkH4ZYXVV2cjs.CalldataAddress) {
187
+ } else if (data instanceof _chunkFPZNF3JHcjs.CalldataAddress) {
187
188
  to.push(SPECIAL_ADDR);
188
189
  for (const c of data.bytes) {
189
190
  to.push(c);
@@ -258,7 +259,7 @@ function decodeImpl(data, index) {
258
259
  case BigInt(SPECIAL_ADDR): {
259
260
  const res = data.slice(index.i, index.i + 20);
260
261
  index.i += 20;
261
- return new (0, _chunkH4ZYXVV2cjs.CalldataAddress)(res);
262
+ return new (0, _chunkFPZNF3JHcjs.CalldataAddress)(res);
262
263
  }
263
264
  }
264
265
  const type = Number(cur & 0xffn) & (1 << BITS_IN_TYPE) - 1;
@@ -370,7 +371,7 @@ function toStringImpl(data, to) {
370
371
  to.push("]");
371
372
  } else if (data instanceof Map) {
372
373
  toStringImplMap(data.entries(), to);
373
- } else if (data instanceof _chunkH4ZYXVV2cjs.CalldataAddress) {
374
+ } else if (data instanceof _chunkFPZNF3JHcjs.CalldataAddress) {
374
375
  to.push("addr#");
375
376
  for (const c of data.bytes) {
376
377
  to.push(c.toString(16));
@@ -493,7 +494,7 @@ function _toJsonSafeDeep(value, seen) {
493
494
  }
494
495
  return obj;
495
496
  }
496
- if (value instanceof _chunkH4ZYXVV2cjs.CalldataAddress) {
497
+ if (value instanceof _chunkFPZNF3JHcjs.CalldataAddress) {
497
498
  return _viem.toHex.call(void 0, value.bytes);
498
499
  }
499
500
  if (Object.getPrototypeOf(value) === Object.prototype) {
@@ -554,7 +555,7 @@ var contractActions = (client, publicClient) => {
554
555
  } = args;
555
556
  const encodedData = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
556
557
  const serializedData = serialize(encodedData);
557
- const senderAddress = _nullishCoalesce(_optionalChain([account, 'optionalAccess', _5 => _5.address]), () => ( _optionalChain([client, 'access', _6 => _6.account, 'optionalAccess', _7 => _7.address])));
558
+ const senderAddress = _nullishCoalesce(_nullishCoalesce(_optionalChain([account, 'optionalAccess', _5 => _5.address]), () => ( _optionalChain([client, 'access', _6 => _6.account, 'optionalAccess', _7 => _7.address]))), () => ( _viem.zeroAddress));
558
559
  const requestParams = {
559
560
  type: "read",
560
561
  to: address,
@@ -589,7 +590,7 @@ var contractActions = (client, publicClient) => {
589
590
  } = args;
590
591
  const encodedData = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
591
592
  const serializedData = serialize(encodedData);
592
- const senderAddress = _nullishCoalesce(_optionalChain([account, 'optionalAccess', _8 => _8.address]), () => ( _optionalChain([client, 'access', _9 => _9.account, 'optionalAccess', _10 => _10.address])));
593
+ const senderAddress = _nullishCoalesce(_nullishCoalesce(_optionalChain([account, 'optionalAccess', _8 => _8.address]), () => ( _optionalChain([client, 'access', _9 => _9.account, 'optionalAccess', _10 => _10.address]))), () => ( _viem.zeroAddress));
593
594
  const requestParams = {
594
595
  type: "write",
595
596
  to: address,
@@ -896,8 +897,8 @@ var decodeTransaction = (tx) => {
896
897
  processingBlock: tx.readStateBlockRange.processingBlock.toString(),
897
898
  proposalBlock: tx.readStateBlockRange.proposalBlock.toString()
898
899
  },
899
- statusName: _chunkH4ZYXVV2cjs.transactionsStatusNumberToName[String(tx.status)],
900
- resultName: _chunkH4ZYXVV2cjs.transactionResultNumberToName[String(tx.result)],
900
+ statusName: _chunkFPZNF3JHcjs.transactionsStatusNumberToName[String(tx.status)],
901
+ resultName: _chunkFPZNF3JHcjs.transactionResultNumberToName[String(tx.result)],
901
902
  lastRound: {
902
903
  ...tx.lastRound,
903
904
  round: tx.lastRound.round.toString(),
@@ -907,7 +908,7 @@ var decodeTransaction = (tx) => {
907
908
  appealBond: tx.lastRound.appealBond.toString(),
908
909
  rotationsLeft: tx.lastRound.rotationsLeft.toString(),
909
910
  validatorVotesName: tx.lastRound.validatorVotes.map(
910
- (vote) => _chunkH4ZYXVV2cjs.voteTypeNumberToName[String(vote)]
911
+ (vote) => _chunkFPZNF3JHcjs.voteTypeNumberToName[String(vote)]
911
912
  )
912
913
  }
913
914
  };
@@ -1046,9 +1047,8 @@ var receiptActions = (client, publicClient) => ({
1046
1047
  throw new Error("Transaction not found");
1047
1048
  }
1048
1049
  const transactionStatusString = String(transaction.status);
1049
- const transactionStatusFinalized = _chunkH4ZYXVV2cjs.transactionsStatusNameToNumber["FINALIZED" /* FINALIZED */];
1050
- const requestedStatus = _chunkH4ZYXVV2cjs.transactionsStatusNameToNumber[status];
1051
- if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && transactionStatusString === transactionStatusFinalized) {
1050
+ const requestedStatus = _chunkFPZNF3JHcjs.transactionsStatusNameToNumber[status];
1051
+ if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && _chunkFPZNF3JHcjs.isDecidedState.call(void 0, transactionStatusString)) {
1052
1052
  let finalTransaction = transaction;
1053
1053
  if (client.chain.id === _chunkZKBMABRAcjs.localnet.id) {
1054
1054
  finalTransaction = decodeLocalnetTransaction(transaction);
@@ -1076,7 +1076,7 @@ var transactionActions = (client, publicClient) => ({
1076
1076
  if (client.chain.id === _chunkZKBMABRAcjs.localnet.id) {
1077
1077
  const transaction2 = await client.getTransaction({ hash });
1078
1078
  const localnetStatus = transaction2.status === "ACTIVATED" ? "PENDING" /* PENDING */ : transaction2.status;
1079
- transaction2.status = Number(_chunkH4ZYXVV2cjs.transactionsStatusNameToNumber[localnetStatus]);
1079
+ transaction2.status = Number(_chunkFPZNF3JHcjs.transactionsStatusNameToNumber[localnetStatus]);
1080
1080
  transaction2.statusName = localnetStatus;
1081
1081
  return decodeLocalnetTransaction(transaction2);
1082
1082
  }
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as viem from 'viem';
2
2
  import { Account, Address, Hex } from 'viem';
3
3
  import { G as GenLayerChain } from './chains-BYSCF33g.cjs';
4
- import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-C_GfhvDJ.cjs';
4
+ import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-tixobC8m.cjs';
5
5
  import * as abitype from 'abitype';
6
6
  import * as viem__types_types_authorization from 'viem/_types/types/authorization';
7
7
  import * as viem_accounts from 'viem/accounts';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as viem from 'viem';
2
2
  import { Account, Address, Hex } from 'viem';
3
3
  import { G as GenLayerChain } from './chains-BYSCF33g.js';
4
- import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-BJebZa37.js';
4
+ import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-Rls_T310.js';
5
5
  import * as abitype from 'abitype';
6
6
  import * as viem__types_types_authorization from 'viem/_types/types/authorization';
7
7
  import * as viem_accounts from 'viem/accounts';
package/dist/index.js CHANGED
@@ -6,11 +6,12 @@ import {
6
6
  } from "./chunk-GEN4SJ6K.js";
7
7
  import {
8
8
  CalldataAddress,
9
+ isDecidedState,
9
10
  transactionResultNumberToName,
10
11
  transactionsStatusNameToNumber,
11
12
  transactionsStatusNumberToName,
12
13
  voteTypeNumberToName
13
- } from "./chunk-GACCNOPJ.js";
14
+ } from "./chunk-47QDX7IX.js";
14
15
  import {
15
16
  __export
16
17
  } from "./chunk-MLKGABMK.js";
@@ -554,7 +555,7 @@ var contractActions = (client, publicClient) => {
554
555
  } = args;
555
556
  const encodedData = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
556
557
  const serializedData = serialize(encodedData);
557
- const senderAddress = account?.address ?? client.account?.address;
558
+ const senderAddress = account?.address ?? client.account?.address ?? zeroAddress;
558
559
  const requestParams = {
559
560
  type: "read",
560
561
  to: address,
@@ -589,7 +590,7 @@ var contractActions = (client, publicClient) => {
589
590
  } = args;
590
591
  const encodedData = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
591
592
  const serializedData = serialize(encodedData);
592
- const senderAddress = account?.address ?? client.account?.address;
593
+ const senderAddress = account?.address ?? client.account?.address ?? zeroAddress;
593
594
  const requestParams = {
594
595
  type: "write",
595
596
  to: address,
@@ -1046,9 +1047,8 @@ var receiptActions = (client, publicClient) => ({
1046
1047
  throw new Error("Transaction not found");
1047
1048
  }
1048
1049
  const transactionStatusString = String(transaction.status);
1049
- const transactionStatusFinalized = transactionsStatusNameToNumber["FINALIZED" /* FINALIZED */];
1050
1050
  const requestedStatus = transactionsStatusNameToNumber[status];
1051
- if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && transactionStatusString === transactionStatusFinalized) {
1051
+ if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && isDecidedState(transactionStatusString)) {
1052
1052
  let finalTransaction = transaction;
1053
1053
  if (client.chain.id === localnet.id) {
1054
1054
  finalTransaction = decodeLocalnetTransaction(transaction);
@@ -10,7 +10,9 @@
10
10
 
11
11
 
12
12
 
13
- var _chunkH4ZYXVV2cjs = require('../chunk-H4ZYXVV2.cjs');
13
+
14
+
15
+ var _chunkFPZNF3JHcjs = require('../chunk-FPZNF3JH.cjs');
14
16
  require('../chunk-75ZPJI57.cjs');
15
17
 
16
18
 
@@ -24,4 +26,6 @@ require('../chunk-75ZPJI57.cjs');
24
26
 
25
27
 
26
28
 
27
- exports.CalldataAddress = _chunkH4ZYXVV2cjs.CalldataAddress; exports.TransactionHashVariant = _chunkH4ZYXVV2cjs.TransactionHashVariant; exports.TransactionResult = _chunkH4ZYXVV2cjs.TransactionResult; exports.TransactionResultNameToNumber = _chunkH4ZYXVV2cjs.TransactionResultNameToNumber; exports.TransactionStatus = _chunkH4ZYXVV2cjs.TransactionStatus; exports.VoteType = _chunkH4ZYXVV2cjs.VoteType; exports.transactionResultNumberToName = _chunkH4ZYXVV2cjs.transactionResultNumberToName; exports.transactionsStatusNameToNumber = _chunkH4ZYXVV2cjs.transactionsStatusNameToNumber; exports.transactionsStatusNumberToName = _chunkH4ZYXVV2cjs.transactionsStatusNumberToName; exports.voteTypeNameToNumber = _chunkH4ZYXVV2cjs.voteTypeNameToNumber; exports.voteTypeNumberToName = _chunkH4ZYXVV2cjs.voteTypeNumberToName;
29
+
30
+
31
+ exports.CalldataAddress = _chunkFPZNF3JHcjs.CalldataAddress; exports.DECIDED_STATES = _chunkFPZNF3JHcjs.DECIDED_STATES; exports.TransactionHashVariant = _chunkFPZNF3JHcjs.TransactionHashVariant; exports.TransactionResult = _chunkFPZNF3JHcjs.TransactionResult; exports.TransactionResultNameToNumber = _chunkFPZNF3JHcjs.TransactionResultNameToNumber; exports.TransactionStatus = _chunkFPZNF3JHcjs.TransactionStatus; exports.VoteType = _chunkFPZNF3JHcjs.VoteType; exports.isDecidedState = _chunkFPZNF3JHcjs.isDecidedState; exports.transactionResultNumberToName = _chunkFPZNF3JHcjs.transactionResultNumberToName; exports.transactionsStatusNameToNumber = _chunkFPZNF3JHcjs.transactionsStatusNameToNumber; exports.transactionsStatusNumberToName = _chunkFPZNF3JHcjs.transactionsStatusNumberToName; exports.voteTypeNameToNumber = _chunkFPZNF3JHcjs.voteTypeNameToNumber; exports.voteTypeNumberToName = _chunkFPZNF3JHcjs.voteTypeNumberToName;
@@ -1,3 +1,3 @@
1
1
  export { Account, Address } from 'viem';
2
- export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-C_GfhvDJ.cjs';
2
+ export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, o as DECIDED_STATES, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, w as TransactionHashVariant, m as TransactionResult, r as TransactionResultNameToNumber, l as TransactionStatus, u as TransactionType, V as VoteType, p as isDecidedState, q as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, s as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-tixobC8m.cjs';
3
3
  export { G as GenLayerChain } from '../chains-BYSCF33g.cjs';
@@ -1,3 +1,3 @@
1
1
  export { Account, Address } from 'viem';
2
- export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-BJebZa37.js';
2
+ export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, o as DECIDED_STATES, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, w as TransactionHashVariant, m as TransactionResult, r as TransactionResultNameToNumber, l as TransactionStatus, u as TransactionType, V as VoteType, p as isDecidedState, q as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, s as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-Rls_T310.js';
3
3
  export { G as GenLayerChain } from '../chains-BYSCF33g.js';
@@ -1,24 +1,28 @@
1
1
  import {
2
2
  CalldataAddress,
3
+ DECIDED_STATES,
3
4
  TransactionHashVariant,
4
5
  TransactionResult,
5
6
  TransactionResultNameToNumber,
6
7
  TransactionStatus,
7
8
  VoteType,
9
+ isDecidedState,
8
10
  transactionResultNumberToName,
9
11
  transactionsStatusNameToNumber,
10
12
  transactionsStatusNumberToName,
11
13
  voteTypeNameToNumber,
12
14
  voteTypeNumberToName
13
- } from "../chunk-GACCNOPJ.js";
15
+ } from "../chunk-47QDX7IX.js";
14
16
  import "../chunk-MLKGABMK.js";
15
17
  export {
16
18
  CalldataAddress,
19
+ DECIDED_STATES,
17
20
  TransactionHashVariant,
18
21
  TransactionResult,
19
22
  TransactionResultNameToNumber,
20
23
  TransactionStatus,
21
24
  VoteType,
25
+ isDecidedState,
22
26
  transactionResultNumberToName,
23
27
  transactionsStatusNameToNumber,
24
28
  transactionsStatusNumberToName,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "genlayer-js",
3
3
  "type": "module",
4
- "version": "0.18.1",
4
+ "version": "0.18.3",
5
5
  "description": "GenLayer JavaScript SDK",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -71,7 +71,7 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
71
71
  const encodedData = [calldata.encode(calldata.makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
72
72
  const serializedData = serialize(encodedData);
73
73
 
74
- const senderAddress = account?.address ?? client.account?.address;
74
+ const senderAddress = account?.address ?? client.account?.address ?? zeroAddress;
75
75
 
76
76
  const requestParams = {
77
77
  type: "read",
@@ -120,7 +120,7 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
120
120
  const encodedData = [calldata.encode(calldata.makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
121
121
  const serializedData = serialize(encodedData);
122
122
 
123
- const senderAddress = account?.address ?? client.account?.address;
123
+ const senderAddress = account?.address ?? client.account?.address ?? zeroAddress;
124
124
 
125
125
  const requestParams = {
126
126
  type: "write",
@@ -5,6 +5,7 @@ import {
5
5
  GenLayerTransaction,
6
6
  GenLayerRawTransaction,
7
7
  transactionsStatusNameToNumber,
8
+ isDecidedState,
8
9
  } from "../types/transactions";
9
10
  import {transactionsConfig} from "../config/transactions";
10
11
  import {sleep} from "../utils/async";
@@ -37,11 +38,10 @@ export const receiptActions = (client: GenLayerClient<GenLayerChain>, publicClie
37
38
  throw new Error("Transaction not found");
38
39
  }
39
40
  const transactionStatusString = String(transaction.status);
40
- const transactionStatusFinalized = transactionsStatusNameToNumber[TransactionStatus.FINALIZED];
41
41
  const requestedStatus = transactionsStatusNameToNumber[status];
42
42
  if (
43
43
  transactionStatusString === requestedStatus ||
44
- (status === TransactionStatus.ACCEPTED && transactionStatusString === transactionStatusFinalized)
44
+ (status === TransactionStatus.ACCEPTED && isDecidedState(transactionStatusString))
45
45
  ) {
46
46
  let finalTransaction = transaction;
47
47
  if (client.chain.id === localnet.id) {
@@ -71,6 +71,21 @@ export const transactionsStatusNameToNumber = {
71
71
  [TransactionStatus.LEADER_TIMEOUT]: "13",
72
72
  };
73
73
 
74
+ export const DECIDED_STATES = [
75
+ TransactionStatus.ACCEPTED,
76
+ TransactionStatus.UNDETERMINED,
77
+ TransactionStatus.LEADER_TIMEOUT,
78
+ TransactionStatus.VALIDATORS_TIMEOUT,
79
+ TransactionStatus.CANCELED,
80
+ TransactionStatus.FINALIZED
81
+ ];
82
+
83
+ export function isDecidedState(status: string): boolean {
84
+ return DECIDED_STATES.some(state =>
85
+ transactionsStatusNameToNumber[state] === status
86
+ );
87
+ }
88
+
74
89
  export const transactionResultNumberToName = {
75
90
  "0": TransactionResult.IDLE,
76
91
  "1": TransactionResult.AGREE,
@@ -5,6 +5,7 @@ import {Address} from "../src/types/accounts";
5
5
  import {createAccount, generatePrivateKey} from "../src/accounts/account";
6
6
  import {vi} from "vitest";
7
7
  import {TransactionHashVariant} from "../src/types/transactions";
8
+ import {zeroAddress} from "viem";
8
9
 
9
10
  // Setup fetch mock
10
11
  const mockFetch = vi.fn();
@@ -168,4 +169,29 @@ describe("Client Overrides", () => {
168
169
  },
169
170
  ]);
170
171
  });
172
+
173
+ it("should use zero address when no account is provided anywhere", async () => {
174
+ const client = createClient({
175
+ chain: localnet,
176
+ // No account provided on client
177
+ });
178
+
179
+ const contractAddress = "0x1234567890123456789012345678901234567890";
180
+ await client.readContract({
181
+ // No account override either
182
+ address: contractAddress as Address,
183
+ functionName: "testFunction",
184
+ args: ["arg1", "arg2"],
185
+ });
186
+
187
+ expect(lastGenCallParams).toEqual([
188
+ {
189
+ type: "read",
190
+ to: contractAddress,
191
+ from: zeroAddress, // Should default to zero address
192
+ data: expect.any(String),
193
+ transaction_hash_variant: TransactionHashVariant.LATEST_NONFINAL,
194
+ },
195
+ ]);
196
+ });
171
197
  });
@@ -0,0 +1,142 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import { TransactionStatus, DECIDED_STATES, isDecidedState } from "../src/types/transactions";
3
+ import { receiptActions } from "../src/transactions/actions";
4
+ import { localnet } from "../src/chains/localnet";
5
+
6
+ const mockFetch = vi.fn();
7
+ vi.stubGlobal("fetch", mockFetch);
8
+
9
+ describe("DECIDED_STATES constant", () => {
10
+ it("should contain all expected decided states", () => {
11
+ const expectedStates = [
12
+ TransactionStatus.ACCEPTED,
13
+ TransactionStatus.UNDETERMINED,
14
+ TransactionStatus.LEADER_TIMEOUT,
15
+ TransactionStatus.VALIDATORS_TIMEOUT,
16
+ TransactionStatus.CANCELED,
17
+ TransactionStatus.FINALIZED
18
+ ];
19
+
20
+ expect(DECIDED_STATES).toEqual(expectedStates);
21
+ });
22
+ });
23
+
24
+ describe("isDecidedState utility function", () => {
25
+ it("should return true for all decided states", () => {
26
+ const decidedStatusNumbers = ["5", "6", "13", "12", "8", "7"]; // ACCEPTED, UNDETERMINED, LEADER_TIMEOUT, VALIDATORS_TIMEOUT, CANCELED, FINALIZED
27
+
28
+ decidedStatusNumbers.forEach(statusNum => {
29
+ expect(isDecidedState(statusNum)).toBe(true);
30
+ });
31
+ });
32
+
33
+ it("should return false for non-decided states", () => {
34
+ const nonDecidedStatusNumbers = ["0", "1", "2", "3", "4", "9", "10", "11"]; // UNINITIALIZED, PENDING, PROPOSING, COMMITTING, REVEALING, APPEAL_REVEALING, APPEAL_COMMITTING, READY_TO_FINALIZE
35
+
36
+ nonDecidedStatusNumbers.forEach(statusNum => {
37
+ expect(isDecidedState(statusNum)).toBe(false);
38
+ });
39
+ });
40
+
41
+ it("should return false for invalid statuses", () => {
42
+ const invalidStatuses = ["999", "invalid", ""];
43
+
44
+ invalidStatuses.forEach(status => {
45
+ expect(isDecidedState(status)).toBe(false);
46
+ });
47
+ });
48
+ });
49
+
50
+ describe("waitForTransactionReceipt with DECIDED_STATES", () => {
51
+ beforeEach(() => {
52
+ mockFetch.mockReset();
53
+ });
54
+
55
+ it("should accept all decided states when waiting for ACCEPTED", async () => {
56
+ const decidedStatusNumbers = ["5", "6", "13", "12", "8", "7"]; // All decided states
57
+
58
+ for (const statusNum of decidedStatusNumbers) {
59
+ const mockTransaction = {
60
+ hash: "0x4b8037744adab7ea8335b4f839979d20031d83a8ccdf706e0ae61312930335f6",
61
+ status: statusNum,
62
+ from_address: "0x123",
63
+ to_address: "0x456",
64
+ value: "0",
65
+ gaslimit: "1000000",
66
+ nonce: "1",
67
+ created_at: "2023-01-01T00:00:00Z",
68
+ };
69
+
70
+ const mockClient = {
71
+ chain: localnet,
72
+ getTransaction: vi.fn().mockResolvedValue(mockTransaction)
73
+ };
74
+
75
+ const mockPublicClient = {} as any;
76
+
77
+ const actions = receiptActions(mockClient as any, mockPublicClient);
78
+ const result = await actions.waitForTransactionReceipt({
79
+ hash: "0x4b8037744adab7ea8335b4f839979d20031d83a8ccdf706e0ae61312930335f6" as any,
80
+ status: TransactionStatus.ACCEPTED,
81
+ });
82
+
83
+ expect(result).toEqual(mockTransaction);
84
+ }
85
+ });
86
+
87
+ it("should not affect waiting for specific non-ACCEPTED statuses", async () => {
88
+ const mockTransaction = {
89
+ hash: "0x4b8037744adab7ea8335b4f839979d20031d83a8ccdf706e0ae61312930335f6",
90
+ status: "7", // FINALIZED
91
+ from_address: "0x123",
92
+ to_address: "0x456",
93
+ value: "0",
94
+ gaslimit: "1000000",
95
+ nonce: "1",
96
+ created_at: "2023-01-01T00:00:00Z",
97
+ };
98
+
99
+ const mockClient = {
100
+ chain: localnet,
101
+ getTransaction: vi.fn().mockResolvedValue(mockTransaction)
102
+ };
103
+
104
+ const mockPublicClient = {} as any;
105
+
106
+ const actions = receiptActions(mockClient as any, mockPublicClient);
107
+ const result = await actions.waitForTransactionReceipt({
108
+ hash: "0x4b8037744adab7ea8335b4f839979d20031d83a8ccdf706e0ae61312930335f6" as any,
109
+ status: TransactionStatus.FINALIZED,
110
+ });
111
+
112
+ expect(result).toEqual(mockTransaction);
113
+ });
114
+
115
+ it("should maintain backward compatibility", async () => {
116
+ const mockTransaction = {
117
+ hash: "0x4b8037744adab7ea8335b4f839979d20031d83a8ccdf706e0ae61312930335f6",
118
+ status: "5", // ACCEPTED
119
+ from_address: "0x123",
120
+ to_address: "0x456",
121
+ value: "0",
122
+ gaslimit: "1000000",
123
+ nonce: "1",
124
+ created_at: "2023-01-01T00:00:00Z",
125
+ };
126
+
127
+ const mockClient = {
128
+ chain: localnet,
129
+ getTransaction: vi.fn().mockResolvedValue(mockTransaction)
130
+ };
131
+
132
+ const mockPublicClient = {} as any;
133
+
134
+ const actions = receiptActions(mockClient as any, mockPublicClient);
135
+ const result = await actions.waitForTransactionReceipt({
136
+ hash: "0x4b8037744adab7ea8335b4f839979d20031d83a8ccdf706e0ae61312930335f6" as any,
137
+ status: TransactionStatus.ACCEPTED,
138
+ });
139
+
140
+ expect(result).toEqual(mockTransaction);
141
+ });
142
+ });