Skip to content

Commit

Permalink
feat: remove totalBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 11, 2019
1 parent 1bc25eb commit 5b0df6f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 16 deletions.
3 changes: 0 additions & 3 deletions packages/neuron-wallet/src/database/address/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface Address {
sentBalance: string
pendingBalance: string
balance: string
totalBalance: string
blake160: string
version: AddressVersion
description?: string
Expand Down Expand Up @@ -54,7 +53,6 @@ export default class AddressDao {
// pendingBalance means balance of OutputStatus.Pending cells (sent from me, but not committed)
// so the final balance is (liveBalance + sentBalance - pendingBalance)
// balance is the balance of the cells those who don't hold data or type script
// totalBalance means balance of all cells, including those who hold data and type script
public static updateTxCountAndBalance = async (
address: string,
url: string = NodeService.getInstance().core.rpc.node.url
Expand All @@ -78,7 +76,6 @@ export default class AddressDao {
addressEntity.liveBalance = await CellsService.getBalance(lockHashes, OutputStatus.Live)
addressEntity.sentBalance = await CellsService.getBalance(lockHashes, OutputStatus.Sent)
addressEntity.pendingBalance = await CellsService.getBalance(lockHashes, OutputStatus.Pending)
addressEntity.totalBalance = '0'
return addressEntity
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ export default class Address extends BaseEntity {
@Column()
pendingBalance: string = '0'

@Column()
totalBalance: string = '0'

public balance = (): string => {
return (BigInt(this.liveBalance) + BigInt(this.sentBalance)).toString()
}
Expand All @@ -94,7 +91,6 @@ export default class Address extends BaseEntity {
sentBalance: this.sentBalance,
pendingBalance: this.pendingBalance,
balance: this.balance(),
totalBalance: this.totalBalance,
description: this.description,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {MigrationInterface, QueryRunner, TableColumn} from "typeorm";

export class RemoveTotalBalance1573458655136 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.dropColumn('address', 'totalBalance')
}

public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.addColumn('address', new TableColumn({
name: 'totalBalance',
type: 'varchar',
default: '0',
}))
}

}
8 changes: 7 additions & 1 deletion packages/neuron-wallet/src/database/address/ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Address from './entities/address'
import { AddAddress1561461669542 } from './migrations/1561461669542-AddAddress'
import { extendBalance1562126909151 } from './migrations/1562126909151-extendBalance'
import { AddTotalBalance1567485550388 } from './migrations/1567485550388-AddTotalBalance'
import { RemoveTotalBalance1573458655136 } from './migrations/1573458655136-RemoveTotalBalance'

const dbPath = path.join(env.fileBasePath, 'address.sqlite')

Expand All @@ -21,7 +22,12 @@ const connectOptions = (): SqliteConnectionOptions => {
type: 'sqlite',
database,
entities: [Address],
migrations: [AddAddress1561461669542, extendBalance1562126909151, AddTotalBalance1567485550388],
migrations: [
AddAddress1561461669542,
extendBalance1562126909151,
AddTotalBalance1567485550388,
RemoveTotalBalance1573458655136,
],
synchronize: false,
migrationsRun: true,
logging: ['error'],
Expand Down
1 change: 0 additions & 1 deletion packages/neuron-wallet/src/services/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export default class AddressService {
sentBalance: '0',
pendingBalance: '0',
balance: '0',
totalBalance: '0',
blake160,
version: AddressVersion.Testnet,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe('balance', () => {
sentBalance: sentBalance.toString(),
pendingBalance: pendingBalance.toString(),
balance: '0',
totalBalance: '0',
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
version: AddressVersion.Testnet,
}
Expand Down
3 changes: 0 additions & 3 deletions packages/neuron-wallet/tests/database/address/dao.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('Address Dao tests', () => {
sentBalance: '0',
pendingBalance: '0',
balance: '0',
totalBalance: '0',
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
version: AddressVersion.Testnet,
}
Expand All @@ -31,7 +30,6 @@ describe('Address Dao tests', () => {
sentBalance: '0',
pendingBalance: '0',
balance: '0',
totalBalance: '0',
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
version: AddressVersion.Testnet,
}
Expand All @@ -47,7 +45,6 @@ describe('Address Dao tests', () => {
sentBalance: '0',
pendingBalance: '0',
balance: '0',
totalBalance: '0',
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
version: AddressVersion.Testnet,
}
Expand Down
3 changes: 0 additions & 3 deletions packages/neuron-wallet/tests/services/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe('Key tests with db', () => {
sentBalance: '0',
pendingBalance: '0',
balance: '0',
totalBalance: '0',
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
version: AddressVersion.Testnet,
}
Expand All @@ -70,7 +69,6 @@ describe('Key tests with db', () => {
sentBalance: '0',
pendingBalance: '0',
balance: '0',
totalBalance: '0',
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
version: AddressVersion.Testnet,
}
Expand All @@ -86,7 +84,6 @@ describe('Key tests with db', () => {
sentBalance: '0',
pendingBalance: '0',
balance: '0',
totalBalance: '0',
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
version: AddressVersion.Testnet,
}
Expand Down

0 comments on commit 5b0df6f

Please sign in to comment.