@@ -79,7 +79,24 @@ export default class MultisigService {
7979 . createQueryBuilder ( )
8080 . orderBy ( 'id' , 'DESC' )
8181 . getMany ( )
82- return result
82+ const existMultisigLockHash : Set < string > = new Set ( )
83+ const uniqueMultisigConfigs : MultisigConfig [ ] = [ ]
84+ for ( const multisigConfig of result ) {
85+ const multisigLockHash = Multisig . getMultisigScript (
86+ multisigConfig . blake160s ,
87+ multisigConfig . r ,
88+ multisigConfig . m ,
89+ multisigConfig . n ,
90+ multisigConfig . lockCodeHash
91+ ) . computeHash ( )
92+ if ( existMultisigLockHash . has ( multisigLockHash ) ) {
93+ await this . deleteConfig ( multisigConfig . id )
94+ } else {
95+ existMultisigLockHash . add ( multisigLockHash )
96+ uniqueMultisigConfigs . push ( multisigConfig )
97+ }
98+ }
99+ return uniqueMultisigConfigs
83100 }
84101
85102 async getMultisigConfigById ( id : number ) {
@@ -141,7 +158,7 @@ export default class MultisigService {
141158 } ,
142159 'desc' ,
143160 '0x64' ,
144- addressCursorMap . get ( script . args ) ,
161+ addressCursorMap . get ( scriptToHash ( script ) ) ,
145162 ] ,
146163 }
147164 } )
@@ -151,7 +168,7 @@ export default class MultisigService {
151168 if ( ! v . error && v ?. result ?. objects ?. length ) {
152169 const config = currentMultisigConfigs [ idx ]
153170 const script = Multisig . getMultisigScript ( config . blake160s , config . r , config . m , config . n , config . lockCodeHash )
154- addressCursorMap . set ( script . args , v ?. result ?. last_cursor )
171+ addressCursorMap . set ( scriptToHash ( script ) , v ?. result ?. last_cursor )
155172 cells . push ( ...v . result . objects )
156173 nextMultisigConfigs . push ( currentMultisigConfigs [ idx ] )
157174 }
@@ -176,54 +193,39 @@ export default class MultisigService {
176193 }
177194
178195 static async saveMultisigDaoTx ( multisigConfigs : MultisigConfig [ ] ) {
179- const cells = await MultisigService . getCells ( multisigConfigs )
180- if ( cells . length ) {
181- const daoTxHash = new Set < string > ( )
182- cells . forEach ( cell => {
183- if ( cell . output ?. type ?. code_hash === SystemScriptInfo . DAO_CODE_HASH ) {
184- daoTxHash . add ( cell . out_point . tx_hash )
185- }
186- } )
187-
188- const network = NetworksService . getInstance ( ) . getCurrent ( )
189- const rpcService = new RpcService ( network . remote , network . type )
190-
191- const getTx = async ( txHash : string ) => {
192- const txWithStatus : TransactionWithStatus | undefined | { transaction : null ; txStatus : TxStatus } =
193- await rpcService . getTransaction ( txHash )
194- if ( txWithStatus ?. transaction ) {
195- const tx = Transaction . fromSDK ( txWithStatus . transaction )
196- tx . blockHash = txWithStatus . txStatus . blockHash || undefined
197- if ( tx . blockHash ) {
198- const header = await rpcService . getHeader ( tx . blockHash )
199- tx . timestamp = header ?. timestamp
200- tx . blockNumber = header ?. number
201- }
202- return tx
196+ const network = NetworksService . getInstance ( ) . getCurrent ( )
197+ const rpcService = new RpcService ( network . remote , network . type )
198+ const getTx = async ( txHash : string ) => {
199+ const txWithStatus : TransactionWithStatus | undefined | { transaction : null ; txStatus : TxStatus } =
200+ await rpcService . getTransaction ( txHash )
201+ if ( txWithStatus ?. transaction ) {
202+ const tx = Transaction . fromSDK ( txWithStatus . transaction )
203+ tx . blockHash = txWithStatus . txStatus . blockHash || undefined
204+ if ( tx . blockHash ) {
205+ const header = await rpcService . getHeader ( tx . blockHash )
206+ tx . timestamp = header ?. timestamp
207+ tx . blockNumber = header ?. number
203208 }
209+ return tx
204210 }
205-
206- if ( daoTxHash . size > 0 ) {
207- for ( const txHash of daoTxHash ) {
208- const tx = await getTx ( txHash )
209- if ( tx ) {
210- const previousTxHashes : string [ ] = [ ]
211- tx . outputs . forEach ( ( output , index ) => {
212- if ( output . type ?. codeHash === SystemScriptInfo . DAO_CODE_HASH ) {
213- output . daoData = tx . outputsData [ index ]
214- if ( tx . outputsData [ index ] !== DAO_DATA ) {
215- const previousTxHash = tx . inputs [ index ] . previousOutput ! . txHash
216- previousTxHashes . push ( previousTxHash )
217- output . setDepositOutPoint ( new OutPoint ( previousTxHash , tx . inputs [ index ] . previousOutput ! . index ) )
218- }
211+ }
212+ const multisigTxHashList = await MultisigService . getMultisigTransactionHashList ( multisigConfigs )
213+ for ( const txHash of [ ... multisigTxHashList ] . reverse ( ) ) {
214+ const tx = await getTx ( txHash )
215+ if ( tx ) {
216+ if ( tx . inputs . some ( input => input . since && + input . since > 0 ) ) {
217+ await TransactionPersistor . saveFetchTx ( tx )
218+ } else if ( tx . outputs . some ( output => output . type ?. codeHash === SystemScriptInfo . DAO_CODE_HASH ) ) {
219+ tx . outputs . forEach ( ( output , index ) => {
220+ if ( output . type ?. codeHash === SystemScriptInfo . DAO_CODE_HASH ) {
221+ output . daoData = tx . outputsData [ index ]
222+ if ( tx . outputsData [ index ] !== DAO_DATA ) {
223+ const previousTxHash = tx . inputs [ index ] . previousOutput ! . txHash
224+ output . setDepositOutPoint ( new OutPoint ( previousTxHash , tx . inputs [ index ] . previousOutput ! . index ) )
219225 }
220- } )
221- for ( const previousTxHash of previousTxHashes ) {
222- const previousTx = await getTx ( previousTxHash )
223- if ( previousTx ) await TransactionPersistor . saveFetchTx ( previousTx )
224226 }
225- await TransactionPersistor . saveFetchTx ( tx )
226- }
227+ } )
228+ await TransactionPersistor . saveFetchTx ( tx )
227229 }
228230 }
229231 }
@@ -255,7 +257,7 @@ export default class MultisigService {
255257 } ,
256258 'desc' ,
257259 '0x64' ,
258- addressCursorMap . get ( script . args ) ,
260+ addressCursorMap . get ( scriptToHash ( script ) ) ,
259261 ] ,
260262 }
261263 } )
@@ -265,7 +267,7 @@ export default class MultisigService {
265267 if ( ! v . error && v ?. result ?. objects ?. length ) {
266268 const config = currentMultisigConfigs [ idx ]
267269 const script = Multisig . getMultisigScript ( config . blake160s , config . r , config . m , config . n , config . lockCodeHash )
268- addressCursorMap . set ( script . args , v ?. result ?. last_cursor )
270+ addressCursorMap . set ( scriptToHash ( script ) , v ?. result ?. last_cursor )
269271 v . result . objects . forEach ( ( obj : any ) => {
270272 multisigOutputTxHashList . add ( obj . tx_hash || obj . transaction ?. hash )
271273 } )
0 commit comments