@ocap/state 1.30.3 → 1.30.5

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/esm/states/tx.mjs CHANGED
@@ -4,7 +4,7 @@ import { BN, fromTokenToUnit, isBN, toBase64 } from "@ocap/util";
4
4
  import { CustomError } from "@ocap/util/lib/error";
5
5
  import pick from "lodash/pick.js";
6
6
  import get from "lodash/get.js";
7
- import { decodeAny, formatMessage, fromTypeUrl } from "@ocap/message";
7
+ import { createMessage, decodeAny, formatMessage, fromTypeUrl, toTypeUrl } from "@ocap/message";
8
8
  import { getListField } from "@ocap/util/lib/get-list-field";
9
9
  import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
10
10
  import camelCase from "lodash/camelCase.js";
@@ -796,10 +796,24 @@ const getTxReceipts = ({ tx, code }, ctx = {}) => {
796
796
  };
797
797
  const create = (context, code = "OK", verifyReceipts = true) => {
798
798
  const { txHash, txTime, tx, totalGas, itxExtras = {}, extra = {} } = context;
799
- const itx = decodeAny(tx.itx).value;
800
- const typeUrl = fromTypeUrl(tx.itx.typeUrl);
801
- const typeName = tx.itx.typeUrl.split(":").pop() || "";
802
- const itxJson = formatMessage(typeUrl, itx);
799
+ const rawItx = tx.itx;
800
+ let typeUrlRaw;
801
+ let itx;
802
+ if (rawItx && typeof rawItx.typeUrl === "string") {
803
+ typeUrlRaw = rawItx.typeUrl;
804
+ if (typeof rawItx.value === "string") itx = decodeAny(rawItx).value;
805
+ else {
806
+ itx = {};
807
+ for (const [k, v] of Object.entries(rawItx)) if (k !== "typeUrl" && k !== "type_url") itx[k] = v;
808
+ }
809
+ } else if (rawItx && typeof rawItx.type === "string" && "value" in rawItx) {
810
+ typeUrlRaw = toTypeUrl(rawItx.type);
811
+ itx = rawItx.value || {};
812
+ } else throw new CustomError("INVALID_TX", "tx.itx missing typeUrl/type");
813
+ const typeUrl = fromTypeUrl(typeUrlRaw);
814
+ const typeName = typeUrlRaw.split(":").pop() || "";
815
+ const innerMessage = createMessage(typeUrl, itx);
816
+ const itxJson = formatMessage(typeUrl, innerMessage?.toObject ? innerMessage.toObject() : itx);
803
817
  const result = {
804
818
  code,
805
819
  hash: txHash,
@@ -830,8 +844,8 @@ const create = (context, code = "OK", verifyReceipts = true) => {
830
844
  itx: { __typename: typeUrl },
831
845
  itxJson: {
832
846
  _type: typeUrl,
833
- encoded_value: tx.itx.value,
834
- type_url: tx.itx.typeUrl,
847
+ encoded_value: rawItx?.value ?? null,
848
+ type_url: typeUrlRaw,
835
849
  ...itxJson,
836
850
  ...itxExtras,
837
851
  data: itx.data || null
package/lib/states/tx.cjs CHANGED
@@ -802,10 +802,24 @@ const getTxReceipts = ({ tx, code }, ctx = {}) => {
802
802
  };
803
803
  const create = (context, code = "OK", verifyReceipts = true) => {
804
804
  const { txHash, txTime, tx, totalGas, itxExtras = {}, extra = {} } = context;
805
- const itx = (0, _ocap_message.decodeAny)(tx.itx).value;
806
- const typeUrl = (0, _ocap_message.fromTypeUrl)(tx.itx.typeUrl);
807
- const typeName = tx.itx.typeUrl.split(":").pop() || "";
808
- const itxJson = (0, _ocap_message.formatMessage)(typeUrl, itx);
805
+ const rawItx = tx.itx;
806
+ let typeUrlRaw;
807
+ let itx;
808
+ if (rawItx && typeof rawItx.typeUrl === "string") {
809
+ typeUrlRaw = rawItx.typeUrl;
810
+ if (typeof rawItx.value === "string") itx = (0, _ocap_message.decodeAny)(rawItx).value;
811
+ else {
812
+ itx = {};
813
+ for (const [k, v] of Object.entries(rawItx)) if (k !== "typeUrl" && k !== "type_url") itx[k] = v;
814
+ }
815
+ } else if (rawItx && typeof rawItx.type === "string" && "value" in rawItx) {
816
+ typeUrlRaw = (0, _ocap_message.toTypeUrl)(rawItx.type);
817
+ itx = rawItx.value || {};
818
+ } else throw new _ocap_util_lib_error.CustomError("INVALID_TX", "tx.itx missing typeUrl/type");
819
+ const typeUrl = (0, _ocap_message.fromTypeUrl)(typeUrlRaw);
820
+ const typeName = typeUrlRaw.split(":").pop() || "";
821
+ const innerMessage = (0, _ocap_message.createMessage)(typeUrl, itx);
822
+ const itxJson = (0, _ocap_message.formatMessage)(typeUrl, innerMessage?.toObject ? innerMessage.toObject() : itx);
809
823
  const result = {
810
824
  code,
811
825
  hash: txHash,
@@ -836,8 +850,8 @@ const create = (context, code = "OK", verifyReceipts = true) => {
836
850
  itx: { __typename: typeUrl },
837
851
  itxJson: {
838
852
  _type: typeUrl,
839
- encoded_value: tx.itx.value,
840
- type_url: tx.itx.typeUrl,
853
+ encoded_value: rawItx?.value ?? null,
854
+ type_url: typeUrlRaw,
841
855
  ...itxJson,
842
856
  ...itxExtras,
843
857
  data: itx.data || null
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.30.3",
6
+ "version": "1.30.5",
7
7
  "description": "State management utilities for OCAP blockchain",
8
8
  "type": "module",
9
9
  "main": "./lib/index.cjs",
@@ -40,14 +40,14 @@
40
40
  "clean": "rm -rf lib esm"
41
41
  },
42
42
  "dependencies": {
43
- "@arcblock/did": "1.30.3",
44
- "@arcblock/validator": "1.30.3",
45
- "@ocap/contract": "1.30.3",
46
- "@ocap/mcrypto": "1.30.3",
47
- "@ocap/message": "1.30.3",
48
- "@ocap/types": "1.30.3",
49
- "@ocap/util": "1.30.3",
50
- "@ocap/wallet": "1.30.3",
43
+ "@arcblock/did": "1.30.5",
44
+ "@arcblock/validator": "1.30.5",
45
+ "@ocap/contract": "1.30.5",
46
+ "@ocap/mcrypto": "1.30.5",
47
+ "@ocap/message": "1.30.5",
48
+ "@ocap/types": "1.30.5",
49
+ "@ocap/util": "1.30.5",
50
+ "@ocap/wallet": "1.30.5",
51
51
  "bloom-filters": "^1.3.9",
52
52
  "lodash": "^4.17.23"
53
53
  },