import { IAsset , Transaction } from 'shared/model/transaction' ; import { TransactionId } from 'shared/model/types' ; import { Address } from 'shared/model/types' ; export interface ITransactionRepository < T extends IAsset > { add ( trs ) : Transaction < T > ; delete ( id ) : void ; has ( trsId ) : boolean ; getById ( transactionId ) : Transaction < IAsset > ; size : number ; } class TransactionRepo implements ITransactionRepository < IAsset > { private readonly memoryTransactionsById : Map < TransactionId , Transaction < IAsset > > = new Map ( ) ; add ( trs ) { this . memoryTransactionsById . set ( trs . id , trs ) ; return trs ; } delete ( id ) { this . memoryTransactionsById . delete ( id ) ; } public has ( id ) { return this . memoryTransactionsById . has ( id ) ; } public getById ( id ) { return this . memoryTransactionsById . get ( id ) ; } public getByAddress ( address ) { const filteredTransaction = [ ] ; for ( const trs of this . memoryTransactionsById . values ( ) ) { if ( trs . senderAddress === address ) { filteredTransaction . push ( trs ) ; } } return filteredTransaction ; } get size ( ) : number { return this . memoryTransactionsById . size ; } } export default new TransactionRepo ( ) ;