Skip to content

Commit

Permalink
feat: skip cells which has data or type
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Aug 30, 2019
1 parent 9fe535b commit 6a85705
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/neuron-wallet/src/services/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ export const MIN_CELL_CAPACITY = '6100000000'
/* eslint no-await-in-loop: "warn" */
/* eslint no-restricted-syntax: "warn" */
export default class CellsService {
// exclude hasData = true and typeScript != null
public static getBalance = async (lockHashes: string[], status: OutputStatus): Promise<string> => {
const cells: OutputEntity[] = await getConnection()
.getRepository(OutputEntity)
.find({
where: {
lockHash: In(lockHashes),
hasData: false,
typeScript: null,
status,
},
})
Expand Down
10 changes: 10 additions & 0 deletions packages/neuron-wallet/src/services/tx/transaction-persistor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class TransactionPersistor {
}
}

const outputsData = transaction.outputsData!
const outputs: OutputEntity[] = await Promise.all(
transaction.outputs!.map(async (o, index) => {
const output = new OutputEntity()
Expand All @@ -143,6 +144,15 @@ export class TransactionPersistor {
output.lockHash = o.lockHash!
output.transaction = tx
output.status = outputStatus
if (o.type) {
output.typeScript = o.type
}
const data = outputsData[index]
if (data && data !== '0x') {
output.hasData = true
} else {
output.hasData = false
}
return output
})
)
Expand Down
6 changes: 6 additions & 0 deletions packages/neuron-wallet/src/types/type-convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class TypeConvert {
witnesses: transaction.witnesses,
inputs: transaction.inputs.map(input => TypeConvert.toInput(input)),
outputs: transaction.outputs.map(output => TypeConvert.toOutput(output)),
outputsData: transaction.outputsData,
}
if (blockHeader) {
tx.timestamp = blockHeader.timestamp
Expand Down Expand Up @@ -72,9 +73,14 @@ export default class TypeConvert {
}

static toOutput(output: CKBComponents.CellOutput): Cell {
let type: Script | undefined
if (output.type) {
type = TypeConvert.toScript(output.type)
}
return {
capacity: output.capacity.toString(),
lock: TypeConvert.toScript(output.lock),
type,
}
}

Expand Down

0 comments on commit 6a85705

Please sign in to comment.