Skip to content

Commit

Permalink
fix: check whether the entity exists before insert.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanguoyu committed Jun 9, 2023
1 parent f32c818 commit 9299615
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SudtTokenInfo from './sudt-token-info'
@Index(['tokenID', 'blake160'], { unique: true })
export default class AssetAccount {
@PrimaryGeneratedColumn()
id: number | null = null
id!: number

@Column({
type: 'varchar',
Expand Down
23 changes: 16 additions & 7 deletions packages/neuron-wallet/src/services/asset-account-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,23 @@ export default class AssetAccountService {
.values(sudtTokenInfoEntity)
.onConflict(`("tokenID") DO NOTHING`)
.execute()

await getConnection()
const existAccountAcount = await getConnection()
.getRepository(AssetAccountEntity)
.createQueryBuilder()
.insert()
.into(AssetAccountEntity)
.values(assetAccountEntity)
.onConflict(`("tokenID", "blake160") DO NOTHING`)
.execute()
.where({
tokenID,
blake160
})
.getCount()
// check whether the entity exists before insert. Reason: https://github.com/Magickbase/neuron-public-issues/issues/184#issue-1749746997
if (!existAccountAcount) {
await getConnection()
.createQueryBuilder()
.insert()
.into(AssetAccountEntity)
.values(assetAccountEntity)
.execute()
}
}

public static async checkAndDeleteWhenFork(startBlockNumber: string, anyoneCanPayLockHashes: string[]) {
Expand Down

0 comments on commit 9299615

Please sign in to comment.