Skip to content

Commit

Permalink
feat: using new tx service and delete old
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Jul 30, 2019
1 parent 1dcf5e1 commit 00da601
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 694 deletions.
5 changes: 4 additions & 1 deletion packages/neuron-wallet/src/controllers/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Transaction } from '../types/cell-types'
import TransactionsService, { PaginationResult, TransactionsByLockHashesParam } from '../services/transactions'
import TransactionsService, {
PaginationResult,
TransactionsByLockHashesParam,
} from '../services/tx/transaction-service'

import AddressesService from '../services/addresses'
import WalletsService from '../services/wallets'
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/database/address/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { Not, In } from 'typeorm'
import AddressEntity, { AddressVersion } from './entities/address'
import { AddressType } from '../../models/keys/address'
import { getConnection } from './ormconfig'
import TransactionsService, { OutputStatus } from '../../services/transactions'
import TransactionsService from '../../services/tx/transaction-service'
import CellsService from '../../services/cells'
import LockUtils from '../../models/lock-utils'
import { TransactionStatus } from '../../types/cell-types'
import { OutputStatus } from '../../services/tx/params'

export interface Address {
walletId: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {MigrationInterface, QueryRunner, TableColumn, getConnection} from "typeorm";
import TransactionEntity from '../entities/transaction'
import { OutputStatus } from '../../../services/transactions'
import { OutputStatus } from '../../../services/tx/params'
import { TransactionStatus } from '../../../types/cell-types'

export class AddStatusToTx1562038960990 implements MigrationInterface {
Expand Down
6 changes: 3 additions & 3 deletions packages/neuron-wallet/src/listeners/tx-status.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { remote } from 'electron'
import { interval } from 'rxjs'
import TransactionsService from '../services/transactions'
import { TransactionStatus } from '../types/cell-types'
import LockUtils from '../models/lock-utils'
import AddressesUsedSubject from '../models/subjects/addresses-used-subject'
import FailedTransaction from '../services/tx/failed-transaction'

const { nodeService } = remote.require('./startup/sync-block-task/params')

Expand All @@ -21,7 +21,7 @@ const getTransactionStatus = async (hash: string) => {
}

const trackingStatus = async () => {
const pendingTransactions = await TransactionsService.pendings()
const pendingTransactions = await FailedTransaction.pendings()
if (!pendingTransactions.length) {
return
}
Expand All @@ -39,7 +39,7 @@ const trackingStatus = async () => {
if (!failedTxs.length) {
return
}
const blake160s = await TransactionsService.updateFailedTxs(failedTxs.map(tx => tx.hash))
const blake160s = await FailedTransaction.updateFailedTxs(failedTxs.map(tx => tx.hash))
const usedAddresses = blake160s.map(blake160 => LockUtils.blake160ToAddress(blake160))
AddressesUsedSubject.getSubject().next(usedAddresses)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/services/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getConnection, In } from 'typeorm'
import OutputEntity from '../database/chain/entities/output'
import { Cell, OutPoint, Input } from '../types/cell-types'
import { CapacityNotEnough } from '../exceptions'
import { OutputStatus } from './transactions'
import { OutputStatus } from './tx/params'

export const MIN_CELL_CAPACITY = '6000000000'

Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/services/sync/check-and-save/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getConnection } from 'typeorm'
import { Subject } from 'rxjs'
import { Transaction, Cell, OutPoint } from '../../../types/cell-types'
import OutputEntity from '../../../database/chain/entities/output'
import TransactionsService from '../../transactions'
import SaveTransaction from '../../tx/save-transaction'
import CheckOutput from './output'
import LockUtils from '../../../models/lock-utils'
import { addressesUsedSubject as addressesUsedSubjectParam } from '../renderer-params'
Expand Down Expand Up @@ -32,7 +32,7 @@ export default class CheckTx {
public checkAndSave = async (lockHashes: string[]): Promise<boolean> => {
const addresses = await this.check(lockHashes)
if (addresses.length > 0) {
await TransactionsService.saveFetchTx(this.tx)
await SaveTransaction.saveFetchTx(this.tx)
this.addressesUsedSubject.next(addresses)
return true
}
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/src/services/sync/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Block, BlockHeader } from '../../types/cell-types'
import RangeForCheck from './range-for-check'
import BlockNumber from './block-number'
import Utils from './utils'
import TransactionsService from '../transactions'
import QueueAdapter from './queue-adapter'
import SaveTransaction from '../tx/save-transaction'

export default class Queue {
private q: any
Expand Down Expand Up @@ -106,7 +106,7 @@ export default class Queue {
const rangeFirstBlockHeader: BlockHeader = range[0]
await this.currentBlockNumber.updateCurrent(BigInt(rangeFirstBlockHeader.number))
await this.rangeForCheck.setRange([])
await TransactionsService.deleteWhenFork(rangeFirstBlockHeader.number)
await SaveTransaction.deleteWhenFork(rangeFirstBlockHeader.number)
await this.cleanQueue()
this.startBlockNumber = await this.currentBlockNumber.getCurrent()
this.batchPush()
Expand Down
Loading

0 comments on commit 00da601

Please sign in to comment.