@@ -14,12 +14,13 @@ import Input from '../../models/chain/input'
1414import CellsService from '../../services/cells'
1515import OutPoint from '../../models/chain/out-point'
1616import RpcService from '../../services/rpc-service'
17- import { TransactionsService } from '../tx'
17+ // import { TransactionsService } from '../tx'
1818import NetworksService from '../networks'
19- import { LightRPC } from 'src/utils/ckb-rpc'
20- import { NetworkType } from '../../models/network'
19+ // import { LightRPC } from 'src/utils/ckb-rpc'
20+ // import { NetworkType } from '../../models/network'
2121import generateConfigFiles , { ConfigFileOptions } from './configFiles'
2222import SettingsService from '../settings'
23+ import { fetchTargetCell } from './fetchCell'
2324
2425const { app } = env
2526
@@ -318,29 +319,30 @@ export class PerunServiceRunner {
318319 let liveCell = undefined
319320 while ( retries < 25 ) {
320321 const fetchedCell = await CellsService . getLiveCell ( OutPoint . fromObject ( input . previousOutput ) )
321- const outputs = await CellsService . getOutputsByTransactionHash ( input . previousOutput . txHash )
322- logger . info ( 'fetched outputs:' , outputs )
323- const tx = await TransactionsService . get ( input . previousOutput . txHash )
324- logger . info ( 'fetched tx:' , tx )
322+ // const outputs = await CellsService.getOutputsByTransactionHash(input.previousOutput.txHash)
323+ // logger.info('fetched outputs:', outputs)
324+ // const tx = await TransactionsService.get(input.previousOutput.txHash)
325+ // logger.info('fetched tx:', tx)
325326 if ( fetchedCell ) {
326327 liveCell = fetchedCell
327328 break
328329 }
329330 logger . info ( 'USING RPC-SERVICE' )
330- const rpcTip = await rpcService . getTipHeader ( )
331- logger . info ( 'TIP:' , rpcTip )
331+ // const rpcTip = await rpcService.getTipHeader()
332+ // logger.info('TIP:', rpcTip)
332333 // const rpcTx = await rpcService.getTransaction(input.previousOutput.txHash)
333- const rpcTx = network . type === NetworkType . Light
334- // light rpc did't include the tx of peer A user
335- ? await ( await ( rpcService . rpc as LightRPC ) . fetchTransaction ( input . previousOutput . txHash ) ) . txWithStatus
336- : await rpcService . getTransaction ( input . previousOutput . txHash )
337- logger . info ( 'RPC-TX:' , rpcTx )
338-
339- if ( rpcTx ?. transaction ) {
340- logger . info ( "rpc output's index:" , input . previousOutput . index )
341- logger . info ( 'rpc outputs' , rpcTx . transaction . outputs )
342- liveCell = rpcTx . transaction . outputs [ Number ( input . previousOutput . index ) ]
343- logger . info ( "live cell found in rpc-tx's outputs:" , liveCell )
334+ // const rpcTx = network.type === NetworkType.Light
335+ // // light rpc did't include the tx of peer A user
336+ // ? await (await (rpcService.rpc as LightRPC).fetchTransaction(input.previousOutput.txHash)).txWithStatus
337+ // : await rpcService.getTransaction(input.previousOutput.txHash)
338+ // const targetCell = rpcTx?.transaction?.outputs[Number(input.previousOutput.index)]
339+ // logger.info('RPC-TX:', rpcTx)
340+ // todo testnet only for now
341+ const targetCell = await fetchTargetCell ( input . previousOutput . txHash , input . previousOutput . index ) ;
342+ // console.log("iCell", targetCell);
343+
344+ if ( targetCell ) {
345+ liveCell = targetCell ; // rpcTx.transaction.outputs[Number(input.previousOutput.index)]
344346 break
345347 }
346348 logger . info ( `Failed to fetch live cell, retrying in ${ delay } ms` )
@@ -351,6 +353,7 @@ export class PerunServiceRunner {
351353 if ( ! liveCell ) {
352354 return reject ( new Error ( 'Failed to fetch live cell' ) )
353355 }
356+ console . log ( "liveCell data check" , liveCell )
354357
355358 const resolvedInput = Input . fromObject ( {
356359 previousOutput : OutPoint . fromObject ( typedInput . previousOutput ) ,
0 commit comments