@ocap/state 1.31.0 → 1.31.1

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.
@@ -19,6 +19,11 @@ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
19
19
  readonly revokedTokens: v.OptionalSchema<any, {}>;
20
20
  readonly revokedAssets: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
21
21
  readonly context: v.ObjectSchema<{
22
+ readonly revokes: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
23
+ readonly txTime: v.OptionalSchema<v.StringSchema<undefined>, "">;
24
+ readonly tokens: v.OptionalSchema<any, {}>;
25
+ readonly assets: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
26
+ }, undefined>, undefined>, undefined>;
22
27
  readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
23
28
  readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
24
29
  readonly renaissanceTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
@@ -1,6 +1,6 @@
1
1
  import { __exportAll } from "../_virtual/rolldown_runtime.mjs";
2
2
  import { create as create$1, update as update$1 } from "../contexts/state.mjs";
3
- import { toAddress } from "@ocap/util";
3
+ import { BN, toAddress } from "@ocap/util";
4
4
  import { CustomError } from "@ocap/util/lib/error";
5
5
  import pick from "lodash/pick.js";
6
6
  import { schemas, v, vBN, vBNMin, vDID, vFilteredRecord, vStripUnknown, vValidate } from "@arcblock/validator";
@@ -12,6 +12,21 @@ var stake_exports = /* @__PURE__ */ __exportAll({
12
12
  update: () => update,
13
13
  validate: () => validate
14
14
  });
15
+ const stakeRevokeEntrySchema = v.object({
16
+ txTime: v.optional(v.string(), ""),
17
+ tokens: v.optional(vFilteredRecord(vDID({
18
+ prefix: true,
19
+ role: "ROLE_TOKEN"
20
+ }), vBN(vBNMin(0))), {}),
21
+ assets: v.optional(v.array(vDID({
22
+ prefix: true,
23
+ role: "ROLE_ASSET"
24
+ })), [])
25
+ });
26
+ const stakeContextSchema = v.object({
27
+ ...schemas.context.entries,
28
+ revokes: v.optional(v.record(v.string(), stakeRevokeEntrySchema))
29
+ });
15
30
  const schema = v.pipe(v.object({
16
31
  address: vDID({
17
32
  prefix: true,
@@ -39,7 +54,7 @@ const schema = v.pipe(v.object({
39
54
  prefix: true,
40
55
  role: "ROLE_ASSET"
41
56
  })), []),
42
- context: schemas.context,
57
+ context: stakeContextSchema,
43
58
  data: v.optional(v.nullable(v.any())),
44
59
  nonce: v.optional(v.nullable(v.pipe(v.string(), v.trim(), v.check((s) => s === "" || s.length >= 1 && s.length <= 256, "Must be 1-256 chars or empty"))))
45
60
  }), vStripUnknown());
@@ -72,6 +87,9 @@ const create = (attrs, context) => {
72
87
  return validate(stake);
73
88
  };
74
89
  const update = (state, attrs, context) => {
90
+ const nextContext = update$1(state.context, context);
91
+ if (attrs.context && "revokes" in attrs.context) if (attrs.context.revokes && Object.keys(attrs.context.revokes).length > 0) nextContext.revokes = attrs.context.revokes;
92
+ else delete nextContext.revokes;
75
93
  return validate({
76
94
  ...state,
77
95
  revokedTokens: state.revokedTokens ?? {},
@@ -88,13 +106,16 @@ const update = (state, attrs, context) => {
88
106
  ]),
89
107
  ...attrs.data !== void 0 ? { data: attrs.data } : {},
90
108
  message: state.message || "empty",
91
- context: update$1(state.context, context)
109
+ context: nextContext
92
110
  });
93
111
  };
94
112
  const validate = (state) => {
95
113
  const { value, error } = vValidate(schema, state);
96
114
  if (error) throw new CustomError("INVALID_STAKE", `Invalid stake state: ${error.details.map((x) => x.message).join(", ")}`);
97
115
  if (!value.data) value.data = null;
116
+ const hasRevokedTokens = Object.values(value.revokedTokens || {}).some((v$1) => new BN(String(v$1 || "0")).gt(new BN(0)));
117
+ const hasRevokedAssets = Array.isArray(value.revokedAssets) && value.revokedAssets.length > 0;
118
+ if (value.context && (!hasRevokedTokens && !hasRevokedAssets ? true : !value.context.revokes || Object.keys(value.context.revokes).length === 0)) delete value.context.revokes;
98
119
  return value;
99
120
  };
100
121
 
@@ -13,6 +13,21 @@ var stake_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
13
13
  update: () => update,
14
14
  validate: () => validate
15
15
  });
16
+ const stakeRevokeEntrySchema = _arcblock_validator.v.object({
17
+ txTime: _arcblock_validator.v.optional(_arcblock_validator.v.string(), ""),
18
+ tokens: _arcblock_validator.v.optional((0, _arcblock_validator.vFilteredRecord)((0, _arcblock_validator.vDID)({
19
+ prefix: true,
20
+ role: "ROLE_TOKEN"
21
+ }), (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0))), {}),
22
+ assets: _arcblock_validator.v.optional(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({
23
+ prefix: true,
24
+ role: "ROLE_ASSET"
25
+ })), [])
26
+ });
27
+ const stakeContextSchema = _arcblock_validator.v.object({
28
+ ..._arcblock_validator.schemas.context.entries,
29
+ revokes: _arcblock_validator.v.optional(_arcblock_validator.v.record(_arcblock_validator.v.string(), stakeRevokeEntrySchema))
30
+ });
16
31
  const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
17
32
  address: (0, _arcblock_validator.vDID)({
18
33
  prefix: true,
@@ -40,7 +55,7 @@ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
40
55
  prefix: true,
41
56
  role: "ROLE_ASSET"
42
57
  })), []),
43
- context: _arcblock_validator.schemas.context,
58
+ context: stakeContextSchema,
44
59
  data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any())),
45
60
  nonce: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.trim(), _arcblock_validator.v.check((s) => s === "" || s.length >= 1 && s.length <= 256, "Must be 1-256 chars or empty"))))
46
61
  }), (0, _arcblock_validator.vStripUnknown)());
@@ -73,6 +88,9 @@ const create = (attrs, context) => {
73
88
  return validate(stake);
74
89
  };
75
90
  const update = (state, attrs, context) => {
91
+ const nextContext = require_contexts_state.update(state.context, context);
92
+ if (attrs.context && "revokes" in attrs.context) if (attrs.context.revokes && Object.keys(attrs.context.revokes).length > 0) nextContext.revokes = attrs.context.revokes;
93
+ else delete nextContext.revokes;
76
94
  return validate({
77
95
  ...state,
78
96
  revokedTokens: state.revokedTokens ?? {},
@@ -89,13 +107,16 @@ const update = (state, attrs, context) => {
89
107
  ]),
90
108
  ...attrs.data !== void 0 ? { data: attrs.data } : {},
91
109
  message: state.message || "empty",
92
- context: require_contexts_state.update(state.context, context)
110
+ context: nextContext
93
111
  });
94
112
  };
95
113
  const validate = (state) => {
96
114
  const { value, error } = (0, _arcblock_validator.vValidate)(schema, state);
97
115
  if (error) throw new _ocap_util_lib_error.CustomError("INVALID_STAKE", `Invalid stake state: ${error.details.map((x) => x.message).join(", ")}`);
98
116
  if (!value.data) value.data = null;
117
+ const hasRevokedTokens = Object.values(value.revokedTokens || {}).some((v$1) => new _ocap_util.BN(String(v$1 || "0")).gt(new _ocap_util.BN(0)));
118
+ const hasRevokedAssets = Array.isArray(value.revokedAssets) && value.revokedAssets.length > 0;
119
+ if (value.context && (!hasRevokedTokens && !hasRevokedAssets ? true : !value.context.revokes || Object.keys(value.context.revokes).length === 0)) delete value.context.revokes;
99
120
  return value;
100
121
  };
101
122
 
@@ -19,6 +19,11 @@ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
19
19
  readonly revokedTokens: v.OptionalSchema<any, {}>;
20
20
  readonly revokedAssets: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
21
21
  readonly context: v.ObjectSchema<{
22
+ readonly revokes: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
23
+ readonly txTime: v.OptionalSchema<v.StringSchema<undefined>, "">;
24
+ readonly tokens: v.OptionalSchema<any, {}>;
25
+ readonly assets: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
26
+ }, undefined>, undefined>, undefined>;
22
27
  readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
23
28
  readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
24
29
  readonly renaissanceTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.31.0",
6
+ "version": "1.31.1",
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.0",
44
- "@arcblock/validator": "1.31.0",
45
- "@ocap/contract": "1.31.0",
46
- "@ocap/mcrypto": "1.31.0",
47
- "@ocap/message": "1.31.0",
48
- "@ocap/types": "1.31.0",
49
- "@ocap/util": "1.31.0",
50
- "@ocap/wallet": "1.31.0",
43
+ "@arcblock/did": "1.31.1",
44
+ "@arcblock/validator": "1.31.1",
45
+ "@ocap/contract": "1.31.1",
46
+ "@ocap/mcrypto": "1.31.1",
47
+ "@ocap/message": "1.31.1",
48
+ "@ocap/types": "1.31.1",
49
+ "@ocap/util": "1.31.1",
50
+ "@ocap/wallet": "1.31.1",
51
51
  "bloom-filters": "^1.3.9",
52
52
  "lodash": "^4.17.23"
53
53
  },