genlayer-js 0.4.1 → 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 +7 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/types/index.d.cts +24 -5
- package/dist/types/index.d.ts +24 -5
- package/package.json +1 -1
- package/src/contracts/actions.ts +2 -2
- package/src/types/calldata.ts +0 -1
- package/src/types/clients.ts +8 -3
- package/src/types/transactions.ts +18 -1
- package/tests/client.test-d.ts +28 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
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
|
+
|
|
3
10
|
## 0.4.1 (2024-11-20)
|
|
4
11
|
|
|
5
12
|
## 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])
|
|
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
|
|
215
|
+
from: account?.address ?? client.account?.address,
|
|
216
216
|
data: encodedData
|
|
217
217
|
};
|
|
218
218
|
const result = await client.request({
|
package/dist/types/index.d.cts
CHANGED
|
@@ -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 |
|
|
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?:
|
|
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
|
|
125
|
+
}) => Promise<`0x${string}`>;
|
|
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
|
|
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/dist/types/index.d.ts
CHANGED
|
@@ -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 |
|
|
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?:
|
|
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
|
|
125
|
+
}) => Promise<`0x${string}`>;
|
|
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
|
|
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
package/src/contracts/actions.ts
CHANGED
|
@@ -32,7 +32,7 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
32
32
|
|
|
33
33
|
const requestParams = {
|
|
34
34
|
to: address,
|
|
35
|
-
from: 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
|
|
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);
|
package/src/types/calldata.ts
CHANGED
package/src/types/clients.ts
CHANGED
|
@@ -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<
|
|
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
|
|
42
|
+
}) => Promise<`0x${string}`>;
|
|
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
|
|
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?:
|
|
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;
|
package/tests/client.test-d.ts
CHANGED
|
@@ -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
|
});
|