@ocap/state 1.18.17 → 1.18.19

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.
@@ -10,6 +10,7 @@ const schema = Joi.object({
10
10
  receiver: Joi.DID().trim().required(),
11
11
  tokens: Joi.object({}).pattern(Joi.DID().role('ROLE_TOKEN'), Joi.BN().min(0)).default({}),
12
12
  assets: Joi.array().items(Joi.DID().role('ROLE_ASSET')).default([]),
13
+ slashers: Joi.array().items(Joi.DID()).default([]),
13
14
  revocable: Joi.boolean().default(true),
14
15
  message: Joi.string().trim().min(1).max(256).required(),
15
16
  revokeWaitingPeriod: Joi.number().integer().min(0).default(0),
@@ -23,6 +24,7 @@ const create = (attrs, context) => {
23
24
  const stake = {
24
25
  tokens: {},
25
26
  assets: [],
27
+ slashers: [],
26
28
  revocable: true,
27
29
  revokedTokens: {},
28
30
  revokedAssets: [],
@@ -34,6 +36,7 @@ const create = (attrs, context) => {
34
36
  'receiver',
35
37
  'tokens',
36
38
  'assets',
39
+ 'slashers',
37
40
  'revocable',
38
41
  'data',
39
42
  'message',
package/lib/states/tx.js CHANGED
@@ -78,12 +78,14 @@ const getTransferReceipts = (tx) => {
78
78
 
79
79
  const getReceiptsFromTxInput = (inputs, symbol, action = 'transfer') => {
80
80
  const receipts = [];
81
- inputs.forEach(({ owner, tokens, assets }) => {
82
- const receipt = { address: owner, changes: [] };
83
- tokens.forEach(({ address, value }) => {
81
+ inputs.forEach((x) => {
82
+ const receipt = { address: x.owner, changes: [] };
83
+ getListField(x, 'tokens').forEach(({ address, value }) => {
84
84
  receipt.changes.push({ target: address, action, value: `${symbol}${value}` });
85
85
  });
86
- assets.forEach((address) => receipt.changes.push({ target: address, action, value: `${symbol}1` }));
86
+ getListField(x, 'assets').forEach((address) =>
87
+ receipt.changes.push({ target: address, action, value: `${symbol}1` })
88
+ );
87
89
  receipts.push(receipt);
88
90
  });
89
91
 
@@ -225,7 +227,7 @@ const getStakeReceipts = (tx) => {
225
227
  return [stakeReceipt, ...getReceiptsFromTxInput(inputs, '-', 'stake')];
226
228
  };
227
229
 
228
- const getClaimStakeReceipts = (tx, ctx) => {
230
+ const getClaimStakeReceipts = (tx, ctx, action) => {
229
231
  const { address } = tx.itxJson;
230
232
  const { outputs } = ctx;
231
233
 
@@ -233,22 +235,22 @@ const getClaimStakeReceipts = (tx, ctx) => {
233
235
  const tokens = {};
234
236
  const assets = [];
235
237
  outputs.forEach((output) => {
236
- output.tokens.forEach((x) => {
238
+ getListField(output, 'tokens').forEach((x) => {
237
239
  if (typeof tokens[x.address] === 'undefined') {
238
240
  tokens[x.address] = new BN(0);
239
241
  }
240
242
  tokens[x.address] = tokens[x.address].add(new BN(x.value));
241
243
  });
242
- assets.push(...output.assets);
244
+ assets.push(...getListField(output, 'assets'));
243
245
  });
244
246
 
245
247
  const stakeReceipt = { address, changes: [] };
246
- assets.forEach((x) => stakeReceipt.changes.push({ target: x, action: 'stake', value: '-1' }));
248
+ assets.forEach((x) => stakeReceipt.changes.push({ target: x, action, value: '-1' }));
247
249
  Object.keys(tokens).forEach((x) =>
248
- stakeReceipt.changes.push({ target: x, action: 'stake', value: `-${tokens[x].toString(10)}` })
250
+ stakeReceipt.changes.push({ target: x, action, value: `-${tokens[x].toString(10)}` })
249
251
  );
250
252
 
251
- return [stakeReceipt, ...getReceiptsFromTxInput(outputs, '', 'claim')];
253
+ return [stakeReceipt, ...getReceiptsFromTxInput(outputs, '', action)];
252
254
  };
253
255
 
254
256
  const getCreateTokenReceipts = (tx) => {
@@ -364,7 +366,9 @@ const getTxReceipts = ({ tx, code }, ctx = {}) => {
364
366
  } else if (['StakeTx'].includes(typeUrl)) {
365
367
  receipts = receipts.concat(getStakeReceipts(tx, ctx));
366
368
  } else if (['ClaimStakeTx'].includes(typeUrl)) {
367
- receipts = receipts.concat(getClaimStakeReceipts(tx, ctx));
369
+ receipts = receipts.concat(getClaimStakeReceipts(tx, ctx, 'claim'));
370
+ } else if (['SlashStakeTx'].includes(typeUrl)) {
371
+ receipts = receipts.concat(getClaimStakeReceipts(tx, ctx, 'slash'));
368
372
  }
369
373
 
370
374
  receipts = receipts.concat(getReceiptsFromContext(ctx));
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.17",
6
+ "version": "1.18.19",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -16,12 +16,12 @@
16
16
  "coverage": "npm run test -- --coverage"
17
17
  },
18
18
  "dependencies": {
19
- "@arcblock/did": "1.18.17",
20
- "@arcblock/validator": "1.18.17",
21
- "@ocap/contract": "1.18.17",
22
- "@ocap/mcrypto": "1.18.17",
23
- "@ocap/message": "1.18.17",
24
- "@ocap/util": "1.18.17",
19
+ "@arcblock/did": "1.18.19",
20
+ "@arcblock/validator": "1.18.19",
21
+ "@ocap/contract": "1.18.19",
22
+ "@ocap/mcrypto": "1.18.19",
23
+ "@ocap/message": "1.18.19",
24
+ "@ocap/util": "1.18.19",
25
25
  "bloom-filters": "^1.3.9",
26
26
  "lodash": "^4.17.21"
27
27
  },
@@ -31,5 +31,5 @@
31
31
  "keywords": [],
32
32
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
33
33
  "license": "MIT",
34
- "gitHead": "be4f07d40599521e3b5364dd7d0ace22ad5f58d6"
34
+ "gitHead": "d13bcea225809e0c0a926cfc246c7a46bd4185f3"
35
35
  }