genlayer-js 0.5.0 → 0.6.0
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/README.md +1 -0
- package/dist/index.cjs +8 -10
- package/dist/index.js +6 -8
- package/dist/types/index.cjs +2 -2
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -1
- package/package.json +1 -1
- package/src/contracts/actions.ts +26 -20
- package/src/types/clients.ts +1 -0
- package/tests/client.test.ts +4 -2
- /package/dist/{chunk-M7SA3INM.js → chunk-G7EQ6KPE.js} +0 -0
- /package/dist/{chunk-YI62SDKV.cjs → chunk-X6WK4DK4.cjs} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## 0.6.0 (2025-01-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add stateStatus in readContract ([#50](https://github.com/yeagerai/genlayer-js/issues/50)) ([a9bcf8d](https://github.com/yeagerai/genlayer-js/commit/a9bcf8d83890448b85282ceb0c33060a19ea4e9a))
|
|
9
|
+
|
|
3
10
|
## 0.5.0 (2025-01-08)
|
|
4
11
|
|
|
5
12
|
|
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var _chunkIINRDYKFcjs = require('./chunk-IINRDYKF.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkX6WK4DK4cjs = require('./chunk-X6WK4DK4.cjs');
|
|
8
8
|
require('./chunk-75ZPJI57.cjs');
|
|
9
9
|
|
|
10
10
|
// src/client/client.ts
|
|
@@ -76,7 +76,7 @@ function decodeImpl(data, index) {
|
|
|
76
76
|
case BigInt(SPECIAL_ADDR): {
|
|
77
77
|
const res = data.slice(index.i, index.i + 20);
|
|
78
78
|
index.i += 20;
|
|
79
|
-
return new (0,
|
|
79
|
+
return new (0, _chunkX6WK4DK4cjs.Address)(res);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
const type = Number(cur & 0xffn) & (1 << BITS_IN_TYPE) - 1;
|
|
@@ -241,7 +241,7 @@ function encodeImpl(to, data) {
|
|
|
241
241
|
}
|
|
242
242
|
} else if (data instanceof Map) {
|
|
243
243
|
encodeMap(to, data);
|
|
244
|
-
} else if (data instanceof
|
|
244
|
+
} else if (data instanceof _chunkX6WK4DK4cjs.Address) {
|
|
245
245
|
to.push(SPECIAL_ADDR);
|
|
246
246
|
for (const c of data.bytes) {
|
|
247
247
|
to.push(c);
|
|
@@ -265,9 +265,6 @@ function encode(data) {
|
|
|
265
265
|
function serialize(data) {
|
|
266
266
|
return _viem.toRlp.call(void 0, data.map((param) => _viem.toHex.call(void 0, param)));
|
|
267
267
|
}
|
|
268
|
-
function encodeAndSerialize(data) {
|
|
269
|
-
return serialize([encode(data)]);
|
|
270
|
-
}
|
|
271
268
|
|
|
272
269
|
// src/contracts/actions.ts
|
|
273
270
|
var contractActions = (client) => {
|
|
@@ -290,13 +287,14 @@ var contractActions = (client) => {
|
|
|
290
287
|
};
|
|
291
288
|
var overrideContractActions = (client) => {
|
|
292
289
|
client.readContract = async (args) => {
|
|
293
|
-
const { account, address, functionName, args: params } = args;
|
|
294
|
-
const encodedData =
|
|
295
|
-
|
|
290
|
+
const { account, address, functionName, args: params, stateStatus = "ACCEPTED" /* ACCEPTED */ } = args;
|
|
291
|
+
const encodedData = [encode({ method: functionName, args: params }), stateStatus];
|
|
292
|
+
const serializedData = serialize(encodedData);
|
|
293
|
+
const senderAddress = _nullishCoalesce(_optionalChain([account, 'optionalAccess', _5 => _5.address]), () => ( _optionalChain([client, 'access', _6 => _6.account, 'optionalAccess', _7 => _7.address])));
|
|
296
294
|
const requestParams = {
|
|
297
295
|
to: address,
|
|
298
296
|
from: senderAddress,
|
|
299
|
-
data:
|
|
297
|
+
data: serializedData
|
|
300
298
|
};
|
|
301
299
|
const result = await client.request({
|
|
302
300
|
method: "eth_call",
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-3TYB36DW.js";
|
|
5
5
|
import {
|
|
6
6
|
Address
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-G7EQ6KPE.js";
|
|
8
8
|
import "./chunk-MLKGABMK.js";
|
|
9
9
|
|
|
10
10
|
// src/client/client.ts
|
|
@@ -265,9 +265,6 @@ function encode(data) {
|
|
|
265
265
|
function serialize(data) {
|
|
266
266
|
return toRlp(data.map((param) => toHex(param)));
|
|
267
267
|
}
|
|
268
|
-
function encodeAndSerialize(data) {
|
|
269
|
-
return serialize([encode(data)]);
|
|
270
|
-
}
|
|
271
268
|
|
|
272
269
|
// src/contracts/actions.ts
|
|
273
270
|
var contractActions = (client) => {
|
|
@@ -290,13 +287,14 @@ var contractActions = (client) => {
|
|
|
290
287
|
};
|
|
291
288
|
var overrideContractActions = (client) => {
|
|
292
289
|
client.readContract = async (args) => {
|
|
293
|
-
const { account, address, functionName, args: params } = args;
|
|
294
|
-
const encodedData =
|
|
295
|
-
|
|
290
|
+
const { account, address, functionName, args: params, stateStatus = "ACCEPTED" /* ACCEPTED */ } = args;
|
|
291
|
+
const encodedData = [encode({ method: functionName, args: params }), stateStatus];
|
|
292
|
+
const serializedData = serialize(encodedData);
|
|
293
|
+
const senderAddress = account?.address ?? client.account?.address;
|
|
296
294
|
const requestParams = {
|
|
297
295
|
to: address,
|
|
298
296
|
from: senderAddress,
|
|
299
|
-
data:
|
|
297
|
+
data: serializedData
|
|
300
298
|
};
|
|
301
299
|
const result = await client.request({
|
|
302
300
|
method: "eth_call",
|
package/dist/types/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkX6WK4DK4cjs = require('../chunk-X6WK4DK4.cjs');
|
|
4
4
|
require('../chunk-75ZPJI57.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.TransactionStatus =
|
|
7
|
+
exports.TransactionStatus = _chunkX6WK4DK4cjs.TransactionStatus;
|
package/dist/types/index.d.cts
CHANGED
|
@@ -131,6 +131,7 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
|
|
|
131
131
|
address: Address$1;
|
|
132
132
|
functionName: string;
|
|
133
133
|
args: CalldataEncodable[];
|
|
134
|
+
stateStatus?: TransactionStatus;
|
|
134
135
|
}) => Promise<unknown>;
|
|
135
136
|
writeContract: (args: {
|
|
136
137
|
account?: Account;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -131,6 +131,7 @@ type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<Client<Transp
|
|
|
131
131
|
address: Address$1;
|
|
132
132
|
functionName: string;
|
|
133
133
|
args: CalldataEncodable[];
|
|
134
|
+
stateStatus?: TransactionStatus;
|
|
134
135
|
}) => Promise<unknown>;
|
|
135
136
|
writeContract: (args: {
|
|
136
137
|
account?: Account;
|
package/dist/types/index.js
CHANGED
package/package.json
CHANGED
package/src/contracts/actions.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import {decode} from "@/abi/calldata/decoder";
|
|
2
|
-
import {encode, serialize
|
|
3
|
-
import {
|
|
2
|
+
import {encode, serialize} from "@/abi/calldata/encoder";
|
|
3
|
+
import {
|
|
4
|
+
Account,
|
|
5
|
+
ContractSchema,
|
|
6
|
+
SimulatorChain,
|
|
7
|
+
GenLayerClient,
|
|
8
|
+
CalldataEncodable,
|
|
9
|
+
Address,
|
|
10
|
+
TransactionStatus,
|
|
11
|
+
} from "@/types";
|
|
4
12
|
|
|
5
13
|
export const contractActions = (client: GenLayerClient<SimulatorChain>) => {
|
|
6
14
|
return {
|
|
@@ -27,16 +35,18 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
27
35
|
address: Address;
|
|
28
36
|
functionName: string;
|
|
29
37
|
args: CalldataEncodable[];
|
|
38
|
+
stateStatus?: TransactionStatus;
|
|
30
39
|
}): Promise<unknown> => {
|
|
31
|
-
const {
|
|
32
|
-
const encodedData =
|
|
40
|
+
const {account, address, functionName, args: params, stateStatus = TransactionStatus.ACCEPTED} = args;
|
|
41
|
+
const encodedData = [encode({method: functionName, args: params}), stateStatus];
|
|
42
|
+
const serializedData = serialize(encodedData);
|
|
33
43
|
|
|
34
|
-
|
|
44
|
+
const senderAddress = account?.address ?? client.account?.address;
|
|
35
45
|
|
|
36
46
|
const requestParams = {
|
|
37
47
|
to: address,
|
|
38
48
|
from: senderAddress,
|
|
39
|
-
data:
|
|
49
|
+
data: serializedData,
|
|
40
50
|
};
|
|
41
51
|
const result = await client.request({
|
|
42
52
|
method: "eth_call",
|
|
@@ -51,7 +61,6 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
51
61
|
}
|
|
52
62
|
};
|
|
53
63
|
|
|
54
|
-
|
|
55
64
|
client.writeContract = async (args: {
|
|
56
65
|
account?: Account;
|
|
57
66
|
address: Address;
|
|
@@ -60,14 +69,12 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
60
69
|
value: bigint;
|
|
61
70
|
leaderOnly?: boolean;
|
|
62
71
|
}): Promise<`0x${string}`> => {
|
|
63
|
-
const {
|
|
64
|
-
const data = [encode({
|
|
72
|
+
const {account, address, functionName, args: params, value = 0n, leaderOnly = false} = args;
|
|
73
|
+
const data = [encode({method: functionName, args: params}), leaderOnly];
|
|
65
74
|
const serializedData = serialize(data);
|
|
66
75
|
const senderAccount = account || client.account;
|
|
67
76
|
|
|
68
|
-
|
|
69
77
|
if (senderAccount?.type !== "local") {
|
|
70
|
-
|
|
71
78
|
const transaction = {
|
|
72
79
|
from: senderAccount?.address,
|
|
73
80
|
to: address,
|
|
@@ -83,7 +90,7 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
83
90
|
|
|
84
91
|
if (!senderAccount) {
|
|
85
92
|
throw new Error(
|
|
86
|
-
|
|
93
|
+
"No account set. Configure the client with an account or pass an account to this function.",
|
|
87
94
|
);
|
|
88
95
|
}
|
|
89
96
|
|
|
@@ -91,7 +98,7 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
91
98
|
throw new Error("Account does not support signTransaction");
|
|
92
99
|
}
|
|
93
100
|
|
|
94
|
-
const nonce = await client.getCurrentNonce({
|
|
101
|
+
const nonce = await client.getCurrentNonce({address: senderAccount.address});
|
|
95
102
|
|
|
96
103
|
const signedTransaction = await senderAccount.signTransaction({
|
|
97
104
|
data: serializedData,
|
|
@@ -113,13 +120,12 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
113
120
|
args: CalldataEncodable[];
|
|
114
121
|
leaderOnly?: boolean;
|
|
115
122
|
}) => {
|
|
116
|
-
const {
|
|
117
|
-
const data = [code, encode({
|
|
123
|
+
const {account, code, args: constructorArgs, leaderOnly = false} = args;
|
|
124
|
+
const data = [code, encode({args: constructorArgs}), leaderOnly];
|
|
118
125
|
const serializedData = serialize(data);
|
|
119
126
|
const senderAccount = account || client.account;
|
|
120
127
|
|
|
121
128
|
if (senderAccount?.type !== "local") {
|
|
122
|
-
|
|
123
129
|
const transaction = {
|
|
124
130
|
from: senderAccount?.address,
|
|
125
131
|
to: null,
|
|
@@ -127,7 +133,7 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
127
133
|
value: "0x0",
|
|
128
134
|
};
|
|
129
135
|
|
|
130
|
-
return
|
|
136
|
+
return await client.request({
|
|
131
137
|
method: "eth_sendTransaction",
|
|
132
138
|
params: [transaction as any],
|
|
133
139
|
});
|
|
@@ -135,7 +141,7 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
135
141
|
|
|
136
142
|
if (!senderAccount) {
|
|
137
143
|
throw new Error(
|
|
138
|
-
|
|
144
|
+
"No account set. Configure the client with an account or pass an account to this function.",
|
|
139
145
|
);
|
|
140
146
|
}
|
|
141
147
|
|
|
@@ -143,7 +149,7 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
143
149
|
throw new Error("Account does not support signTransaction");
|
|
144
150
|
}
|
|
145
151
|
|
|
146
|
-
const nonce = await client.getCurrentNonce({
|
|
152
|
+
const nonce = await client.getCurrentNonce({address: senderAccount.address});
|
|
147
153
|
|
|
148
154
|
const signedTransaction = await senderAccount.signTransaction({
|
|
149
155
|
data: serializedData,
|
|
@@ -151,7 +157,7 @@ export const overrideContractActions = (client: GenLayerClient<SimulatorChain>)
|
|
|
151
157
|
nonce,
|
|
152
158
|
});
|
|
153
159
|
|
|
154
|
-
return
|
|
160
|
+
return await client.request({
|
|
155
161
|
method: "eth_sendRawTransaction",
|
|
156
162
|
params: [signedTransaction],
|
|
157
163
|
});
|
package/src/types/clients.ts
CHANGED
|
@@ -39,6 +39,7 @@ export type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<
|
|
|
39
39
|
address: Address;
|
|
40
40
|
functionName: string;
|
|
41
41
|
args: CalldataEncodable[];
|
|
42
|
+
stateStatus?: TransactionStatus;
|
|
42
43
|
}) => Promise<unknown>;
|
|
43
44
|
writeContract: (args: {
|
|
44
45
|
account?: Account;
|
package/tests/client.test.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {simulator} from "../src/chains/simulator";
|
|
|
4
4
|
import {Address} from "../src/types/accounts";
|
|
5
5
|
import {createAccount, generatePrivateKey} from "../src/accounts/account";
|
|
6
6
|
import {vi} from "vitest";
|
|
7
|
+
import {TransactionStatus} from "../src/types/transactions";
|
|
7
8
|
|
|
8
9
|
describe("Client Creation", () => {
|
|
9
10
|
it("should create a client for the simulator", () => {
|
|
@@ -29,6 +30,7 @@ describe("Client Overrides", () => {
|
|
|
29
30
|
address: contractAddress as Address,
|
|
30
31
|
functionName: "testFunction",
|
|
31
32
|
args: ["arg1", "arg2"],
|
|
33
|
+
stateStatus: TransactionStatus.ACCEPTED,
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
expect(client.request).toHaveBeenCalledWith({
|
|
@@ -62,6 +64,7 @@ describe("Client Overrides", () => {
|
|
|
62
64
|
address: contractAddress as Address,
|
|
63
65
|
functionName: "testFunction",
|
|
64
66
|
args: ["arg1", "arg2"],
|
|
67
|
+
stateStatus: TransactionStatus.ACCEPTED,
|
|
65
68
|
});
|
|
66
69
|
|
|
67
70
|
expect(client.request).toHaveBeenCalledWith({
|
|
@@ -77,7 +80,7 @@ describe("Client Overrides", () => {
|
|
|
77
80
|
});
|
|
78
81
|
});
|
|
79
82
|
it("should override client account if address is provided", async () => {
|
|
80
|
-
const account =
|
|
83
|
+
const account = "0x65e03a3e916CF1dC92d3C8E8186a89CfAB0D2bc2";
|
|
81
84
|
const client = createClient({
|
|
82
85
|
chain: simulator,
|
|
83
86
|
account,
|
|
@@ -105,5 +108,4 @@ describe("Client Overrides", () => {
|
|
|
105
108
|
],
|
|
106
109
|
});
|
|
107
110
|
});
|
|
108
|
-
|
|
109
111
|
});
|
|
File without changes
|
|
File without changes
|