@@ -19,9 +19,15 @@ import { MIN_CELL_CAPACITY, UDTType } from '../utils/const'
1919import SudtTokenInfoService from './sudt-token-info'
2020
2121export default class AssetAccountService {
22- public static async getACPCells ( publicKeyHash : string , tokenId : string = 'CKBytes' , udtType ?: UDTType ) {
22+ public static async getACPCells (
23+ publicKeyHash : string ,
24+ tokenId : string = 'CKBytes' ,
25+ udtType ?: UDTType ,
26+ outpoint ?: OutPoint
27+ ) {
2328 const assetAccountInfo = new AssetAccountInfo ( )
2429 const anyoneCanPayLockHash = assetAccountInfo . generateAnyoneCanPayScript ( publicKeyHash ) . computeHash ( )
30+
2531 const outputs = await getConnection ( )
2632 . getRepository ( OutputEntity )
2733 . findBy ( {
@@ -31,6 +37,12 @@ export default class AssetAccountService {
3137 tokenId !== 'CKBytes'
3238 ? assetAccountInfo . generateUdtScript ( tokenId , udtType ?? UDTType . SUDT ) ! . computeHash ( )
3339 : IsNull ( ) ,
40+ ...( outpoint
41+ ? {
42+ outPointTxHash : outpoint . txHash ,
43+ outPointIndex : outpoint . index ,
44+ }
45+ : { } ) ,
3446 } )
3547
3648 return outputs
@@ -52,7 +64,12 @@ export default class AssetAccountService {
5264 return availableBalance >= 0 ? availableBalance . toString ( ) : BigInt ( 0 )
5365 }
5466
55- public static async calculateUDTAccountBalance ( publicKeyHash : string , tokenId : string , udtType ?: UDTType ) {
67+ public static async calculateUDTAccountBalance (
68+ publicKeyHash : string ,
69+ tokenId : string ,
70+ udtType ?: UDTType ,
71+ outpoint ?: OutPoint
72+ ) {
5673 const assetAccountInfo = new AssetAccountInfo ( )
5774 const anyoneCanPayLockHash = assetAccountInfo . generateAnyoneCanPayScript ( publicKeyHash ) . computeHash ( )
5875 const typeHash =
@@ -66,6 +83,12 @@ export default class AssetAccountService {
6683 status : In ( [ OutputStatus . Live , OutputStatus . Sent ] ) ,
6784 lockHash : anyoneCanPayLockHash ,
6885 typeHash,
86+ ...( outpoint
87+ ? {
88+ outPointTxHash : outpoint . txHash ,
89+ outPointIndex : outpoint . index ,
90+ }
91+ : { } ) ,
6992 } )
7093 . getMany ( )
7194
@@ -117,10 +140,11 @@ export default class AssetAccountService {
117140 holder : string
118141 tokenID : string
119142 receiver : string
120- udtType : UDTType
143+ udtType ?: UDTType
144+ outpoint ?: CKBComponents . OutPoint
121145 } ) {
122- const { walletId, holder, tokenID, udtType, receiver } = params
123- const cells = await AssetAccountService . getACPCells ( holder , tokenID , udtType )
146+ const { walletId, holder, tokenID, receiver , udtType, outpoint } = params
147+ const cells = await AssetAccountService . getACPCells ( holder , tokenID , udtType , outpoint )
124148
125149 if ( ! cells . length ) {
126150 throw new Error ( `No cells found!` )
0 commit comments