Skip to content

Commit

Permalink
feat: add inputIndex to inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 11, 2019
1 parent 5a3f8a5 commit c760db5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/neuron-wallet/src/database/chain/entities/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export default class Input extends BaseEntity {
})
capacity: string | null = null

@Column({
type: 'varchar',
nullable: true,
})
inputIndex: string | null = null

public previousOutput(): OutPoint | null {
if (!this.outPointTxHash || !this.outPointIndex) {
return null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {MigrationInterface, QueryRunner, TableColumn} from "typeorm";

export class AddInputIndexToInput1573461100330 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.addColumn('input', new TableColumn({
name: 'inputIndex',
type: 'varchar',
isNullable: true,
}))
}

public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.dropColumn('input', 'inputIndex')
}

}
4 changes: 3 additions & 1 deletion packages/neuron-wallet/src/database/chain/ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { AddLockToInput1570522869590 } from './migrations/1570522869590-AddLockT
import { AddIndices1572006450765 } from './migrations/1572006450765-AddIndices'
import { AddIndexToTxTimestamp1572137226866 } from './migrations/1572137226866-AddIndexToTxTimestamp'
import { AddOutputIndex1572226722928 } from './migrations/1572226722928-AddOutputIndex'
import { AddInputIndexToInput1573461100330 } from './migrations/1573461100330-AddInputIndexToInput'

export const CONNECTION_NOT_FOUND_NAME = 'ConnectionNotFoundError'

Expand Down Expand Up @@ -43,7 +44,8 @@ const connectOptions = async (genesisBlockHash: string): Promise<SqliteConnectio
AddLockToInput1570522869590,
AddIndices1572006450765,
AddIndexToTxTimestamp1572137226866,
AddOutputIndex1572226722928
AddOutputIndex1572226722928,
AddInputIndexToInput1573461100330,
],
logging,
maxQueryExecutionTime: 30
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/services/indexer/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export default class IndexerQueue {
let txEntity: TransactionEntity | undefined = await TransactionPersistor.get(transaction.hash)
if (!txEntity || !txEntity.blockHash) {
if (!txEntity) {
for (const input of transaction.inputs!) {
for (const [inputIndex, input] of transaction.inputs!.entries()) {
if (input.previousOutput!.txHash === this.emptyTxHash) {
continue
}
Expand All @@ -224,6 +224,7 @@ export default class IndexerQueue {
input.lock = previousOutput.lock
input.lockHash = LockUtils.lockScriptToHash(input.lock)
input.capacity = previousOutput.capacity
input.inputIndex = inputIndex.toString()
}
}
const { blockHash } = transactionWithStatus.txStatus
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/services/sync/get-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class GetBlocks {
const addresses = await checkTx.check(lockHashes)
if (addresses.length > 0) {
if (i > 0) {
for (const input of tx.inputs!) {
for (const [inputIndex, input] of tx.inputs!.entries()) {
const previousTxHash = input.previousOutput!.txHash
let previousTxWithStatus = cachedPreviousTxs.get(previousTxHash)
if (!previousTxWithStatus) {
Expand All @@ -60,6 +60,7 @@ export default class GetBlocks {
input.lock = previousOutput.lock
input.lockHash = LockUtils.lockScriptToHash(input.lock)
input.capacity = previousOutput.capacity
input.inputIndex = inputIndex.toString()
}
}
await TransactionPersistor.saveFetchTx(tx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ export class TransactionPersistor {
input.lockHash = i.lockHash || null
input.lock = i.lock || null
input.since = i.since!
if (i.inputIndex) {
input.inputIndex = i.inputIndex
}
inputs.push(input)

if (outPoint) {
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-wallet/src/types/cell-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface Input {
capacity?: string | null
lockHash?: string | null
lock?: Script | null
inputIndex?: string
}

export interface Cell {
Expand Down

0 comments on commit c760db5

Please sign in to comment.