genlayer 0.27.0 → 0.28.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.28.0 (2025-09-03)
4
+
5
+ ### Features
6
+
7
+ * improve how cli shows transactions receipts ([#250](https://github.com/yeagerai/genlayer-cli/issues/250)) ([610831a](https://github.com/yeagerai/genlayer-cli/commit/610831a23d0fc35b6b2d1ec0e1b1d88fb357c4b5))
8
+
3
9
  ## 0.27.0 (2025-09-01)
4
10
 
5
11
  ### Features
package/dist/index.js CHANGED
@@ -17856,7 +17856,7 @@ var require_semver2 = __commonJS({
17856
17856
  import { program } from "commander";
17857
17857
 
17858
17858
  // package.json
17859
- var version = "0.27.0";
17859
+ var version = "0.28.0";
17860
17860
  var package_default = {
17861
17861
  name: "genlayer",
17862
17862
  version,
@@ -43132,7 +43132,9 @@ var ReceiptAction = class extends BaseAction {
43132
43132
  status = TransactionStatus.FINALIZED,
43133
43133
  retries,
43134
43134
  interval,
43135
- rpc
43135
+ rpc,
43136
+ stdout,
43137
+ stderr
43136
43138
  }) {
43137
43139
  const client = await this.getClient(rpc);
43138
43140
  await client.initializeConsensusSmartContract();
@@ -43148,6 +43150,22 @@ var ReceiptAction = class extends BaseAction {
43148
43150
  retries,
43149
43151
  interval
43150
43152
  });
43153
+ if (stdout || stderr) {
43154
+ const stdoutValue = result?.consensus_data?.leader_receipt[0]?.genvm_result?.stdout;
43155
+ const stderrValue = result?.consensus_data?.leader_receipt[0]?.genvm_result?.stderr;
43156
+ if (stdout && stderr) {
43157
+ this.succeedSpinner("Transaction stdout and stderr", { stdout: stdoutValue, stderr: stderrValue });
43158
+ return;
43159
+ }
43160
+ if (stdout) {
43161
+ this.succeedSpinner("Transaction stdout retrieved successfully", stdoutValue);
43162
+ return;
43163
+ }
43164
+ if (stderr) {
43165
+ this.succeedSpinner("Transaction stderr retrieved successfully", stderrValue);
43166
+ return;
43167
+ }
43168
+ }
43151
43169
  this.succeedSpinner("Transaction receipt retrieved successfully", result);
43152
43170
  } catch (error) {
43153
43171
  this.failSpinner("Error retrieving transaction receipt", error);
@@ -43190,7 +43208,7 @@ function parseIntOption(value, fallback2) {
43190
43208
  }
43191
43209
  function initializeTransactionsCommands(program2) {
43192
43210
  const validStatuses = Object.values(TransactionStatus).join(", ");
43193
- program2.command("receipt <txId>").description("Get transaction receipt by hash").option("--status <status>", `Transaction status to wait for (${validStatuses})`, TransactionStatus.FINALIZED).option("--retries <retries>", "Number of retries", (value) => parseIntOption(value, 100), 100).option("--interval <interval>", "Interval between retries in milliseconds", (value) => parseIntOption(value, 5e3), 5e3).option("--rpc <rpcUrl>", "RPC URL for the network").action(async (txId, options) => {
43211
+ program2.command("receipt <txId>").description("Get transaction receipt by hash").option("--status <status>", `Transaction status to wait for (${validStatuses})`, TransactionStatus.FINALIZED).option("--retries <retries>", "Number of retries", (value) => parseIntOption(value, 100), 100).option("--interval <interval>", "Interval between retries in milliseconds", (value) => parseIntOption(value, 5e3), 5e3).option("--rpc <rpcUrl>", "RPC URL for the network").option("--stdout", "Print only stdout from the receipt").option("--stderr", "Print only stderr from the receipt").action(async (txId, options) => {
43194
43212
  const receiptAction = new ReceiptAction();
43195
43213
  await receiptAction.receipt({ txId, ...options });
43196
43214
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genlayer",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "GenLayer Command Line Tool",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -18,6 +18,8 @@ export function initializeTransactionsCommands(program: Command) {
18
18
  .option("--retries <retries>", "Number of retries", (value) => parseIntOption(value, 100), 100)
19
19
  .option("--interval <interval>", "Interval between retries in milliseconds", (value) => parseIntOption(value, 5000), 5000)
20
20
  .option("--rpc <rpcUrl>", "RPC URL for the network")
21
+ .option("--stdout", "Print only stdout from the receipt")
22
+ .option("--stderr", "Print only stderr from the receipt")
21
23
  .action(async (txId: TransactionHash, options: ReceiptOptions) => {
22
24
  const receiptAction = new ReceiptAction();
23
25
 
@@ -7,6 +7,8 @@ export interface ReceiptParams {
7
7
  retries?: number;
8
8
  interval?: number;
9
9
  rpc?: string;
10
+ stdout?: boolean;
11
+ stderr?: boolean;
10
12
  }
11
13
 
12
14
  export interface ReceiptOptions extends Omit<ReceiptParams, 'txId'> {}
@@ -37,6 +39,8 @@ export class ReceiptAction extends BaseAction {
37
39
  retries,
38
40
  interval,
39
41
  rpc,
42
+ stdout,
43
+ stderr,
40
44
  }: ReceiptParams): Promise<void> {
41
45
  const client = await this.getClient(rpc);
42
46
  await client.initializeConsensusSmartContract();
@@ -55,7 +59,29 @@ export class ReceiptAction extends BaseAction {
55
59
  retries,
56
60
  interval,
57
61
  });
58
-
62
+
63
+ // If specific output flags are provided, print only those fields
64
+ if (stdout || stderr) {
65
+ const stdoutValue = (result as any)?.consensus_data?.leader_receipt[0]?.genvm_result?.stdout;
66
+ const stderrValue = (result as any)?.consensus_data?.leader_receipt[0]?.genvm_result?.stderr;
67
+
68
+ if (stdout && stderr) {
69
+ this.succeedSpinner("Transaction stdout and stderr", { stdout: stdoutValue, stderr: stderrValue });
70
+ return;
71
+ }
72
+
73
+ if (stdout) {
74
+ this.succeedSpinner("Transaction stdout retrieved successfully", stdoutValue);
75
+ return;
76
+ }
77
+
78
+ if (stderr) {
79
+ this.succeedSpinner("Transaction stderr retrieved successfully", stderrValue);
80
+ return;
81
+ }
82
+ }
83
+
84
+ // Default behavior (no flags): show full receipt result
59
85
  this.succeedSpinner("Transaction receipt retrieved successfully", result);
60
86
  } catch (error) {
61
87
  this.failSpinner("Error retrieving transaction receipt", error);
@@ -170,4 +170,92 @@ describe("ReceiptAction", () => {
170
170
  }
171
171
  });
172
172
 
173
+ test("prints only stdout when --stdout is provided", async () => {
174
+ const mockReceipt = {
175
+ consensus_data: {
176
+ leader_receipt: [
177
+ {
178
+ genvm_result: {
179
+ stdout: "program stdout",
180
+ stderr: "program stderr",
181
+ },
182
+ },
183
+ ],
184
+ },
185
+ };
186
+
187
+ vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt as any);
188
+
189
+ await receiptAction.receipt({
190
+ txId: mockTxId,
191
+ retries: defaultRetries,
192
+ interval: defaultInterval,
193
+ stdout: true,
194
+ } as ReceiptParams);
195
+
196
+ expect(receiptAction["succeedSpinner"]).toHaveBeenCalledWith(
197
+ "Transaction stdout retrieved successfully",
198
+ "program stdout",
199
+ );
200
+ });
201
+
202
+ test("prints only stderr when --stderr is provided", async () => {
203
+ const mockReceipt = {
204
+ consensus_data: {
205
+ leader_receipt: [
206
+ {
207
+ genvm_result: {
208
+ stdout: "program stdout",
209
+ stderr: "program stderr",
210
+ },
211
+ },
212
+ ],
213
+ },
214
+ };
215
+
216
+ vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt as any);
217
+
218
+ await receiptAction.receipt({
219
+ txId: mockTxId,
220
+ retries: defaultRetries,
221
+ interval: defaultInterval,
222
+ stderr: true,
223
+ } as ReceiptParams);
224
+
225
+ expect(receiptAction["succeedSpinner"]).toHaveBeenCalledWith(
226
+ "Transaction stderr retrieved successfully",
227
+ "program stderr",
228
+ );
229
+ });
230
+
231
+ test("prints both stdout and stderr when both flags are provided", async () => {
232
+ const mockReceipt = {
233
+ consensus_data: {
234
+ leader_receipt: [
235
+ {
236
+ genvm_result: {
237
+ stdout: "program stdout",
238
+ stderr: "program stderr",
239
+ },
240
+ },
241
+ ],
242
+ },
243
+ };
244
+
245
+ vi.mocked(mockClient.waitForTransactionReceipt).mockResolvedValue(mockReceipt as any);
246
+
247
+ await receiptAction.receipt({
248
+ txId: mockTxId,
249
+ retries: defaultRetries,
250
+ interval: defaultInterval,
251
+ stdout: true,
252
+ stderr: true,
253
+ } as ReceiptParams);
254
+
255
+ expect(receiptAction["succeedSpinner"]).toHaveBeenCalledWith(
256
+ "Transaction stdout and stderr",
257
+ { stdout: "program stdout", stderr: "program stderr" },
258
+ );
259
+ });
260
+
173
261
  });
@@ -105,4 +105,38 @@ describe("receipt command", () => {
105
105
  interval: 5000,
106
106
  });
107
107
  });
108
+
109
+ test("parses --stdout flag", async () => {
110
+ program.parse(["node", "test", "receipt", mockTxId, "--stdout"]);
111
+ expect(ReceiptAction.prototype.receipt).toHaveBeenCalledWith({
112
+ txId: mockTxId,
113
+ status: "FINALIZED",
114
+ retries: 100,
115
+ interval: 5000,
116
+ stdout: true,
117
+ });
118
+ });
119
+
120
+ test("parses --stderr flag", async () => {
121
+ program.parse(["node", "test", "receipt", mockTxId, "--stderr"]);
122
+ expect(ReceiptAction.prototype.receipt).toHaveBeenCalledWith({
123
+ txId: mockTxId,
124
+ status: "FINALIZED",
125
+ retries: 100,
126
+ interval: 5000,
127
+ stderr: true,
128
+ });
129
+ });
130
+
131
+ test("parses both --stdout and --stderr flags", async () => {
132
+ program.parse(["node", "test", "receipt", mockTxId, "--stdout", "--stderr"]);
133
+ expect(ReceiptAction.prototype.receipt).toHaveBeenCalledWith({
134
+ txId: mockTxId,
135
+ status: "FINALIZED",
136
+ retries: 100,
137
+ interval: 5000,
138
+ stdout: true,
139
+ stderr: true,
140
+ });
141
+ });
108
142
  });