Skip to content

Commit

Permalink
fix(core-transactions): throw if transaction key is already tak… (#3095)
Browse files Browse the repository at this point in the history
  • Loading branch information
spkjp committed Nov 21, 2019
1 parent b96bb49 commit eaadddc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/crypto/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ export class TransactionAlreadyRegisteredError extends CryptoError {
}
}

export class TransactionKeyAlreadyRegisteredError extends CryptoError {
constructor(name: string) {
super(`Transaction key ${name} is already registered.`);
}
}

export class CoreTransactionTypeGroupImmutableError extends CryptoError {
constructor() {
super(`The Core transaction type group is immutable.`);
Expand Down
5 changes: 5 additions & 0 deletions packages/crypto/src/transactions/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TransactionTypeGroup } from "../enums";
import {
CoreTransactionTypeGroupImmutableError,
TransactionAlreadyRegisteredError,
TransactionKeyAlreadyRegisteredError,
UnkownTransactionError,
} from "../errors";
import { validator } from "../validation";
Expand Down Expand Up @@ -60,6 +61,10 @@ class TransactionRegistry {
throw new TransactionAlreadyRegisteredError(constructor.name);
}

if (Array.from(this.transactionTypes.values()).some(({ key }) => key === constructor.key)) {
throw new TransactionKeyAlreadyRegisteredError(constructor.key);
}

this.transactionTypes.set(internalType, constructor);
this.updateSchemas(constructor);
}
Expand Down

0 comments on commit eaadddc

Please sign in to comment.