genlayer-js 0.21.2 → 0.21.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/dist/index.cjs CHANGED
@@ -514,6 +514,19 @@ function _toJsonSafeDeep(value, seen) {
514
514
  }
515
515
 
516
516
  // src/contracts/actions.ts
517
+ function extractGenCallResult(result) {
518
+ if (typeof result === "string") {
519
+ return `0x${result}`;
520
+ }
521
+ if (result && typeof result === "object" && "data" in result) {
522
+ const obj = result;
523
+ if (obj.status && obj.status.code !== 0) {
524
+ throw new Error(`gen_call failed: ${obj.status.message}`);
525
+ }
526
+ return `0x${obj.data}`;
527
+ }
528
+ throw new Error(`Unexpected gen_call response: ${JSON.stringify(result)}`);
529
+ }
517
530
  var contractActions = (client, publicClient) => {
518
531
  return {
519
532
  getContractCode: async (address) => {
@@ -572,7 +585,7 @@ var contractActions = (client, publicClient) => {
572
585
  method: "gen_call",
573
586
  params: [requestParams]
574
587
  });
575
- const prefixedResult = `0x${result}`;
588
+ const prefixedResult = extractGenCallResult(result);
576
589
  if (args.rawReturn) {
577
590
  return prefixedResult;
578
591
  }
@@ -607,7 +620,7 @@ var contractActions = (client, publicClient) => {
607
620
  method: "gen_call",
608
621
  params: [requestParams]
609
622
  });
610
- const prefixedResult = `0x${result}`;
623
+ const prefixedResult = extractGenCallResult(result);
611
624
  if (args.rawReturn) {
612
625
  return prefixedResult;
613
626
  }
package/dist/index.js CHANGED
@@ -514,6 +514,19 @@ function _toJsonSafeDeep(value, seen) {
514
514
  }
515
515
 
516
516
  // src/contracts/actions.ts
517
+ function extractGenCallResult(result) {
518
+ if (typeof result === "string") {
519
+ return `0x${result}`;
520
+ }
521
+ if (result && typeof result === "object" && "data" in result) {
522
+ const obj = result;
523
+ if (obj.status && obj.status.code !== 0) {
524
+ throw new Error(`gen_call failed: ${obj.status.message}`);
525
+ }
526
+ return `0x${obj.data}`;
527
+ }
528
+ throw new Error(`Unexpected gen_call response: ${JSON.stringify(result)}`);
529
+ }
517
530
  var contractActions = (client, publicClient) => {
518
531
  return {
519
532
  getContractCode: async (address) => {
@@ -572,7 +585,7 @@ var contractActions = (client, publicClient) => {
572
585
  method: "gen_call",
573
586
  params: [requestParams]
574
587
  });
575
- const prefixedResult = `0x${result}`;
588
+ const prefixedResult = extractGenCallResult(result);
576
589
  if (args.rawReturn) {
577
590
  return prefixedResult;
578
591
  }
@@ -607,7 +620,7 @@ var contractActions = (client, publicClient) => {
607
620
  method: "gen_call",
608
621
  params: [requestParams]
609
622
  });
610
- const prefixedResult = `0x${result}`;
623
+ const prefixedResult = extractGenCallResult(result);
611
624
  if (args.rawReturn) {
612
625
  return prefixedResult;
613
626
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "genlayer-js",
3
3
  "type": "module",
4
- "version": "0.21.2",
4
+ "version": "0.21.3",
5
5
  "description": "GenLayer JavaScript SDK",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",