-
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.
Merge pull request #1889 from nervosnetwork/rc/v0.33.0
Rc/v0.33.0
- Loading branch information
Showing
7 changed files
with
161 additions
and
53 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
24 changes: 24 additions & 0 deletions
24
packages/neuron-wallet/src/database/chain/entities/address-description.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,24 @@ | ||
import { Entity, Column, PrimaryGeneratedColumn, Index } from 'typeorm' | ||
|
||
@Entity() | ||
export default class AddressDescription { | ||
@PrimaryGeneratedColumn() | ||
id!: number | ||
|
||
@Column({ | ||
type: 'varchar', | ||
}) | ||
@Index() | ||
walletId!: string | ||
|
||
@Column({ | ||
type: 'varchar', | ||
}) | ||
@Index() | ||
address!: string | ||
|
||
@Column({ | ||
type: 'varchar', | ||
}) | ||
description!: string | ||
} |
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
45 changes: 45 additions & 0 deletions
45
packages/neuron-wallet/src/database/chain/migrations/1602543179168-AddAddressDescription.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,45 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
import fs from "fs"; | ||
import env from "env"; | ||
import path from "path"; | ||
import NetworksService from "services/networks"; | ||
import AddressMeta from "database/address/meta"; | ||
|
||
export class AddAddressDescription1602543179168 implements MigrationInterface { | ||
name = 'AddAddressDescription1602543179168' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<any> { | ||
await queryRunner.query(`CREATE TABLE "address_description" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "walletId" varchar NOT NULL, "address" varchar NOT NULL, "description" varchar NOT NULL)`, undefined); | ||
await queryRunner.query(`CREATE INDEX "IDX_eb54f769e9f6d23d51b8d02d1d" ON "address_description" ("walletId") `, undefined); | ||
await queryRunner.query(`CREATE INDEX "IDX_bc3931239490edba9ad200ce29" ON "address_description" ("address") `, undefined); | ||
|
||
await queryRunner.dropColumn(`hd_public_key_info`, 'description'); | ||
|
||
//migration from the legacy address json store | ||
const fileBasePath = env.fileBasePath | ||
const legacyAddressPath = path.join(fileBasePath, 'addresses/index.json') | ||
|
||
if (!fs.existsSync(legacyAddressPath)) { | ||
return | ||
} | ||
|
||
const json = fs.readFileSync(legacyAddressPath, {encoding: 'utf8'}) | ||
const {addresses} = JSON.parse(json) | ||
|
||
const currentChain = NetworksService.getInstance().getCurrent().chain | ||
|
||
let addressesByNetwork = [] | ||
if (currentChain === 'ckb') { | ||
addressesByNetwork = addresses.filter((addr:AddressMeta) => addr.version === 'mainnet' && addr.description) | ||
} | ||
else { | ||
addressesByNetwork = addresses.filter((addr:AddressMeta) => addr.version !== 'mainnet' && addr.description) | ||
} | ||
for (const {walletId, address, description} of addressesByNetwork) { | ||
await queryRunner.query(`INSERT INTO "address_description" ("walletId", "address", "description") values('${walletId}', '${address}', '${description}')`, undefined); | ||
} | ||
} | ||
|
||
public async down(): Promise<any> {} | ||
|
||
} |
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
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