@blocklet/meta 1.8.19 → 1.8.21
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/lib/constants.js +0 -1
- package/lib/payment/v2.js +44 -6
- package/lib/schema.js +0 -2
- package/package.json +4 -4
package/lib/constants.js
CHANGED
|
@@ -80,7 +80,6 @@ const BlockletEvents = Object.freeze({
|
|
|
80
80
|
upgradeFailed: 'blocklet.upgradedFailed',
|
|
81
81
|
downgraded: 'blocklet.downgraded',
|
|
82
82
|
downgradeFailed: 'blocklet.downgradedFailed',
|
|
83
|
-
deployed: 'blocklet.deployed',
|
|
84
83
|
updated: 'blocklet.updated',
|
|
85
84
|
statusChange: 'blocklet.statusChange',
|
|
86
85
|
removed: 'blocklet.removed',
|
package/lib/payment/v2.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const crypto = require('crypto');
|
|
3
3
|
const debug = require('debug')('@blocklet/meta:payment');
|
|
4
4
|
const joinURL = require('url-join');
|
|
5
|
-
const axios = require('axios');
|
|
5
|
+
const axios = require('axios').create();
|
|
6
6
|
const stableStringify = require('json-stable-stringify');
|
|
7
7
|
const get = require('lodash/get');
|
|
8
8
|
const pick = require('lodash/pick');
|
|
@@ -243,7 +243,9 @@ const getTokenTransfers = ({ priceToken, shares = [], components = [] }) => {
|
|
|
243
243
|
const [token] = child.meta.payment.price || [];
|
|
244
244
|
if (token && token.address !== priceToken.address) {
|
|
245
245
|
throw new Error(
|
|
246
|
-
`
|
|
246
|
+
`The token address of the component "${
|
|
247
|
+
child.meta.title || child.meta.name
|
|
248
|
+
}" is inconsistent with the blocklet. Component: ${priceToken.address}, Composite Blocklet: ${token.address}`
|
|
247
249
|
);
|
|
248
250
|
}
|
|
249
251
|
|
|
@@ -251,10 +253,6 @@ const getTokenTransfers = ({ priceToken, shares = [], components = [] }) => {
|
|
|
251
253
|
|
|
252
254
|
parentShareBN = parentShareBN.sub(fromTokenToUnit(childShare, priceToken.decimal));
|
|
253
255
|
|
|
254
|
-
if (parentShareBN.lt(ZeroBN)) {
|
|
255
|
-
throw new Error('Price is not enough for component sharing');
|
|
256
|
-
}
|
|
257
|
-
|
|
258
256
|
const componentContracts = getTokenTransfers({
|
|
259
257
|
priceToken: { ...priceToken, value: childShare },
|
|
260
258
|
shares: child.meta.payment.share,
|
|
@@ -265,6 +263,13 @@ const getTokenTransfers = ({ priceToken, shares = [], components = [] }) => {
|
|
|
265
263
|
}
|
|
266
264
|
}
|
|
267
265
|
|
|
266
|
+
if (parentShareBN.lt(ZeroBN)) {
|
|
267
|
+
const needPrice = fromUnitToToken(fromTokenToUnit(price, priceToken.decimal).sub(parentShareBN));
|
|
268
|
+
throw new Error(
|
|
269
|
+
`Price for composite blocklet must be greater than ${needPrice} because paid components are included.`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
268
273
|
shares.forEach(({ name, address: accountAddress, value: ratio }) => {
|
|
269
274
|
contracts.push({
|
|
270
275
|
tokenAddress: priceToken.address,
|
|
@@ -604,10 +609,43 @@ const verifyNftFactory = async ({ factoryState, signerWallet }) => {
|
|
|
604
609
|
return { components };
|
|
605
610
|
};
|
|
606
611
|
|
|
612
|
+
/**
|
|
613
|
+
* Check blocklet and all of components are free
|
|
614
|
+
* Throw Error if not free
|
|
615
|
+
*
|
|
616
|
+
* @param {BlockletMeta} meta
|
|
617
|
+
*/
|
|
618
|
+
const checkFreeBlocklet = async (blockletMeta) => {
|
|
619
|
+
if (!isFreeBlocklet(blockletMeta)) {
|
|
620
|
+
return Promise.reject(new Error('blocklet is not free'));
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const { components } = await getComponents(blockletMeta);
|
|
624
|
+
|
|
625
|
+
const shouldAllComponentFree = (arr) => {
|
|
626
|
+
arr.forEach(({ meta, children }) => {
|
|
627
|
+
if (!isFreeBlocklet(meta) || !isFreeComponent(meta)) {
|
|
628
|
+
// throw new Error(`Found paid component "${meta.title || meta.name}" in free blocklet`);
|
|
629
|
+
throw new Error(
|
|
630
|
+
`Paid component "${meta.title || meta.name}" found in free blocklet "${
|
|
631
|
+
blockletMeta.title || blockletMeta.name
|
|
632
|
+
}", which is forbidden`
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
shouldAllComponentFree(children || []);
|
|
636
|
+
});
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
shouldAllComponentFree(components);
|
|
640
|
+
|
|
641
|
+
return true;
|
|
642
|
+
};
|
|
643
|
+
|
|
607
644
|
module.exports = {
|
|
608
645
|
createNftFactoryItx,
|
|
609
646
|
verifyPaymentIntegrity,
|
|
610
647
|
verifyNftFactory,
|
|
648
|
+
checkFreeBlocklet,
|
|
611
649
|
version: VERSION,
|
|
612
650
|
_test: {
|
|
613
651
|
getPriceTokens,
|
package/lib/schema.js
CHANGED
|
@@ -71,7 +71,6 @@ const scriptsSchema = Joi.object({
|
|
|
71
71
|
e2eDev: Joi.string().trim().min(1),
|
|
72
72
|
preInstall: Joi.string().trim().min(1),
|
|
73
73
|
postInstall: Joi.string().trim().min(1),
|
|
74
|
-
preDeploy: Joi.string().trim().min(1),
|
|
75
74
|
preStart: Joi.string().trim().min(1),
|
|
76
75
|
postStart: Joi.string().trim().min(1),
|
|
77
76
|
preStop: Joi.string().trim().min(1),
|
|
@@ -80,7 +79,6 @@ const scriptsSchema = Joi.object({
|
|
|
80
79
|
})
|
|
81
80
|
.rename('pre-install', 'preInstall')
|
|
82
81
|
.rename('post-install', 'postInstall')
|
|
83
|
-
.rename('pre-deploy', 'preDeploy')
|
|
84
82
|
.rename('pre-start', 'preStart')
|
|
85
83
|
.rename('post-start', 'postStart')
|
|
86
84
|
.rename('pre-stop', 'preStop')
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.21",
|
|
7
7
|
"description": "Library to parse/validate/fix blocklet meta",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.8.
|
|
22
|
-
"@abtnode/util": "1.8.
|
|
21
|
+
"@abtnode/constant": "1.8.21",
|
|
22
|
+
"@abtnode/util": "1.8.21",
|
|
23
23
|
"@arcblock/did": "1.17.19",
|
|
24
24
|
"@arcblock/did-ext": "1.17.19",
|
|
25
25
|
"@arcblock/did-util": "1.17.19",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"express": "^4.18.1",
|
|
54
54
|
"jest": "^27.5.1"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "f990cddd5ef18ece7ada5d7573b8e0652d74abdc"
|
|
57
57
|
}
|