Skip to content

Commit

Permalink
feat: Remove address sqlite db
Browse files Browse the repository at this point in the history
  • Loading branch information
ashchan committed Nov 13, 2019
1 parent 617a9a3 commit 6f95340
Show file tree
Hide file tree
Showing 20 changed files with 21 additions and 287 deletions.
21 changes: 0 additions & 21 deletions ormconfig-address.json

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"test:e2e": "yarn build && ./scripts/copy-ui-files.sh && lerna run --parallel test:e2e",
"lint": "lerna run --stream lint",
"postinstall": "lerna run rebuild:nativemodules",
"db:chain": "node ./node_modules/.bin/typeorm",
"db:address": "node ./node_modules/.bin/typeorm --config ormconfig-address.json"
"db:chain": "node ./node_modules/.bin/typeorm"
},
"husky": {
"hooks": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import CellsService from 'services/cells'
import LockUtils from 'models/lock-utils'
import { TransactionStatus } from 'types/cell-types'
import { OutputStatus } from 'services/tx/params'
import { AddressVersion } from './entities/address'
import NodeService from 'services/node'
import Store from 'models/store'
import AddressDbChangedSubject from 'models/subjects/address-db-changed-subject'

export enum AddressVersion {
Testnet = 'testnet',
Mainnet = 'mainnet',
}

export interface Address {
walletId: string
address: string
Expand Down
116 changes: 0 additions & 116 deletions packages/neuron-wallet/src/database/address/entities/address.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

51 changes: 0 additions & 51 deletions packages/neuron-wallet/src/database/address/ormconfig.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/listeners/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ReplaySubject } from 'rxjs'
import { bufferTime } from 'rxjs/operators'
import AddressesUsedSubject, { AddressesWithURL } from 'models/subjects/addresses-used-subject'
import AddressService from 'services/addresses'
import { Address } from 'database/address/address-dao'
import WalletService from 'services/wallets'
import { AccountExtendedPublicKey } from 'models/keys/key'

Expand All @@ -27,7 +28,7 @@ export const register = () => {
const url: string = addressesList[addressesList.length - 1].url
const uniqueAddresses = [...new Set(addresses)]
const addrs = await AddressService.updateTxCountAndBalances(uniqueAddresses, url)
const walletIds: string[] = addrs.map(addr => addr.walletId).filter((value, idx, a) => a.indexOf(value) === idx)
const walletIds: string[] = addrs.map(addr => (addr as Address).walletId).filter((value, idx, a) => a.indexOf(value) === idx)
await Promise.all(
walletIds.map(async id => {
const wallet = WalletService.getInstance().get(id)
Expand Down
2 changes: 0 additions & 2 deletions packages/neuron-wallet/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { app } from 'electron'

import AppController from 'controllers/app'
import initConnection from 'database/address/ormconfig'
import createSyncBlockTask from 'startup/sync-block-task/create'
import { changeLanguage } from 'utils/i18n'

Expand All @@ -10,7 +9,6 @@ const appController = new AppController()
app.on('ready', async () => {
changeLanguage(app.getLocale())

await initConnection()
createSyncBlockTask()

appController.openWindow()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReplaySubject } from 'rxjs'
import { Address } from 'database/address/dao'
import { Address } from 'database/address/address-dao'

export default class AddressCreatedSubject {
static subject = new ReplaySubject<Address[]>(100)
Expand Down
16 changes: 6 additions & 10 deletions packages/neuron-wallet/src/services/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { AddressPrefix } from '@nervosnetwork/ckb-sdk-utils'
import { AccountExtendedPublicKey } from 'models/keys/key'
import Address, { AddressType } from 'models/keys/address'
import LockUtils from 'models/lock-utils'
import AddressDao, { Address as AddressInterface } from 'database/address/dao'
import { AddressVersion } from 'database/address/entities/address'
import AddressDao, { Address as AddressInterface, AddressVersion } from 'database/address/address-dao'
import AddressCreatedSubject from 'models/subjects/address-created-subject'
import NodeService from './node'
import ChainInfo from 'models/chain-info'
Expand Down Expand Up @@ -95,16 +94,13 @@ export default class AddressService {
)
}

public static updateTxCountAndBalances = async (
addresses: string[],
url: string = NodeService.getInstance().core.rpc.node.url
) => {
let addrs: Address[] = []
public static updateTxCountAndBalances = async (addresses: string[], url: string = NodeService.getInstance().core.rpc.node.url) => {
let result: Address[] = []
for (const address of addresses) {
const ads = await AddressDao.updateTxCountAndBalance(address, url)
addrs = addrs.concat(ads)
const updatedAddress = await AddressDao.updateTxCountAndBalance(address, url)
result = result.concat(updatedAddress)
}
return addrs
return result
}

// Generate both receiving and change addresses.
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/services/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import LockUtils from 'models/lock-utils'
import { TransactionWithoutHash, Input, OutPoint, WitnessArgs } from 'types/cell-types'
import ConvertTo from 'types/convert-to'
import { WalletNotFound, IsRequired, UsedName } from 'exceptions'
import { Address as AddressInterface } from 'database/address/dao'
import { Address as AddressInterface } from 'database/address/address-dao'
import Keychain from 'models/keys/keychain'
import AddressDbChangedSubject from 'models/subjects/address-db-changed-subject'
import AddressesUsedSubject from 'models/subjects/addresses-used-subject'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { remote } from 'electron'
import AddressService from 'services/addresses'
import LockUtils from 'models/lock-utils'
import IndexerQueue, { LockHashInfo } from 'services/indexer/queue'
import { Address } from 'database/address/dao'
import { Address } from 'database/address/address-dao'

import initConnection from 'database/chain/ormconfig'
import ChainInfo from 'models/chain-info'
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/startup/sync-block-task/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { remote } from 'electron'
import AddressService from 'services/addresses'
import LockUtils from 'models/lock-utils'
import BlockListener from 'services/sync/block-listener'
import { Address } from 'database/address/dao'
import { Address } from 'database/address/address-dao'

import initConnection from 'database/chain/ormconfig'
import ChainInfo from 'models/chain-info'
Expand Down
Loading

0 comments on commit 6f95340

Please sign in to comment.