Skip to content

Commit

Permalink
chore: document canEnterTransactionPool() (#3323)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vasild authored and faustbrian committed Dec 5, 2019
1 parent c84943a commit ee1a131
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 26 deletions.
12 changes: 1 addition & 11 deletions packages/core-transactions/src/handlers/delegate-resignation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,7 @@ export class DelegateResignationTransactionHandler extends TransactionHandler {
pool: TransactionPool.IConnection,
processor: TransactionPool.IProcessor,
): Promise<boolean> {
if (await this.typeFromSenderAlreadyInPool(data, pool, processor)) {
const wallet: State.IWallet = pool.walletManager.findByPublicKey(data.senderPublicKey);
processor.pushError(
data,
"ERR_PENDING",
`Delegate resignation for "${wallet.getAttribute("delegate.username")}" already in the pool`,
);
return false;
}

return true;
return !await this.typeFromSenderAlreadyInPool(data, pool, processor);
}

public async applyToSender(
Expand Down
6 changes: 1 addition & 5 deletions packages/core-transactions/src/handlers/multi-signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ export class MultiSignatureTransactionHandler extends TransactionHandler {
pool: TransactionPool.IConnection,
processor: TransactionPool.IProcessor,
): Promise<boolean> {
if (await this.typeFromSenderAlreadyInPool(data, pool, processor)) {
return false;
}

return true;
return !await this.typeFromSenderAlreadyInPool(data, pool, processor);
}

public async applyToSender(
Expand Down
6 changes: 1 addition & 5 deletions packages/core-transactions/src/handlers/second-signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ export class SecondSignatureTransactionHandler extends TransactionHandler {
pool: TransactionPool.IConnection,
processor: TransactionPool.IProcessor,
): Promise<boolean> {
if (await this.typeFromSenderAlreadyInPool(data, pool, processor)) {
return false;
}

return true;
return !await this.typeFromSenderAlreadyInPool(data, pool, processor);
}

public async applyToSender(
Expand Down
6 changes: 1 addition & 5 deletions packages/core-transactions/src/handlers/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ export class VoteTransactionHandler extends TransactionHandler {
pool: TransactionPool.IConnection,
processor: TransactionPool.IProcessor,
): Promise<boolean> {
if (await this.typeFromSenderAlreadyInPool(data, pool, processor)) {
return false;
}

return true;
return !await this.typeFromSenderAlreadyInPool(data, pool, processor);
}

public async applyToSender(
Expand Down
6 changes: 6 additions & 0 deletions packages/core-transactions/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export interface ITransactionHandler {
apply(transaction: Interfaces.ITransaction, walletManager: State.IWalletManager): Promise<void>;
revert(transaction: Interfaces.ITransaction, walletManager: State.IWalletManager): Promise<void>;

/**
* Check if a transaction of this type can enter the pool.
* If `false` is returned to designate that the transaction cannot enter the pool,
* then this method will have called processor.pushError() to give a detailed
* description of the reason.
*/
canEnterTransactionPool(
data: Interfaces.ITransactionData,
pool: TransactionPool.IConnection,
Expand Down

0 comments on commit ee1a131

Please sign in to comment.