Skip to content

Commit 6a85705

Browse files
committed
feat: skip cells which has data or type
1 parent 9fe535b commit 6a85705

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

packages/neuron-wallet/src/services/cells.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ export const MIN_CELL_CAPACITY = '6100000000'
1010
/* eslint no-await-in-loop: "warn" */
1111
/* eslint no-restricted-syntax: "warn" */
1212
export default class CellsService {
13+
// exclude hasData = true and typeScript != null
1314
public static getBalance = async (lockHashes: string[], status: OutputStatus): Promise<string> => {
1415
const cells: OutputEntity[] = await getConnection()
1516
.getRepository(OutputEntity)
1617
.find({
1718
where: {
1819
lockHash: In(lockHashes),
20+
hasData: false,
21+
typeScript: null,
1922
status,
2023
},
2124
})

packages/neuron-wallet/src/services/tx/transaction-persistor.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export class TransactionPersistor {
133133
}
134134
}
135135

136+
const outputsData = transaction.outputsData!
136137
const outputs: OutputEntity[] = await Promise.all(
137138
transaction.outputs!.map(async (o, index) => {
138139
const output = new OutputEntity()
@@ -143,6 +144,15 @@ export class TransactionPersistor {
143144
output.lockHash = o.lockHash!
144145
output.transaction = tx
145146
output.status = outputStatus
147+
if (o.type) {
148+
output.typeScript = o.type
149+
}
150+
const data = outputsData[index]
151+
if (data && data !== '0x') {
152+
output.hasData = true
153+
} else {
154+
output.hasData = false
155+
}
146156
return output
147157
})
148158
)

packages/neuron-wallet/src/types/type-convert.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default class TypeConvert {
4141
witnesses: transaction.witnesses,
4242
inputs: transaction.inputs.map(input => TypeConvert.toInput(input)),
4343
outputs: transaction.outputs.map(output => TypeConvert.toOutput(output)),
44+
outputsData: transaction.outputsData,
4445
}
4546
if (blockHeader) {
4647
tx.timestamp = blockHeader.timestamp
@@ -72,9 +73,14 @@ export default class TypeConvert {
7273
}
7374

7475
static toOutput(output: CKBComponents.CellOutput): Cell {
76+
let type: Script | undefined
77+
if (output.type) {
78+
type = TypeConvert.toScript(output.type)
79+
}
7580
return {
7681
capacity: output.capacity.toString(),
7782
lock: TypeConvert.toScript(output.lock),
83+
type,
7884
}
7985
}
8086

0 commit comments

Comments
 (0)