@ocap/state 1.31.5 → 1.31.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.
- package/esm/states/evidence.d.mts +1 -1
- package/esm/states/evidence.mjs +2 -1
- package/esm/states/tx.mjs +14 -10
- package/lib/states/evidence.cjs +2 -1
- package/lib/states/evidence.d.cts +1 -1
- package/lib/states/tx.cjs +14 -10
- package/package.json +9 -9
|
@@ -7,7 +7,7 @@ declare namespace evidence_d_exports {
|
|
|
7
7
|
export { create, schema, validate };
|
|
8
8
|
}
|
|
9
9
|
declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
10
|
-
readonly hash: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
10
|
+
readonly hash: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>], undefined>;
|
|
11
11
|
readonly context: v.ObjectSchema<{
|
|
12
12
|
readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
|
|
13
13
|
readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
|
package/esm/states/evidence.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { create as create$1 } from "../contexts/state.mjs";
|
|
|
3
3
|
import { CustomError } from "@ocap/util/lib/error";
|
|
4
4
|
import pick from "lodash/pick.js";
|
|
5
5
|
import { patterns, schemas, v, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
6
|
+
import { BRIDGE_RELEASE_KEY_PATTERN } from "@ocap/mcrypto";
|
|
6
7
|
|
|
7
8
|
//#region src/states/evidence.ts
|
|
8
9
|
var evidence_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -11,7 +12,7 @@ var evidence_exports = /* @__PURE__ */ __exportAll({
|
|
|
11
12
|
validate: () => validate
|
|
12
13
|
});
|
|
13
14
|
const schema = v.pipe(v.object({
|
|
14
|
-
hash: v.pipe(v.string(), v.regex(patterns.txHash)),
|
|
15
|
+
hash: v.union([v.pipe(v.string(), v.regex(patterns.txHash)), v.pipe(v.string(), v.regex(BRIDGE_RELEASE_KEY_PATTERN))]),
|
|
15
16
|
context: schemas.context,
|
|
16
17
|
data: v.optional(v.nullable(v.any()))
|
|
17
18
|
}), vStripUnknown());
|
package/esm/states/tx.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { CustomError } from "@ocap/util/lib/error";
|
|
|
5
5
|
import pick from "lodash/pick.js";
|
|
6
6
|
import get from "lodash/get.js";
|
|
7
7
|
import { createMessage, decodeAny, formatMessage, fromTypeUrl, toTypeUrl } from "@ocap/message";
|
|
8
|
+
import { stripDefaultDepositV2BridgeFields } from "@ocap/util/lib/deposit-v2-bridge-fields";
|
|
8
9
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
9
10
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
10
11
|
import camelCase from "lodash/camelCase.js";
|
|
@@ -47,13 +48,15 @@ function groupReceiptTokenChanges(receipts) {
|
|
|
47
48
|
});
|
|
48
49
|
return tokenChanges;
|
|
49
50
|
}
|
|
51
|
+
/** `kind` of a bridge release (DepositTokenV2Tx fields 8-13, #1692): 1 DEPOSIT, 2 REFUND, 3 DEPOSIT_B. */
|
|
52
|
+
const isBridgeReleaseKind = (kind) => kind === 1 || kind === 2 || kind === 3;
|
|
50
53
|
const getTxReceiver = ({ tx, itx, typeUrl }) => {
|
|
51
54
|
switch (typeUrl) {
|
|
52
55
|
case "TransferTx":
|
|
53
56
|
case "ExchangeTx":
|
|
54
57
|
case "TransferV2Tx":
|
|
55
|
-
case "ExchangeV2Tx":
|
|
56
|
-
case "
|
|
58
|
+
case "ExchangeV2Tx": return itx.to;
|
|
59
|
+
case "DepositTokenV2Tx": return isBridgeReleaseKind(itx?.kind) ? itx.to : "";
|
|
57
60
|
case "MintAssetTx": return itx.owner;
|
|
58
61
|
case "CreateTokenTx":
|
|
59
62
|
case "CreateAssetTx":
|
|
@@ -195,14 +198,13 @@ const getReceiptsFromGasPaid = (tx, { config, typeUrl }) => {
|
|
|
195
198
|
}];
|
|
196
199
|
};
|
|
197
200
|
/**
|
|
198
|
-
*
|
|
199
|
-
* not part of the itx (the protocol derives it from `itx.
|
|
200
|
-
* `ctx.bridgeReserve` and the bridge token as `ctx.bridgeToken`.
|
|
201
|
+
* A bridge release (#1466, `deposit_token_v2` kind 1/2/3): the reserve pays `amount` of the bridge token to `itx.to`.
|
|
202
|
+
* The reserve address is not part of the itx (the protocol derives it from `itx.rollup`), so the protocol hands the
|
|
203
|
+
* paying reserve over as `ctx.bridgeReserve` and the bridge token as `ctx.bridgeToken`.
|
|
201
204
|
*/
|
|
202
|
-
const
|
|
205
|
+
const getBridgeReleaseReceipts = (tx, ctx, amount) => {
|
|
203
206
|
const reserve = ctx.bridgeReserve;
|
|
204
207
|
const tokenAddress = ctx.bridgeToken || ctx.config?.token?.address;
|
|
205
|
-
const amount = tx.itxJson?.amount;
|
|
206
208
|
const to = tx.itxJson?.to;
|
|
207
209
|
if (!reserve || !tokenAddress || !amount || !to) return [];
|
|
208
210
|
return [{
|
|
@@ -790,8 +792,10 @@ const getTxReceipts = ({ tx, code }, ctx = {}) => {
|
|
|
790
792
|
let receipts = Array.isArray(ctx.receipts) ? ctx.receipts : [];
|
|
791
793
|
if (["TransferTx", "TransferV2Tx"].includes(typeUrl)) receipts = receipts.concat(getTransferReceipts(tx));
|
|
792
794
|
else if (["TransferV3Tx"].includes(typeUrl)) receipts = receipts.concat(getTransferV3Receipts(tx));
|
|
793
|
-
else if (
|
|
794
|
-
|
|
795
|
+
else if (typeUrl === "DepositTokenV2Tx" && isBridgeReleaseKind(tx.itxJson?.kind)) {
|
|
796
|
+
const token = tx.itxJson?.token;
|
|
797
|
+
receipts = receipts.concat(getBridgeReleaseReceipts(tx, ctx, token?.value));
|
|
798
|
+
} else if (["ExchangeTx", "ExchangeV2Tx"].includes(typeUrl)) receipts = receipts.concat(getExchangeReceipts(tx, ctx));
|
|
795
799
|
else if (["CreateAssetTx"].includes(typeUrl)) receipts = receipts.concat(getCreateAssetReceipts(tx));
|
|
796
800
|
else if (["MintAssetTx"].includes(typeUrl)) receipts = receipts.concat(getMintAssetReceipts(tx, ctx));
|
|
797
801
|
else if (["AcquireAssetV2Tx"].includes(typeUrl)) receipts = receipts.concat(getAcquireAssetReceipts(tx, ctx));
|
|
@@ -844,7 +848,7 @@ const create = (context, code = "OK", verifyReceipts = true) => {
|
|
|
844
848
|
const typeUrl = fromTypeUrl(typeUrlRaw);
|
|
845
849
|
const typeName = typeUrlRaw.split(":").pop() || "";
|
|
846
850
|
const innerMessage = !isProtoWire ? createMessage(typeUrl, itx) : void 0;
|
|
847
|
-
const itxJson = formatMessage(typeUrl, innerMessage?.toObject ? innerMessage.toObject() : itx);
|
|
851
|
+
const itxJson = stripDefaultDepositV2BridgeFields(typeUrl, formatMessage(typeUrl, innerMessage?.toObject ? innerMessage.toObject() : itx));
|
|
848
852
|
const result = {
|
|
849
853
|
code,
|
|
850
854
|
hash: txHash,
|
package/lib/states/evidence.cjs
CHANGED
|
@@ -4,6 +4,7 @@ let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
|
4
4
|
let lodash_pick = require("lodash/pick");
|
|
5
5
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
6
6
|
let _arcblock_validator = require("@arcblock/validator");
|
|
7
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
7
8
|
|
|
8
9
|
//#region src/states/evidence.ts
|
|
9
10
|
var evidence_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
@@ -12,7 +13,7 @@ var evidence_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
|
12
13
|
validate: () => validate
|
|
13
14
|
});
|
|
14
15
|
const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
|
|
15
|
-
hash: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_arcblock_validator.patterns.txHash)),
|
|
16
|
+
hash: _arcblock_validator.v.union([_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_arcblock_validator.patterns.txHash)), _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.regex(_ocap_mcrypto.BRIDGE_RELEASE_KEY_PATTERN))]),
|
|
16
17
|
context: _arcblock_validator.schemas.context,
|
|
17
18
|
data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
|
|
18
19
|
}), (0, _arcblock_validator.vStripUnknown)());
|
|
@@ -7,7 +7,7 @@ declare namespace evidence_d_exports {
|
|
|
7
7
|
export { create, schema, validate };
|
|
8
8
|
}
|
|
9
9
|
declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
10
|
-
readonly hash: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
10
|
+
readonly hash: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>], undefined>;
|
|
11
11
|
readonly context: v.ObjectSchema<{
|
|
12
12
|
readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
|
|
13
13
|
readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
|
package/lib/states/tx.cjs
CHANGED
|
@@ -7,6 +7,7 @@ lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
|
7
7
|
let lodash_get = require("lodash/get");
|
|
8
8
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
9
9
|
let _ocap_message = require("@ocap/message");
|
|
10
|
+
let _ocap_util_lib_deposit_v2_bridge_fields = require("@ocap/util/lib/deposit-v2-bridge-fields");
|
|
10
11
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
11
12
|
let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
|
|
12
13
|
let lodash_camelCase = require("lodash/camelCase");
|
|
@@ -53,13 +54,15 @@ function groupReceiptTokenChanges(receipts) {
|
|
|
53
54
|
});
|
|
54
55
|
return tokenChanges;
|
|
55
56
|
}
|
|
57
|
+
/** `kind` of a bridge release (DepositTokenV2Tx fields 8-13, #1692): 1 DEPOSIT, 2 REFUND, 3 DEPOSIT_B. */
|
|
58
|
+
const isBridgeReleaseKind = (kind) => kind === 1 || kind === 2 || kind === 3;
|
|
56
59
|
const getTxReceiver = ({ tx, itx, typeUrl }) => {
|
|
57
60
|
switch (typeUrl) {
|
|
58
61
|
case "TransferTx":
|
|
59
62
|
case "ExchangeTx":
|
|
60
63
|
case "TransferV2Tx":
|
|
61
|
-
case "ExchangeV2Tx":
|
|
62
|
-
case "
|
|
64
|
+
case "ExchangeV2Tx": return itx.to;
|
|
65
|
+
case "DepositTokenV2Tx": return isBridgeReleaseKind(itx?.kind) ? itx.to : "";
|
|
63
66
|
case "MintAssetTx": return itx.owner;
|
|
64
67
|
case "CreateTokenTx":
|
|
65
68
|
case "CreateAssetTx":
|
|
@@ -201,14 +204,13 @@ const getReceiptsFromGasPaid = (tx, { config, typeUrl }) => {
|
|
|
201
204
|
}];
|
|
202
205
|
};
|
|
203
206
|
/**
|
|
204
|
-
*
|
|
205
|
-
* not part of the itx (the protocol derives it from `itx.
|
|
206
|
-
* `ctx.bridgeReserve` and the bridge token as `ctx.bridgeToken`.
|
|
207
|
+
* A bridge release (#1466, `deposit_token_v2` kind 1/2/3): the reserve pays `amount` of the bridge token to `itx.to`.
|
|
208
|
+
* The reserve address is not part of the itx (the protocol derives it from `itx.rollup`), so the protocol hands the
|
|
209
|
+
* paying reserve over as `ctx.bridgeReserve` and the bridge token as `ctx.bridgeToken`.
|
|
207
210
|
*/
|
|
208
|
-
const
|
|
211
|
+
const getBridgeReleaseReceipts = (tx, ctx, amount) => {
|
|
209
212
|
const reserve = ctx.bridgeReserve;
|
|
210
213
|
const tokenAddress = ctx.bridgeToken || ctx.config?.token?.address;
|
|
211
|
-
const amount = tx.itxJson?.amount;
|
|
212
214
|
const to = tx.itxJson?.to;
|
|
213
215
|
if (!reserve || !tokenAddress || !amount || !to) return [];
|
|
214
216
|
return [{
|
|
@@ -796,8 +798,10 @@ const getTxReceipts = ({ tx, code }, ctx = {}) => {
|
|
|
796
798
|
let receipts = Array.isArray(ctx.receipts) ? ctx.receipts : [];
|
|
797
799
|
if (["TransferTx", "TransferV2Tx"].includes(typeUrl)) receipts = receipts.concat(getTransferReceipts(tx));
|
|
798
800
|
else if (["TransferV3Tx"].includes(typeUrl)) receipts = receipts.concat(getTransferV3Receipts(tx));
|
|
799
|
-
else if (
|
|
800
|
-
|
|
801
|
+
else if (typeUrl === "DepositTokenV2Tx" && isBridgeReleaseKind(tx.itxJson?.kind)) {
|
|
802
|
+
const token = tx.itxJson?.token;
|
|
803
|
+
receipts = receipts.concat(getBridgeReleaseReceipts(tx, ctx, token?.value));
|
|
804
|
+
} else if (["ExchangeTx", "ExchangeV2Tx"].includes(typeUrl)) receipts = receipts.concat(getExchangeReceipts(tx, ctx));
|
|
801
805
|
else if (["CreateAssetTx"].includes(typeUrl)) receipts = receipts.concat(getCreateAssetReceipts(tx));
|
|
802
806
|
else if (["MintAssetTx"].includes(typeUrl)) receipts = receipts.concat(getMintAssetReceipts(tx, ctx));
|
|
803
807
|
else if (["AcquireAssetV2Tx"].includes(typeUrl)) receipts = receipts.concat(getAcquireAssetReceipts(tx, ctx));
|
|
@@ -850,7 +854,7 @@ const create = (context, code = "OK", verifyReceipts = true) => {
|
|
|
850
854
|
const typeUrl = (0, _ocap_message.fromTypeUrl)(typeUrlRaw);
|
|
851
855
|
const typeName = typeUrlRaw.split(":").pop() || "";
|
|
852
856
|
const innerMessage = !isProtoWire ? (0, _ocap_message.createMessage)(typeUrl, itx) : void 0;
|
|
853
|
-
const itxJson = (0, _ocap_message.formatMessage)(typeUrl, innerMessage?.toObject ? innerMessage.toObject() : itx);
|
|
857
|
+
const itxJson = (0, _ocap_util_lib_deposit_v2_bridge_fields.stripDefaultDepositV2BridgeFields)(typeUrl, (0, _ocap_message.formatMessage)(typeUrl, innerMessage?.toObject ? innerMessage.toObject() : itx));
|
|
854
858
|
const result = {
|
|
855
859
|
code,
|
|
856
860
|
hash: txHash,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.31.
|
|
6
|
+
"version": "1.31.7",
|
|
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.31.
|
|
44
|
-
"@arcblock/validator": "1.31.
|
|
45
|
-
"@ocap/contract": "1.31.
|
|
46
|
-
"@ocap/mcrypto": "1.31.
|
|
47
|
-
"@ocap/message": "1.31.
|
|
48
|
-
"@ocap/types": "1.31.
|
|
49
|
-
"@ocap/util": "1.31.
|
|
50
|
-
"@ocap/wallet": "1.31.
|
|
43
|
+
"@arcblock/did": "1.31.7",
|
|
44
|
+
"@arcblock/validator": "1.31.7",
|
|
45
|
+
"@ocap/contract": "1.31.7",
|
|
46
|
+
"@ocap/mcrypto": "1.31.7",
|
|
47
|
+
"@ocap/message": "1.31.7",
|
|
48
|
+
"@ocap/types": "1.31.7",
|
|
49
|
+
"@ocap/util": "1.31.7",
|
|
50
|
+
"@ocap/wallet": "1.31.7",
|
|
51
51
|
"bloom-filters": "^1.3.9",
|
|
52
52
|
"lodash": "^4.17.23"
|
|
53
53
|
},
|