genlayer-js 0.4.1 → 0.4.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.4.3 (2024-11-26)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * readContract return type ([#32](https://github.com/yeagerai/genlayer-js/issues/32)) ([8222453](https://github.com/yeagerai/genlayer-js/commit/82224530cf5c28b17b43943fad92cd5782ecf1be))
9
+
10
+ ## 0.4.2 (2024-11-22)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * types ([#29](https://github.com/yeagerai/genlayer-js/issues/29)) ([d8f16fd](https://github.com/yeagerai/genlayer-js/commit/d8f16fdb739e32e6eea52a38e23d96a4433728ad))
16
+
3
17
  ## 0.4.1 (2024-11-20)
4
18
 
5
19
  ## 0.4.0 (2024-11-14)
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
4
  var _chunkIINRDYKFcjs = require('./chunk-IINRDYKF.cjs');
@@ -212,7 +212,7 @@ var overrideContractActions = (client) => {
212
212
  const encodedData = encodeAndSerialize({ method: functionName, args: params });
213
213
  const requestParams = {
214
214
  to: address,
215
- from: _optionalChain([account, 'optionalAccess', _5 => _5.address]) || _optionalChain([client, 'access', _6 => _6.account, 'optionalAccess', _7 => _7.address]),
215
+ from: _nullishCoalesce(_optionalChain([account, 'optionalAccess', _5 => _5.address]), () => ( _optionalChain([client, 'access', _6 => _6.account, 'optionalAccess', _7 => _7.address]))),
216
216
  data: encodedData
217
217
  };
218
218
  const result = await client.request({
package/dist/index.js CHANGED
@@ -212,7 +212,7 @@ var overrideContractActions = (client) => {
212
212
  const encodedData = encodeAndSerialize({ method: functionName, args: params });
213
213
  const requestParams = {
214
214
  to: address,
215
- from: account?.address || client.account?.address,
215
+ from: account?.address ?? client.account?.address,
216
216
  data: encodedData
217
217
  };
218
218
  const result = await client.request({
@@ -10,7 +10,7 @@ declare class Address {
10
10
  bytes: Uint8Array;
11
11
  constructor(addr: Uint8Array);
12
12
  }
13
- type CalldataEncodable = null | boolean | Address | number | bigint | string | Uint8Array | Address | Array<CalldataEncodable> | Map<string, CalldataEncodable> | {
13
+ type CalldataEncodable = null | boolean | Address | number | bigint | string | Uint8Array | Array<CalldataEncodable> | Map<string, CalldataEncodable> | {
14
14
  [key: string]: CalldataEncodable;
15
15
  };
16
16
  type MethodDescription = {
@@ -41,7 +41,24 @@ type GenLayerTransaction = {
41
41
  from_address?: string;
42
42
  to_address?: string;
43
43
  data?: Record<string, unknown>;
44
- consensus_data?: Record<string, unknown>;
44
+ consensus_data?: {
45
+ final: boolean;
46
+ leader_receipt?: {
47
+ calldata: string;
48
+ class_name: string;
49
+ contract_state: string;
50
+ eq_outputs: Record<string, unknown>;
51
+ error: string | null;
52
+ execution_result: string;
53
+ gas_used: number;
54
+ mode: string;
55
+ node_config: Record<string, unknown>;
56
+ pending_transactions: unknown[];
57
+ vote: string;
58
+ };
59
+ validators?: Record<string, unknown>[];
60
+ votes?: Record<string, string>;
61
+ };
45
62
  nonce?: number;
46
63
  value?: number;
47
64
  type?: number;
@@ -94,7 +111,7 @@ type GenLayerMethod = {
94
111
  method: "eth_getTransactionCount";
95
112
  params: [address: string];
96
113
  };
97
- type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transport, TSimulatorChain>, "transport" | "getTransaction" | "readContract"> & Omit<PublicActions<Transport, TSimulatorChain>, "readContract" | "getTransaction"> & {
114
+ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transport, TSimulatorChain>, "transport" | "getTransaction" | "readContract"> & Omit<PublicActions<Transport, TSimulatorChain>, "readContract" | "getTransaction" | "waitForTransactionReceipt"> & {
98
115
  request: Client<Transport, TSimulatorChain>["request"] & {
99
116
  <TMethod extends GenLayerMethod>(args: Extract<GenLayerMethod, {
100
117
  method: TMethod["method"];
@@ -105,7 +122,7 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
105
122
  address: Address$1;
106
123
  functionName: string;
107
124
  args: CalldataEncodable[];
108
- }) => Promise<any>;
125
+ }) => Promise<unknown>;
109
126
  writeContract: (args: {
110
127
  account?: Account;
111
128
  address: Address$1;
@@ -119,7 +136,7 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
119
136
  code: string;
120
137
  args: CalldataEncodable[];
121
138
  leader_only?: boolean;
122
- }) => Promise<any>;
139
+ }) => Promise<`0x${string}`>;
123
140
  getTransaction: (args: {
124
141
  hash: TransactionHash;
125
142
  }) => Promise<GenLayerTransaction>;
@@ -129,6 +146,8 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
129
146
  waitForTransactionReceipt: (args: {
130
147
  hash: TransactionHash;
131
148
  status?: TransactionStatus;
149
+ interval?: number;
150
+ retries?: number;
132
151
  }) => Promise<GenLayerTransaction>;
133
152
  getContractSchema: (address: string) => Promise<ContractSchema>;
134
153
  getContractSchemaForCode: (contractCode: string) => Promise<ContractSchema>;
@@ -10,7 +10,7 @@ declare class Address {
10
10
  bytes: Uint8Array;
11
11
  constructor(addr: Uint8Array);
12
12
  }
13
- type CalldataEncodable = null | boolean | Address | number | bigint | string | Uint8Array | Address | Array<CalldataEncodable> | Map<string, CalldataEncodable> | {
13
+ type CalldataEncodable = null | boolean | Address | number | bigint | string | Uint8Array | Array<CalldataEncodable> | Map<string, CalldataEncodable> | {
14
14
  [key: string]: CalldataEncodable;
15
15
  };
16
16
  type MethodDescription = {
@@ -41,7 +41,24 @@ type GenLayerTransaction = {
41
41
  from_address?: string;
42
42
  to_address?: string;
43
43
  data?: Record<string, unknown>;
44
- consensus_data?: Record<string, unknown>;
44
+ consensus_data?: {
45
+ final: boolean;
46
+ leader_receipt?: {
47
+ calldata: string;
48
+ class_name: string;
49
+ contract_state: string;
50
+ eq_outputs: Record<string, unknown>;
51
+ error: string | null;
52
+ execution_result: string;
53
+ gas_used: number;
54
+ mode: string;
55
+ node_config: Record<string, unknown>;
56
+ pending_transactions: unknown[];
57
+ vote: string;
58
+ };
59
+ validators?: Record<string, unknown>[];
60
+ votes?: Record<string, string>;
61
+ };
45
62
  nonce?: number;
46
63
  value?: number;
47
64
  type?: number;
@@ -94,7 +111,7 @@ type GenLayerMethod = {
94
111
  method: "eth_getTransactionCount";
95
112
  params: [address: string];
96
113
  };
97
- type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transport, TSimulatorChain>, "transport" | "getTransaction" | "readContract"> & Omit<PublicActions<Transport, TSimulatorChain>, "readContract" | "getTransaction"> & {
114
+ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transport, TSimulatorChain>, "transport" | "getTransaction" | "readContract"> & Omit<PublicActions<Transport, TSimulatorChain>, "readContract" | "getTransaction" | "waitForTransactionReceipt"> & {
98
115
  request: Client<Transport, TSimulatorChain>["request"] & {
99
116
  <TMethod extends GenLayerMethod>(args: Extract<GenLayerMethod, {
100
117
  method: TMethod["method"];
@@ -105,7 +122,7 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
105
122
  address: Address$1;
106
123
  functionName: string;
107
124
  args: CalldataEncodable[];
108
- }) => Promise<any>;
125
+ }) => Promise<unknown>;
109
126
  writeContract: (args: {
110
127
  account?: Account;
111
128
  address: Address$1;
@@ -119,7 +136,7 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
119
136
  code: string;
120
137
  args: CalldataEncodable[];
121
138
  leader_only?: boolean;
122
- }) => Promise<any>;
139
+ }) => Promise<`0x${string}`>;
123
140
  getTransaction: (args: {
124
141
  hash: TransactionHash;
125
142
  }) => Promise<GenLayerTransaction>;
@@ -129,6 +146,8 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
129
146
  waitForTransactionReceipt: (args: {
130
147
  hash: TransactionHash;
131
148
  status?: TransactionStatus;
149
+ interval?: number;
150
+ retries?: number;
132
151
  }) => Promise<GenLayerTransaction>;
133
152
  getContractSchema: (address: string) => Promise<ContractSchema>;
134
153
  getContractSchemaForCode: (contractCode: string) => Promise<ContractSchema>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "genlayer-js",
3
3
  "type": "module",
4
- "version": "0.4.1",
4
+ "version": "0.4.3",
5
5
  "description": "GenLayer JavaScript SDK",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -26,13 +26,13 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
26
26
  address: Address;
27
27
  functionName: string;
28
28
  args: CalldataEncodable[];
29
- }): Promise<any> => {
29
+ }): Promise<unknown> => {
30
30
  const {account, address, functionName, args: params} = args;
31
31
  const encodedData = encodeAndSerialize({method: functionName, args: params});
32
32
 
33
33
  const requestParams = {
34
34
  to: address,
35
- from: account?.address || client.account?.address,
35
+ from: account?.address ?? client.account?.address,
36
36
  data: encodedData,
37
37
  };
38
38
  const result = await client.request({
@@ -49,7 +49,7 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
49
49
  args: CalldataEncodable[];
50
50
  value: bigint;
51
51
  leader_only?: boolean;
52
- }): Promise<any> => {
52
+ }): Promise<`0x${string}`> => {
53
53
  const {account, address, functionName, args: params, value = 0n, leader_only = false} = args;
54
54
  const data = [encode({method: functionName, args: params}), leader_only];
55
55
  const serializedData = serialize(data);
@@ -18,7 +18,6 @@ export type CalldataEncodable =
18
18
  | bigint
19
19
  | string
20
20
  | Uint8Array /// bytes
21
- | Address
22
21
  | Array<CalldataEncodable>
23
22
  | Map<string, CalldataEncodable>
24
23
  | {[key: string]: CalldataEncodable}; /// also a "map"
@@ -25,7 +25,10 @@ export type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<
25
25
  Client<Transport, TSimulatorChain>,
26
26
  "transport" | "getTransaction" | "readContract"
27
27
  > &
28
- Omit<PublicActions<Transport, TSimulatorChain>, "readContract" | "getTransaction"> & {
28
+ Omit<
29
+ PublicActions<Transport, TSimulatorChain>,
30
+ "readContract" | "getTransaction" | "waitForTransactionReceipt"
31
+ > & {
29
32
  request: Client<Transport, TSimulatorChain>["request"] & {
30
33
  <TMethod extends GenLayerMethod>(
31
34
  args: Extract<GenLayerMethod, {method: TMethod["method"]}>,
@@ -36,7 +39,7 @@ export type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<
36
39
  address: Address;
37
40
  functionName: string;
38
41
  args: CalldataEncodable[];
39
- }) => Promise<any>;
42
+ }) => Promise<unknown>;
40
43
  writeContract: (args: {
41
44
  account?: Account;
42
45
  address: Address;
@@ -50,12 +53,14 @@ export type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<
50
53
  code: string;
51
54
  args: CalldataEncodable[];
52
55
  leader_only?: boolean;
53
- }) => Promise<any>;
56
+ }) => Promise<`0x${string}`>;
54
57
  getTransaction: (args: {hash: TransactionHash}) => Promise<GenLayerTransaction>;
55
58
  getCurrentNonce: (args: {address: string}) => Promise<number>;
56
59
  waitForTransactionReceipt: (args: {
57
60
  hash: TransactionHash;
58
61
  status?: TransactionStatus;
62
+ interval?: number;
63
+ retries?: number;
59
64
  }) => Promise<GenLayerTransaction>;
60
65
  getContractSchema: (address: string) => Promise<ContractSchema>;
61
66
  getContractSchemaForCode: (contractCode: string) => Promise<ContractSchema>;
@@ -17,7 +17,24 @@ export type GenLayerTransaction = {
17
17
  from_address?: string;
18
18
  to_address?: string;
19
19
  data?: Record<string, unknown>;
20
- consensus_data?: Record<string, unknown>;
20
+ consensus_data?: {
21
+ final: boolean;
22
+ leader_receipt?: {
23
+ calldata: string;
24
+ class_name: string;
25
+ contract_state: string;
26
+ eq_outputs: Record<string, unknown>;
27
+ error: string | null;
28
+ execution_result: string;
29
+ gas_used: number;
30
+ mode: string;
31
+ node_config: Record<string, unknown>;
32
+ pending_transactions: unknown[];
33
+ vote: string;
34
+ };
35
+ validators?: Record<string, unknown>[];
36
+ votes?: Record<string, string>;
37
+ };
21
38
  nonce?: number;
22
39
  value?: number;
23
40
  type?: number;
@@ -1,6 +1,7 @@
1
1
  import {createClient} from "../src/client/client";
2
2
  import {simulator} from "../src/chains/simulator";
3
3
  import {createAccount, generatePrivateKey} from "../src/accounts/account";
4
+ import {TransactionHash, TransactionStatus} from "../src/types/transactions";
4
5
 
5
6
  test("type checks", () => {
6
7
  const client = createClient({
@@ -36,4 +37,31 @@ test("type checks", () => {
36
37
  void client.getContractSchema(exampleAddress);
37
38
 
38
39
  void client.getContractSchemaForCode("class SomeContract...");
40
+
41
+ void client.waitForTransactionReceipt({
42
+ hash: "0x1234567890123456789012345678901234567890123456789012345678901234" as TransactionHash,
43
+ });
44
+
45
+ void client.waitForTransactionReceipt({
46
+ hash: "0x1234567890123456789012345678901234567890123456789012345678901234" as TransactionHash,
47
+ status: TransactionStatus.FINALIZED,
48
+ });
49
+
50
+ void client.waitForTransactionReceipt({
51
+ hash: "0x1234567890123456789012345678901234567890123456789012345678901234" as TransactionHash,
52
+ status: TransactionStatus.FINALIZED,
53
+ interval: 1000,
54
+ });
55
+
56
+ void client.waitForTransactionReceipt({
57
+ hash: "0x1234567890123456789012345678901234567890123456789012345678901234" as TransactionHash,
58
+ status: TransactionStatus.FINALIZED,
59
+ interval: 1000,
60
+ retries: 10,
61
+ });
62
+
63
+ // @ts-expect-error missing hash
64
+ void client.waitForTransactionReceipt({
65
+ status: TransactionStatus.FINALIZED,
66
+ });
39
67
  });