genlayer-js 0.4.0 → 0.4.2

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,14 @@
1
1
 
2
2
 
3
+ ## 0.4.2 (2024-11-22)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * types ([#29](https://github.com/yeagerai/genlayer-js/issues/29)) ([d8f16fd](https://github.com/yeagerai/genlayer-js/commit/d8f16fdb739e32e6eea52a38e23d96a4433728ad))
9
+
10
+ ## 0.4.1 (2024-11-20)
11
+
3
12
  ## 0.4.0 (2024-11-14)
4
13
 
5
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({
@@ -222,8 +222,9 @@ var overrideContractActions = (client) => {
222
222
  return result;
223
223
  };
224
224
  client.writeContract = async (args) => {
225
- const { account, address, functionName, args: params, value = 0n } = args;
226
- const encodedData = encodeAndSerialize({ method: functionName, args: params });
225
+ const { account, address, functionName, args: params, value = 0n, leader_only = false } = args;
226
+ const data = [encode({ method: functionName, args: params }), leader_only];
227
+ const serializedData = serialize(data);
227
228
  const senderAccount = account || client.account;
228
229
  if (!senderAccount) {
229
230
  throw new Error(
@@ -235,7 +236,7 @@ var overrideContractActions = (client) => {
235
236
  }
236
237
  const nonce = await client.getCurrentNonce({ address: senderAccount.address });
237
238
  const signedTransaction = await senderAccount.signTransaction({
238
- data: encodedData,
239
+ data: serializedData,
239
240
  to: address,
240
241
  value,
241
242
  type: "legacy",
@@ -248,8 +249,8 @@ var overrideContractActions = (client) => {
248
249
  return result;
249
250
  };
250
251
  client.deployContract = async (args) => {
251
- const { account, code, args: constructorArgs } = args;
252
- const data = [code, encode({ args: constructorArgs })];
252
+ const { account, code, args: constructorArgs, leader_only = false } = args;
253
+ const data = [code, encode({ args: constructorArgs }), leader_only];
253
254
  const serializedData = serialize(data);
254
255
  const senderAccount = account || client.account;
255
256
  if (!senderAccount) {
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({
@@ -222,8 +222,9 @@ var overrideContractActions = (client) => {
222
222
  return result;
223
223
  };
224
224
  client.writeContract = async (args) => {
225
- const { account, address, functionName, args: params, value = 0n } = args;
226
- const encodedData = encodeAndSerialize({ method: functionName, args: params });
225
+ const { account, address, functionName, args: params, value = 0n, leader_only = false } = args;
226
+ const data = [encode({ method: functionName, args: params }), leader_only];
227
+ const serializedData = serialize(data);
227
228
  const senderAccount = account || client.account;
228
229
  if (!senderAccount) {
229
230
  throw new Error(
@@ -235,7 +236,7 @@ var overrideContractActions = (client) => {
235
236
  }
236
237
  const nonce = await client.getCurrentNonce({ address: senderAccount.address });
237
238
  const signedTransaction = await senderAccount.signTransaction({
238
- data: encodedData,
239
+ data: serializedData,
239
240
  to: address,
240
241
  value,
241
242
  type: "legacy",
@@ -248,8 +249,8 @@ var overrideContractActions = (client) => {
248
249
  return result;
249
250
  };
250
251
  client.deployContract = async (args) => {
251
- const { account, code, args: constructorArgs } = args;
252
- const data = [code, encode({ args: constructorArgs })];
252
+ const { account, code, args: constructorArgs, leader_only = false } = args;
253
+ const data = [code, encode({ args: constructorArgs }), leader_only];
253
254
  const serializedData = serialize(data);
254
255
  const senderAccount = account || client.account;
255
256
  if (!senderAccount) {
@@ -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,19 +122,21 @@ 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<`0x${string}`>;
109
126
  writeContract: (args: {
110
127
  account?: Account;
111
128
  address: Address$1;
112
129
  functionName: string;
113
130
  args: CalldataEncodable[];
114
131
  value: bigint;
132
+ leader_only?: boolean;
115
133
  }) => Promise<any>;
116
134
  deployContract: (args: {
117
135
  account?: Account;
118
136
  code: string;
119
137
  args: CalldataEncodable[];
120
- }) => Promise<any>;
138
+ leader_only?: boolean;
139
+ }) => Promise<`0x${string}`>;
121
140
  getTransaction: (args: {
122
141
  hash: TransactionHash;
123
142
  }) => Promise<GenLayerTransaction>;
@@ -127,6 +146,8 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
127
146
  waitForTransactionReceipt: (args: {
128
147
  hash: TransactionHash;
129
148
  status?: TransactionStatus;
149
+ interval?: number;
150
+ retries?: number;
130
151
  }) => Promise<GenLayerTransaction>;
131
152
  getContractSchema: (address: string) => Promise<ContractSchema>;
132
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,19 +122,21 @@ 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<`0x${string}`>;
109
126
  writeContract: (args: {
110
127
  account?: Account;
111
128
  address: Address$1;
112
129
  functionName: string;
113
130
  args: CalldataEncodable[];
114
131
  value: bigint;
132
+ leader_only?: boolean;
115
133
  }) => Promise<any>;
116
134
  deployContract: (args: {
117
135
  account?: Account;
118
136
  code: string;
119
137
  args: CalldataEncodable[];
120
- }) => Promise<any>;
138
+ leader_only?: boolean;
139
+ }) => Promise<`0x${string}`>;
121
140
  getTransaction: (args: {
122
141
  hash: TransactionHash;
123
142
  }) => Promise<GenLayerTransaction>;
@@ -127,6 +146,8 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
127
146
  waitForTransactionReceipt: (args: {
128
147
  hash: TransactionHash;
129
148
  status?: TransactionStatus;
149
+ interval?: number;
150
+ retries?: number;
130
151
  }) => Promise<GenLayerTransaction>;
131
152
  getContractSchema: (address: string) => Promise<ContractSchema>;
132
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.0",
4
+ "version": "0.4.2",
5
5
  "description": "GenLayer JavaScript SDK",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -32,7 +32,7 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
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({
@@ -48,9 +48,11 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
48
48
  functionName: string;
49
49
  args: CalldataEncodable[];
50
50
  value: bigint;
51
- }): Promise<any> => {
52
- const {account, address, functionName, args: params, value = 0n} = args;
53
- const encodedData = encodeAndSerialize({method: functionName, args: params});
51
+ leader_only?: boolean;
52
+ }): Promise<`0x${string}`> => {
53
+ const {account, address, functionName, args: params, value = 0n, leader_only = false} = args;
54
+ const data = [encode({method: functionName, args: params}), leader_only];
55
+ const serializedData = serialize(data);
54
56
 
55
57
  const senderAccount = account || client.account;
56
58
  if (!senderAccount) {
@@ -66,7 +68,7 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
66
68
  const nonce = await client.getCurrentNonce({address: senderAccount.address});
67
69
 
68
70
  const signedTransaction = await senderAccount.signTransaction({
69
- data: encodedData,
71
+ data: serializedData,
70
72
  to: address,
71
73
  value,
72
74
  type: "legacy",
@@ -79,9 +81,14 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
79
81
  return result;
80
82
  };
81
83
 
82
- client.deployContract = async (args: {account?: Account; code: string; args: CalldataEncodable[]}) => {
83
- const {account, code, args: constructorArgs} = args;
84
- const data = [code, encode({args: constructorArgs})];
84
+ client.deployContract = async (args: {
85
+ account?: Account;
86
+ code: string;
87
+ args: CalldataEncodable[];
88
+ leader_only?: boolean;
89
+ }) => {
90
+ const {account, code, args: constructorArgs, leader_only = false} = args;
91
+ const data = [code, encode({args: constructorArgs}), leader_only];
85
92
  const serializedData = serialize(data);
86
93
 
87
94
  const senderAccount = account || client.account;
@@ -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,20 +39,28 @@ export type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<
36
39
  address: Address;
37
40
  functionName: string;
38
41
  args: CalldataEncodable[];
39
- }) => Promise<any>;
42
+ }) => Promise<`0x${string}`>;
40
43
  writeContract: (args: {
41
44
  account?: Account;
42
45
  address: Address;
43
46
  functionName: string;
44
47
  args: CalldataEncodable[];
45
48
  value: bigint;
49
+ leader_only?: boolean;
46
50
  }) => Promise<any>;
47
- deployContract: (args: {account?: Account; code: string; args: CalldataEncodable[]}) => Promise<any>;
51
+ deployContract: (args: {
52
+ account?: Account;
53
+ code: string;
54
+ args: CalldataEncodable[];
55
+ leader_only?: boolean;
56
+ }) => Promise<`0x${string}`>;
48
57
  getTransaction: (args: {hash: TransactionHash}) => Promise<GenLayerTransaction>;
49
58
  getCurrentNonce: (args: {address: string}) => Promise<number>;
50
59
  waitForTransactionReceipt: (args: {
51
60
  hash: TransactionHash;
52
61
  status?: TransactionStatus;
62
+ interval?: number;
63
+ retries?: number;
53
64
  }) => Promise<GenLayerTransaction>;
54
65
  getContractSchema: (address: string) => Promise<ContractSchema>;
55
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
  });