@@ -585,36 +585,28 @@ export default class TransactionsService {
585585 return [ ...new Set ( inputBlake160s . concat ( outputBlake160s ) ) ]
586586 }
587587
588- // tx count with one lockHash
589- public static getCountByLockHash = async ( lockHash : string ) : Promise < number > => {
590- const outputs : OutputEntity [ ] = await getConnection ( )
591- . getRepository ( OutputEntity )
592- . createQueryBuilder ( 'output' )
593- . where ( `output.lockHash = :lockHash` , { lockHash } )
594- . select ( 'DISTINCT output.outPointTxHash' , 'outPointTxHash' )
595- . getRawMany ( )
596-
597- const outputTxHashes : string [ ] = outputs . map ( output => output . outPointTxHash )
598-
599- const inputs : InputEntity [ ] = await getConnection ( )
600- . getRepository ( InputEntity )
601- . createQueryBuilder ( 'input' )
602- . where ( `input.lockHash = :lockHash` , { lockHash } )
603- . select ( `DISTINCT input.transactionHash` , 'transactionHash' )
604- . getRawMany ( )
605-
606- const inputTxHashes : string [ ] = inputs . map ( ( input : any ) => input . transactionHash )
607-
608- const hashes : string [ ] = [ ...new Set ( outputTxHashes . concat ( inputTxHashes ) ) ]
609-
610- const count : number = hashes . length
588+ // tx count with one lockHash and status
589+ public static getCountByLockHashAndStatus = async (
590+ lockHash : string ,
591+ status : TransactionStatus [ ]
592+ ) : Promise < number > => {
593+ const count : number = await getConnection ( )
594+ . getRepository ( TransactionEntity )
595+ . createQueryBuilder ( 'tx' )
596+ . leftJoinAndSelect ( 'tx.inputs' , 'input' )
597+ . leftJoinAndSelect ( 'tx.outputs' , 'output' )
598+ . where ( `(input.lockHash = :lockHash OR output.lockHash = :lockHash) AND tx.status IN (:...status)` , {
599+ lockHash,
600+ status,
601+ } )
602+ . getCount ( )
611603
612604 return count
613605 }
614606
615- public static getCountByAddress = async ( address : string ) : Promise < number > => {
607+ public static getCountByAddressAndStatus = async ( address : string , status : TransactionStatus [ ] ) : Promise < number > => {
616608 const lockHash : string = await LockUtils . addressToLockHash ( address )
617- return TransactionsService . getCountByLockHash ( lockHash )
609+ return TransactionsService . getCountByLockHashAndStatus ( lockHash , status )
618610 }
619611
620612 public static pendings = async ( ) : Promise < TransactionEntity [ ] > => {
0 commit comments