Skip to content

Commit ee1a131

Browse files
vasildfaustbrian
authored andcommitted
chore: document canEnterTransactionPool() (#3323)
Explain that if canEnterTransactionPool() returns false it would have called processor.pushError(). In addition: Simplify some code that did "if (A) { return false } return true" to "return !A". Remove redundant processor.pushError() from DelegateResignationTransactionHandler() because typeFromSenderAlreadyInPool() would have already pushed a very similar error message. Closes #3322
1 parent c84943a commit ee1a131

File tree

5 files changed

+10
-26
lines changed

5 files changed

+10
-26
lines changed

packages/core-transactions/src/handlers/delegate-resignation.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,7 @@ export class DelegateResignationTransactionHandler extends TransactionHandler {
8383
pool: TransactionPool.IConnection,
8484
processor: TransactionPool.IProcessor,
8585
): Promise<boolean> {
86-
if (await this.typeFromSenderAlreadyInPool(data, pool, processor)) {
87-
const wallet: State.IWallet = pool.walletManager.findByPublicKey(data.senderPublicKey);
88-
processor.pushError(
89-
data,
90-
"ERR_PENDING",
91-
`Delegate resignation for "${wallet.getAttribute("delegate.username")}" already in the pool`,
92-
);
93-
return false;
94-
}
95-
96-
return true;
86+
return !await this.typeFromSenderAlreadyInPool(data, pool, processor);
9787
}
9888

9989
public async applyToSender(

packages/core-transactions/src/handlers/multi-signature.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,7 @@ export class MultiSignatureTransactionHandler extends TransactionHandler {
9696
pool: TransactionPool.IConnection,
9797
processor: TransactionPool.IProcessor,
9898
): Promise<boolean> {
99-
if (await this.typeFromSenderAlreadyInPool(data, pool, processor)) {
100-
return false;
101-
}
102-
103-
return true;
99+
return !await this.typeFromSenderAlreadyInPool(data, pool, processor);
104100
}
105101

106102
public async applyToSender(

packages/core-transactions/src/handlers/second-signature.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ export class SecondSignatureTransactionHandler extends TransactionHandler {
5555
pool: TransactionPool.IConnection,
5656
processor: TransactionPool.IProcessor,
5757
): Promise<boolean> {
58-
if (await this.typeFromSenderAlreadyInPool(data, pool, processor)) {
59-
return false;
60-
}
61-
62-
return true;
58+
return !await this.typeFromSenderAlreadyInPool(data, pool, processor);
6359
}
6460

6561
public async applyToSender(

packages/core-transactions/src/handlers/vote.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ export class VoteTransactionHandler extends TransactionHandler {
106106
pool: TransactionPool.IConnection,
107107
processor: TransactionPool.IProcessor,
108108
): Promise<boolean> {
109-
if (await this.typeFromSenderAlreadyInPool(data, pool, processor)) {
110-
return false;
111-
}
112-
113-
return true;
109+
return !await this.typeFromSenderAlreadyInPool(data, pool, processor);
114110
}
115111

116112
public async applyToSender(

packages/core-transactions/src/interfaces.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ export interface ITransactionHandler {
2525
apply(transaction: Interfaces.ITransaction, walletManager: State.IWalletManager): Promise<void>;
2626
revert(transaction: Interfaces.ITransaction, walletManager: State.IWalletManager): Promise<void>;
2727

28+
/**
29+
* Check if a transaction of this type can enter the pool.
30+
* If `false` is returned to designate that the transaction cannot enter the pool,
31+
* then this method will have called processor.pushError() to give a detailed
32+
* description of the reason.
33+
*/
2834
canEnterTransactionPool(
2935
data: Interfaces.ITransactionData,
3036
pool: TransactionPool.IConnection,

0 commit comments

Comments
 (0)