@ocap/tx-protocols 1.18.113 → 1.18.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/pipes/ensure-gas.js
CHANGED
|
@@ -2,7 +2,7 @@ const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
|
2
2
|
const { BN, hexToNumber } = require('@ocap/util');
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line global-require
|
|
5
|
-
const debug = require('debug')(`${require('../../package.json').name}:pipes:
|
|
5
|
+
const debug = require('debug')(`${require('../../package.json').name}:pipes:ensure-gas`);
|
|
6
6
|
|
|
7
7
|
// Must be called after all state ready
|
|
8
8
|
// Must be called before creating/updating any state
|
|
@@ -19,9 +19,12 @@ module.exports = function CreateGasEnsureFn(estimateTxGas) {
|
|
|
19
19
|
const basePrice = new BN(txGas.price);
|
|
20
20
|
|
|
21
21
|
const estimate = estimateTxGas(context);
|
|
22
|
-
let totalGas =
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
let totalGas = new BN(0);
|
|
23
|
+
if (context.txBaseGas) {
|
|
24
|
+
totalGas = basePrice.mul(new BN(txGas.dataStorage)).mul(new BN(context.txSize));
|
|
25
|
+
totalGas = totalGas.add(basePrice.mul(new BN(txGas.createState)).mul(new BN(estimate.create + 1))); // 1 = tx insert
|
|
26
|
+
totalGas = totalGas.add(basePrice.mul(new BN(txGas.updateState)).mul(new BN(estimate.update)));
|
|
27
|
+
}
|
|
25
28
|
|
|
26
29
|
// gas receiver address
|
|
27
30
|
const { txGas: gasVaults } = config.vaults;
|
|
@@ -42,6 +45,7 @@ module.exports = function CreateGasEnsureFn(estimateTxGas) {
|
|
|
42
45
|
txType: context.txType,
|
|
43
46
|
txHash: context.txHash,
|
|
44
47
|
txSize: context.txSize,
|
|
48
|
+
txBaseGas: context.txBaseGas,
|
|
45
49
|
totalGas: totalGas.toString(10),
|
|
46
50
|
gasVault,
|
|
47
51
|
estimate,
|
|
@@ -145,8 +145,16 @@ runner.use(async (context, next) => {
|
|
|
145
145
|
// Ensure tx fee and gas
|
|
146
146
|
runner.use(
|
|
147
147
|
EnsureTxGas((context) => {
|
|
148
|
-
// FIXME: payment check
|
|
149
148
|
const result = { create: 0, update: 0, payment: 0 };
|
|
149
|
+
|
|
150
|
+
// Do not charge tx fee for self stake: https://github.com/ArcBlock/arc-wallet-ios/issues/4005
|
|
151
|
+
const sender = context.senderState ? context.senderState.address : context.tx.from;
|
|
152
|
+
const receiver = context.receiverState ? context.receiverState.address : context.itx.receiver;
|
|
153
|
+
if (sender === receiver) {
|
|
154
|
+
Object.defineProperty(context, 'txBaseGas', { value: false });
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
|
|
150
158
|
if (context.senderState) {
|
|
151
159
|
result.update += 1;
|
|
152
160
|
} else {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.18.
|
|
6
|
+
"version": "1.18.115",
|
|
7
7
|
"description": "Predefined tx pipeline sets to execute certain type of transactions",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -21,18 +21,18 @@
|
|
|
21
21
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@arcblock/did": "1.18.
|
|
25
|
-
"@arcblock/did-util": "1.18.
|
|
26
|
-
"@arcblock/jwt": "1.18.
|
|
27
|
-
"@arcblock/validator": "1.18.
|
|
28
|
-
"@ocap/asset": "1.18.
|
|
29
|
-
"@ocap/mcrypto": "1.18.
|
|
30
|
-
"@ocap/merkle-tree": "1.18.
|
|
31
|
-
"@ocap/message": "1.18.
|
|
32
|
-
"@ocap/state": "1.18.
|
|
33
|
-
"@ocap/tx-pipeline": "1.18.
|
|
34
|
-
"@ocap/util": "1.18.
|
|
35
|
-
"@ocap/wallet": "1.18.
|
|
24
|
+
"@arcblock/did": "1.18.115",
|
|
25
|
+
"@arcblock/did-util": "1.18.115",
|
|
26
|
+
"@arcblock/jwt": "1.18.115",
|
|
27
|
+
"@arcblock/validator": "1.18.115",
|
|
28
|
+
"@ocap/asset": "1.18.115",
|
|
29
|
+
"@ocap/mcrypto": "1.18.115",
|
|
30
|
+
"@ocap/merkle-tree": "1.18.115",
|
|
31
|
+
"@ocap/message": "1.18.115",
|
|
32
|
+
"@ocap/state": "1.18.115",
|
|
33
|
+
"@ocap/tx-pipeline": "1.18.115",
|
|
34
|
+
"@ocap/util": "1.18.115",
|
|
35
|
+
"@ocap/wallet": "1.18.115",
|
|
36
36
|
"debug": "^4.3.4",
|
|
37
37
|
"deep-diff": "^1.0.2",
|
|
38
38
|
"empty-value": "^1.0.1",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"jest": "^27.5.1",
|
|
48
48
|
"start-server-and-test": "^1.14.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "aba7f4c4ec81a37b0977da9ea7b80c9504e8d4e1"
|
|
51
51
|
}
|