@ocap/tx-protocols 1.14.5 → 1.14.9
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/README.md +1 -0
- package/lib/protocols/asset/acquire-v2.js +13 -0
- package/lib/protocols/asset/acquire-v3.js +13 -0
- package/lib/protocols/asset/create.js +2 -2
- package/lib/protocols/asset/mint.js +13 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.js +8 -2
- package/lib/protocols/asset/update.js +31 -6
- package/lib/protocols/factory/create.js +2 -2
- package/lib/protocols/rollup/create.js +4 -3
- package/lib/protocols/rollup/pipes/{ensure-tx-fee.js → ensure-service-fee.js} +0 -1
- package/lib/protocols/token/create.js +3 -2
- package/package.json +14 -13
package/README.md
CHANGED
|
@@ -72,6 +72,7 @@ But this will make some transaction protocol logic harder to understand.
|
|
|
72
72
|
The are some inconsistencies in server and client implementation code.
|
|
73
73
|
|
|
74
74
|
On the server side, `delegator` must be interpreted as `delegatee`, but in `@ocap/client`, `delegator` is interpreted as `delegator`.
|
|
75
|
+
For delegated create-x transactions, the service-fee is charged against `tx.from`.
|
|
75
76
|
|
|
76
77
|
### How to add a new tx protocol
|
|
77
78
|
|
|
@@ -24,6 +24,19 @@ const runner = new Runner();
|
|
|
24
24
|
runner.use(pipes.VerifyMultiSig(0));
|
|
25
25
|
runner.use(verifyAcquireParams('acquire-v2'));
|
|
26
26
|
|
|
27
|
+
// ensure asset not exist
|
|
28
|
+
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'duplicateAsset', status: 'OK', table: 'asset' }));
|
|
29
|
+
runner.use(
|
|
30
|
+
pipes.VerifyInfo([
|
|
31
|
+
{
|
|
32
|
+
error: 'FORBIDDEN',
|
|
33
|
+
message: 'Asset with same address already exists',
|
|
34
|
+
fn: ({ duplicateAsset }) => !duplicateAsset,
|
|
35
|
+
persist: true,
|
|
36
|
+
},
|
|
37
|
+
])
|
|
38
|
+
);
|
|
39
|
+
|
|
27
40
|
runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })); // prettier-ignore
|
|
28
41
|
runner.use(pipes.VerifyAccountMigration({ senderKey: 'senderState' }));
|
|
29
42
|
|
|
@@ -27,6 +27,19 @@ const runner = new Runner();
|
|
|
27
27
|
|
|
28
28
|
// 1. extract & verify itx input
|
|
29
29
|
runner.use(verifyAcquireParams('acquire-v3'));
|
|
30
|
+
|
|
31
|
+
// ensure asset not exist
|
|
32
|
+
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'duplicateAsset', status: 'OK', table: 'asset' }));
|
|
33
|
+
runner.use(
|
|
34
|
+
pipes.VerifyInfo([
|
|
35
|
+
{
|
|
36
|
+
error: 'FORBIDDEN',
|
|
37
|
+
message: 'Asset with same address already exists',
|
|
38
|
+
fn: ({ duplicateAsset }) => !duplicateAsset,
|
|
39
|
+
persist: true,
|
|
40
|
+
},
|
|
41
|
+
])
|
|
42
|
+
);
|
|
30
43
|
runner.use(
|
|
31
44
|
pipes.VerifyTxInput({
|
|
32
45
|
fieldKey: 'itx.inputs',
|
|
@@ -10,7 +10,7 @@ const { toAssetAddress } = require('@arcblock/did-util');
|
|
|
10
10
|
const debug = require('debug')(`${require('../../../package.json').name}:create-asset`);
|
|
11
11
|
|
|
12
12
|
const { decodeAnySafe } = require('../../util');
|
|
13
|
-
const
|
|
13
|
+
const ensureServiceFee = require('../rollup/pipes/ensure-service-fee');
|
|
14
14
|
|
|
15
15
|
const runner = new Runner();
|
|
16
16
|
|
|
@@ -81,7 +81,7 @@ runner.use(
|
|
|
81
81
|
// Ensure parent exist
|
|
82
82
|
runner.use(pipes.ExtractState({ from: 'itx.parent', to: 'parentAsset', status: 'INVALID_ASSET', table: 'asset' }));
|
|
83
83
|
|
|
84
|
-
runner.use(
|
|
84
|
+
runner.use(ensureServiceFee);
|
|
85
85
|
|
|
86
86
|
// Update asset state
|
|
87
87
|
runner.use(
|
|
@@ -16,6 +16,19 @@ const runner = new Runner();
|
|
|
16
16
|
runner.use(pipes.VerifyMultiSig(0));
|
|
17
17
|
runner.use(verifyAcquireParams('mint'));
|
|
18
18
|
|
|
19
|
+
// ensure asset not exist
|
|
20
|
+
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'duplicateAsset', status: 'OK', table: 'asset' }));
|
|
21
|
+
runner.use(
|
|
22
|
+
pipes.VerifyInfo([
|
|
23
|
+
{
|
|
24
|
+
error: 'FORBIDDEN',
|
|
25
|
+
message: 'Asset with same address already exists',
|
|
26
|
+
fn: ({ duplicateAsset }) => !duplicateAsset,
|
|
27
|
+
persist: true,
|
|
28
|
+
},
|
|
29
|
+
])
|
|
30
|
+
);
|
|
31
|
+
|
|
19
32
|
// Ensure sender exist
|
|
20
33
|
runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })); // prettier-ignore
|
|
21
34
|
runner.use(pipes.VerifyAccountMigration({ senderKey: 'senderState' }));
|
|
@@ -10,8 +10,14 @@ module.exports = (context, next) => {
|
|
|
10
10
|
acc[x.name] = x.value;
|
|
11
11
|
return acc;
|
|
12
12
|
}, {});
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const missingVariables = variables.filter((x) => x.required && !factoryInputs[x.name]);
|
|
14
|
+
if (missingVariables.length) {
|
|
15
|
+
return next(
|
|
16
|
+
new Error(
|
|
17
|
+
'INVALID_FACTORY_INPUT',
|
|
18
|
+
`Invalid itx.variables: missing required input variable: ${missingVariables.map((x) => x.name).join(', ')}`
|
|
19
|
+
)
|
|
20
|
+
);
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
context.factoryInputs = factoryInputs;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const deepDiff = require('deep-diff');
|
|
1
2
|
const Error = require('@ocap/util/lib/error');
|
|
2
3
|
const Joi = require('@ocap/validator');
|
|
3
4
|
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
@@ -18,19 +19,23 @@ const schema = Joi.object({
|
|
|
18
19
|
moniker: Joi.string().min(2).max(255).required(),
|
|
19
20
|
data: Joi.any().optional(),
|
|
20
21
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
21
|
-
runner.use((
|
|
22
|
+
runner.use((context, next) => {
|
|
23
|
+
const { itx } = context;
|
|
22
24
|
const { error } = schema.validate(itx);
|
|
23
25
|
if (error) {
|
|
24
26
|
return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
|
|
25
27
|
}
|
|
28
|
+
|
|
29
|
+
context.newData = decodeAnySafe(itx.data);
|
|
26
30
|
return next();
|
|
27
31
|
});
|
|
28
32
|
|
|
29
|
-
// Ensure asset exist
|
|
30
|
-
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'assetState', status: 'INVALID_ASSET' }));
|
|
33
|
+
// Ensure asset exist
|
|
34
|
+
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'assetState', status: 'INVALID_ASSET', table: 'asset' }));
|
|
35
|
+
runner.use(pipes.ExtractState({ from: 'assetState.issuer', to: 'issuerState', status: 'OK', table: 'account' }));
|
|
31
36
|
|
|
32
37
|
// Ensure sender exist
|
|
33
|
-
runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE' }));
|
|
38
|
+
runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })); // prettier-ignore
|
|
34
39
|
runner.use(pipes.VerifyAccountMigration({ senderKey: 'senderState' }));
|
|
35
40
|
|
|
36
41
|
// Ensure asset owned by sender and can be modified
|
|
@@ -46,10 +51,30 @@ runner.use(
|
|
|
46
51
|
])
|
|
47
52
|
);
|
|
48
53
|
|
|
54
|
+
// Ensure we are in append-only mode update proposed by issuer
|
|
55
|
+
runner.use(async (context, next) => {
|
|
56
|
+
const { itx, newData, senderState, assetState, issuerState } = context;
|
|
57
|
+
if (issuerState && senderState.address === issuerState.address) {
|
|
58
|
+
if (itx.moniker !== assetState.moniker) {
|
|
59
|
+
return next(new Error('FORBIDDEN', 'Asset moniker can only be updated by owner'));
|
|
60
|
+
}
|
|
61
|
+
if (newData.type !== assetState.data.type) {
|
|
62
|
+
return next(new Error('FORBIDDEN', 'Asset data type can only be updated by owner'));
|
|
63
|
+
}
|
|
64
|
+
const dataDiff = deepDiff(assetState.data.value, newData.value);
|
|
65
|
+
const appendOnly = dataDiff.every((x) => x.kind === 'N' || (x.kind === 'A' && x.item.kind === 'N'));
|
|
66
|
+
if (appendOnly === false) {
|
|
67
|
+
return next(new Error('APPEND_ONLY', 'Asset data value can only be updated in append only mode'));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return next();
|
|
72
|
+
});
|
|
73
|
+
|
|
49
74
|
// Update asset state
|
|
50
75
|
runner.use(
|
|
51
76
|
async (context, next) => {
|
|
52
|
-
const { tx, itx, statedb, senderState, assetState } = context;
|
|
77
|
+
const { tx, itx, newData, statedb, senderState, assetState } = context;
|
|
53
78
|
|
|
54
79
|
const [newSenderState, newAssetState] = await Promise.all([
|
|
55
80
|
// update owner state
|
|
@@ -62,7 +87,7 @@ runner.use(
|
|
|
62
87
|
// update asset state
|
|
63
88
|
statedb.asset.update(
|
|
64
89
|
itx.address,
|
|
65
|
-
asset.update(assetState, { moniker: itx.moniker, data:
|
|
90
|
+
asset.update(assetState, { moniker: itx.moniker, data: newData }, context),
|
|
66
91
|
context
|
|
67
92
|
),
|
|
68
93
|
]);
|
|
@@ -14,7 +14,7 @@ const { toFactoryAddress } = require('@arcblock/did-util');
|
|
|
14
14
|
const debug = require('debug')(`${require('../../../package.json').name}:create-factory`);
|
|
15
15
|
|
|
16
16
|
const { decodeAnySafe } = require('../../util');
|
|
17
|
-
const
|
|
17
|
+
const ensureServiceFee = require('../rollup/pipes/ensure-service-fee');
|
|
18
18
|
|
|
19
19
|
const runner = new Runner();
|
|
20
20
|
|
|
@@ -106,7 +106,7 @@ runner.use((context, next) => {
|
|
|
106
106
|
return next(new Error('INVALID_FACTORY_INPUT', 'Not all input.assets exist on chain'));
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
-
runner.use(
|
|
109
|
+
runner.use(ensureServiceFee);
|
|
110
110
|
|
|
111
111
|
// Create factory state
|
|
112
112
|
runner.use(
|
|
@@ -12,7 +12,7 @@ const { toRollupAddress } = require('@arcblock/did-util');
|
|
|
12
12
|
const debug = require('debug')(`${require('../../../package.json').name}:create-rollup`);
|
|
13
13
|
|
|
14
14
|
const { decodeAnySafe } = require('../../util');
|
|
15
|
-
const
|
|
15
|
+
const ensureServiceFee = require('./pipes/ensure-service-fee');
|
|
16
16
|
|
|
17
17
|
const runner = new Runner();
|
|
18
18
|
|
|
@@ -108,7 +108,7 @@ runner.use(
|
|
|
108
108
|
])
|
|
109
109
|
);
|
|
110
110
|
|
|
111
|
-
runner.use(
|
|
111
|
+
runner.use(ensureServiceFee);
|
|
112
112
|
|
|
113
113
|
// 5. create rollup state
|
|
114
114
|
runner.use(
|
|
@@ -125,6 +125,7 @@ runner.use(
|
|
|
125
125
|
vaultUpdates,
|
|
126
126
|
} = context;
|
|
127
127
|
|
|
128
|
+
const issuer = delegatorState ? delegatorState.address : senderState.address;
|
|
128
129
|
const [newSenderState, rollupState, newVaultState] = await Promise.all([
|
|
129
130
|
statedb.account.update(
|
|
130
131
|
senderState.address,
|
|
@@ -137,7 +138,7 @@ runner.use(
|
|
|
137
138
|
rollup.create(
|
|
138
139
|
{
|
|
139
140
|
...formattedItx,
|
|
140
|
-
issuer
|
|
141
|
+
issuer,
|
|
141
142
|
validators: formattedItx.seedValidators,
|
|
142
143
|
data: rollupData,
|
|
143
144
|
},
|
|
@@ -3,7 +3,6 @@ const { fromTokenToUnit, BN } = require('@ocap/util');
|
|
|
3
3
|
|
|
4
4
|
const { applyTokenUpdates } = require('../../../util');
|
|
5
5
|
|
|
6
|
-
// FIXME: There maybe bug for tx that decrease senderState token balance
|
|
7
6
|
module.exports = async (context, next) => {
|
|
8
7
|
const { config, statedb, txType, senderState } = context;
|
|
9
8
|
const txFee = config.transaction.txFee[txType];
|
|
@@ -10,7 +10,7 @@ const { fromTokenToUnit } = require('@ocap/util');
|
|
|
10
10
|
// eslint-disable-next-line global-require
|
|
11
11
|
const debug = require('debug')(`${require('../../../package.json').name}:create-token`);
|
|
12
12
|
const { decodeAnySafe } = require('../../util');
|
|
13
|
-
const
|
|
13
|
+
const ensureServiceFee = require('../rollup/pipes/ensure-service-fee');
|
|
14
14
|
|
|
15
15
|
const MAX_TOTAL_SUPPLY = fromTokenToUnit(10000 * 100000000, 18); // 32
|
|
16
16
|
|
|
@@ -92,7 +92,7 @@ runner.use(async (context, next) => {
|
|
|
92
92
|
return next();
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
runner.use(
|
|
95
|
+
runner.use(ensureServiceFee);
|
|
96
96
|
|
|
97
97
|
// Update sender state, token state
|
|
98
98
|
runner.use(
|
|
@@ -105,6 +105,7 @@ runner.use(
|
|
|
105
105
|
senderUpdates.tokens = senderUpdates.tokens || {};
|
|
106
106
|
|
|
107
107
|
// We are definitely creating a different token, so it is safe to set tokens to initial supply
|
|
108
|
+
// For delegated create-token, the delegator is the actual token-holder
|
|
108
109
|
if (delegatorState) {
|
|
109
110
|
delegatorUpdates.tokens = delegatorState.tokens || {};
|
|
110
111
|
delegatorUpdates.tokens[itx.address] = itx.initialSupply;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.14.
|
|
6
|
+
"version": "1.14.9",
|
|
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,19 @@
|
|
|
21
21
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@arcblock/did": "1.14.
|
|
25
|
-
"@arcblock/did-util": "1.14.
|
|
26
|
-
"@ocap/asset": "1.14.
|
|
27
|
-
"@ocap/mcrypto": "1.14.
|
|
28
|
-
"@ocap/merkle-tree": "1.14.
|
|
29
|
-
"@ocap/message": "1.14.
|
|
30
|
-
"@ocap/state": "1.14.
|
|
31
|
-
"@ocap/tx-pipeline": "1.14.
|
|
32
|
-
"@ocap/util": "1.14.
|
|
33
|
-
"@ocap/validator": "1.14.
|
|
34
|
-
"@ocap/wallet": "1.14.
|
|
24
|
+
"@arcblock/did": "1.14.9",
|
|
25
|
+
"@arcblock/did-util": "1.14.9",
|
|
26
|
+
"@ocap/asset": "1.14.9",
|
|
27
|
+
"@ocap/mcrypto": "1.14.9",
|
|
28
|
+
"@ocap/merkle-tree": "1.14.9",
|
|
29
|
+
"@ocap/message": "1.14.9",
|
|
30
|
+
"@ocap/state": "1.14.9",
|
|
31
|
+
"@ocap/tx-pipeline": "1.14.9",
|
|
32
|
+
"@ocap/util": "1.14.9",
|
|
33
|
+
"@ocap/validator": "1.14.9",
|
|
34
|
+
"@ocap/wallet": "1.14.9",
|
|
35
35
|
"debug": "^4.3.2",
|
|
36
|
+
"deep-diff": "^1.0.2",
|
|
36
37
|
"empty-value": "^1.0.1",
|
|
37
38
|
"lodash": "^4.17.21",
|
|
38
39
|
"url-join": "^4.0.1"
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"jest": "^27.3.1",
|
|
46
47
|
"start-server-and-test": "^1.14.0"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "19fd75486457b972da40d7d1d043f389738aa1da"
|
|
49
50
|
}
|