Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
fix: makes domain name sha3 to hex w/o lead 0s (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajpiar authored May 14, 2020
1 parent 5d4b953 commit cd5aa77
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/rns/hooks/domain-offer.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { disallow } from 'feathers-hooks-common'

import Domain from '../models/domain.model'
import { Op } from 'sequelize'
import { sha3 } from 'web3-utils'
import { sha3, numberToHex } from 'web3-utils'

export default {
before: {
Expand Down Expand Up @@ -42,7 +42,7 @@ export default {
[Op.like]: `%${$like}%`
},
tokenId: {
[Op.eq]: sha3($like)
[Op.eq]: numberToHex(((sha3($like)) as string))
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/rns/hooks/domain.hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HookContext } from '@feathersjs/feathers'
import { disallow } from 'feathers-hooks-common'
import { sha3, numberToHex } from 'web3-utils'

export default {
before: {
Expand Down Expand Up @@ -78,7 +79,7 @@ export default {
)
${isOwned ? `AND "active_offers"."tokenId" IS NULL
AND ("INACTIVE_OFFERS"."tokenId" IS NOT NULL OR "offers"."tokenId" IS NULL)` : ''}
${nameFilter?.$like ? `AND "Domain"."name" LIKE '%${nameFilter.$like}%'` : ''}
${nameFilter?.$like ? `AND ("Domain"."name" LIKE '%${nameFilter.$like}%' OR "Domain"."tokenId" = '${numberToHex((sha3(nameFilter.$like)) as string)}')` : ''}
`

const sequelize = context.app.get('sequelize')
Expand Down
32 changes: 31 additions & 1 deletion src/rns/hooks/sold-domain.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { HookContext } from '@feathersjs/feathers'
import { disallow } from 'feathers-hooks-common'

import Domain from '../models/domain.model'
import { Op } from 'sequelize'
import { numberToHex, sha3 } from 'web3-utils'

export default {
before: {
Expand All @@ -22,7 +24,35 @@ export default {
}
}
],
find: [],
find: [
(context: HookContext) => {
context.params.sequelize = {
raw: false,
nest: true,
include: {
model: Domain
}
}
const { params: { sequelize: { include } } } = context
const { domain } = context.params.query as any

if (include && domain) {
const { name: { $like } } = domain
include.where = {
[Op.or]: {
name: {
[Op.like]: `%${$like}%`
},
tokenId: {
[Op.eq]: numberToHex(((sha3($like)) as string))
}
}
}
}

delete (context.params.query as any).domain
}
],
get: [],
create: disallow(),
update: disallow(),
Expand Down

0 comments on commit cd5aa77

Please sign in to comment.