Skip to content

Commit c760db5

Browse files
committed
feat: add inputIndex to inputs
1 parent 5a3f8a5 commit c760db5

7 files changed

Lines changed: 34 additions & 3 deletions

File tree

packages/neuron-wallet/src/database/chain/entities/input.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ export default class Input extends BaseEntity {
4848
})
4949
capacity: string | null = null
5050

51+
@Column({
52+
type: 'varchar',
53+
nullable: true,
54+
})
55+
inputIndex: string | null = null
56+
5157
public previousOutput(): OutPoint | null {
5258
if (!this.outPointTxHash || !this.outPointIndex) {
5359
return null
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {MigrationInterface, QueryRunner, TableColumn} from "typeorm";
2+
3+
export class AddInputIndexToInput1573461100330 implements MigrationInterface {
4+
5+
public async up(queryRunner: QueryRunner): Promise<any> {
6+
await queryRunner.addColumn('input', new TableColumn({
7+
name: 'inputIndex',
8+
type: 'varchar',
9+
isNullable: true,
10+
}))
11+
}
12+
13+
public async down(queryRunner: QueryRunner): Promise<any> {
14+
await queryRunner.dropColumn('input', 'inputIndex')
15+
}
16+
17+
}

packages/neuron-wallet/src/database/chain/ormconfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { AddLockToInput1570522869590 } from './migrations/1570522869590-AddLockT
1616
import { AddIndices1572006450765 } from './migrations/1572006450765-AddIndices'
1717
import { AddIndexToTxTimestamp1572137226866 } from './migrations/1572137226866-AddIndexToTxTimestamp'
1818
import { AddOutputIndex1572226722928 } from './migrations/1572226722928-AddOutputIndex'
19+
import { AddInputIndexToInput1573461100330 } from './migrations/1573461100330-AddInputIndexToInput'
1920

2021
export const CONNECTION_NOT_FOUND_NAME = 'ConnectionNotFoundError'
2122

@@ -43,7 +44,8 @@ const connectOptions = async (genesisBlockHash: string): Promise<SqliteConnectio
4344
AddLockToInput1570522869590,
4445
AddIndices1572006450765,
4546
AddIndexToTxTimestamp1572137226866,
46-
AddOutputIndex1572226722928
47+
AddOutputIndex1572226722928,
48+
AddInputIndexToInput1573461100330,
4749
],
4850
logging,
4951
maxQueryExecutionTime: 30

packages/neuron-wallet/src/services/indexer/queue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export default class IndexerQueue {
214214
let txEntity: TransactionEntity | undefined = await TransactionPersistor.get(transaction.hash)
215215
if (!txEntity || !txEntity.blockHash) {
216216
if (!txEntity) {
217-
for (const input of transaction.inputs!) {
217+
for (const [inputIndex, input] of transaction.inputs!.entries()) {
218218
if (input.previousOutput!.txHash === this.emptyTxHash) {
219219
continue
220220
}
@@ -224,6 +224,7 @@ export default class IndexerQueue {
224224
input.lock = previousOutput.lock
225225
input.lockHash = LockUtils.lockScriptToHash(input.lock)
226226
input.capacity = previousOutput.capacity
227+
input.inputIndex = inputIndex.toString()
227228
}
228229
}
229230
const { blockHash } = transactionWithStatus.txStatus

packages/neuron-wallet/src/services/sync/get-blocks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default class GetBlocks {
4848
const addresses = await checkTx.check(lockHashes)
4949
if (addresses.length > 0) {
5050
if (i > 0) {
51-
for (const input of tx.inputs!) {
51+
for (const [inputIndex, input] of tx.inputs!.entries()) {
5252
const previousTxHash = input.previousOutput!.txHash
5353
let previousTxWithStatus = cachedPreviousTxs.get(previousTxHash)
5454
if (!previousTxWithStatus) {
@@ -60,6 +60,7 @@ export default class GetBlocks {
6060
input.lock = previousOutput.lock
6161
input.lockHash = LockUtils.lockScriptToHash(input.lock)
6262
input.capacity = previousOutput.capacity
63+
input.inputIndex = inputIndex.toString()
6364
}
6465
}
6566
await TransactionPersistor.saveFetchTx(tx)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ export class TransactionPersistor {
134134
input.lockHash = i.lockHash || null
135135
input.lock = i.lock || null
136136
input.since = i.since!
137+
if (i.inputIndex) {
138+
input.inputIndex = i.inputIndex
139+
}
137140
inputs.push(input)
138141

139142
if (outPoint) {

packages/neuron-wallet/src/types/cell-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface Input {
7979
capacity?: string | null
8080
lockHash?: string | null
8181
lock?: Script | null
82+
inputIndex?: string
8283
}
8384

8485
export interface Cell {

0 commit comments

Comments
 (0)