@ocap/tx-protocols 1.19.15 → 1.19.17
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/LICENSE +1 -1
- package/lib/execute.js +67 -41
- package/lib/pipes/ensure-cost.js +18 -7
- package/lib/pipes/ensure-gas.js +2 -2
- package/lib/protocols/account/delegate.js +20 -13
- package/lib/protocols/account/migrate.js +1 -1
- package/lib/protocols/account/revoke-delegate.js +1 -1
- package/lib/protocols/asset/acquire-v2.js +2 -2
- package/lib/protocols/asset/acquire-v3.js +2 -2
- package/lib/protocols/asset/consume.js +1 -1
- package/lib/protocols/asset/mint.js +2 -2
- package/lib/protocols/asset/pipes/exec-mint-hook.js +1 -0
- package/lib/protocols/asset/update.js +3 -3
- package/lib/protocols/governance/claim-stake.js +1 -1
- package/lib/protocols/governance/return-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 +2 -2
- package/lib/protocols/rollup/claim-reward.js +1 -1
- package/lib/protocols/rollup/close.js +1 -1
- 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.js +1 -1
- 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 +3 -3
- package/lib/protocols/token/deposit-v2.js +1 -1
- package/lib/protocols/token/withdraw-v2.js +2 -2
- package/lib/protocols/trade/exchange-v2.js +2 -2
- package/lib/protocols/trade/transfer-v2.js +36 -25
- package/lib/protocols/trade/transfer-v3.js +1 -1
- package/package.json +14 -14
package/LICENSE
CHANGED
package/lib/execute.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
const { promisify } = require('util');
|
|
3
3
|
const get = require('lodash/get');
|
|
4
4
|
const pick = require('lodash/pick');
|
|
5
|
-
const omit = require('lodash/omit');
|
|
6
5
|
const camelCase = require('lodash/camelCase');
|
|
7
6
|
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
8
7
|
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
@@ -132,49 +131,76 @@ module.exports = ({ filter, runAsLambda }) => {
|
|
|
132
131
|
return async (context, protocols) => {
|
|
133
132
|
let ctx = null;
|
|
134
133
|
let error = null;
|
|
134
|
+
let runCount = 0;
|
|
135
|
+
const retryLimit = context.statedb?.config?.retryLimit || 0;
|
|
136
|
+
const shouldRetry = context.statedb?.config?.shouldRetry || (() => false);
|
|
137
|
+
const startTime = Date.now();
|
|
138
|
+
|
|
139
|
+
await runAsLambda(async (txn) => {
|
|
140
|
+
runCount += 1;
|
|
141
|
+
|
|
142
|
+
// create a new context each time in case we are retrying
|
|
143
|
+
ctx = pick(context, ['txBase64', 'statedb', 'indexdb', 'config', 'states', 'filter', 'extra', 'logger']);
|
|
144
|
+
Object.defineProperty(ctx, 'txn', { value: txn });
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
await execute(ctx, protocols, true);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
if (runCount <= retryLimit && shouldRetry(err)) {
|
|
150
|
+
// throw the error to retry
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
error = err;
|
|
154
|
+
}
|
|
135
155
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (error) {
|
|
153
|
-
await ensureGasFeePaid(ctx);
|
|
154
|
-
// Recreate tx to pick up gas related fields
|
|
155
|
-
txState = context.states.tx.create(ctx, error ? error.code || 'INTERNAL' : 'OK');
|
|
156
|
-
}
|
|
157
|
-
await context.statedb.tx.create(txState.hash, txState, ctx);
|
|
158
|
-
});
|
|
159
|
-
flushEvents(ctx, { txState });
|
|
160
|
-
ctx?.logger?.info('Tx finalized', {
|
|
161
|
-
txHash: ctx.txHash,
|
|
162
|
-
txStatus: error ? error.code || 'INTERNAL' : 'OK',
|
|
163
|
-
txState,
|
|
164
|
-
error,
|
|
165
|
-
});
|
|
166
|
-
} catch (err) {
|
|
167
|
-
const txState = context.states.tx.create(ctx, error ? error.code || 'INTERNAL' : 'OK', false);
|
|
168
|
-
ctx?.logger?.error('Failed to save invalid transaction to statedb', {
|
|
169
|
-
error: err,
|
|
170
|
-
txHash: ctx.txHash,
|
|
171
|
-
txState,
|
|
172
|
-
});
|
|
156
|
+
if (error && !shouldPersistTx(error)) {
|
|
157
|
+
ctx.logger?.error('Failed to execute transaction', { error, txHash: ctx.txHash });
|
|
158
|
+
// throw the error to the abort transaction
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// create tx
|
|
163
|
+
const txStatus = error ? error.code || 'INTERNAL' : 'OK';
|
|
164
|
+
try {
|
|
165
|
+
let txState = context.states.tx.create(ctx, txStatus);
|
|
166
|
+
flushEvents(ctx, { txState });
|
|
167
|
+
|
|
168
|
+
if (error) {
|
|
169
|
+
await ensureGasFeePaid(ctx);
|
|
170
|
+
// Recreate tx to pick up gas related fields
|
|
171
|
+
txState = context.states.tx.create(ctx, txStatus);
|
|
173
172
|
}
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
|
|
174
|
+
await context.statedb.tx.create(txState.hash, txState, ctx);
|
|
175
|
+
flushEvents(ctx, { txState });
|
|
176
|
+
|
|
177
|
+
ctx.logger?.info('Tx finalized', {
|
|
178
|
+
txHash: ctx.txHash,
|
|
179
|
+
txStatus,
|
|
180
|
+
txState,
|
|
181
|
+
error,
|
|
182
|
+
runCount,
|
|
183
|
+
duration: Date.now() - startTime,
|
|
184
|
+
});
|
|
185
|
+
} catch (err) {
|
|
186
|
+
if (runCount <= retryLimit && shouldRetry(err)) {
|
|
187
|
+
// throw error to retry
|
|
188
|
+
throw err;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const txState = context.states.tx.create(ctx, txStatus, false);
|
|
192
|
+
ctx.logger?.error('Failed to save invalid transaction to statedb', {
|
|
193
|
+
error: err,
|
|
194
|
+
protocolError: error,
|
|
195
|
+
txHash: ctx.txHash,
|
|
196
|
+
txState,
|
|
197
|
+
duration: Date.now() - startTime,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// throw error to abort transaction
|
|
201
|
+
throw err;
|
|
176
202
|
}
|
|
177
|
-
}
|
|
203
|
+
});
|
|
178
204
|
|
|
179
205
|
if (error) {
|
|
180
206
|
throw error;
|
package/lib/pipes/ensure-cost.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const noop = require('lodash/noop');
|
|
2
2
|
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
3
|
-
const { fromTokenToUnit, BN, fromUnitToToken } = require('@ocap/util');
|
|
3
|
+
const { fromTokenToUnit, BN, fromUnitToToken, hexToNumber } = require('@ocap/util');
|
|
4
4
|
const JWT = require('@arcblock/jwt');
|
|
5
5
|
const { account } = require('@ocap/state');
|
|
6
6
|
const { toAddress } = require('@arcblock/did');
|
|
@@ -71,6 +71,17 @@ module.exports = function CreateEnsureTxCostPipe({
|
|
|
71
71
|
context.gasVaultChange = changes.gas;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
// pick fee vault
|
|
75
|
+
if (changes.fee) {
|
|
76
|
+
if (config.vaults.txFees?.length) {
|
|
77
|
+
const feeIndex = hexToNumber(txHash.slice(-8)) % config.vaults.txFees.length;
|
|
78
|
+
const feeVault = config.vaults.txFees[feeIndex];
|
|
79
|
+
context.feeVault = feeVault;
|
|
80
|
+
} else {
|
|
81
|
+
context.feeVault = config.vaults.txFee;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
74
85
|
let isCostCharged = false;
|
|
75
86
|
if (senderState && txCost.gt(ZERO)) {
|
|
76
87
|
const expected = new BN(gasEstimate.payment || 0).add(txCost);
|
|
@@ -96,8 +107,8 @@ module.exports = function CreateEnsureTxCostPipe({
|
|
|
96
107
|
// to be called in later pipes
|
|
97
108
|
context.updateVaults = async function updateVaults() {
|
|
98
109
|
const [feeVaultState, gasVaultState] = await Promise.all([
|
|
99
|
-
statedb.account.get(
|
|
100
|
-
statedb.account.get(gasVault, context),
|
|
110
|
+
changes.fee ? statedb.account.get(context.feeVault, context) : null,
|
|
111
|
+
changes.gas ? statedb.account.get(gasVault, context) : null,
|
|
101
112
|
]);
|
|
102
113
|
|
|
103
114
|
const [newFeeVaultState, newGasVaultState] = await Promise.all([
|
|
@@ -107,18 +118,18 @@ module.exports = function CreateEnsureTxCostPipe({
|
|
|
107
118
|
account.update(feeVaultState, applyTokenUpdates([changes.fee], feeVaultState, 'add'), context),
|
|
108
119
|
context
|
|
109
120
|
)
|
|
110
|
-
:
|
|
121
|
+
: null,
|
|
111
122
|
changes.gas
|
|
112
123
|
? statedb.account.update(
|
|
113
124
|
gasVaultState.address,
|
|
114
125
|
account.update(gasVaultState, applyTokenUpdates([changes.gas], gasVaultState, 'add'), context),
|
|
115
126
|
context
|
|
116
127
|
)
|
|
117
|
-
:
|
|
128
|
+
: null,
|
|
118
129
|
]);
|
|
119
130
|
|
|
120
|
-
context.feeVaultState = newFeeVaultState;
|
|
121
|
-
context.gasVaultState = newGasVaultState;
|
|
131
|
+
if (newFeeVaultState) context.feeVaultState = newFeeVaultState;
|
|
132
|
+
if (newGasVaultState) context.gasVaultState = newGasVaultState;
|
|
122
133
|
|
|
123
134
|
context.updatedAccounts = context.updatedAccounts || [];
|
|
124
135
|
if (changes.fee) {
|
package/lib/pipes/ensure-gas.js
CHANGED
|
@@ -27,8 +27,8 @@ module.exports = function CreateGasEnsureFn(estimateTxGas) {
|
|
|
27
27
|
|
|
28
28
|
// gas receiver address
|
|
29
29
|
const { txGas: gasVaults } = config.vaults;
|
|
30
|
-
const
|
|
31
|
-
const gasVault = gasVaults[
|
|
30
|
+
const gasIndex = hexToNumber(txHash.slice(-8)) % gasVaults.length;
|
|
31
|
+
const gasVault = gasVaults[gasIndex];
|
|
32
32
|
context.gasVault = gasVault;
|
|
33
33
|
|
|
34
34
|
debug({
|
|
@@ -21,25 +21,31 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
21
21
|
|
|
22
22
|
const rateLimit = Joi.object({
|
|
23
23
|
interval: Joi.number().integer().greater(0).required(),
|
|
24
|
-
anchor: Joi.number().integer().min(0).optional().default(0),
|
|
24
|
+
anchor: Joi.number().integer().min(0).optional().allow(null).default(0),
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
const tokenLimit = Joi.object({
|
|
28
28
|
address: Joi.DID().prefix().role('ROLE_TOKEN').required(),
|
|
29
|
-
toList: Joi.array().items(Joi.DID().prefix()).max(32).unique().optional().default([]),
|
|
30
|
-
txCount: Joi.number().integer().min(0).empty('').optional().default(0),
|
|
31
|
-
txAllowance: Joi.BN().optional().default('0'),
|
|
32
|
-
totalAllowance: Joi.BN().optional().default('0'),
|
|
33
|
-
validUntil: Joi.number().integer().min(0).empty('').optional().default(0),
|
|
34
|
-
rate: rateLimit.optional(),
|
|
29
|
+
toList: Joi.array().items(Joi.DID().prefix()).max(32).unique().optional().allow(null).default([]),
|
|
30
|
+
txCount: Joi.number().integer().min(0).empty('').optional().allow(null).default(0),
|
|
31
|
+
txAllowance: Joi.BN().optional().allow(null).default('0'),
|
|
32
|
+
totalAllowance: Joi.BN().optional().allow(null).default('0'),
|
|
33
|
+
validUntil: Joi.number().integer().min(0).empty('').optional().allow(null).default(0),
|
|
34
|
+
rate: rateLimit.optional().allow(null),
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
const assetLimit = Joi.object({
|
|
38
|
-
address: Joi.array()
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
address: Joi.array()
|
|
39
|
+
.items(Joi.DID().prefix().role('ROLE_ASSET'))
|
|
40
|
+
.unique()
|
|
41
|
+
.max(1024)
|
|
42
|
+
.optional()
|
|
43
|
+
.allow(null)
|
|
44
|
+
.default([]),
|
|
45
|
+
toList: Joi.array().items(Joi.DID().prefix()).unique().max(32).optional().allow(null).default([]),
|
|
46
|
+
txCount: Joi.number().integer().min(0).empty('').optional().allow(null).default(0),
|
|
47
|
+
validUntil: Joi.number().integer().min(0).empty('').optional().allow(null).default(0),
|
|
48
|
+
rate: rateLimit.optional().allow(null),
|
|
43
49
|
});
|
|
44
50
|
|
|
45
51
|
// verify itx
|
|
@@ -58,13 +64,14 @@ const schema = Joi.object({
|
|
|
58
64
|
assetsList: Joi.array().items(assetLimit).max(32),
|
|
59
65
|
})
|
|
60
66
|
.optional()
|
|
67
|
+
.allow(null)
|
|
61
68
|
.default({ tokensList: [], assetsList: [] }),
|
|
62
69
|
})
|
|
63
70
|
)
|
|
64
71
|
.unique((a, b) => a.typeUrl === b.typeUrl)
|
|
65
72
|
.min(1)
|
|
66
73
|
.required(),
|
|
67
|
-
data: Joi.any().optional(),
|
|
74
|
+
data: Joi.any().optional().allow(null),
|
|
68
75
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
69
76
|
runner.use((context, next) => {
|
|
70
77
|
const { error, value } = schema.validate(context.itx);
|
|
@@ -24,7 +24,7 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
24
24
|
const schema = Joi.object({
|
|
25
25
|
address: Joi.DID().prefix().required(),
|
|
26
26
|
pk: Joi.any().required(),
|
|
27
|
-
data: Joi.any().optional(),
|
|
27
|
+
data: Joi.any().optional().allow(null),
|
|
28
28
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
29
29
|
runner.use(({ itx }, next) => {
|
|
30
30
|
const { error } = schema.validate(itx);
|
|
@@ -22,7 +22,7 @@ const schema = Joi.object({
|
|
|
22
22
|
address: Joi.DID().prefix().role('ROLE_DELEGATION').required(),
|
|
23
23
|
to: Joi.DID().prefix().required(),
|
|
24
24
|
typeUrlsList: Joi.array().items(Joi.string().required()).min(1).required(),
|
|
25
|
-
data: Joi.any().optional(),
|
|
25
|
+
data: Joi.any().optional().allow(null),
|
|
26
26
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
27
27
|
runner.use(({ itx }, next) => {
|
|
28
28
|
const { error } = schema.validate(itx);
|
|
@@ -32,9 +32,9 @@ const schema = Joi.object({
|
|
|
32
32
|
factory: Joi.DID().prefix().role('ROLE_FACTORY').required(),
|
|
33
33
|
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
34
34
|
assetsList: Joi.array().items(Joi.DID().prefix().role('ROLE_ASSET')).default([]),
|
|
35
|
-
variablesList: Joi.array().items(schemas.variableInput).optional().default([]),
|
|
35
|
+
variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
|
|
36
36
|
issuer: schemas.nftIssuer.required(),
|
|
37
|
-
data: Joi.any().optional(),
|
|
37
|
+
data: Joi.any().optional().allow(null),
|
|
38
38
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
39
39
|
runner.use(({ itx }, next) => {
|
|
40
40
|
const { error } = schema.validate(itx);
|
|
@@ -35,9 +35,9 @@ const schema = Joi.object({
|
|
|
35
35
|
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
36
36
|
inputsList: schemas.multiInput.min(1).required(),
|
|
37
37
|
owner: schemas.tokenHolder.required(),
|
|
38
|
-
variablesList: Joi.array().items(schemas.variableInput).optional().default([]),
|
|
38
|
+
variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
|
|
39
39
|
issuer: schemas.nftIssuer.required(),
|
|
40
|
-
data: Joi.any().optional(),
|
|
40
|
+
data: Joi.any().optional().allow(null),
|
|
41
41
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
42
42
|
runner.use(({ itx }, next) => {
|
|
43
43
|
const { error } = schema.validate(itx);
|
|
@@ -14,7 +14,7 @@ const runner = new Runner();
|
|
|
14
14
|
// Verify itx
|
|
15
15
|
const schema = Joi.object({
|
|
16
16
|
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
17
|
-
data: Joi.any().optional(),
|
|
17
|
+
data: Joi.any().optional().allow(null),
|
|
18
18
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
19
19
|
runner.use((context, next) => {
|
|
20
20
|
const { itx } = context;
|
|
@@ -24,9 +24,9 @@ const schema = Joi.object({
|
|
|
24
24
|
factory: Joi.DID().prefix().role('ROLE_FACTORY').required(),
|
|
25
25
|
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
26
26
|
assetsList: Joi.array().items(Joi.DID().prefix().role('ROLE_ASSET')).default([]),
|
|
27
|
-
variablesList: Joi.array().items(schemas.variableInput).optional().default([]),
|
|
27
|
+
variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
|
|
28
28
|
owner: schemas.tokenHolder.required(),
|
|
29
|
-
data: Joi.any().optional(),
|
|
29
|
+
data: Joi.any().optional().allow(null),
|
|
30
30
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
31
31
|
runner.use(({ itx }, next) => {
|
|
32
32
|
const { error } = schema.validate(itx);
|
|
@@ -19,9 +19,9 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
19
19
|
// Verify itx
|
|
20
20
|
const schema = Joi.object({
|
|
21
21
|
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
22
|
-
moniker: Joi.string().min(2).max(255).optional().allow(''),
|
|
23
|
-
consumed: Joi.boolean().optional().default(false),
|
|
24
|
-
data: Joi.any().optional(),
|
|
22
|
+
moniker: Joi.string().min(2).max(255).optional().allow(null).allow(''),
|
|
23
|
+
consumed: Joi.boolean().optional().allow(null).default(false),
|
|
24
|
+
data: Joi.any().optional().allow(null),
|
|
25
25
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
26
26
|
runner.use((context, next) => {
|
|
27
27
|
const { itx } = context;
|
|
@@ -22,7 +22,7 @@ const schema = Joi.object({
|
|
|
22
22
|
evidence: Joi.object({
|
|
23
23
|
hash: Joi.string().regex(patterns.txHash).required(),
|
|
24
24
|
}).required(),
|
|
25
|
-
data: Joi.any().optional(),
|
|
25
|
+
data: Joi.any().optional().allow(null),
|
|
26
26
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
27
27
|
runner.use(({ itx }, next) => {
|
|
28
28
|
const { error } = schema.validate(itx);
|
|
@@ -22,7 +22,7 @@ const schema = Joi.object({
|
|
|
22
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
|
-
data: Joi.any().optional(),
|
|
25
|
+
data: Joi.any().optional().allow(null),
|
|
26
26
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
27
27
|
runner.use(({ itx }, next) => {
|
|
28
28
|
const { error } = schema.validate(itx);
|
|
@@ -21,7 +21,7 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
21
21
|
const schema = Joi.object({
|
|
22
22
|
address: Joi.DID().prefix().role('ROLE_STAKE').required(),
|
|
23
23
|
outputsList: schemas.multiInput.min(1).required(),
|
|
24
|
-
data: Joi.any().optional(),
|
|
24
|
+
data: Joi.any().optional().allow(null),
|
|
25
25
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
26
26
|
runner.use(({ itx }, next) => {
|
|
27
27
|
const { error } = schema.validate(itx);
|
|
@@ -22,7 +22,7 @@ const schema = Joi.object({
|
|
|
22
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
|
-
data: Joi.any().optional(),
|
|
25
|
+
data: Joi.any().optional().allow(null),
|
|
26
26
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
27
27
|
runner.use(({ itx }, next) => {
|
|
28
28
|
const { error } = schema.validate(itx);
|
|
@@ -29,8 +29,8 @@ const schema = Joi.object({
|
|
|
29
29
|
inputsList: schemas.multiInput.min(1).required(),
|
|
30
30
|
message: Joi.string().trim().min(1).max(256).required(),
|
|
31
31
|
revokeWaitingPeriod: Joi.number().integer().min(0).default(0),
|
|
32
|
-
data: Joi.any().optional(),
|
|
33
|
-
nonce: Joi.string().trim().min(1).max(256).allow('').optional(),
|
|
32
|
+
data: Joi.any().optional().allow(null),
|
|
33
|
+
nonce: Joi.string().trim().min(1).max(256).allow('').optional().allow(null),
|
|
34
34
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
35
35
|
runner.use(({ itx }, next) => {
|
|
36
36
|
const { error } = schema.validate(itx);
|
|
@@ -29,7 +29,7 @@ const schema = Joi.object({
|
|
|
29
29
|
hash: Joi.string().regex(patterns.txHash).required(),
|
|
30
30
|
}).required(),
|
|
31
31
|
publisher: Joi.DID().prefix().wallet('ethereum').required(),
|
|
32
|
-
data: Joi.any().optional(),
|
|
32
|
+
data: Joi.any().optional().allow(null),
|
|
33
33
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
34
34
|
runner.use((context, next) => {
|
|
35
35
|
const { tx, itx } = context;
|
|
@@ -20,7 +20,7 @@ const schema = Joi.object({
|
|
|
20
20
|
address: Joi.DID().prefix().wallet('ethereum').required(),
|
|
21
21
|
value: Joi.BN().positive().required(),
|
|
22
22
|
}),
|
|
23
|
-
data: Joi.any().optional(),
|
|
23
|
+
data: Joi.any().optional().allow(null),
|
|
24
24
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
25
25
|
runner.use(({ itx }, next) => {
|
|
26
26
|
const { error } = schema.validate(itx);
|
|
@@ -30,7 +30,7 @@ const schema = Joi.object({
|
|
|
30
30
|
merkleRoot: Joi.string().regex(patterns.txHash).required(),
|
|
31
31
|
previousHash: Joi.string().when('height', {
|
|
32
32
|
is: 1,
|
|
33
|
-
then: Joi.string().optional().allow(''),
|
|
33
|
+
then: Joi.string().optional().allow(null).allow(''),
|
|
34
34
|
otherwise: Joi.string().regex(patterns.txHash).required(),
|
|
35
35
|
}),
|
|
36
36
|
txsHash: Joi.string().regex(patterns.txHash).required(),
|
|
@@ -40,7 +40,7 @@ const schema = Joi.object({
|
|
|
40
40
|
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
41
41
|
minReward: Joi.BN().min(0).required(),
|
|
42
42
|
governance: Joi.boolean().default(false),
|
|
43
|
-
data: Joi.any().optional(),
|
|
43
|
+
data: Joi.any().optional().allow(null),
|
|
44
44
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
45
45
|
|
|
46
46
|
runner.use((context, next) => {
|
|
@@ -30,7 +30,7 @@ const schema = Joi.object({
|
|
|
30
30
|
hash: Joi.string().regex(patterns.txHash).required(),
|
|
31
31
|
}).required(),
|
|
32
32
|
signaturesList: schemas.multiSig.min(1).required(),
|
|
33
|
-
data: Joi.any().optional(),
|
|
33
|
+
data: Joi.any().optional().allow(null),
|
|
34
34
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
35
35
|
runner.use(({ itx }, next) => {
|
|
36
36
|
const { error } = schema.validate(itx);
|
|
@@ -25,7 +25,7 @@ const schema = Joi.object({
|
|
|
25
25
|
hash: Joi.string().regex(patterns.txHash).required(),
|
|
26
26
|
}).required(),
|
|
27
27
|
signaturesList: schemas.multiSig.min(1).required(),
|
|
28
|
-
data: Joi.any().optional(),
|
|
28
|
+
data: Joi.any().optional().allow(null),
|
|
29
29
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
30
30
|
runner.use(({ itx }, next) => {
|
|
31
31
|
const { error } = schema.validate(itx);
|
|
@@ -17,7 +17,7 @@ const schema = Joi.object({
|
|
|
17
17
|
to: Joi.DID().prefix().wallet('ethereum').required(),
|
|
18
18
|
type: Joi.string().trim().valid('vault', 'contract').required(),
|
|
19
19
|
message: Joi.string().trim().min(1).max(512).required(),
|
|
20
|
-
data: Joi.any().optional(),
|
|
20
|
+
data: Joi.any().optional().allow(null),
|
|
21
21
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
22
22
|
runner.use(({ itx }, next) => {
|
|
23
23
|
const { error } = schema.validate(itx);
|
|
@@ -14,7 +14,7 @@ const runner = new Runner();
|
|
|
14
14
|
// 1. verify itx
|
|
15
15
|
const schema = Joi.object({
|
|
16
16
|
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
17
|
-
data: Joi.any().optional(),
|
|
17
|
+
data: Joi.any().optional().allow(null),
|
|
18
18
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
19
19
|
runner.use(({ itx }, next) => {
|
|
20
20
|
const { error } = schema.validate(itx);
|
|
@@ -14,7 +14,7 @@ const runner = new Runner();
|
|
|
14
14
|
// 1. verify itx
|
|
15
15
|
const schema = Joi.object({
|
|
16
16
|
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
17
|
-
data: Joi.any().optional(),
|
|
17
|
+
data: Joi.any().optional().allow(null),
|
|
18
18
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
19
19
|
runner.use(({ itx }, next) => {
|
|
20
20
|
const { error } = schema.validate(itx);
|
|
@@ -45,7 +45,7 @@ const schema = Joi.object({
|
|
|
45
45
|
minWithdrawFee: Joi.BN().positive().required(),
|
|
46
46
|
maxWithdrawFee: Joi.BN().greater(Joi.ref('minWithdrawFee')).required(),
|
|
47
47
|
|
|
48
|
-
data: Joi.any().optional(),
|
|
48
|
+
data: Joi.any().optional().allow(null),
|
|
49
49
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
50
50
|
runner.use(({ itx }, next) => {
|
|
51
51
|
const { error } = schema.validate(itx);
|
|
@@ -27,11 +27,11 @@ const schema = Joi.object({
|
|
|
27
27
|
symbol: Joi.string().min(2).max(6).uppercase().required(),
|
|
28
28
|
unit: Joi.string().min(1).max(6).lowercase().required(),
|
|
29
29
|
decimal: Joi.number().min(6).max(18).required(),
|
|
30
|
-
icon: Joi.string().optional().valid(''),
|
|
30
|
+
icon: Joi.string().optional().allow(null).valid(''),
|
|
31
31
|
totalSupply: Joi.BN().greater(0).max(MAX_TOTAL_SUPPLY).required(),
|
|
32
32
|
initialSupply: Joi.BN().greater(0).max(Joi.ref('totalSupply')).required(),
|
|
33
|
-
foreignToken: schemas.foreignToken.optional().default(null),
|
|
34
|
-
data: Joi.any().optional(),
|
|
33
|
+
foreignToken: schemas.foreignToken.optional().allow(null).default(null),
|
|
34
|
+
data: Joi.any().optional().allow(null),
|
|
35
35
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
36
36
|
|
|
37
37
|
// 1. verify itx
|
|
@@ -26,7 +26,7 @@ const schema = Joi.object({
|
|
|
26
26
|
}).required(),
|
|
27
27
|
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
28
28
|
actualFee: Joi.BN().min(0).required(),
|
|
29
|
-
data: Joi.any().optional(),
|
|
29
|
+
data: Joi.any().optional().allow(null),
|
|
30
30
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
31
31
|
|
|
32
32
|
const runner = new Runner();
|
|
@@ -22,10 +22,10 @@ const schema = Joi.object({
|
|
|
22
22
|
token: schemas.tokenInput.required(),
|
|
23
23
|
to: Joi.DID().prefix().wallet('ethereum').required(),
|
|
24
24
|
rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
25
|
-
proposer: Joi.DID().prefix().wallet('ethereum').optional().allow('').default(''),
|
|
25
|
+
proposer: Joi.DID().prefix().wallet('ethereum').optional().allow(null).allow('').default(''),
|
|
26
26
|
actualFee: Joi.BN().min(0).required(),
|
|
27
27
|
maxFee: Joi.BN().min(0).required(),
|
|
28
|
-
data: Joi.any().optional(),
|
|
28
|
+
data: Joi.any().optional().allow(null),
|
|
29
29
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
30
30
|
|
|
31
31
|
const runner = new Runner();
|
|
@@ -19,7 +19,7 @@ const runner = new Runner();
|
|
|
19
19
|
|
|
20
20
|
// 0. verify itx
|
|
21
21
|
const exchangeInfoSchema = Joi.object({
|
|
22
|
-
value: Joi.any().optional(),
|
|
22
|
+
value: Joi.any().optional().allow(null),
|
|
23
23
|
tokensList: Joi.array().items(schemas.tokenInput).default([]),
|
|
24
24
|
assetsList: Joi.array().items(Joi.DID().prefix().role('ROLE_ASSET')).default([]),
|
|
25
25
|
});
|
|
@@ -27,7 +27,7 @@ const schema = Joi.object({
|
|
|
27
27
|
to: schemas.tokenHolder.required(),
|
|
28
28
|
sender: exchangeInfoSchema.required(),
|
|
29
29
|
receiver: exchangeInfoSchema.required(),
|
|
30
|
-
data: Joi.any().optional(),
|
|
30
|
+
data: Joi.any().optional().allow(null),
|
|
31
31
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
32
32
|
runner.use(({ itx }, next) => {
|
|
33
33
|
const { error } = schema.validate(itx);
|
|
@@ -6,9 +6,7 @@ const { Joi, schemas } = require('@arcblock/validator');
|
|
|
6
6
|
const { BN } = require('@ocap/util');
|
|
7
7
|
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
8
8
|
const { account, delegation } = require('@ocap/state');
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line global-require
|
|
11
|
-
const debug = require('debug')(`${require('../../../package.json').name}:transfer-v2`);
|
|
9
|
+
const { toStakeAddress } = require('@arcblock/did-util');
|
|
12
10
|
|
|
13
11
|
const EnsureTxGas = require('../../pipes/ensure-gas');
|
|
14
12
|
const EnsureTxCost = require('../../pipes/ensure-cost');
|
|
@@ -21,10 +19,10 @@ runner.use(pipes.VerifyMultiSig(0));
|
|
|
21
19
|
// 1. verify itx
|
|
22
20
|
const schema = Joi.object({
|
|
23
21
|
to: schemas.tokenHolder.required(),
|
|
24
|
-
value: Joi.any().optional(),
|
|
22
|
+
value: Joi.any().optional().allow(null),
|
|
25
23
|
tokensList: Joi.array().items(schemas.tokenInput).default([]),
|
|
26
24
|
assetsList: Joi.array().items(Joi.DID().prefix().role('ROLE_ASSET')).default([]),
|
|
27
|
-
data: Joi.any().optional(),
|
|
25
|
+
data: Joi.any().optional().allow(null),
|
|
28
26
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
29
27
|
runner.use(({ itx }, next) => {
|
|
30
28
|
const { error } = schema.validate(itx);
|
|
@@ -82,7 +80,38 @@ runner.use((context, next) => {
|
|
|
82
80
|
next();
|
|
83
81
|
});
|
|
84
82
|
|
|
85
|
-
runner.use(
|
|
83
|
+
runner.use(
|
|
84
|
+
EnsureTxGas((context) => {
|
|
85
|
+
// FIXME: payment check
|
|
86
|
+
const result = { create: 0, update: 2, payment: 0 };
|
|
87
|
+
result.update += context.assetStates?.length || 0;
|
|
88
|
+
|
|
89
|
+
if (context.receiverState) {
|
|
90
|
+
result.update += 1;
|
|
91
|
+
} else {
|
|
92
|
+
result.create += 1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return result;
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Pre-query states to cache them for later use
|
|
100
|
+
runner.use(async (context, next) => {
|
|
101
|
+
const { statedb, tx, gasVault } = context;
|
|
102
|
+
const accounts = [tx.from, context.receiver, gasVault].filter(Boolean);
|
|
103
|
+
|
|
104
|
+
await Promise.all([
|
|
105
|
+
...accounts.map((x) => statedb.account.get(x, context)),
|
|
106
|
+
statedb.stake.get(toStakeAddress(tx.from, tx.from), context),
|
|
107
|
+
]);
|
|
108
|
+
|
|
109
|
+
next();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
runner.use(
|
|
113
|
+
pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })
|
|
114
|
+
);
|
|
86
115
|
runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
|
|
87
116
|
|
|
88
117
|
runner.use(pipes.ExtractState({ from: 'tokenAddress', to: 'tokenStates', status: 'INVALID_TOKEN', table: 'token' }));
|
|
@@ -119,21 +148,6 @@ runner.use(pipes.VerifyTransferrable({ assets: 'assetStates' }));
|
|
|
119
148
|
runner.use(pipes.VerifyUpdater({ assetKey: 'assetStates', ownerKey: 'senderState' }));
|
|
120
149
|
|
|
121
150
|
// Ensure tx fee and gas
|
|
122
|
-
runner.use(
|
|
123
|
-
EnsureTxGas((context) => {
|
|
124
|
-
// FIXME: payment check
|
|
125
|
-
const result = { create: 0, update: 2, payment: 0 };
|
|
126
|
-
result.update += context.assetStates?.length || 0;
|
|
127
|
-
|
|
128
|
-
if (context.receiverState) {
|
|
129
|
-
result.update += 1;
|
|
130
|
-
} else {
|
|
131
|
-
result.create += 1;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return result;
|
|
135
|
-
})
|
|
136
|
-
);
|
|
137
151
|
runner.use(EnsureTxCost({ attachSenderChanges: true }));
|
|
138
152
|
|
|
139
153
|
// transfer assets to new owner
|
|
@@ -152,7 +166,6 @@ runner.use(
|
|
|
152
166
|
async (context, next) => {
|
|
153
167
|
const {
|
|
154
168
|
tx,
|
|
155
|
-
itx,
|
|
156
169
|
tokens,
|
|
157
170
|
senderState,
|
|
158
171
|
receiverAddr,
|
|
@@ -196,13 +209,11 @@ runner.use(
|
|
|
196
209
|
: delegationState,
|
|
197
210
|
]);
|
|
198
211
|
|
|
199
|
-
await updateVaults();
|
|
200
|
-
|
|
201
212
|
context.senderState = newSenderState;
|
|
202
213
|
context.receiverState = newReceiverState;
|
|
203
214
|
context.delegationState = newDelegationState;
|
|
204
215
|
|
|
205
|
-
|
|
216
|
+
await updateVaults();
|
|
206
217
|
|
|
207
218
|
next();
|
|
208
219
|
},
|
|
@@ -25,7 +25,7 @@ const verifyAssetOwner = promisify(pipes.VerifyUpdater({ assetKey: 'assets', own
|
|
|
25
25
|
const schema = Joi.object({
|
|
26
26
|
inputsList: schemas.multiInput.min(1).required(),
|
|
27
27
|
outputsList: schemas.multiInput.min(1).required(),
|
|
28
|
-
data: Joi.any().optional(),
|
|
28
|
+
data: Joi.any().optional().allow(null),
|
|
29
29
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
30
30
|
runner.use(({ itx }, next) => {
|
|
31
31
|
const { error } = schema.validate(itx);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.19.
|
|
6
|
+
"version": "1.19.17",
|
|
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.19.
|
|
25
|
-
"@arcblock/did-util": "1.19.
|
|
26
|
-
"@arcblock/jwt": "1.19.
|
|
27
|
-
"@arcblock/validator": "1.19.
|
|
28
|
-
"@ocap/asset": "1.19.
|
|
29
|
-
"@ocap/mcrypto": "1.19.
|
|
30
|
-
"@ocap/merkle-tree": "1.19.
|
|
31
|
-
"@ocap/message": "1.19.
|
|
32
|
-
"@ocap/state": "1.19.
|
|
33
|
-
"@ocap/tx-pipeline": "1.19.
|
|
34
|
-
"@ocap/util": "1.19.
|
|
35
|
-
"@ocap/wallet": "1.19.
|
|
24
|
+
"@arcblock/did": "1.19.17",
|
|
25
|
+
"@arcblock/did-util": "1.19.17",
|
|
26
|
+
"@arcblock/jwt": "1.19.17",
|
|
27
|
+
"@arcblock/validator": "1.19.17",
|
|
28
|
+
"@ocap/asset": "1.19.17",
|
|
29
|
+
"@ocap/mcrypto": "1.19.17",
|
|
30
|
+
"@ocap/merkle-tree": "1.19.17",
|
|
31
|
+
"@ocap/message": "1.19.17",
|
|
32
|
+
"@ocap/state": "1.19.17",
|
|
33
|
+
"@ocap/tx-pipeline": "1.19.17",
|
|
34
|
+
"@ocap/util": "1.19.17",
|
|
35
|
+
"@ocap/wallet": "1.19.17",
|
|
36
36
|
"debug": "^4.3.6",
|
|
37
37
|
"deep-diff": "^1.0.2",
|
|
38
38
|
"empty-value": "^1.0.1",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"jest": "^29.7.0",
|
|
48
48
|
"start-server-and-test": "^1.14.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "d25d8b52053b0e3254a28c3b44ea5e447ce1c08a"
|
|
51
51
|
}
|