Skip to content

Commit

Permalink
chore: add dao script support in indexer sync
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 7, 2019
1 parent 77a505d commit 2756a15
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/neuron-wallet/src/services/indexer/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import HexUtils from 'utils/hex'
import { TxUniqueFlagCache } from './tx-unique-flag'
import { TransactionCache } from './transaction-cache'
import TransactionEntity from 'database/chain/entities/transaction'
import DaoUtils from 'models/dao-utils'

export interface LockHashInfo {
lockHash: string
Expand Down Expand Up @@ -90,13 +91,19 @@ export default class IndexerQueue {
await this.indexLockHashes(lockHashInfos)
this.indexed = true
}
const daoScriptInfo = await DaoUtils.daoScript(this.url)
const daoScriptHash = LockUtils.computeScriptHash({
codeHash: daoScriptInfo.codeHash,
args: "0x",
hashType: daoScriptInfo.hashType,
})
const lockHashes: string[] = lockHashInfos.map(info => info.lockHash)
const minBlockNumber = await this.getCurrentBlockNumber(lockHashes)
for (const lockHash of lockHashes) {
await this.pipeline(lockHash, TxPointType.CreatedBy, currentBlockNumber)
await this.pipeline(lockHash, TxPointType.CreatedBy, currentBlockNumber, daoScriptHash)
}
for (const lockHash of lockHashes) {
await this.pipeline(lockHash, TxPointType.ConsumedBy, currentBlockNumber)
await this.pipeline(lockHash, TxPointType.ConsumedBy, currentBlockNumber, daoScriptHash)
}
if (minBlockNumber) {
await this.blockNumberService.updateCurrent(minBlockNumber)
Expand Down Expand Up @@ -171,7 +178,7 @@ export default class IndexerQueue {
}

// type: 'createdBy' | 'consumedBy'
public pipeline = async (lockHash: string, type: TxPointType, startBlockNumber: bigint) => {
public pipeline = async (lockHash: string, type: TxPointType, startBlockNumber: bigint, daoScriptHash: string) => {
let page = 0
let stopped = false
while (!stopped) {
Expand Down Expand Up @@ -220,6 +227,18 @@ export default class IndexerQueue {
input.lockHash = LockUtils.lockScriptToHash(input.lock)
input.capacity = previousOutput.capacity
}

const outputs = transaction.outputs!
for (let i = 0; i < outputs.length; ++i) {
const output = outputs[i]
const typeScript = output.type
if (typeScript) {
output.typeHash = LockUtils.computeScriptHash(typeScript)
if (output.typeHash === daoScriptHash) {
output.daoData = transaction.outputsData![i]
}
}
}
}
const { blockHash } = transactionWithStatus.txStatus
if (blockHash) {
Expand Down

0 comments on commit 2756a15

Please sign in to comment.