@@ -3,6 +3,7 @@ import OutputEntity from 'database/chain/entities/output'
33import { Cell , OutPoint , Input } from 'types/cell-types'
44import { CapacityNotEnough } from 'exceptions'
55import { OutputStatus } from './tx/params'
6+ import SkipDataAndType from './skip-data-and-type'
67
78export const MIN_CELL_CAPACITY = '6100000000'
89
@@ -11,16 +12,27 @@ export const MIN_CELL_CAPACITY = '6100000000'
1112/* eslint no-restricted-syntax: "warn" */
1213export default class CellsService {
1314 // exclude hasData = true and typeScript != null
14- public static getBalance = async ( lockHashes : string [ ] , status : OutputStatus ) : Promise < string > => {
15+ public static getBalance = async (
16+ lockHashes : string [ ] ,
17+ status : OutputStatus ,
18+ skipDataAndType : boolean
19+ ) : Promise < string > => {
20+ const queryParams = {
21+ lockHash : In ( lockHashes ) ,
22+ status,
23+ }
24+
25+ if ( skipDataAndType ) {
26+ Object . assign ( queryParams , {
27+ hasData : false ,
28+ typeScript : null ,
29+ } )
30+ }
31+
1532 const cells : OutputEntity [ ] = await getConnection ( )
1633 . getRepository ( OutputEntity )
1734 . find ( {
18- where : {
19- lockHash : In ( lockHashes ) ,
20- hasData : false ,
21- typeScript : null ,
22- status,
23- } ,
35+ where : queryParams ,
2436 } )
2537
2638 const capacity : bigint = cells . map ( c => BigInt ( c . capacity ) ) . reduce ( ( result , c ) => result + c , BigInt ( 0 ) )
@@ -70,16 +82,23 @@ export default class CellsService {
7082 throw new Error ( `capacity can't be less than ${ MIN_CELL_CAPACITY } ` )
7183 }
7284
85+ const queryParams = {
86+ lockHashes : In ( lockHashes ) ,
87+ status : OutputStatus . Live ,
88+ }
89+ const skipDataAndType = SkipDataAndType . getInstance ( ) . get ( )
90+ if ( skipDataAndType ) {
91+ Object . assign ( queryParams , {
92+ hasData : false ,
93+ typeScript : null ,
94+ } )
95+ }
96+
7397 // only live cells, skip which has data or type
7498 const cellEntities : OutputEntity [ ] = await getConnection ( )
7599 . getRepository ( OutputEntity )
76100 . find ( {
77- where : {
78- lockHash : In ( lockHashes ) ,
79- status : 'live' ,
80- hasData : false ,
81- typeScript : null ,
82- } ,
101+ where : queryParams ,
83102 } )
84103 cellEntities . sort ( ( a , b ) => {
85104 const result = BigInt ( a . capacity ) - BigInt ( b . capacity )
0 commit comments