From df118be318b007e597e157504d105dfa3e6322a1 Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 2 Oct 2020 12:14:40 +0300 Subject: [PATCH] prettier --- .prettierrc | 7 +++++++ index.js | 2 +- src/Transaction.js | 18 ++++++++---------- src/utils.js | 3 ++- test/TxManager.test.js | 9 ++++++--- 5 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..7d955c2 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "semi": false, + "arrowParens": "always", + "singleQuote": true, + "printWidth": 110, + "trailingComma": "all" +} diff --git a/index.js b/index.js index 391ff8d..21e247e 100644 --- a/index.js +++ b/index.js @@ -3,5 +3,5 @@ const Transaction = require('./src/Transaction') module.exports = { TxManager, - Transaction + Transaction, } diff --git a/src/Transaction.js b/src/Transaction.js index 97d2767..a9a229b 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -14,9 +14,7 @@ const gasPriceErrors = [ /Returned error: Transaction gas price \d+wei is too low. There is another transaction with same nonce in the queue with gas price: \d+wei. Try increasing the gas price or incrementing the nonce./, ] -const sameTxErrors = [ - 'Returned error: Transaction with the same hash was already imported.', -] +const sameTxErrors = ['Returned error: Transaction with the same hash was already imported.'] class Transaction { constructor(tx, manager) { @@ -41,9 +39,7 @@ class Transaction { throw new Error('The transaction was already executed') } this.executed = true - this._execute() - .then(this._promise.resolve) - .catch(this._promise.reject) + this._execute().then(this._promise.resolve).catch(this._promise.reject) return this._emitter } @@ -184,7 +180,7 @@ class Transaction { } // Tx is still pending - if (await this._getLastNonce() <= this.tx.nonce) { + if ((await this._getLastNonce()) <= this.tx.nonce) { // todo optionally run estimateGas on each iteration and cancel the transaction if it fails // We were waiting too long, increase gas price and resubmit @@ -206,7 +202,7 @@ class Transaction { // There is a mined tx with current nonce, but it's not one of ours // Probably other tx submitted by other process/client if (!receipt) { - console.log('Can\'t find our transaction receipt, retrying a few times') + console.log("Can't find our transaction receipt, retrying a few times") // Give node a few more attempts to respond with our receipt let retries = 5 while (!receipt && retries--) { @@ -217,7 +213,9 @@ class Transaction { // Receipt was not found after a few retries // Resubmit our tx if (!receipt) { - console.log('There is a mined tx with our nonce but unknown tx hash, resubmitting with tx with increased nonce') + console.log( + 'There is a mined tx with our nonce but unknown tx hash, resubmitting with tx with increased nonce', + ) this.tx.nonce++ // todo drop gas price to original value? await this._send() @@ -293,7 +291,7 @@ class Transaction { * @private */ _hasError(message, errors) { - return errors.find(e => typeof e === 'string' ? e === message : message.match(e)) !== undefined + return errors.find((e) => (typeof e === 'string' ? e === message : message.match(e))) !== undefined } _increaseGasPrice() { diff --git a/src/utils.js b/src/utils.js index 7394b78..88abbbf 100644 --- a/src/utils.js +++ b/src/utils.js @@ -6,7 +6,8 @@ const sleep = (ms) => new Promise((res) => setTimeout(res, ms)) /** * A promise that resolves when the source emits specified event */ -const when = (source, event) => new Promise((resolve, reject) => source.once(event, resolve).on('error', reject)) +const when = (source, event) => + new Promise((resolve, reject) => source.once(event, resolve).on('error', reject)) module.exports = { sleep, diff --git a/test/TxManager.test.js b/test/TxManager.test.js index cf8812e..202a99d 100644 --- a/test/TxManager.test.js +++ b/test/TxManager.test.js @@ -30,7 +30,8 @@ describe('TxManager', () => { it('should work', async () => { const tx = manager.createTx(tx1) - const receipt = await tx.send() + const receipt = await tx + .send() .on('transactionHash', (hash) => console.log('hash', hash)) .on('mined', (receipt) => console.log('Mined in block', receipt.blockNumber)) .on('confirmations', (confirmations) => console.log('confirmations', confirmations)) @@ -43,7 +44,8 @@ describe('TxManager', () => { setTimeout(() => tx.cancel(), 1000) - const receipt = await tx.send() + const receipt = await tx + .send() .on('transactionHash', (hash) => console.log('hash', hash)) .on('mined', (receipt) => console.log('Mined in block', receipt.blockNumber)) .on('confirmations', (confirmations) => console.log('confirmations', confirmations)) @@ -56,7 +58,8 @@ describe('TxManager', () => { setTimeout(() => tx.replace(tx2), 1000) - const receipt = await tx.send() + const receipt = await tx + .send() .on('transactionHash', (hash) => console.log('hash', hash)) .on('mined', (receipt) => console.log('Mined in block', receipt.blockNumber)) .on('confirmations', (confirmations) => console.log('confirmations', confirmations))