From c760db543252457a98a8e5d545f10eb1f842a063 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Mon, 11 Nov 2019 17:20:31 +0800 Subject: [PATCH] feat: add inputIndex to inputs --- .../src/database/chain/entities/input.ts | 6 ++++++ .../1573461100330-AddInputIndexToInput.ts | 17 +++++++++++++++++ .../src/database/chain/ormconfig.ts | 4 +++- .../neuron-wallet/src/services/indexer/queue.ts | 3 ++- .../src/services/sync/get-blocks.ts | 3 ++- .../src/services/tx/transaction-persistor.ts | 3 +++ packages/neuron-wallet/src/types/cell-types.ts | 1 + 7 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 packages/neuron-wallet/src/database/chain/migrations/1573461100330-AddInputIndexToInput.ts diff --git a/packages/neuron-wallet/src/database/chain/entities/input.ts b/packages/neuron-wallet/src/database/chain/entities/input.ts index 4c4fb018c4..db00b35006 100644 --- a/packages/neuron-wallet/src/database/chain/entities/input.ts +++ b/packages/neuron-wallet/src/database/chain/entities/input.ts @@ -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 diff --git a/packages/neuron-wallet/src/database/chain/migrations/1573461100330-AddInputIndexToInput.ts b/packages/neuron-wallet/src/database/chain/migrations/1573461100330-AddInputIndexToInput.ts new file mode 100644 index 0000000000..f3c1fb4c65 --- /dev/null +++ b/packages/neuron-wallet/src/database/chain/migrations/1573461100330-AddInputIndexToInput.ts @@ -0,0 +1,17 @@ +import {MigrationInterface, QueryRunner, TableColumn} from "typeorm"; + +export class AddInputIndexToInput1573461100330 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.addColumn('input', new TableColumn({ + name: 'inputIndex', + type: 'varchar', + isNullable: true, + })) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.dropColumn('input', 'inputIndex') + } + +} diff --git a/packages/neuron-wallet/src/database/chain/ormconfig.ts b/packages/neuron-wallet/src/database/chain/ormconfig.ts index 75b405fe6e..3e81a5ff9d 100644 --- a/packages/neuron-wallet/src/database/chain/ormconfig.ts +++ b/packages/neuron-wallet/src/database/chain/ormconfig.ts @@ -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' @@ -43,7 +44,8 @@ const connectOptions = async (genesisBlockHash: string): Promise 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) { @@ -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) diff --git a/packages/neuron-wallet/src/services/tx/transaction-persistor.ts b/packages/neuron-wallet/src/services/tx/transaction-persistor.ts index e2ddc6d5c3..561d4907dd 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-persistor.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-persistor.ts @@ -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) { diff --git a/packages/neuron-wallet/src/types/cell-types.ts b/packages/neuron-wallet/src/types/cell-types.ts index 43cf664568..7920f7d446 100644 --- a/packages/neuron-wallet/src/types/cell-types.ts +++ b/packages/neuron-wallet/src/types/cell-types.ts @@ -79,6 +79,7 @@ export interface Input { capacity?: string | null lockHash?: string | null lock?: Script | null + inputIndex?: string } export interface Cell {