@@ -4,24 +4,35 @@ import { getConnection } from 'typeorm'
44import { TransactionStatus } from 'types/cell-types'
55import LockUtils from 'models/lock-utils'
66import AddressesUsedSubject from 'models/subjects/addresses-used-subject'
7- import { FailedTransaction } from 'services/tx'
7+ import { FailedTransaction , TransactionPersistor } from 'services/tx'
88import { CONNECTION_NOT_FOUND_NAME } from 'database/chain/ormconfig'
9+ import TypeConvert from 'types/type-convert'
910
1011const { nodeService } = remote . require ( './startup/sync-block-task/params' )
1112
1213const getTransactionStatus = async ( hash : string ) => {
1314 const { core } = nodeService
14- // getTransaction function return type seems error
15- const tx = ( await core . rpc . getTransaction ( hash ) ) as any
15+ const tx = ( await core . rpc . getTransaction ( hash ) ) as CKBComponents . TransactionWithStatus
1616 if ( ! tx ) {
17- return TransactionStatus . Failed
17+ return {
18+ tx,
19+ status : TransactionStatus . Failed ,
20+ }
1821 }
1922 if ( tx . txStatus . status === 'committed' ) {
20- return TransactionStatus . Success
23+ return {
24+ tx : tx . transaction ,
25+ status : TransactionStatus . Success ,
26+ }
27+ }
28+ return {
29+ tx : tx . transaction ,
30+ status : TransactionStatus . Pending ,
2131 }
22- return TransactionStatus . Pending
2332}
2433
34+ /* eslint no-await-in-loop: "off" */
35+ /* eslint no-restricted-syntax: "off" */
2536const trackingStatus = async ( ) => {
2637 const pendingTransactions = await FailedTransaction . pendings ( )
2738 if ( ! pendingTransactions . length ) {
@@ -30,20 +41,27 @@ const trackingStatus = async () => {
3041 const pendingHashes = pendingTransactions . map ( tx => tx . hash )
3142 const txs = await Promise . all (
3243 pendingHashes . map ( async hash => {
33- const status = await getTransactionStatus ( hash )
44+ const txWithStatus = await getTransactionStatus ( hash )
3445 return {
3546 hash,
36- status,
47+ tx : txWithStatus . tx ,
48+ status : txWithStatus . status ,
3749 }
3850 } )
3951 )
4052 const failedTxs = txs . filter ( tx => tx . status === TransactionStatus . Failed )
41- if ( ! failedTxs . length ) {
42- return
53+ const successTxs = txs . filter ( tx => tx . status === TransactionStatus . Success )
54+
55+ if ( failedTxs . length ) {
56+ const blake160s = await FailedTransaction . updateFailedTxs ( failedTxs . map ( tx => tx . hash ) )
57+ const usedAddresses = blake160s . map ( blake160 => LockUtils . blake160ToAddress ( blake160 ) )
58+ AddressesUsedSubject . getSubject ( ) . next ( usedAddresses )
59+ }
60+
61+ for ( const successTx of successTxs ) {
62+ const transaction = TypeConvert . toTransaction ( successTx . tx )
63+ await TransactionPersistor . saveFetchTx ( transaction )
4364 }
44- const blake160s = await FailedTransaction . updateFailedTxs ( failedTxs . map ( tx => tx . hash ) )
45- const usedAddresses = blake160s . map ( blake160 => LockUtils . blake160ToAddress ( blake160 ) )
46- AddressesUsedSubject . getSubject ( ) . next ( usedAddresses )
4765}
4866
4967export const register = ( ) => {
0 commit comments