@ocap/tx-protocols 1.18.32 → 1.18.33
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/protocols/account/declare.js +1 -1
- package/lib/protocols/account/delegate.js +2 -2
- package/lib/protocols/account/migrate.js +1 -1
- package/lib/protocols/account/revoke-delegate.js +2 -2
- package/lib/protocols/asset/acquire-v2.js +21 -2
- package/lib/protocols/asset/acquire-v3.js +18 -2
- package/lib/protocols/asset/mint.js +21 -2
- package/lib/protocols/asset/update.js +1 -1
- package/lib/protocols/governance/claim-stake.js +1 -1
- package/lib/protocols/governance/revoke-stake.js +1 -1
- package/lib/protocols/governance/slash-stake.js +1 -1
- package/lib/protocols/governance/stake.js +3 -3
- package/lib/protocols/rollup/claim-reward.js +2 -2
- package/lib/protocols/rollup/create-block.js +2 -2
- package/lib/protocols/rollup/join.js +1 -1
- package/lib/protocols/rollup/leave.js +1 -1
- package/lib/protocols/rollup/migrate-contract.js +2 -2
- package/lib/protocols/rollup/migrate-token.js +4 -4
- package/lib/protocols/rollup/pause.js +1 -1
- package/lib/protocols/rollup/resume.js +1 -1
- package/lib/protocols/rollup/update.js +1 -1
- package/lib/protocols/token/create.js +1 -1
- package/lib/protocols/token/deposit-v2.js +3 -3
- package/lib/protocols/token/withdraw-v2.js +3 -3
- package/lib/protocols/trade/exchange-v2.js +19 -15
- package/lib/protocols/trade/transfer-v2.js +17 -1
- package/lib/protocols/trade/transfer-v3.js +13 -0
- package/package.json +14 -14
- package/lib/protocols/asset/pipes/verify-acquire-params.js +0 -30
|
@@ -10,7 +10,7 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
10
10
|
|
|
11
11
|
// verify itx
|
|
12
12
|
const schema = Joi.object({
|
|
13
|
-
issuer: Joi.DID().optional().allow(''),
|
|
13
|
+
issuer: Joi.DID().prefix().optional().allow(''),
|
|
14
14
|
moniker: Joi.string()
|
|
15
15
|
.regex(/^[a-zA-Z0-9][-a-zA-Z0-9_]{2,40}$/)
|
|
16
16
|
.required(),
|
|
@@ -19,8 +19,8 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
19
19
|
|
|
20
20
|
// verify itx
|
|
21
21
|
const schema = Joi.object({
|
|
22
|
-
address: Joi.DID().role('ROLE_DELEGATION').required(),
|
|
23
|
-
to: Joi.DID().required(),
|
|
22
|
+
address: Joi.DID().prefix().role('ROLE_DELEGATION').required(),
|
|
23
|
+
to: Joi.DID().prefix().required(),
|
|
24
24
|
opsList: Joi.array()
|
|
25
25
|
.items(
|
|
26
26
|
Joi.object({
|
|
@@ -17,7 +17,7 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
17
17
|
|
|
18
18
|
// verify itx
|
|
19
19
|
const schema = Joi.object({
|
|
20
|
-
address: Joi.DID().required(),
|
|
20
|
+
address: Joi.DID().prefix().required(),
|
|
21
21
|
pk: Joi.any().required(),
|
|
22
22
|
data: Joi.any().optional(),
|
|
23
23
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
@@ -19,8 +19,8 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
19
19
|
|
|
20
20
|
// Verify itx
|
|
21
21
|
const schema = Joi.object({
|
|
22
|
-
address: Joi.DID().role('ROLE_DELEGATION').required(),
|
|
23
|
-
to: Joi.DID().required(),
|
|
22
|
+
address: Joi.DID().prefix().role('ROLE_DELEGATION').required(),
|
|
23
|
+
to: Joi.DID().prefix().required(),
|
|
24
24
|
typeUrlsList: Joi.array().items(Joi.string().required()).min(1).required(),
|
|
25
25
|
data: Joi.any().optional(),
|
|
26
26
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
const { promisify } = require('util');
|
|
3
3
|
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
4
4
|
const { account, asset, factory } = require('@ocap/state');
|
|
5
|
+
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
6
|
+
const { Joi, schemas } = require('@arcblock/validator');
|
|
5
7
|
|
|
6
8
|
// eslint-disable-next-line global-require
|
|
7
9
|
const debug = require('debug')(`${require('../../../package.json').name}:acquire-asset-v2`);
|
|
8
10
|
|
|
9
11
|
// custom pipes
|
|
10
|
-
const verifyAcquireParams = require('./pipes/verify-acquire-params');
|
|
11
12
|
const verifyMintLimit = require('./pipes/verify-mint-limit');
|
|
12
13
|
const verifyItxVariables = require('./pipes/verify-itx-variables');
|
|
13
14
|
const verifyItxAssets = require('./pipes/verify-itx-assets');
|
|
@@ -25,7 +26,25 @@ const verifyTokenBalance = promisify(pipes.VerifyTokenBalance({ ownerKey: 'sende
|
|
|
25
26
|
const runner = new Runner();
|
|
26
27
|
|
|
27
28
|
runner.use(pipes.VerifyMultiSig(0));
|
|
28
|
-
|
|
29
|
+
|
|
30
|
+
// verify itx
|
|
31
|
+
const schema = Joi.object({
|
|
32
|
+
factory: Joi.DID().prefix().role('ROLE_FACTORY').required(),
|
|
33
|
+
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
34
|
+
assetsList: Joi.array()
|
|
35
|
+
.items(Joi.alternatives().try(Joi.DID().prefix().role('ROLE_ASSET'), Joi.DID().prefix().role('ROLE_FACTORY')))
|
|
36
|
+
.default([]),
|
|
37
|
+
variablesList: Joi.array().items(schemas.variableInput).min(1).required(),
|
|
38
|
+
issuer: schemas.nftIssuer.required(),
|
|
39
|
+
data: Joi.any().optional(),
|
|
40
|
+
}).options({ stripUnknown: true, noDefaults: false });
|
|
41
|
+
runner.use(({ itx }, next) => {
|
|
42
|
+
const { error } = schema.validate(itx);
|
|
43
|
+
if (error) {
|
|
44
|
+
return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
|
|
45
|
+
}
|
|
46
|
+
return next();
|
|
47
|
+
});
|
|
29
48
|
|
|
30
49
|
// ensure asset not exist
|
|
31
50
|
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'duplicateAsset', status: 'OK', table: 'asset' }));
|
|
@@ -6,6 +6,8 @@ const isEqual = require('lodash/isEqual');
|
|
|
6
6
|
const { BN } = require('@ocap/util');
|
|
7
7
|
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
8
8
|
const { account, asset, factory } = require('@ocap/state');
|
|
9
|
+
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
10
|
+
const { Joi, schemas } = require('@arcblock/validator');
|
|
9
11
|
|
|
10
12
|
// eslint-disable-next-line global-require
|
|
11
13
|
const debug = require('debug')(`${require('../../../package.json').name}:acquire-asset-v3`);
|
|
@@ -13,7 +15,6 @@ const debug = require('debug')(`${require('../../../package.json').name}:acquire
|
|
|
13
15
|
const { applyTokenUpdates, applyTokenChange } = require('../../util');
|
|
14
16
|
|
|
15
17
|
// custom pipes
|
|
16
|
-
const verifyAcquireParams = require('./pipes/verify-acquire-params');
|
|
17
18
|
const verifyMintLimit = require('./pipes/verify-mint-limit');
|
|
18
19
|
const verifyItxVariables = require('./pipes/verify-itx-variables');
|
|
19
20
|
const verifyItxAssets = require('./pipes/verify-itx-assets');
|
|
@@ -29,7 +30,22 @@ const verifyAssetOwner = promisify(pipes.VerifyUpdater({ assetKey: 'assets', own
|
|
|
29
30
|
const runner = new Runner();
|
|
30
31
|
|
|
31
32
|
// 1. extract & verify itx input
|
|
32
|
-
|
|
33
|
+
const schema = Joi.object({
|
|
34
|
+
factory: Joi.DID().prefix().role('ROLE_FACTORY').required(),
|
|
35
|
+
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
36
|
+
inputsList: schemas.multiInput.min(1).required(),
|
|
37
|
+
owner: Joi.DID().prefix().required(),
|
|
38
|
+
variablesList: Joi.array().items(schemas.variableInput).min(1).required(),
|
|
39
|
+
issuer: schemas.nftIssuer.required(),
|
|
40
|
+
data: Joi.any().optional(),
|
|
41
|
+
}).options({ stripUnknown: true, noDefaults: false });
|
|
42
|
+
runner.use(({ itx }, next) => {
|
|
43
|
+
const { error } = schema.validate(itx);
|
|
44
|
+
if (error) {
|
|
45
|
+
return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
});
|
|
33
49
|
|
|
34
50
|
// ensure asset not exist
|
|
35
51
|
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'duplicateAsset', status: 'OK', table: 'asset' }));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/* eslint-disable function-paren-newline */
|
|
2
2
|
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
3
|
+
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
4
|
+
const { Joi, schemas } = require('@arcblock/validator');
|
|
3
5
|
const { account, asset, factory } = require('@ocap/state');
|
|
4
6
|
|
|
5
7
|
// eslint-disable-next-line global-require
|
|
6
8
|
const debug = require('debug')(`${require('../../../package.json').name}:acquire-asset`);
|
|
7
9
|
|
|
8
|
-
const verifyAcquireParams = require('./pipes/verify-acquire-params');
|
|
9
10
|
const verifyMintLimit = require('./pipes/verify-mint-limit');
|
|
10
11
|
const verifyItxVariables = require('./pipes/verify-itx-variables');
|
|
11
12
|
const verifyItxAssets = require('./pipes/verify-itx-assets');
|
|
@@ -17,7 +18,25 @@ const EnsureTxGas = require('../../pipes/ensure-gas');
|
|
|
17
18
|
const EnsureTxCost = require('../../pipes/ensure-cost');
|
|
18
19
|
|
|
19
20
|
runner.use(pipes.VerifyMultiSig(0));
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
// verify itx
|
|
23
|
+
const schema = Joi.object({
|
|
24
|
+
factory: Joi.DID().prefix().role('ROLE_FACTORY').required(),
|
|
25
|
+
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
26
|
+
assetsList: Joi.array()
|
|
27
|
+
.items(Joi.alternatives().try(Joi.DID().prefix().role('ROLE_ASSET'), Joi.DID().prefix().role('ROLE_FACTORY')))
|
|
28
|
+
.default([]),
|
|
29
|
+
variablesList: Joi.array().items(schemas.variableInput).min(1).required(),
|
|
30
|
+
owner: Joi.DID().prefix().required(),
|
|
31
|
+
data: Joi.any().optional(),
|
|
32
|
+
}).options({ stripUnknown: true, noDefaults: false });
|
|
33
|
+
runner.use(({ itx }, next) => {
|
|
34
|
+
const { error } = schema.validate(itx);
|
|
35
|
+
if (error) {
|
|
36
|
+
return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
|
|
37
|
+
}
|
|
38
|
+
return next();
|
|
39
|
+
});
|
|
21
40
|
|
|
22
41
|
// ensure asset not exist
|
|
23
42
|
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'duplicateAsset', status: 'OK', table: 'asset' }));
|
|
@@ -18,7 +18,7 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
18
18
|
|
|
19
19
|
// Verify itx
|
|
20
20
|
const schema = Joi.object({
|
|
21
|
-
address: Joi.DID().role('ROLE_ASSET').required(),
|
|
21
|
+
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
22
22
|
moniker: Joi.string().min(2).max(255).optional().allow(''),
|
|
23
23
|
data: Joi.any().optional(),
|
|
24
24
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
@@ -18,7 +18,7 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
18
18
|
|
|
19
19
|
// 1. verify itx output
|
|
20
20
|
const schema = Joi.object({
|
|
21
|
-
address: Joi.DID().role('ROLE_STAKE').required(),
|
|
21
|
+
address: Joi.DID().prefix().role('ROLE_STAKE').required(),
|
|
22
22
|
evidence: Joi.object({
|
|
23
23
|
hash: Joi.string().regex(patterns.txHash).required(),
|
|
24
24
|
}).required(),
|
|
@@ -19,7 +19,7 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
19
19
|
|
|
20
20
|
// 0. verify itx
|
|
21
21
|
const schema = Joi.object({
|
|
22
|
-
address: Joi.DID().role('ROLE_STAKE').required(),
|
|
22
|
+
address: Joi.DID().prefix().role('ROLE_STAKE').required(),
|
|
23
23
|
outputsList: schemas.multiInput.min(1).required(),
|
|
24
24
|
data: Joi.any().optional(),
|
|
25
25
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
@@ -19,7 +19,7 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
19
19
|
|
|
20
20
|
// 0. verify itx
|
|
21
21
|
const schema = Joi.object({
|
|
22
|
-
address: Joi.DID().role('ROLE_STAKE').required(),
|
|
22
|
+
address: Joi.DID().prefix().role('ROLE_STAKE').required(),
|
|
23
23
|
message: Joi.string().trim().min(1).max(256).required(),
|
|
24
24
|
outputsList: schemas.multiInput.min(1).required(),
|
|
25
25
|
data: Joi.any().optional(),
|
|
@@ -22,9 +22,9 @@ const runner = new Runner();
|
|
|
22
22
|
|
|
23
23
|
// 0. verify itx
|
|
24
24
|
const schema = Joi.object({
|
|
25
|
-
address: Joi.DID().role('ROLE_STAKE').required(),
|
|
26
|
-
receiver: Joi.DID().required(),
|
|
27
|
-
slashersList: Joi.array().items(Joi.DID()).default([]),
|
|
25
|
+
address: Joi.DID().prefix().role('ROLE_STAKE').required(),
|
|
26
|
+
receiver: Joi.DID().prefix().required(),
|
|
27
|
+
slashersList: Joi.array().items(Joi.DID().prefix()).default([]),
|
|
28
28
|
locked: Joi.boolean().default(false),
|
|
29
29
|
inputsList: schemas.multiInput.min(1).required(),
|
|
30
30
|
message: Joi.string().trim().min(1).max(256).required(),
|
|
@@ -20,13 +20,13 @@ const runner = new Runner();
|
|
|
20
20
|
|
|
21
21
|
// 1. verify itx
|
|
22
22
|
const schema = Joi.object({
|
|
23
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
23
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
24
24
|
blockHeight: Joi.number().integer().greater(0).required(),
|
|
25
25
|
blockHash: Joi.string().regex(patterns.txHash).required(),
|
|
26
26
|
evidence: Joi.object({
|
|
27
27
|
hash: Joi.string().regex(patterns.txHash).required(),
|
|
28
28
|
}).required(),
|
|
29
|
-
publisher: Joi.DID().wallet('ethereum').required(),
|
|
29
|
+
publisher: Joi.DID().prefix().wallet('ethereum').required(),
|
|
30
30
|
data: Joi.any().optional(),
|
|
31
31
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
32
32
|
runner.use((context, next) => {
|
|
@@ -34,9 +34,9 @@ const schema = Joi.object({
|
|
|
34
34
|
}),
|
|
35
35
|
txsHash: Joi.string().regex(patterns.txHash).required(),
|
|
36
36
|
txsList: Joi.array().items(Joi.string().regex(patterns.txHash).required()).min(1).unique().required(),
|
|
37
|
-
proposer: Joi.DID().wallet('ethereum').required(),
|
|
37
|
+
proposer: Joi.DID().prefix().wallet('ethereum').required(),
|
|
38
38
|
signaturesList: schemas.multiSig.min(1).required(),
|
|
39
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
39
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
40
40
|
minReward: Joi.BN().min(0).required(),
|
|
41
41
|
data: Joi.any().optional(),
|
|
42
42
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
@@ -22,7 +22,7 @@ const runner = new Runner();
|
|
|
22
22
|
|
|
23
23
|
// 1. verify itx
|
|
24
24
|
const schema = Joi.object({
|
|
25
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
25
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
26
26
|
endpoint: Joi.string()
|
|
27
27
|
.uri({ scheme: [/https?/] })
|
|
28
28
|
.required(),
|
|
@@ -19,7 +19,7 @@ const runner = new Runner();
|
|
|
19
19
|
|
|
20
20
|
// 1. verify itx
|
|
21
21
|
const schema = Joi.object({
|
|
22
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
22
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
23
23
|
evidence: Joi.object({
|
|
24
24
|
hash: Joi.string().regex(patterns.txHash).required(),
|
|
25
25
|
}).required(),
|
|
@@ -12,8 +12,8 @@ const runner = new Runner();
|
|
|
12
12
|
|
|
13
13
|
// 1. verify itx
|
|
14
14
|
const schema = Joi.object({
|
|
15
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
16
|
-
to: Joi.DID().wallet('ethereum').required(),
|
|
15
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
16
|
+
to: Joi.DID().prefix().wallet('ethereum').required(),
|
|
17
17
|
data: Joi.any().optional(),
|
|
18
18
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
19
19
|
runner.use(({ itx }, next) => {
|
|
@@ -12,11 +12,11 @@ const runner = new Runner();
|
|
|
12
12
|
|
|
13
13
|
// 1. verify itx
|
|
14
14
|
const schema = Joi.object({
|
|
15
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
16
|
-
from: Joi.DID().wallet('ethereum').required(),
|
|
17
|
-
to: Joi.DID().wallet('ethereum').required(),
|
|
15
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
16
|
+
from: Joi.DID().prefix().wallet('ethereum').required(),
|
|
17
|
+
to: Joi.DID().prefix().wallet('ethereum').required(),
|
|
18
18
|
token: Joi.object({
|
|
19
|
-
address: Joi.DID().wallet('ethereum').required(),
|
|
19
|
+
address: Joi.DID().prefix().wallet('ethereum').required(),
|
|
20
20
|
value: Joi.BN().positive().required(),
|
|
21
21
|
}),
|
|
22
22
|
data: Joi.any().optional(),
|
|
@@ -12,7 +12,7 @@ const runner = new Runner();
|
|
|
12
12
|
|
|
13
13
|
// 1. verify itx
|
|
14
14
|
const schema = Joi.object({
|
|
15
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
15
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
16
16
|
data: Joi.any().optional(),
|
|
17
17
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
18
18
|
runner.use(({ itx }, next) => {
|
|
@@ -12,7 +12,7 @@ const runner = new Runner();
|
|
|
12
12
|
|
|
13
13
|
// 1. verify itx
|
|
14
14
|
const schema = Joi.object({
|
|
15
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
15
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
16
16
|
data: Joi.any().optional(),
|
|
17
17
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
18
18
|
runner.use(({ itx }, next) => {
|
|
@@ -16,7 +16,7 @@ const runner = new Runner();
|
|
|
16
16
|
|
|
17
17
|
// 1. verify itx: client must use previous rollup state to construct this itx
|
|
18
18
|
const schema = Joi.object({
|
|
19
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
19
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
20
20
|
|
|
21
21
|
minStakeAmount: Joi.BN().greater(0).required(),
|
|
22
22
|
maxStakeAmount: Joi.BN().greater(Joi.ref('minStakeAmount')).required(),
|
|
@@ -21,7 +21,7 @@ const runner = new Runner();
|
|
|
21
21
|
runner.use(pipes.VerifyMultiSig(0));
|
|
22
22
|
|
|
23
23
|
const schema = Joi.object({
|
|
24
|
-
address: Joi.DID().role('ROLE_TOKEN').required(),
|
|
24
|
+
address: Joi.DID().prefix().role('ROLE_TOKEN').required(),
|
|
25
25
|
name: Joi.string().min(1).max(32).required(),
|
|
26
26
|
description: Joi.string().min(1).max(128).required(),
|
|
27
27
|
symbol: Joi.string().min(2).max(6).uppercase().required(),
|
|
@@ -19,12 +19,12 @@ const { applyTokenUpdates, applyTokenChange, getTxFee, getBNSum, getRewardLocker
|
|
|
19
19
|
|
|
20
20
|
const schema = Joi.object({
|
|
21
21
|
token: schemas.tokenInput.required(),
|
|
22
|
-
to: Joi.DID().wallet('ethereum').required(),
|
|
23
|
-
proposer: Joi.DID().wallet('ethereum').required(),
|
|
22
|
+
to: Joi.DID().prefix().wallet('ethereum').required(),
|
|
23
|
+
proposer: Joi.DID().prefix().wallet('ethereum').required(),
|
|
24
24
|
evidence: Joi.object({
|
|
25
25
|
hash: Joi.string().regex(patterns.txHash).required(),
|
|
26
26
|
}).required(),
|
|
27
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
27
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
28
28
|
actualFee: Joi.BN().min(0).required(),
|
|
29
29
|
data: Joi.any().optional(),
|
|
30
30
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
@@ -20,9 +20,9 @@ const verifyMultiSigV2 = pipes.VerifyMultiSigV2({ signersKey: 'signers' });
|
|
|
20
20
|
|
|
21
21
|
const schema = Joi.object({
|
|
22
22
|
token: schemas.tokenInput.required(),
|
|
23
|
-
to: Joi.DID().wallet('ethereum').required(),
|
|
24
|
-
rollup: Joi.DID().role('ROLE_ROLLUP').required(),
|
|
25
|
-
proposer: Joi.DID().wallet('ethereum').optional().allow('').default(''),
|
|
23
|
+
to: Joi.DID().prefix().wallet('ethereum').required(),
|
|
24
|
+
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
25
|
+
proposer: Joi.DID().prefix().wallet('ethereum').optional().allow('').default(''),
|
|
26
26
|
actualFee: Joi.BN().min(0).required(),
|
|
27
27
|
maxFee: Joi.BN().min(0).required(),
|
|
28
28
|
data: Joi.any().optional(),
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const isEmpty = require('empty-value');
|
|
2
|
+
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
3
|
+
const { Joi, schemas } = require('@arcblock/validator');
|
|
2
4
|
const { getListField } = require('@ocap/util/lib/get-list-field');
|
|
3
5
|
const { createSortedList } = require('@ocap/util/lib/create-sorted-list');
|
|
4
6
|
const { decodeBigInt } = require('@ocap/message');
|
|
@@ -15,16 +17,28 @@ const { applyTokenChange } = require('../../util');
|
|
|
15
17
|
|
|
16
18
|
const runner = new Runner();
|
|
17
19
|
|
|
20
|
+
// 0. verify itx
|
|
21
|
+
const exchangeInfoSchema = Joi.object({
|
|
22
|
+
value: Joi.any().optional(),
|
|
23
|
+
tokensList: Joi.array().items(schemas.tokenInput).default([]),
|
|
24
|
+
assetsList: Joi.array().items(Joi.DID().prefix().role('ROLE_ASSET')).default([]),
|
|
25
|
+
});
|
|
26
|
+
const schema = Joi.object({
|
|
27
|
+
to: Joi.DID().prefix().role('ROLE_ACCOUNT').required(),
|
|
28
|
+
sender: exchangeInfoSchema.required(),
|
|
29
|
+
receiver: exchangeInfoSchema.required(),
|
|
30
|
+
data: Joi.any().optional(),
|
|
31
|
+
}).options({ stripUnknown: true, noDefaults: false });
|
|
32
|
+
runner.use(({ itx }, next) => {
|
|
33
|
+
const { error } = schema.validate(itx);
|
|
34
|
+
return next(error ? new Error('INVALID_TX', `Invalid itx: ${error.message}`) : null);
|
|
35
|
+
});
|
|
36
|
+
|
|
18
37
|
runner.use(pipes.VerifyMultiSig(1));
|
|
19
38
|
runner.use(pipes.ExtractReceiver({ from: ['tx.signaturesList', 'tx.signatures', 'itx.to'] }));
|
|
20
39
|
|
|
21
40
|
runner.use(
|
|
22
41
|
pipes.VerifyInfo([
|
|
23
|
-
{
|
|
24
|
-
error: 'INSUFFICIENT_DATA',
|
|
25
|
-
message: 'itx.sender, itx.receiver and itx.to can not be empty',
|
|
26
|
-
fn: ({ itx }) => itx.sender && itx.receiver && itx.to,
|
|
27
|
-
},
|
|
28
42
|
{
|
|
29
43
|
error: 'INVALID_TX',
|
|
30
44
|
message: 'Can not exchange without any token or assets',
|
|
@@ -64,16 +78,6 @@ runner.use(
|
|
|
64
78
|
return true;
|
|
65
79
|
},
|
|
66
80
|
},
|
|
67
|
-
{
|
|
68
|
-
error: 'INVALID_TX',
|
|
69
|
-
message: 'Sender token value must be positive',
|
|
70
|
-
fn: (context) => context.senderTokens.every((x) => new BN(x.value).gt(new BN(0))),
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
error: 'INVALID_TX',
|
|
74
|
-
message: 'Receiver token value must be positive',
|
|
75
|
-
fn: (context) => context.receiverTokens.every((x) => new BN(x.value).gt(new BN(0))),
|
|
76
|
-
},
|
|
77
81
|
])
|
|
78
82
|
);
|
|
79
83
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const isEmpty = require('empty-value');
|
|
2
|
+
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
2
3
|
const { getListField } = require('@ocap/util/lib/get-list-field');
|
|
3
4
|
const { decodeBigInt } = require('@ocap/message');
|
|
5
|
+
const { Joi, schemas } = require('@arcblock/validator');
|
|
4
6
|
const { BN } = require('@ocap/util');
|
|
5
7
|
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
6
8
|
const { account } = require('@ocap/state');
|
|
@@ -16,13 +18,27 @@ const runner = new Runner();
|
|
|
16
18
|
|
|
17
19
|
runner.use(pipes.VerifyMultiSig(0));
|
|
18
20
|
|
|
21
|
+
// 1. verify itx
|
|
22
|
+
const schema = Joi.object({
|
|
23
|
+
to: Joi.DID().prefix().role('ROLE_ACCOUNT').required(),
|
|
24
|
+
value: Joi.any().optional(),
|
|
25
|
+
tokensList: Joi.array().items(schemas.tokenInput).default([]),
|
|
26
|
+
assetsList: Joi.array().items(Joi.DID().prefix().role('ROLE_ASSET')).default([]),
|
|
27
|
+
data: Joi.any().optional(),
|
|
28
|
+
}).options({ stripUnknown: true, noDefaults: false });
|
|
29
|
+
runner.use(({ itx }, next) => {
|
|
30
|
+
const { error } = schema.validate(itx);
|
|
31
|
+
if (error) {
|
|
32
|
+
return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
|
|
33
|
+
}
|
|
34
|
+
return next();
|
|
35
|
+
});
|
|
19
36
|
runner.use((context, next) => {
|
|
20
37
|
context.assets = getListField(context, 'itx.assets');
|
|
21
38
|
context.tokens = getListField(context, 'itx.tokens');
|
|
22
39
|
context.tokenAddress = context.tokens.map((x) => x.address);
|
|
23
40
|
next();
|
|
24
41
|
});
|
|
25
|
-
|
|
26
42
|
runner.use(
|
|
27
43
|
pipes.VerifyInfo([
|
|
28
44
|
{
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
/* eslint-disable no-restricted-syntax */
|
|
4
4
|
const { promisify } = require('util');
|
|
5
5
|
const isEqual = require('lodash/isEqual');
|
|
6
|
+
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
7
|
+
const { Joi, schemas } = require('@arcblock/validator');
|
|
6
8
|
const { BN } = require('@ocap/util');
|
|
7
9
|
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
8
10
|
const { account, asset } = require('@ocap/state');
|
|
@@ -19,6 +21,17 @@ const runner = new Runner();
|
|
|
19
21
|
|
|
20
22
|
const verifyAssetOwner = promisify(pipes.VerifyUpdater({ assetKey: 'assets', ownerKey: 'owner' }));
|
|
21
23
|
|
|
24
|
+
// 0. verify itx
|
|
25
|
+
const schema = Joi.object({
|
|
26
|
+
inputsList: schemas.multiInput.min(1).required(),
|
|
27
|
+
outputsList: schemas.multiInput.min(1).required(),
|
|
28
|
+
data: Joi.any().optional(),
|
|
29
|
+
}).options({ stripUnknown: true, noDefaults: false });
|
|
30
|
+
runner.use(({ itx }, next) => {
|
|
31
|
+
const { error } = schema.validate(itx);
|
|
32
|
+
return next(error ? new Error('INVALID_TX', `Invalid itx: ${error.message}`) : null);
|
|
33
|
+
});
|
|
34
|
+
|
|
22
35
|
// 0. extract itx
|
|
23
36
|
runner.use(
|
|
24
37
|
pipes.VerifyTxInput({
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.18.
|
|
6
|
+
"version": "1.18.33",
|
|
7
7
|
"description": "Predefined tx pipeline sets to execute certain type of transactions",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -21,18 +21,18 @@
|
|
|
21
21
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@arcblock/did": "1.18.
|
|
25
|
-
"@arcblock/did-util": "1.18.
|
|
26
|
-
"@arcblock/jwt": "1.18.
|
|
27
|
-
"@arcblock/validator": "1.18.
|
|
28
|
-
"@ocap/asset": "1.18.
|
|
29
|
-
"@ocap/mcrypto": "1.18.
|
|
30
|
-
"@ocap/merkle-tree": "1.18.
|
|
31
|
-
"@ocap/message": "1.18.
|
|
32
|
-
"@ocap/state": "1.18.
|
|
33
|
-
"@ocap/tx-pipeline": "1.18.
|
|
34
|
-
"@ocap/util": "1.18.
|
|
35
|
-
"@ocap/wallet": "1.18.
|
|
24
|
+
"@arcblock/did": "1.18.33",
|
|
25
|
+
"@arcblock/did-util": "1.18.33",
|
|
26
|
+
"@arcblock/jwt": "1.18.33",
|
|
27
|
+
"@arcblock/validator": "1.18.33",
|
|
28
|
+
"@ocap/asset": "1.18.33",
|
|
29
|
+
"@ocap/mcrypto": "1.18.33",
|
|
30
|
+
"@ocap/merkle-tree": "1.18.33",
|
|
31
|
+
"@ocap/message": "1.18.33",
|
|
32
|
+
"@ocap/state": "1.18.33",
|
|
33
|
+
"@ocap/tx-pipeline": "1.18.33",
|
|
34
|
+
"@ocap/util": "1.18.33",
|
|
35
|
+
"@ocap/wallet": "1.18.33",
|
|
36
36
|
"debug": "^4.3.4",
|
|
37
37
|
"deep-diff": "^1.0.2",
|
|
38
38
|
"empty-value": "^1.0.1",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"jest": "^27.5.1",
|
|
48
48
|
"start-server-and-test": "^1.14.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "0d03089c6651d92a3451e9bbbc865c18c2f5d8ad"
|
|
51
51
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
2
|
-
const { getListField } = require('@ocap/util/lib/get-list-field');
|
|
3
|
-
|
|
4
|
-
module.exports =
|
|
5
|
-
(mode) =>
|
|
6
|
-
({ itx }, next) => {
|
|
7
|
-
if (!itx.factory) {
|
|
8
|
-
return next(new Error('INSUFFICIENT_DATA', 'itx.factory must not be empty'));
|
|
9
|
-
}
|
|
10
|
-
if (!itx.address) {
|
|
11
|
-
return next(new Error('INSUFFICIENT_DATA', 'itx.address must not be empty'));
|
|
12
|
-
}
|
|
13
|
-
if (mode === 'acquire-v2') {
|
|
14
|
-
if (!itx.issuer) {
|
|
15
|
-
return next(new Error('INSUFFICIENT_DATA', 'itx.issuer must not be empty'));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (['mint', 'acquire-v3'].includes(mode)) {
|
|
19
|
-
if (!itx.owner) {
|
|
20
|
-
return next(new Error('INSUFFICIENT_DATA', 'itx.owner must not be empty'));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const variables = getListField(itx, 'variables');
|
|
25
|
-
if (!Array.isArray(variables) && !variables.length) {
|
|
26
|
-
return next(new Error('INSUFFICIENT_DATA', 'itx.variables must not be empty'));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return next();
|
|
30
|
-
};
|