@ocap/tx-protocols 1.28.9 → 1.29.0
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/esm/execute.d.mts +53 -0
- package/esm/execute.mjs +225 -0
- package/esm/index.d.mts +95 -0
- package/esm/index.mjs +100 -0
- package/esm/pipes/ensure-cost.d.mts +18 -0
- package/esm/pipes/ensure-cost.mjs +136 -0
- package/esm/pipes/ensure-gas.d.mts +14 -0
- package/esm/pipes/ensure-gas.mjs +38 -0
- package/esm/protocols/account/delegate.d.mts +4 -0
- package/esm/protocols/account/delegate.mjs +195 -0
- package/esm/protocols/account/migrate.d.mts +4 -0
- package/esm/protocols/account/migrate.mjs +130 -0
- package/esm/protocols/account/revoke-delegate.d.mts +4 -0
- package/esm/protocols/account/revoke-delegate.mjs +102 -0
- package/esm/protocols/asset/acquire-v2.d.mts +9 -0
- package/esm/protocols/asset/acquire-v2.mjs +213 -0
- package/esm/protocols/asset/acquire-v3.d.mts +17 -0
- package/esm/protocols/asset/acquire-v3.mjs +265 -0
- package/esm/protocols/asset/calls/transfer-token.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer-token.mjs +36 -0
- package/esm/protocols/asset/calls/transfer.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer.mjs +32 -0
- package/esm/protocols/asset/consume.d.mts +4 -0
- package/esm/protocols/asset/consume.mjs +92 -0
- package/esm/protocols/asset/create.d.mts +4 -0
- package/esm/protocols/asset/create.mjs +136 -0
- package/esm/protocols/asset/mint.d.mts +4 -0
- package/esm/protocols/asset/mint.mjs +156 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +24 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +54 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.d.mts +21 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +22 -0
- package/esm/protocols/asset/pipes/verify-itx-address.d.mts +32 -0
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +56 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.d.mts +18 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +27 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.d.mts +17 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.mjs +20 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.d.mts +15 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.mjs +14 -0
- package/esm/protocols/asset/update.d.mts +4 -0
- package/esm/protocols/asset/update.mjs +111 -0
- package/esm/protocols/factory/create.d.mts +29 -0
- package/esm/protocols/factory/create.mjs +155 -0
- package/esm/protocols/governance/claim-stake.d.mts +27 -0
- package/esm/protocols/governance/claim-stake.mjs +220 -0
- package/esm/protocols/governance/return-stake.d.mts +27 -0
- package/esm/protocols/governance/return-stake.mjs +211 -0
- package/esm/protocols/governance/revoke-stake.d.mts +27 -0
- package/esm/protocols/governance/revoke-stake.mjs +178 -0
- package/esm/protocols/governance/slash-stake.d.mts +17 -0
- package/esm/protocols/governance/slash-stake.mjs +213 -0
- package/esm/protocols/governance/stake.d.mts +15 -0
- package/esm/protocols/governance/stake.mjs +270 -0
- package/esm/protocols/rollup/claim-reward.d.mts +11 -0
- package/esm/protocols/rollup/claim-reward.mjs +322 -0
- package/esm/protocols/rollup/close.d.mts +4 -0
- package/esm/protocols/rollup/close.mjs +105 -0
- package/esm/protocols/rollup/create-block.d.mts +11 -0
- package/esm/protocols/rollup/create-block.mjs +303 -0
- package/esm/protocols/rollup/create.d.mts +4 -0
- package/esm/protocols/rollup/create.mjs +164 -0
- package/esm/protocols/rollup/join.d.mts +4 -0
- package/esm/protocols/rollup/join.mjs +152 -0
- package/esm/protocols/rollup/leave.d.mts +4 -0
- package/esm/protocols/rollup/leave.mjs +137 -0
- package/esm/protocols/rollup/migrate.d.mts +4 -0
- package/esm/protocols/rollup/migrate.mjs +85 -0
- package/esm/protocols/rollup/pause.d.mts +4 -0
- package/esm/protocols/rollup/pause.mjs +76 -0
- package/esm/protocols/rollup/pipes/ensure-validator.d.mts +6 -0
- package/esm/protocols/rollup/pipes/ensure-validator.mjs +12 -0
- package/esm/protocols/rollup/pipes/verify-evidence.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +29 -0
- package/esm/protocols/rollup/pipes/verify-signers.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-signers.mjs +36 -0
- package/esm/protocols/rollup/pipes/verify-status.d.mts +13 -0
- package/esm/protocols/rollup/pipes/verify-status.mjs +26 -0
- package/esm/protocols/rollup/resume.d.mts +4 -0
- package/esm/protocols/rollup/resume.mjs +79 -0
- package/esm/protocols/rollup/update.d.mts +4 -0
- package/esm/protocols/rollup/update.mjs +111 -0
- package/esm/protocols/token/create.d.mts +4 -0
- package/esm/protocols/token/create.mjs +150 -0
- package/esm/protocols/token/deposit-v2.d.mts +11 -0
- package/esm/protocols/token/deposit-v2.mjs +216 -0
- package/esm/protocols/token/withdraw-v2.d.mts +9 -0
- package/esm/protocols/token/withdraw-v2.mjs +222 -0
- package/esm/protocols/token-factory/burn.d.mts +15 -0
- package/esm/protocols/token-factory/burn.mjs +233 -0
- package/esm/protocols/token-factory/create.d.mts +4 -0
- package/esm/protocols/token-factory/create.mjs +254 -0
- package/esm/protocols/token-factory/mint.d.mts +15 -0
- package/esm/protocols/token-factory/mint.mjs +234 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.d.mts +21 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.mjs +34 -0
- package/esm/protocols/token-factory/pipes/verify-icon.d.mts +14 -0
- package/esm/protocols/token-factory/pipes/verify-icon.mjs +18 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.mjs +63 -0
- package/esm/protocols/token-factory/pipes/verify-url.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-url.mjs +26 -0
- package/esm/protocols/token-factory/update.d.mts +10 -0
- package/esm/protocols/token-factory/update.mjs +152 -0
- package/esm/protocols/trade/exchange-v2.d.mts +9 -0
- package/esm/protocols/trade/exchange-v2.mjs +239 -0
- package/esm/protocols/trade/transfer-v2.d.mts +9 -0
- package/esm/protocols/trade/transfer-v2.mjs +226 -0
- package/esm/protocols/trade/transfer-v3.d.mts +17 -0
- package/esm/protocols/trade/transfer-v3.mjs +270 -0
- package/esm/util.d.mts +141 -0
- package/esm/util.mjs +278 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/execute.cjs +231 -0
- package/lib/execute.d.cts +53 -0
- package/lib/index.cjs +105 -0
- package/lib/index.d.cts +95 -0
- package/lib/pipes/ensure-cost.cjs +141 -0
- package/lib/pipes/ensure-cost.d.cts +18 -0
- package/lib/pipes/ensure-gas.cjs +41 -0
- package/lib/pipes/ensure-gas.d.cts +14 -0
- package/lib/protocols/account/delegate.cjs +201 -0
- package/lib/protocols/account/delegate.d.cts +4 -0
- package/lib/protocols/account/migrate.cjs +135 -0
- package/lib/protocols/account/migrate.d.cts +4 -0
- package/lib/protocols/account/revoke-delegate.cjs +107 -0
- package/lib/protocols/account/revoke-delegate.d.cts +4 -0
- package/lib/protocols/asset/acquire-v2.cjs +216 -0
- package/lib/protocols/asset/acquire-v2.d.cts +9 -0
- package/lib/protocols/asset/acquire-v3.cjs +269 -0
- package/lib/protocols/asset/acquire-v3.d.cts +17 -0
- package/lib/protocols/asset/calls/transfer-token.cjs +40 -0
- package/lib/protocols/asset/calls/transfer-token.d.cts +4 -0
- package/lib/protocols/asset/calls/transfer.cjs +35 -0
- package/lib/protocols/asset/calls/transfer.d.cts +4 -0
- package/lib/protocols/asset/consume.cjs +95 -0
- package/lib/protocols/asset/consume.d.cts +4 -0
- package/lib/protocols/asset/create.cjs +140 -0
- package/lib/protocols/asset/create.d.cts +4 -0
- package/lib/protocols/asset/mint.cjs +159 -0
- package/lib/protocols/asset/mint.d.cts +4 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +57 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +24 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +25 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.d.cts +21 -0
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +59 -0
- package/lib/protocols/asset/pipes/verify-itx-address.d.cts +32 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +29 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.d.cts +18 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.cjs +22 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.d.cts +17 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.cjs +16 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.d.cts +15 -0
- package/lib/protocols/asset/update.cjs +114 -0
- package/lib/protocols/asset/update.d.cts +4 -0
- package/lib/protocols/factory/create.cjs +161 -0
- package/lib/protocols/factory/create.d.cts +29 -0
- package/lib/protocols/governance/claim-stake.cjs +223 -0
- package/lib/protocols/governance/claim-stake.d.cts +27 -0
- package/lib/protocols/governance/return-stake.cjs +215 -0
- package/lib/protocols/governance/return-stake.d.cts +27 -0
- package/lib/protocols/governance/revoke-stake.cjs +182 -0
- package/lib/protocols/governance/revoke-stake.d.cts +27 -0
- package/lib/protocols/governance/slash-stake.cjs +217 -0
- package/lib/protocols/governance/slash-stake.d.cts +17 -0
- package/lib/protocols/governance/stake.cjs +275 -0
- package/lib/protocols/governance/stake.d.cts +15 -0
- package/lib/protocols/rollup/claim-reward.cjs +328 -0
- package/lib/protocols/rollup/claim-reward.d.cts +11 -0
- package/lib/protocols/rollup/close.cjs +107 -0
- package/lib/protocols/rollup/close.d.cts +4 -0
- package/lib/protocols/rollup/create-block.cjs +309 -0
- package/lib/protocols/rollup/create-block.d.cts +11 -0
- package/lib/protocols/rollup/create.cjs +169 -0
- package/lib/protocols/rollup/create.d.cts +4 -0
- package/lib/protocols/rollup/join.cjs +157 -0
- package/lib/protocols/rollup/join.d.cts +4 -0
- package/lib/protocols/rollup/leave.cjs +141 -0
- package/lib/protocols/rollup/leave.d.cts +4 -0
- package/lib/protocols/rollup/migrate.cjs +87 -0
- package/lib/protocols/rollup/migrate.d.cts +4 -0
- package/lib/protocols/rollup/pause.cjs +78 -0
- package/lib/protocols/rollup/pause.d.cts +4 -0
- package/lib/protocols/rollup/pipes/ensure-validator.cjs +14 -0
- package/lib/protocols/rollup/pipes/ensure-validator.d.cts +6 -0
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +32 -0
- package/lib/protocols/rollup/pipes/verify-evidence.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-signers.cjs +39 -0
- package/lib/protocols/rollup/pipes/verify-signers.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-status.cjs +28 -0
- package/lib/protocols/rollup/pipes/verify-status.d.cts +13 -0
- package/lib/protocols/rollup/resume.cjs +81 -0
- package/lib/protocols/rollup/resume.d.cts +4 -0
- package/lib/protocols/rollup/update.cjs +114 -0
- package/lib/protocols/rollup/update.d.cts +4 -0
- package/lib/protocols/token/create.cjs +156 -0
- package/lib/protocols/token/create.d.cts +4 -0
- package/lib/protocols/token/deposit-v2.cjs +219 -0
- package/lib/protocols/token/deposit-v2.d.cts +11 -0
- package/lib/protocols/token/withdraw-v2.cjs +225 -0
- package/lib/protocols/token/withdraw-v2.d.cts +9 -0
- package/lib/protocols/token-factory/burn.cjs +236 -0
- package/lib/protocols/token-factory/burn.d.cts +15 -0
- package/lib/protocols/token-factory/create.cjs +260 -0
- package/lib/protocols/token-factory/create.d.cts +4 -0
- package/lib/protocols/token-factory/mint.cjs +237 -0
- package/lib/protocols/token-factory/mint.d.cts +15 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.cjs +38 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.d.cts +21 -0
- package/lib/protocols/token-factory/pipes/verify-icon.cjs +22 -0
- package/lib/protocols/token-factory/pipes/verify-icon.d.cts +14 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.cjs +66 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.d.cts +12 -0
- package/lib/protocols/token-factory/pipes/verify-url.cjs +29 -0
- package/lib/protocols/token-factory/pipes/verify-url.d.cts +12 -0
- package/lib/protocols/token-factory/update.cjs +155 -0
- package/lib/protocols/token-factory/update.d.cts +10 -0
- package/lib/protocols/trade/exchange-v2.cjs +243 -0
- package/lib/protocols/trade/exchange-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v2.cjs +229 -0
- package/lib/protocols/trade/transfer-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v3.cjs +274 -0
- package/lib/protocols/trade/transfer-v3.d.cts +17 -0
- package/lib/util.cjs +296 -0
- package/lib/util.d.cts +141 -0
- package/package.json +49 -22
- package/tools/fixtures.ts +564 -0
- package/lib/execute.js +0 -254
- package/lib/index.js +0 -117
- package/lib/pipes/ensure-cost.js +0 -193
- package/lib/pipes/ensure-gas.js +0 -48
- package/lib/protocols/account/delegate.js +0 -223
- package/lib/protocols/account/migrate.js +0 -153
- package/lib/protocols/account/revoke-delegate.js +0 -110
- package/lib/protocols/asset/acquire-v2.js +0 -262
- package/lib/protocols/asset/acquire-v3.js +0 -330
- package/lib/protocols/asset/calls/README.md +0 -5
- package/lib/protocols/asset/calls/transfer-token.js +0 -36
- package/lib/protocols/asset/calls/transfer.js +0 -28
- package/lib/protocols/asset/consume.js +0 -105
- package/lib/protocols/asset/create.js +0 -151
- package/lib/protocols/asset/mint.js +0 -199
- package/lib/protocols/asset/pipes/exec-mint-hook.js +0 -62
- package/lib/protocols/asset/pipes/extract-factory-tokens.js +0 -18
- package/lib/protocols/asset/pipes/verify-itx-address.js +0 -54
- package/lib/protocols/asset/pipes/verify-itx-assets.js +0 -51
- package/lib/protocols/asset/pipes/verify-itx-variables.js +0 -26
- package/lib/protocols/asset/pipes/verify-mint-limit.js +0 -13
- package/lib/protocols/asset/update.js +0 -131
- package/lib/protocols/factory/create.js +0 -191
- package/lib/protocols/governance/claim-stake.js +0 -266
- package/lib/protocols/governance/return-stake.js +0 -248
- package/lib/protocols/governance/revoke-stake.js +0 -172
- package/lib/protocols/governance/slash-stake.js +0 -271
- package/lib/protocols/governance/stake.js +0 -303
- package/lib/protocols/rollup/claim-reward.js +0 -342
- package/lib/protocols/rollup/close.js +0 -104
- package/lib/protocols/rollup/create-block.js +0 -413
- package/lib/protocols/rollup/create.js +0 -197
- package/lib/protocols/rollup/join.js +0 -182
- package/lib/protocols/rollup/leave.js +0 -145
- package/lib/protocols/rollup/migrate.js +0 -85
- package/lib/protocols/rollup/pause.js +0 -75
- package/lib/protocols/rollup/pipes/ensure-validator.js +0 -12
- package/lib/protocols/rollup/pipes/verify-evidence.js +0 -37
- package/lib/protocols/rollup/pipes/verify-signers.js +0 -87
- package/lib/protocols/rollup/pipes/verify-status.js +0 -30
- package/lib/protocols/rollup/resume.js +0 -75
- package/lib/protocols/rollup/update.js +0 -122
- package/lib/protocols/token/create.js +0 -199
- package/lib/protocols/token/deposit-v2.js +0 -290
- package/lib/protocols/token/withdraw-v2.js +0 -305
- package/lib/protocols/token-factory/burn.js +0 -371
- package/lib/protocols/token-factory/create.js +0 -342
- package/lib/protocols/token-factory/mint.js +0 -385
- package/lib/protocols/token-factory/pipes/calc-reserve.js +0 -37
- package/lib/protocols/token-factory/pipes/verify-icon.js +0 -27
- package/lib/protocols/token-factory/pipes/verify-ownership.js +0 -93
- package/lib/protocols/token-factory/pipes/verify-url.js +0 -32
- package/lib/protocols/token-factory/update.js +0 -208
- package/lib/protocols/trade/exchange-v2.js +0 -239
- package/lib/protocols/trade/transfer-v2.js +0 -233
- package/lib/protocols/trade/transfer-v3.js +0 -333
- package/lib/util.js +0 -442
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
2
|
-
const { Joi } = require('@arcblock/validator');
|
|
3
|
-
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
4
|
-
const { account, asset } = require('@ocap/state');
|
|
5
|
-
|
|
6
|
-
const debug = require('debug')(`${require('../../../package.json').name}:consume-asset`);
|
|
7
|
-
|
|
8
|
-
const EnsureTxGas = require('../../pipes/ensure-gas');
|
|
9
|
-
const EnsureTxCost = require('../../pipes/ensure-cost');
|
|
10
|
-
|
|
11
|
-
const runner = new Runner();
|
|
12
|
-
|
|
13
|
-
// Verify itx
|
|
14
|
-
const schema = Joi.object({
|
|
15
|
-
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
16
|
-
data: Joi.any().optional().allow(null),
|
|
17
|
-
}).options({ stripUnknown: true, noDefaults: false });
|
|
18
|
-
runner.use((context, next) => {
|
|
19
|
-
const { itx } = context;
|
|
20
|
-
const { error } = schema.validate(itx);
|
|
21
|
-
if (error) {
|
|
22
|
-
return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return next();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// Ensure asset exist
|
|
29
|
-
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'assetState', status: 'INVALID_ASSET', table: 'asset' }));
|
|
30
|
-
|
|
31
|
-
// Ensure asset can be consumed
|
|
32
|
-
runner.use((context, next) => {
|
|
33
|
-
const { issuer, consumedTime } = context.assetState;
|
|
34
|
-
if (!issuer) {
|
|
35
|
-
return next(new Error('INVALID_TX', 'Asset without issuer can not be consumed'));
|
|
36
|
-
}
|
|
37
|
-
if (consumedTime) {
|
|
38
|
-
return next(new Error('INVALID_TX', `Asset already consumed on ${consumedTime}`));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return next();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Ensure sender exist
|
|
45
|
-
runner.use(
|
|
46
|
-
pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })
|
|
47
|
-
);
|
|
48
|
-
runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
|
|
49
|
-
|
|
50
|
-
// Ensure owner/issuer exist
|
|
51
|
-
runner.use(
|
|
52
|
-
pipes.ExtractState({ from: 'assetState.issuer', to: 'issuerState', status: 'INVALID_ISSUER_STATE', table: 'account' })
|
|
53
|
-
);
|
|
54
|
-
runner.use(
|
|
55
|
-
pipes.ExtractState({ from: 'assetState.owner', to: 'ownerState', status: 'INVALID_OWNER_STATE', table: 'account' })
|
|
56
|
-
);
|
|
57
|
-
runner.use((context, next) => {
|
|
58
|
-
context.signerStates = [context.ownerState, context.issuerState];
|
|
59
|
-
context.signers = [context.ownerState.address, context.issuerState.address];
|
|
60
|
-
return next();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Ensure owner and issuer signed: and not migrated
|
|
64
|
-
runner.use(pipes.VerifyMultiSigV2({ signersKey: 'signers' }));
|
|
65
|
-
runner.use(pipes.VerifyAccountMigration({ signerKey: 'signerStates' }));
|
|
66
|
-
|
|
67
|
-
// Ensure tx fee and gas
|
|
68
|
-
runner.use(EnsureTxGas(() => ({ create: 0, update: 2, payment: 0 })));
|
|
69
|
-
runner.use(EnsureTxCost({ attachSenderChanges: true }));
|
|
70
|
-
|
|
71
|
-
// Save context snapshot before updating states
|
|
72
|
-
runner.use(pipes.TakeStateSnapshot());
|
|
73
|
-
|
|
74
|
-
// Update asset state
|
|
75
|
-
runner.use(
|
|
76
|
-
async (context, next) => {
|
|
77
|
-
const { tx, itx, txTime, statedb, senderState, senderUpdates, assetState, updateVaults } = context;
|
|
78
|
-
|
|
79
|
-
const [newSenderState, newAssetState] = await Promise.all([
|
|
80
|
-
// update sender state
|
|
81
|
-
statedb.account.update(
|
|
82
|
-
senderState.address,
|
|
83
|
-
account.update(senderState, { nonce: tx.nonce, pk: tx.pk, ...senderUpdates }, context),
|
|
84
|
-
context
|
|
85
|
-
),
|
|
86
|
-
|
|
87
|
-
// update asset state
|
|
88
|
-
statedb.asset.update(itx.address, asset.update(assetState, { consumedTime: txTime }, context), context),
|
|
89
|
-
]);
|
|
90
|
-
|
|
91
|
-
await updateVaults();
|
|
92
|
-
|
|
93
|
-
context.senderState = newSenderState;
|
|
94
|
-
context.assetState = newAssetState;
|
|
95
|
-
|
|
96
|
-
debug('consume', newAssetState);
|
|
97
|
-
|
|
98
|
-
next();
|
|
99
|
-
},
|
|
100
|
-
{ persistError: true }
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
runner.use(pipes.VerifyStateDiff());
|
|
104
|
-
|
|
105
|
-
module.exports = runner;
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
2
|
-
const cloneDeep = require('lodash/cloneDeep');
|
|
3
|
-
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
4
|
-
const { account, asset, delegation } = require('@ocap/state');
|
|
5
|
-
const { formatMessage } = require('@ocap/message');
|
|
6
|
-
const { toAssetAddress } = require('@arcblock/did-util');
|
|
7
|
-
|
|
8
|
-
const debug = require('debug')(`${require('../../../package.json').name}:create-asset`);
|
|
9
|
-
|
|
10
|
-
const { decodeAnySafe, getDelegationRequirements } = require('../../util');
|
|
11
|
-
|
|
12
|
-
const EnsureTxGas = require('../../pipes/ensure-gas');
|
|
13
|
-
const EnsureTxCost = require('../../pipes/ensure-cost');
|
|
14
|
-
|
|
15
|
-
const runner = new Runner();
|
|
16
|
-
|
|
17
|
-
// Verify itx
|
|
18
|
-
runner.use((context, next) => {
|
|
19
|
-
const itx = formatMessage('CreateAssetTx', context.itx);
|
|
20
|
-
const { error } = asset.schema.validate(itx);
|
|
21
|
-
if (error) {
|
|
22
|
-
return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
|
|
23
|
-
}
|
|
24
|
-
return next();
|
|
25
|
-
});
|
|
26
|
-
runner.use(
|
|
27
|
-
pipes.VerifyInfo([
|
|
28
|
-
{
|
|
29
|
-
error: 'INVALID_ASSET',
|
|
30
|
-
message: 'Asset address is not valid',
|
|
31
|
-
fn: (context) => {
|
|
32
|
-
const itx = cloneDeep(context.itx);
|
|
33
|
-
itx.data = decodeAnySafe(itx.data);
|
|
34
|
-
itx.address = '';
|
|
35
|
-
|
|
36
|
-
// Save for later use
|
|
37
|
-
context.assetData = itx.data;
|
|
38
|
-
context.signers = [itx.issuer].filter(Boolean);
|
|
39
|
-
|
|
40
|
-
return toAssetAddress(itx) === context.itx.address;
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
])
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// Ensure issuer signed
|
|
47
|
-
runner.use(pipes.VerifyMultiSigV2({ signersKey: 'signers' }));
|
|
48
|
-
|
|
49
|
-
// Ensure asset not exist
|
|
50
|
-
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'assetState', status: 'OK' }));
|
|
51
|
-
runner.use(
|
|
52
|
-
pipes.VerifyInfo([
|
|
53
|
-
{
|
|
54
|
-
error: 'INVALID_ASSET',
|
|
55
|
-
message: 'This asset already exist on chain',
|
|
56
|
-
fn: (context) => !context.assetState,
|
|
57
|
-
},
|
|
58
|
-
])
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
// Ensure issuer exist
|
|
62
|
-
runner.use(
|
|
63
|
-
pipes.ExtractState({ from: 'itx.issuer', to: 'issuerState', status: 'INVALID_ISSUER_STATE', table: 'account' })
|
|
64
|
-
);
|
|
65
|
-
runner.use(pipes.VerifyAccountMigration({ signerKey: 'issuerState' }));
|
|
66
|
-
|
|
67
|
-
// Ensure sender exist
|
|
68
|
-
runner.use(
|
|
69
|
-
pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })
|
|
70
|
-
);
|
|
71
|
-
runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
|
|
72
|
-
|
|
73
|
-
// Ensure delegation
|
|
74
|
-
runner.use(pipes.ExtractState({ from: 'tx.delegator', to: 'delegatorState', status: 'OK', table: 'account' }));
|
|
75
|
-
runner.use(pipes.VerifyAccountMigration({ stateKey: 'delegatorState', addressKey: 'tx.delegator' }));
|
|
76
|
-
runner.use(
|
|
77
|
-
pipes.VerifyDelegation({
|
|
78
|
-
type: 'signature',
|
|
79
|
-
signerKey: 'senderState',
|
|
80
|
-
delegatorKey: 'delegatorState',
|
|
81
|
-
getRequirements: getDelegationRequirements,
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
// Check if parent is a factory
|
|
86
|
-
runner.use(pipes.ExtractState({ from: 'itx.parent', to: 'factoryState', status: 'OK', table: 'factory' }));
|
|
87
|
-
runner.use(
|
|
88
|
-
pipes.VerifyInfo([
|
|
89
|
-
// For security consideration, user can not create fake assets from a factory
|
|
90
|
-
// https://github.com/ArcBlock/blockchain/issues/97
|
|
91
|
-
{
|
|
92
|
-
error: 'CREATE_FROM_FACTORY',
|
|
93
|
-
message: 'You can only get asset from factory from acquire or mint',
|
|
94
|
-
fn: ({ itx, factoryState }) => !(itx.parent && factoryState),
|
|
95
|
-
persist: true,
|
|
96
|
-
},
|
|
97
|
-
])
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
// Ensure parent exist
|
|
101
|
-
runner.use(pipes.ExtractState({ from: 'itx.parent', to: 'parentAsset', status: 'INVALID_ASSET', table: 'asset' }));
|
|
102
|
-
|
|
103
|
-
// Ensure tx fee and gas
|
|
104
|
-
runner.use(EnsureTxGas(() => ({ create: 1, update: 2, payment: 0 })));
|
|
105
|
-
runner.use(EnsureTxCost({ attachSenderChanges: true }));
|
|
106
|
-
|
|
107
|
-
// Save context snapshot before updating states
|
|
108
|
-
runner.use(pipes.TakeStateSnapshot());
|
|
109
|
-
|
|
110
|
-
// Update asset state
|
|
111
|
-
runner.use(
|
|
112
|
-
async (context, next) => {
|
|
113
|
-
const { tx, itx, assetData, statedb, senderState, delegatorState, delegationState, senderUpdates, updateVaults } =
|
|
114
|
-
context;
|
|
115
|
-
const owner = delegatorState ? delegatorState.address : senderState.address;
|
|
116
|
-
|
|
117
|
-
const [newSenderState, assetState, newDelegationState] = await Promise.all([
|
|
118
|
-
statedb.account.update(
|
|
119
|
-
senderState.address,
|
|
120
|
-
account.update(senderState, { nonce: tx.nonce, pk: tx.pk, ...senderUpdates }, context),
|
|
121
|
-
context
|
|
122
|
-
),
|
|
123
|
-
|
|
124
|
-
statedb.asset.create(
|
|
125
|
-
itx.address,
|
|
126
|
-
asset.create({ ...itx, tags: itx.tagsList, data: assetData, owner }, context),
|
|
127
|
-
context
|
|
128
|
-
),
|
|
129
|
-
|
|
130
|
-
// Update delegation state
|
|
131
|
-
context.isDelegationChanged
|
|
132
|
-
? statedb.delegation.update(delegationState.address, delegation.update(delegationState, {}, context), context)
|
|
133
|
-
: delegationState,
|
|
134
|
-
]);
|
|
135
|
-
|
|
136
|
-
await updateVaults();
|
|
137
|
-
|
|
138
|
-
context.senderState = newSenderState;
|
|
139
|
-
context.assetState = assetState;
|
|
140
|
-
context.delegationState = newDelegationState;
|
|
141
|
-
|
|
142
|
-
debug('createAsset', assetState);
|
|
143
|
-
|
|
144
|
-
next();
|
|
145
|
-
},
|
|
146
|
-
{ persistError: true }
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
runner.use(pipes.VerifyStateDiff());
|
|
150
|
-
|
|
151
|
-
module.exports = runner;
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
const { Runner, pipes } = require('@ocap/tx-pipeline');
|
|
2
|
-
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
3
|
-
const { Joi, schemas } = require('@arcblock/validator');
|
|
4
|
-
const { account, asset, factory } = require('@ocap/state');
|
|
5
|
-
|
|
6
|
-
const debug = require('debug')(`${require('../../../package.json').name}:mint-asset`);
|
|
7
|
-
|
|
8
|
-
const verifyMintLimit = require('./pipes/verify-mint-limit');
|
|
9
|
-
const verifyItxVariables = require('./pipes/verify-itx-variables');
|
|
10
|
-
const verifyItxAssets = require('./pipes/verify-itx-assets');
|
|
11
|
-
const verifyItxAddress = require('./pipes/verify-itx-address');
|
|
12
|
-
|
|
13
|
-
const runner = new Runner();
|
|
14
|
-
|
|
15
|
-
const EnsureTxGas = require('../../pipes/ensure-gas');
|
|
16
|
-
const EnsureTxCost = require('../../pipes/ensure-cost');
|
|
17
|
-
|
|
18
|
-
runner.use(pipes.VerifyMultiSig(0));
|
|
19
|
-
|
|
20
|
-
// verify itx
|
|
21
|
-
const schema = Joi.object({
|
|
22
|
-
factory: Joi.DID().prefix().role('ROLE_FACTORY').required(),
|
|
23
|
-
address: Joi.DID().prefix().role('ROLE_ASSET').required(),
|
|
24
|
-
assetsList: Joi.array().items(Joi.DID().prefix().role('ROLE_ASSET')).default([]),
|
|
25
|
-
variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
|
|
26
|
-
owner: schemas.tokenHolder.required(),
|
|
27
|
-
data: Joi.any().optional().allow(null),
|
|
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
|
-
});
|
|
36
|
-
|
|
37
|
-
// ensure asset not exist
|
|
38
|
-
runner.use(pipes.ExtractState({ from: 'itx.address', to: 'duplicateAsset', status: 'OK', table: 'asset' }));
|
|
39
|
-
runner.use(
|
|
40
|
-
pipes.VerifyInfo([
|
|
41
|
-
{
|
|
42
|
-
error: 'FORBIDDEN',
|
|
43
|
-
message: 'Asset with same address already exists',
|
|
44
|
-
fn: ({ duplicateAsset }) => !duplicateAsset,
|
|
45
|
-
persist: true,
|
|
46
|
-
},
|
|
47
|
-
])
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
// Ensure sender exist
|
|
51
|
-
runner.use(
|
|
52
|
-
pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })
|
|
53
|
-
);
|
|
54
|
-
runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
|
|
55
|
-
|
|
56
|
-
// Ensure factory exist
|
|
57
|
-
runner.use(
|
|
58
|
-
pipes.ExtractState({ from: 'itx.factory', to: 'factoryState', status: 'INVALID_FACTORY_STATE', table: 'factory' })
|
|
59
|
-
);
|
|
60
|
-
runner.use(
|
|
61
|
-
pipes.ExtractState({
|
|
62
|
-
from: 'factoryState.owner',
|
|
63
|
-
to: 'factoryOwnerState',
|
|
64
|
-
status: 'INVALID_ISSUER_STATE',
|
|
65
|
-
table: 'account',
|
|
66
|
-
})
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
// Ensure issuer exist: read them here because some maybe migrated
|
|
70
|
-
runner.use(
|
|
71
|
-
pipes.ExtractState({
|
|
72
|
-
from: 'factoryState.trustedIssuers',
|
|
73
|
-
to: 'issuerStates',
|
|
74
|
-
status: 'INVALID_ISSUER_STATE',
|
|
75
|
-
table: 'account',
|
|
76
|
-
})
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
runner.use(pipes.ExtractState({ from: 'itx.owner', to: 'ownerState', status: 'OK', table: 'account' }));
|
|
80
|
-
runner.use(pipes.VerifyBlocked({ stateKeys: ['ownerState'] }));
|
|
81
|
-
runner.use(
|
|
82
|
-
pipes.VerifyInfo([
|
|
83
|
-
{
|
|
84
|
-
error: 'FORBIDDEN',
|
|
85
|
-
message: 'Only factory owner and trusted issuers are allowed to mint',
|
|
86
|
-
fn: ({ factoryOwnerState, senderState, issuerStates }) =>
|
|
87
|
-
senderState.address === factoryOwnerState.address ||
|
|
88
|
-
issuerStates.find((x) => x.address === senderState.address),
|
|
89
|
-
persist: true,
|
|
90
|
-
},
|
|
91
|
-
])
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
// Prepare for itx.assets verify
|
|
95
|
-
runner.use(pipes.ExtractState({ from: 'itx.assetsList', to: 'assetStates', status: 'OK', table: 'asset' }));
|
|
96
|
-
runner.use(
|
|
97
|
-
pipes.ExtractState({
|
|
98
|
-
from: 'factoryState.input.assets',
|
|
99
|
-
to: 'expectedFactoryStates',
|
|
100
|
-
status: 'OK',
|
|
101
|
-
table: 'factory',
|
|
102
|
-
})
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
runner.use(verifyMintLimit);
|
|
106
|
-
runner.use(verifyItxVariables);
|
|
107
|
-
runner.use(verifyItxAddress('mint'));
|
|
108
|
-
runner.use(pipes.VerifyUpdater({ assetKey: 'assetStates', ownerKey: 'ownerState' }));
|
|
109
|
-
runner.use(verifyItxAssets);
|
|
110
|
-
|
|
111
|
-
// Ensure tx fee and gas
|
|
112
|
-
runner.use(
|
|
113
|
-
EnsureTxGas((context) => {
|
|
114
|
-
const result = { create: 1, update: 2, payment: 0 };
|
|
115
|
-
if (!context.ownerState) {
|
|
116
|
-
result.create += 1;
|
|
117
|
-
}
|
|
118
|
-
if (context.assetStates) {
|
|
119
|
-
result.update += context.assetStates.length;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return result;
|
|
123
|
-
})
|
|
124
|
-
);
|
|
125
|
-
runner.use(EnsureTxCost({ attachSenderChanges: true }));
|
|
126
|
-
|
|
127
|
-
// Save context snapshot before updating states
|
|
128
|
-
runner.use(pipes.TakeStateSnapshot());
|
|
129
|
-
|
|
130
|
-
// update statedb
|
|
131
|
-
runner.use(
|
|
132
|
-
async (context, next) => {
|
|
133
|
-
const {
|
|
134
|
-
tx,
|
|
135
|
-
itx,
|
|
136
|
-
txTime,
|
|
137
|
-
statedb,
|
|
138
|
-
senderState,
|
|
139
|
-
factoryState,
|
|
140
|
-
mintedAsset,
|
|
141
|
-
mintedAddress,
|
|
142
|
-
ownerState,
|
|
143
|
-
senderUpdates,
|
|
144
|
-
assetStates = [],
|
|
145
|
-
updateVaults,
|
|
146
|
-
ownerAddress,
|
|
147
|
-
} = context;
|
|
148
|
-
|
|
149
|
-
const factoryUpdates = { numMinted: factoryState.numMinted + 1 };
|
|
150
|
-
|
|
151
|
-
const [newSenderState, newReceiverState, assetState, newFactoryState, newAssetStates] = await Promise.all([
|
|
152
|
-
// update sender
|
|
153
|
-
statedb.account.update(
|
|
154
|
-
senderState.address,
|
|
155
|
-
account.update(senderState, { nonce: tx.nonce, pk: tx.pk, ...senderUpdates }, context),
|
|
156
|
-
context
|
|
157
|
-
),
|
|
158
|
-
|
|
159
|
-
// create receiver if not exist: asset owner
|
|
160
|
-
ownerState
|
|
161
|
-
? Promise.resolve(ownerState)
|
|
162
|
-
: statedb.account.create(ownerAddress, account.create({ address: ownerAddress }, context), context),
|
|
163
|
-
|
|
164
|
-
// create asset
|
|
165
|
-
statedb.asset.create(
|
|
166
|
-
itx.address,
|
|
167
|
-
asset.create({ ...mintedAsset, owner: ownerAddress, address: mintedAddress }, context),
|
|
168
|
-
context
|
|
169
|
-
),
|
|
170
|
-
|
|
171
|
-
// update factory
|
|
172
|
-
statedb.factory.update(factoryState.address, factory.update(factoryState, factoryUpdates, context), context),
|
|
173
|
-
|
|
174
|
-
// mark input assets as consumed
|
|
175
|
-
Promise.all(
|
|
176
|
-
assetStates.map((x) =>
|
|
177
|
-
statedb.asset.update(x.address, asset.update(x, { consumedTime: txTime }, context), context)
|
|
178
|
-
)
|
|
179
|
-
),
|
|
180
|
-
]);
|
|
181
|
-
|
|
182
|
-
await updateVaults();
|
|
183
|
-
|
|
184
|
-
context.senderState = newSenderState;
|
|
185
|
-
context.receiverState = newReceiverState;
|
|
186
|
-
context.assetState = assetState;
|
|
187
|
-
context.factoryState = newFactoryState;
|
|
188
|
-
context.assetStates = newAssetStates;
|
|
189
|
-
|
|
190
|
-
debug('mint', assetState);
|
|
191
|
-
|
|
192
|
-
next();
|
|
193
|
-
},
|
|
194
|
-
{ persistError: true }
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
runner.use(pipes.VerifyStateDiff());
|
|
198
|
-
|
|
199
|
-
module.exports = runner;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// contract calls
|
|
2
|
-
const cloneDeep = require('lodash/cloneDeep');
|
|
3
|
-
const transferCall = require('../calls/transfer');
|
|
4
|
-
const transferTokenCall = require('../calls/transfer-token');
|
|
5
|
-
|
|
6
|
-
const contractCalls = {
|
|
7
|
-
transfer: transferCall,
|
|
8
|
-
transferToken: transferTokenCall,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
module.exports = async (context, next) => {
|
|
12
|
-
const { statedb, factoryState, tokenUpdates, config } = context;
|
|
13
|
-
|
|
14
|
-
if (factoryState.settlement === 'instant') {
|
|
15
|
-
const mintHook = factoryState.hooks.find((x) => x.name === 'mint');
|
|
16
|
-
if (mintHook && mintHook.type === 'contract') {
|
|
17
|
-
context.updatedAccounts = context.updatedAccounts || [];
|
|
18
|
-
|
|
19
|
-
// These calls must be run sequentially, because different calls may update same account
|
|
20
|
-
const clone = cloneDeep(mintHook.compiled);
|
|
21
|
-
const mintHookStates = {};
|
|
22
|
-
for (const x of clone) {
|
|
23
|
-
// Convert transfer to transferToken call for backwards compatibility
|
|
24
|
-
if (x.call === 'transfer') {
|
|
25
|
-
x.call = 'transferToken';
|
|
26
|
-
x.args.tokenAddress = config.token.address;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const pipeline = contractCalls[x.call];
|
|
30
|
-
const { updateSet } = await pipeline.runAsync({
|
|
31
|
-
states: context.states,
|
|
32
|
-
statedb,
|
|
33
|
-
txn: context.txn,
|
|
34
|
-
txTime: context.txTime,
|
|
35
|
-
txHash: context.txHash,
|
|
36
|
-
logger: context.logger,
|
|
37
|
-
args: x.args,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
mintHookStates[updateSet.address] = await statedb.account.update(updateSet.address, updateSet.updates, context);
|
|
41
|
-
context.updatedAccounts.push(updateSet);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
context.mintHookStates = Object.values(mintHookStates);
|
|
45
|
-
}
|
|
46
|
-
} else {
|
|
47
|
-
context.receipts = [
|
|
48
|
-
{
|
|
49
|
-
address: factoryState.address,
|
|
50
|
-
changes: Object.keys(tokenUpdates.tokens)
|
|
51
|
-
.map((x) => ({
|
|
52
|
-
target: x,
|
|
53
|
-
action: 'transfer',
|
|
54
|
-
value: tokenUpdates.tokens[x],
|
|
55
|
-
}))
|
|
56
|
-
.filter((x) => x.value > 0),
|
|
57
|
-
},
|
|
58
|
-
];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
next();
|
|
62
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const uniqBy = require('lodash/uniqBy');
|
|
2
|
-
const { BN } = require('@ocap/util');
|
|
3
|
-
const { createSortedList } = require('@ocap/util/lib/create-sorted-list');
|
|
4
|
-
|
|
5
|
-
// Create token requirements from factoryState
|
|
6
|
-
module.exports = (context, next) => {
|
|
7
|
-
const { factoryState, config } = context;
|
|
8
|
-
context.factoryTokens = [...factoryState.input.tokens];
|
|
9
|
-
|
|
10
|
-
const exist = context.factoryTokens.find((x) => x.address === config.token.address);
|
|
11
|
-
if (!exist && new BN(factoryState.input.value).gt(new BN(0))) {
|
|
12
|
-
context.factoryTokens.push({ address: config.token.address, value: factoryState.input.value });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
context.factoryTokens = uniqBy(context.factoryTokens, 'address');
|
|
16
|
-
context.tokenAddress = createSortedList(context.factoryTokens.map((x) => x.address));
|
|
17
|
-
next();
|
|
18
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
2
|
-
const { mintFromFactory } = require('@ocap/asset');
|
|
3
|
-
|
|
4
|
-
const debug = require('debug')('@ocap/tx-protocols:pipes:verify-itx-address');
|
|
5
|
-
|
|
6
|
-
module.exports = (mode) => (context, next) => {
|
|
7
|
-
const { itx, senderState, factoryState, delegatorState, factoryInputs } = context;
|
|
8
|
-
|
|
9
|
-
let issuer = null;
|
|
10
|
-
let owner = null;
|
|
11
|
-
|
|
12
|
-
if (mode === 'acquire-v2') {
|
|
13
|
-
owner = delegatorState || senderState;
|
|
14
|
-
issuer = itx.issuer;
|
|
15
|
-
context.assetOwner = owner;
|
|
16
|
-
} else if (mode === 'acquire-v3') {
|
|
17
|
-
owner = { address: itx.owner };
|
|
18
|
-
issuer = itx.issuer;
|
|
19
|
-
} else if (mode === 'mint') {
|
|
20
|
-
owner = { address: itx.owner };
|
|
21
|
-
issuer = {
|
|
22
|
-
id: senderState.address,
|
|
23
|
-
pk: senderState.pk,
|
|
24
|
-
name: senderState.moniker,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const minted = mintFromFactory({
|
|
29
|
-
factory: factoryState,
|
|
30
|
-
inputs: factoryInputs,
|
|
31
|
-
owner: owner.address,
|
|
32
|
-
issuer,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (minted.address !== itx.address) {
|
|
36
|
-
debug('asset address mismatch', {
|
|
37
|
-
owner,
|
|
38
|
-
issuer,
|
|
39
|
-
minted,
|
|
40
|
-
itx,
|
|
41
|
-
factoryInputs,
|
|
42
|
-
factoryState,
|
|
43
|
-
senderState,
|
|
44
|
-
delegatorState,
|
|
45
|
-
});
|
|
46
|
-
return next(new Error('INVALID_ASSET', 'Invalid itx.address: does not match with minted asset address'));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
context.ownerAddress = owner.address;
|
|
50
|
-
context.mintedAsset = minted.asset;
|
|
51
|
-
context.mintedAddress = minted.address;
|
|
52
|
-
|
|
53
|
-
return next();
|
|
54
|
-
};
|
|
@@ -1,51 +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 = (context, next) => {
|
|
5
|
-
const { factoryState, expectedFactoryStates = [], assetStates: actualAssetStates = [], itx } = context;
|
|
6
|
-
const { assets: expectedAssets } = factoryState.input;
|
|
7
|
-
|
|
8
|
-
if (expectedAssets.length === 0) {
|
|
9
|
-
return next();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const inputAssets = getListField(itx, 'assets');
|
|
13
|
-
|
|
14
|
-
// Are all input assets found on chain?
|
|
15
|
-
if (inputAssets.length > actualAssetStates.length) {
|
|
16
|
-
return next(new Error('INVALID_ASSET', 'Input asset does not exist on chain'));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// https://github.com/ArcBlock/blockchain/issues/96
|
|
20
|
-
// If factory.input.assets are all factory
|
|
21
|
-
if (expectedFactoryStates.length === expectedAssets.length) {
|
|
22
|
-
// Just ensure that input assets are minted from any of the factory
|
|
23
|
-
// They do not need to match on number
|
|
24
|
-
if (actualAssetStates.every((x) => x.parent && expectedAssets.includes(x.parent)) === false) {
|
|
25
|
-
return next(new Error('INVALID_ASSET', 'Input asset not minted from any of factory.input.assets'));
|
|
26
|
-
}
|
|
27
|
-
if (actualAssetStates.every((x) => !x.consumedTime) === false) {
|
|
28
|
-
return next(new Error('INVALID_ASSET', 'Some input asset already consumed'));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return next();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// For specific assets, they must not be consumed
|
|
35
|
-
// For factory, they must exist on chain
|
|
36
|
-
for (const address of expectedAssets) {
|
|
37
|
-
const plainAsset = actualAssetStates.find((x) => x.address === address);
|
|
38
|
-
if (plainAsset) {
|
|
39
|
-
if (plainAsset.consumedTime) {
|
|
40
|
-
return next(new Error('INVALID_ASSET', `Input asset ${address} already consumed`));
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
const childAsset = actualAssetStates.find((x) => x.parent === address);
|
|
44
|
-
if (!childAsset) {
|
|
45
|
-
return next(new Error('INVALID_ASSET', `Input asset not found ${address}`));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return next();
|
|
51
|
-
};
|
|
@@ -1,26 +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 = (context, next) => {
|
|
5
|
-
const { factoryState, itx } = context;
|
|
6
|
-
const { variables } = factoryState.input;
|
|
7
|
-
|
|
8
|
-
// validate input variables
|
|
9
|
-
const factoryInputs = getListField(itx, 'variables').reduce((acc, x) => {
|
|
10
|
-
acc[x.name] = x.value;
|
|
11
|
-
return acc;
|
|
12
|
-
}, {});
|
|
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
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
context.factoryInputs = factoryInputs;
|
|
24
|
-
|
|
25
|
-
return next();
|
|
26
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
2
|
-
|
|
3
|
-
module.exports = ({ factoryState }, next) => {
|
|
4
|
-
if (factoryState.limit === 0) {
|
|
5
|
-
return next();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (factoryState.numMinted < factoryState.limit) {
|
|
9
|
-
return next();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return next(new Error('EXCEED_MINT_LIMIT', 'This request will exceed factory mint limit'));
|
|
13
|
-
};
|