@ocap/tx-protocols 1.14.2 → 1.14.6
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/execute.js +2 -2
- package/lib/protocols/account/declare.js +9 -5
- package/lib/protocols/asset/create.js +3 -14
- 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 +18 -15
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
|
|
package/lib/execute.js
CHANGED
|
@@ -62,7 +62,7 @@ module.exports = ({ filter, runAsLambda }) => {
|
|
|
62
62
|
// we should only flush events when retry is not supported
|
|
63
63
|
// otherwise the outer caller should handle these 2
|
|
64
64
|
if (shouldPersistTx(err) && isRetrySupported === false) {
|
|
65
|
-
const txState = context.states.tx.create(context, err ? err.code : 'OK');
|
|
65
|
+
const txState = context.states.tx.create(context, err ? err.code || 'INTERNAL' : 'OK');
|
|
66
66
|
try {
|
|
67
67
|
await context.statedb.tx.create(txState.hash, txState, context);
|
|
68
68
|
} catch (e) {
|
|
@@ -100,7 +100,7 @@ module.exports = ({ filter, runAsLambda }) => {
|
|
|
100
100
|
} finally {
|
|
101
101
|
if (shouldPersistTx(error)) {
|
|
102
102
|
try {
|
|
103
|
-
const txState = context.states.tx.create(ctx, error ? error.code : 'OK');
|
|
103
|
+
const txState = context.states.tx.create(ctx, error ? error.code || 'INTERNAL' : 'OK');
|
|
104
104
|
flushEvents(ctx, { txState });
|
|
105
105
|
await runAsLambda(async (txn) => {
|
|
106
106
|
const newCtx = { ...omit(ctx, ['txn']), txn };
|
|
@@ -38,11 +38,15 @@ runner.use(
|
|
|
38
38
|
const { tx, itx, statedb } = context;
|
|
39
39
|
const tokens = { [context.config.token.address]: '0' };
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
const [senderState] = await Promise.all([
|
|
42
|
+
statedb.account.create(
|
|
43
|
+
tx.from,
|
|
44
|
+
account.create({ address: tx.from, pk: toBase58(tx.pk), nonce: tx.nonce, tokens, ...itx }, context),
|
|
45
|
+
context
|
|
46
|
+
),
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
context.senderState = senderState;
|
|
46
50
|
|
|
47
51
|
next();
|
|
48
52
|
},
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const Error = require('@ocap/util/lib/error');
|
|
3
3
|
const isEmpty = require('lodash/isEmpty');
|
|
4
4
|
const cloneDeep = require('lodash/cloneDeep');
|
|
5
|
-
const Joi = require('@ocap/validator');
|
|
6
5
|
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
7
6
|
const { account, asset } = require('@ocap/state');
|
|
8
7
|
const { toAssetAddress } = require('@arcblock/did-util');
|
|
@@ -11,25 +10,15 @@ const { toAssetAddress } = require('@arcblock/did-util');
|
|
|
11
10
|
const debug = require('debug')(`${require('../../../package.json').name}:create-asset`);
|
|
12
11
|
|
|
13
12
|
const { decodeAnySafe } = require('../../util');
|
|
14
|
-
const
|
|
13
|
+
const ensureServiceFee = require('../rollup/pipes/ensure-service-fee');
|
|
15
14
|
|
|
16
15
|
const runner = new Runner();
|
|
17
16
|
|
|
18
17
|
runner.use(pipes.VerifyMultiSig(0));
|
|
19
18
|
|
|
20
19
|
// Verify itx
|
|
21
|
-
const schema = Joi.object({
|
|
22
|
-
moniker: Joi.string().min(2).max(255).required(),
|
|
23
|
-
data: Joi.any().required(),
|
|
24
|
-
readonly: Joi.boolean().default(false),
|
|
25
|
-
transferrable: Joi.boolean().default(false),
|
|
26
|
-
ttl: Joi.number().min(0).default(0),
|
|
27
|
-
parent: Joi.DID().optional().allow(''),
|
|
28
|
-
address: Joi.DID().role('ROLE_ASSET').required(),
|
|
29
|
-
issuer: Joi.DID().optional().allow(''),
|
|
30
|
-
}).options({ stripUnknown: true, noDefaults: false });
|
|
31
20
|
runner.use(({ itx }, next) => {
|
|
32
|
-
const { error } = schema.validate(itx);
|
|
21
|
+
const { error } = asset.schema.validate(itx);
|
|
33
22
|
if (error) {
|
|
34
23
|
return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
|
|
35
24
|
}
|
|
@@ -92,7 +81,7 @@ runner.use(
|
|
|
92
81
|
// Ensure parent exist
|
|
93
82
|
runner.use(pipes.ExtractState({ from: 'itx.parent', to: 'parentAsset', status: 'INVALID_ASSET', table: 'asset' }));
|
|
94
83
|
|
|
95
|
-
runner.use(
|
|
84
|
+
runner.use(ensureServiceFee);
|
|
96
85
|
|
|
97
86
|
// Update asset state
|
|
98
87
|
runner.use(
|
|
@@ -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.6",
|
|
7
7
|
"description": "Predefined tx pipeline sets to execute certain type of transactions",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -12,24 +12,26 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"lint": "eslint tests lib",
|
|
14
14
|
"lint:fix": "eslint --fix tests lib",
|
|
15
|
+
"start": "node tools/start-chain.js",
|
|
15
16
|
"test": "jest --forceExit --detectOpenHandles",
|
|
16
|
-
"
|
|
17
|
+
"test:ci": "jest --forceExit --detectOpenHandles --coverage",
|
|
18
|
+
"coverage": "start-server-and-test start http://127.0.0.1:4001 test:ci"
|
|
17
19
|
},
|
|
18
20
|
"keywords": [],
|
|
19
21
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
22
|
"license": "MIT",
|
|
21
23
|
"dependencies": {
|
|
22
|
-
"@arcblock/did": "1.14.
|
|
23
|
-
"@arcblock/did-util": "1.14.
|
|
24
|
-
"@ocap/asset": "1.14.
|
|
25
|
-
"@ocap/mcrypto": "1.14.
|
|
26
|
-
"@ocap/merkle-tree": "1.14.
|
|
27
|
-
"@ocap/message": "1.14.
|
|
28
|
-
"@ocap/state": "1.14.
|
|
29
|
-
"@ocap/tx-pipeline": "1.14.
|
|
30
|
-
"@ocap/util": "1.14.
|
|
31
|
-
"@ocap/validator": "1.14.
|
|
32
|
-
"@ocap/wallet": "1.14.
|
|
24
|
+
"@arcblock/did": "1.14.6",
|
|
25
|
+
"@arcblock/did-util": "1.14.6",
|
|
26
|
+
"@ocap/asset": "1.14.6",
|
|
27
|
+
"@ocap/mcrypto": "1.14.6",
|
|
28
|
+
"@ocap/merkle-tree": "1.14.6",
|
|
29
|
+
"@ocap/message": "1.14.6",
|
|
30
|
+
"@ocap/state": "1.14.6",
|
|
31
|
+
"@ocap/tx-pipeline": "1.14.6",
|
|
32
|
+
"@ocap/util": "1.14.6",
|
|
33
|
+
"@ocap/validator": "1.14.6",
|
|
34
|
+
"@ocap/wallet": "1.14.6",
|
|
33
35
|
"debug": "^4.3.2",
|
|
34
36
|
"empty-value": "^1.0.1",
|
|
35
37
|
"lodash": "^4.17.21",
|
|
@@ -40,7 +42,8 @@
|
|
|
40
42
|
"elliptic": "6.5.3"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"jest": "^27.3.1"
|
|
45
|
+
"jest": "^27.3.1",
|
|
46
|
+
"start-server-and-test": "^1.14.0"
|
|
44
47
|
},
|
|
45
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "dd379a7d1bd2a46be27a29e6f0c65fa161ec0b0c"
|
|
46
49
|
}
|