@@ -19,6 +19,7 @@ import RpcService from '../services/rpc-service'
1919import TransactionWithStatus from '../models/chain/transaction-with-status'
2020import TxStatus from '../models/chain/tx-status'
2121import SystemScriptInfo from '../models/system-script-info'
22+ import OutPoint from '../models/chain/out-point'
2223
2324const max64Int = '0x' + 'f' . repeat ( 16 )
2425export default class MultisigService {
@@ -182,25 +183,44 @@ export default class MultisigService {
182183 daoTxHash . add ( cell . out_point . tx_hash )
183184 }
184185 } )
186+
187+ const network = NetworksService . getInstance ( ) . getCurrent ( )
188+ const rpcService = new RpcService ( network . remote , network . type )
189+
190+ const getTx = async ( txHash : string ) => {
191+ const txWithStatus : TransactionWithStatus | undefined | { transaction : null ; txStatus : TxStatus } =
192+ await rpcService . getTransaction ( txHash )
193+ if ( txWithStatus ?. transaction ) {
194+ const tx = Transaction . fromSDK ( txWithStatus . transaction )
195+ tx . blockHash = txWithStatus . txStatus . blockHash || undefined
196+ if ( tx . blockHash ) {
197+ const header = await rpcService . getHeader ( tx . blockHash )
198+ tx . timestamp = header ?. timestamp
199+ tx . blockNumber = header ?. number
200+ }
201+ return tx
202+ }
203+ }
204+
185205 if ( daoTxHash . size > 0 ) {
186- const network = NetworksService . getInstance ( ) . getCurrent ( )
187- const rpcService = new RpcService ( network . remote , network . type )
188206 for ( const txHash of daoTxHash ) {
189- const txWithStatus : TransactionWithStatus | undefined | { transaction : null ; txStatus : TxStatus } =
190- await rpcService . getTransaction ( txHash )
191- if ( txWithStatus ?. transaction ) {
192- const tx = Transaction . fromSDK ( txWithStatus . transaction )
193- tx . blockHash = txWithStatus . txStatus . blockHash || undefined
194- if ( tx . blockHash ) {
195- const header = await rpcService . getHeader ( tx . blockHash )
196- tx . timestamp = header ?. timestamp
197- tx . blockNumber = header ?. number
198- }
199- tx . outputsData . forEach ( ( item , index ) => {
200- if ( item === DAO_DATA ) {
201- tx . outputs [ index ] . daoData = DAO_DATA
207+ const tx = await getTx ( txHash )
208+ if ( tx ) {
209+ const previousTxHashes : string [ ] = [ ]
210+ tx . outputs . forEach ( ( output , index ) => {
211+ if ( output . type ?. codeHash === SystemScriptInfo . DAO_CODE_HASH ) {
212+ output . daoData = tx . outputsData [ index ]
213+ if ( tx . outputsData [ index ] !== DAO_DATA ) {
214+ const previousTxHash = tx . inputs [ index ] . previousOutput ! . txHash
215+ previousTxHashes . push ( previousTxHash )
216+ output . setDepositOutPoint ( new OutPoint ( previousTxHash , tx . inputs [ index ] . previousOutput ! . index ) )
217+ }
202218 }
203219 } )
220+ for ( const previousTxHash of previousTxHashes ) {
221+ const previousTx = await getTx ( previousTxHash )
222+ if ( previousTx ) await TransactionPersistor . saveFetchTx ( previousTx )
223+ }
204224 await TransactionPersistor . saveFetchTx ( tx )
205225 }
206226 }
0 commit comments