Skip to content

Commit 40df3b9

Browse files
committed
chore: update
1 parent 2d7e1dc commit 40df3b9

File tree

5 files changed

+377
-22
lines changed

5 files changed

+377
-22
lines changed

packages/neuron-wallet/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
]
4343
},
4444
"dependencies": {
45+
"@ckb-ccc/ccc": "^1.1.22",
4546
"@ckb-lumos/base": "0.23.0",
4647
"@ckb-lumos/ckb-indexer": "0.23.0",
4748
"@ckb-lumos/helpers": "0.23.0",

packages/neuron-wallet/src/controllers/perun.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export default class PerunController {
138138
}
139139

140140
async openChannel(params: Controller.Params.OpenChannelParams): Promise<Controller.Response> {
141-
logger.info('PerunController: openChannel----------', params)
141+
logger.info('PerunController: openChannel----------')
142142
const alloc = Allocation.create({
143143
assets: [new Uint8Array(1)],
144144
balances: Balances.create({
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { ccc } from "@ckb-ccc/core";
2+
3+
4+
const networkMap = {
5+
// https://testnet.ckb.dev,https://testnet.ckbapp.dev
6+
testnet: "https://testnet.ckb.dev",
7+
// https://mainnet.ckb.dev,https://mainnet.ckbapp.dev
8+
mainnet: "https://mainnet.ckb.dev",
9+
} as const
10+
11+
const testnetService = new ccc.ClientPublicTestnet({ url: networkMap.testnet })
12+
13+
export async function fetchTargetCell(txhash: string, outputIndex: number) {
14+
const txResponse = await testnetService.getTransaction(txhash);
15+
const tx = txResponse?.transaction;
16+
if (!tx) {
17+
return null;
18+
}
19+
const cellInfo = tx.getOutput(outputIndex);
20+
const cell = {
21+
capacity: '0x' + cellInfo?.cellOutput.capacity.toString(16),
22+
lock: cellInfo?.cellOutput.lock,
23+
lockHash: cellInfo?.cellOutput.lock.hash(),
24+
// todo
25+
multiSignBlake160: null,
26+
type: cellInfo?.cellOutput.type,
27+
typeHash: cellInfo?.cellOutput.type?.hash(),
28+
data: cellInfo?.outputData,
29+
}
30+
return cell;
31+
}

packages/neuron-wallet/src/services/perun/service-runner.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import Input from '../../models/chain/input'
1414
import CellsService from '../../services/cells'
1515
import OutPoint from '../../models/chain/out-point'
1616
import RpcService from '../../services/rpc-service'
17-
import { TransactionsService } from '../tx'
17+
// import { TransactionsService } from '../tx'
1818
import 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'
2121
import generateConfigFiles, { ConfigFileOptions } from './configFiles'
2222
import SettingsService from '../settings'
23+
import { fetchTargetCell } from './fetchCell'
2324

2425
const { 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

Comments
 (0)