-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a038e18
commit a7ad2d5
Showing
7 changed files
with
118 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 22 additions & 10 deletions
32
packages/neuron-wallet/src/database/chain/migrations/1562038960990-AddStatusToTx.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/neuron-wallet/src/database/chain/migrations/1565693320664-AddConfirmed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class AddConfirmed1565693320664 implements MigrationInterface { | ||
|
||
public async up(queryRunner: QueryRunner): Promise<any> { | ||
await queryRunner.query(`ALTER TABLE 'transaction' ADD COLUMN 'confirmed' boolean NOT NULL DEFAULT false;`) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<any> { | ||
await queryRunner.dropColumn('transaction', 'confirmed') | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/neuron-wallet/src/services/tx/indexer-transaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { getConnection } from 'typeorm' | ||
import TransactionEntity from 'database/chain/entities/transaction' | ||
import Utils from 'services/sync/utils' | ||
import InputEntity from 'database/chain/entities/input' | ||
import OutputEntity from 'database/chain/entities/output' | ||
import { OutputStatus } from './params' | ||
|
||
export default class IndexerTransaction { | ||
public static txHashes = async () => { | ||
const txs = await getConnection() | ||
.getRepository(TransactionEntity) | ||
.createQueryBuilder('tx') | ||
.where(`tx.confirmed = false`) | ||
.getMany() | ||
|
||
return txs | ||
} | ||
|
||
public static confirm = async (hash: string) => { | ||
await getConnection().manager.update(TransactionEntity, hash, { confirmed: true }) | ||
} | ||
|
||
public static deleteTxWhenFork = async (hash: string) => { | ||
const tx = await getConnection() | ||
.getRepository(TransactionEntity) | ||
.findOne(hash, { relations: ['inputs', 'outputs'] }) | ||
|
||
if (!tx) { | ||
return | ||
} | ||
|
||
// reset previous output to OutputStatus.Live | ||
await getConnection().transaction(async transactionalEntityManager => { | ||
await Utils.mapSeries(tx.inputs, async (input: InputEntity) => { | ||
if (!input.lockHash) { | ||
return | ||
} | ||
|
||
await transactionalEntityManager.update( | ||
OutputEntity, | ||
{ | ||
outPointTxHash: input.outPointTxHash, | ||
outPointIndex: input.outPointIndex, | ||
}, | ||
{ status: OutputStatus.Live } | ||
) | ||
}) | ||
|
||
await transactionalEntityManager.remove([tx, ...tx.inputs, ...tx.outputs]) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,5 @@ export const switchNetwork = async (nodeURL: string) => { | |
}) | ||
|
||
indexerQueue.start() | ||
indexerQueue.processFork() | ||
} |