From 4b25c077eed6321a685f7710e22f1ea0a6c25519 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Wed, 27 Mar 2019 07:04:57 +0200 Subject: [PATCH 1/5] feat: add more block and transaction pool events --- packages/core-blockchain/src/blockchain.ts | 6 ++++++ packages/core-transaction-pool/src/connection.ts | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/core-blockchain/src/blockchain.ts b/packages/core-blockchain/src/blockchain.ts index b85c99050d..8ef8828af5 100644 --- a/packages/core-blockchain/src/blockchain.ts +++ b/packages/core-blockchain/src/blockchain.ts @@ -262,6 +262,8 @@ export class Blockchain implements blockchain.IBlockchain { } else { logger.info(`Block disregarded because blockchain is not ready`); } + + emitter.emit("block.received", block); } /** @@ -539,6 +541,7 @@ export class Blockchain implements blockchain.IBlockchain { "block.applied", "block.forged", "block.reverted", + "block.received", "delegate.registered", "delegate.resigned", "forger.failed", @@ -552,6 +555,9 @@ export class Blockchain implements blockchain.IBlockchain { "transaction.expired", "transaction.forged", "transaction.reverted", + "transaction.pool.added", + "transaction.pool.not-added", + "transaction.pool.removed", "wallet.saved", "wallet.created.cold", ]; diff --git a/packages/core-transaction-pool/src/connection.ts b/packages/core-transaction-pool/src/connection.ts index f30d8abf3e..60216213db 100644 --- a/packages/core-transaction-pool/src/connection.ts +++ b/packages/core-transaction-pool/src/connection.ts @@ -137,6 +137,14 @@ export class TransactionPool implements transactionPool.ITransactionPool { } } + if (added.length > 0) { + this.emitter.emit("transaction.pool.added", added); + } + + if (notAdded.length > 0) { + this.emitter.emit("transaction.pool.not-added", notAdded); + } + return { added, notAdded }; } @@ -216,6 +224,8 @@ export class TransactionPool implements transactionPool.ITransactionPool { this.mem.remove(id, senderPublicKey); this.__syncToPersistentStorageIfNecessary(); + + this.emitter.emit("transaction.pool.removed", id); } /** From ae176cab683551c454233926bcbf0c0b3ae1e36c Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Wed, 27 Mar 2019 08:17:26 +0200 Subject: [PATCH 2/5] feat(core-blockchain): add block.disregarded event --- packages/core-blockchain/src/blockchain.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/core-blockchain/src/blockchain.ts b/packages/core-blockchain/src/blockchain.ts index 8ef8828af5..54152bb53b 100644 --- a/packages/core-blockchain/src/blockchain.ts +++ b/packages/core-blockchain/src/blockchain.ts @@ -259,11 +259,13 @@ export class Blockchain implements blockchain.IBlockchain { if (this.state.started) { this.dispatch("NEWBLOCK"); this.enqueueBlocks([block]); + + emitter.emit("block.received", block); } else { logger.info(`Block disregarded because blockchain is not ready`); + + emitter.emit("block.disregarded", block); } - - emitter.emit("block.received", block); } /** @@ -542,6 +544,7 @@ export class Blockchain implements blockchain.IBlockchain { "block.forged", "block.reverted", "block.received", + "block.disregarded", "delegate.registered", "delegate.resigned", "forger.failed", From 9119e6375d8cf7f444c9fdcf8bc290d2e73d6385 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Wed, 27 Mar 2019 10:59:44 +0200 Subject: [PATCH 3/5] test(core-blockchain): update getEvent return assertion --- __tests__/unit/core-blockchain/blockchain.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/__tests__/unit/core-blockchain/blockchain.test.ts b/__tests__/unit/core-blockchain/blockchain.test.ts index b99704d3d0..7ecb57b4fa 100644 --- a/__tests__/unit/core-blockchain/blockchain.test.ts +++ b/__tests__/unit/core-blockchain/blockchain.test.ts @@ -303,6 +303,7 @@ describe("Blockchain", () => { "block.applied", "block.forged", "block.reverted", + "block.received", "delegate.registered", "delegate.resigned", "forger.failed", @@ -316,6 +317,9 @@ describe("Blockchain", () => { "transaction.expired", "transaction.forged", "transaction.reverted", + "transaction.pool.added", + "transaction.pool.not-added", + "transaction.pool.removed", "wallet.saved", "wallet.created.cold", ]); From 48af43925bb3ccdbd08cad99d98739380823ee77 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Wed, 27 Mar 2019 11:06:05 +0200 Subject: [PATCH 4/5] test(core-blockchain): add block.disregarded to expected events --- __tests__/unit/core-blockchain/blockchain.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/__tests__/unit/core-blockchain/blockchain.test.ts b/__tests__/unit/core-blockchain/blockchain.test.ts index 7ecb57b4fa..518d68a038 100644 --- a/__tests__/unit/core-blockchain/blockchain.test.ts +++ b/__tests__/unit/core-blockchain/blockchain.test.ts @@ -304,6 +304,7 @@ describe("Blockchain", () => { "block.forged", "block.reverted", "block.received", + "block.disregarded", "delegate.registered", "delegate.resigned", "forger.failed", From 3f36a46fd83353692d8447b153e9e83b2485b4ca Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Wed, 27 Mar 2019 13:42:42 +0200 Subject: [PATCH 5/5] refactor: rename transaction.pool.not-added to transaction.pool.rejected --- __tests__/unit/core-blockchain/blockchain.test.ts | 2 +- packages/core-blockchain/src/blockchain.ts | 6 +++--- packages/core-transaction-pool/src/connection.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/unit/core-blockchain/blockchain.test.ts b/__tests__/unit/core-blockchain/blockchain.test.ts index 518d68a038..4f8aa775de 100644 --- a/__tests__/unit/core-blockchain/blockchain.test.ts +++ b/__tests__/unit/core-blockchain/blockchain.test.ts @@ -319,7 +319,7 @@ describe("Blockchain", () => { "transaction.forged", "transaction.reverted", "transaction.pool.added", - "transaction.pool.not-added", + "transaction.pool.rejected", "transaction.pool.removed", "wallet.saved", "wallet.created.cold", diff --git a/packages/core-blockchain/src/blockchain.ts b/packages/core-blockchain/src/blockchain.ts index 54152bb53b..d51a86b328 100644 --- a/packages/core-blockchain/src/blockchain.ts +++ b/packages/core-blockchain/src/blockchain.ts @@ -259,11 +259,11 @@ export class Blockchain implements blockchain.IBlockchain { if (this.state.started) { this.dispatch("NEWBLOCK"); this.enqueueBlocks([block]); - + emitter.emit("block.received", block); } else { logger.info(`Block disregarded because blockchain is not ready`); - + emitter.emit("block.disregarded", block); } } @@ -559,7 +559,7 @@ export class Blockchain implements blockchain.IBlockchain { "transaction.forged", "transaction.reverted", "transaction.pool.added", - "transaction.pool.not-added", + "transaction.pool.rejected", "transaction.pool.removed", "wallet.saved", "wallet.created.cold", diff --git a/packages/core-transaction-pool/src/connection.ts b/packages/core-transaction-pool/src/connection.ts index 60216213db..55549e6fbe 100644 --- a/packages/core-transaction-pool/src/connection.ts +++ b/packages/core-transaction-pool/src/connection.ts @@ -142,7 +142,7 @@ export class TransactionPool implements transactionPool.ITransactionPool { } if (notAdded.length > 0) { - this.emitter.emit("transaction.pool.not-added", notAdded); + this.emitter.emit("transaction.pool.rejected", notAdded); } return { added, notAdded };