@ocap/tx-protocols 1.18.113 → 1.18.114

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.
@@ -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:estimate-gas`);
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 = basePrice.mul(new BN(txGas.dataStorage)).mul(new BN(context.txSize));
23
- totalGas = totalGas.add(basePrice.mul(new BN(txGas.createState)).mul(new BN(estimate.create + 1))); // 1 = tx insert
24
- totalGas = totalGas.add(basePrice.mul(new BN(txGas.updateState)).mul(new BN(estimate.update)));
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.113",
6
+ "version": "1.18.114",
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.113",
25
- "@arcblock/did-util": "1.18.113",
26
- "@arcblock/jwt": "1.18.113",
27
- "@arcblock/validator": "1.18.113",
28
- "@ocap/asset": "1.18.113",
29
- "@ocap/mcrypto": "1.18.113",
30
- "@ocap/merkle-tree": "1.18.113",
31
- "@ocap/message": "1.18.113",
32
- "@ocap/state": "1.18.113",
33
- "@ocap/tx-pipeline": "1.18.113",
34
- "@ocap/util": "1.18.113",
35
- "@ocap/wallet": "1.18.113",
24
+ "@arcblock/did": "1.18.114",
25
+ "@arcblock/did-util": "1.18.114",
26
+ "@arcblock/jwt": "1.18.114",
27
+ "@arcblock/validator": "1.18.114",
28
+ "@ocap/asset": "1.18.114",
29
+ "@ocap/mcrypto": "1.18.114",
30
+ "@ocap/merkle-tree": "1.18.114",
31
+ "@ocap/message": "1.18.114",
32
+ "@ocap/state": "1.18.114",
33
+ "@ocap/tx-pipeline": "1.18.114",
34
+ "@ocap/util": "1.18.114",
35
+ "@ocap/wallet": "1.18.114",
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": "658f9e820479ce9ee2280f524a4e471d58cde39f"
50
+ "gitHead": "e2f91c7848d50b6614c6e90ce3992a88ebc57f39"
51
51
  }