@mentaproject/client 0.0.5 → 0.0.7

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.
@@ -2,7 +2,7 @@ import { createBlockRangePager, getBalance, getBlockNumber, getCode, getTransact
2
2
  import { Transaction } from "./Transaction";
3
3
  import { toHex } from "@mentaproject/core/utils";
4
4
  import { getContractType } from "@mentaproject/contracts";
5
- import { toJSON } from "src/utils/toJSON";
5
+ import { toJSON } from "../utils/toJSON";
6
6
  /**
7
7
  * Represents an account with methods for interacting with it.
8
8
  */
@@ -1,6 +1,6 @@
1
1
  import { Account } from "./Account";
2
2
  import { Transaction } from "./Transaction";
3
- import { toJSON } from "src/utils/toJSON";
3
+ import { toJSON } from "../utils/toJSON";
4
4
  export class Block {
5
5
  constructor(rpcClient, data, includeTransactions = false) {
6
6
  this.rpcClient = rpcClient;
@@ -2,7 +2,7 @@ import { Account } from './Account';
2
2
  import { Block } from './Block';
3
3
  import { getBlock, getTransactionReceipt, traceTransaction, waitForTransactionReceipt } from '@mentaproject/core/actions';
4
4
  import { hexToBigInt } from '@mentaproject/core/utils';
5
- import { toJSON } from 'src/utils/toJSON';
5
+ import { toJSON } from '../utils/toJSON';
6
6
  export class Transaction {
7
7
  constructor(rpcClient, data) {
8
8
  this.rpcClient = rpcClient;
@@ -25,22 +25,16 @@ function convertBigintsToStrings(obj) {
25
25
  return obj;
26
26
  }
27
27
  export async function toJSON({ obj, depth = 0 }) {
28
- // copy the properties of the object
29
- const data = Object.assign({}, obj);
28
+ const data = {};
30
29
  for (const key in obj) {
31
30
  // skip class related properties
32
- if (key === "toJSON" || key === "constructor" || key === "rpcClient") {
33
- delete data[key];
31
+ if (key === "toJSON" || key === "constructor" || key === "rpcClient")
34
32
  continue;
35
- }
36
- ;
37
33
  const prop = obj[key];
38
34
  if (typeof prop === "function") {
39
35
  // do not fetch getters if depth is 0
40
- if (depth === 0) {
41
- delete data[key];
36
+ if (depth === 0)
42
37
  continue;
43
- }
44
38
  // fetch getters
45
39
  const value = await obj[key]();
46
40
  // if the value is a class instance, convert it to JSON recursively
@@ -48,6 +42,7 @@ export async function toJSON({ obj, depth = 0 }) {
48
42
  data[key] = await toJSON({ obj: value, depth: depth - 1 });
49
43
  continue;
50
44
  }
45
+ ;
51
46
  data[key] = value;
52
47
  continue;
53
48
  }
@@ -63,7 +58,9 @@ export async function toJSON({ obj, depth = 0 }) {
63
58
  ;
64
59
  // If depth is not 0, fetch the object
65
60
  data[key] = await prop.toJSON({ depth: depth - 1 });
61
+ continue;
66
62
  }
63
+ data[key] = prop;
67
64
  }
68
65
  ;
69
66
  return convertBigintsToStrings(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentaproject/client",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "High level EVM library used into the Menta App to facilitate Blockchain interactions. ",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/test.ts CHANGED
@@ -15,7 +15,7 @@ const client = new MentaClient({
15
15
 
16
16
  (async () => {
17
17
  const firstTx = await client.transactions.get({ hash: "0xeae261aeada2db19fee5cc4dfd47d575ff2380a5fb6a4039685d5044fdc8e2bb" });
18
- const json = await firstTx.toJSON(2);
18
+ const json = await firstTx.toJSON();
19
19
 
20
20
  writeFileSync("./test.json", JSON.stringify(json, null, 2));
21
21
  })()