@ensdomains/ensjs 3.0.0-alpha.46 → 3.0.0-alpha.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,28 +2,34 @@ import { keccak256 as solidityKeccak256 } from '@ethersproject/solidity'
2
2
  import { ENSArgs } from '..'
3
3
  import { namehash } from '../utils/normalise'
4
4
 
5
- type Args = {
5
+ type BaseArgs = {
6
6
  contract: 'registry' | 'nameWrapper'
7
+ method?: 'setRecord' | 'setSubnodeOwner'
7
8
  }
8
9
 
10
+ type NameWrapperArgs = {
11
+ contract: 'nameWrapper'
12
+ method: 'setRecord' | 'setSubnodeOwner'
13
+ }
14
+
15
+ type Args = BaseArgs | NameWrapperArgs
16
+
9
17
  export default async function (
10
- { contracts, signer }: ENSArgs<'contracts' | 'signer' | 'getExpiry'>,
18
+ { contracts, signer }: ENSArgs<'contracts' | 'signer'>,
11
19
  name: string,
12
- { contract }: Args,
20
+ { contract, ...args }: Args,
13
21
  ) {
14
22
  const labels = name.split('.')
15
-
16
23
  if (labels.length < 3) {
17
24
  throw new Error(`${name} is not a valid subname`)
18
25
  }
19
26
 
20
- const label = labels.shift() as string
21
- const labelhash = solidityKeccak256(['string'], [label])
22
- const parentNodehash = namehash(labels.join('.'))
23
-
24
27
  switch (contract) {
25
28
  case 'registry': {
26
29
  const registry = (await contracts!.getRegistry()!).connect(signer)
30
+ const label = labels.shift() as string
31
+ const labelhash = solidityKeccak256(['string'], [label])
32
+ const parentNodehash = namehash(labels.join('.'))
27
33
 
28
34
  return registry.populateTransaction.setSubnodeRecord(
29
35
  parentNodehash,
@@ -35,13 +41,24 @@ export default async function (
35
41
  }
36
42
  case 'nameWrapper': {
37
43
  const nameWrapper = (await contracts!.getNameWrapper()!).connect(signer)
44
+ const { method } = args as NameWrapperArgs
45
+
46
+ if (method === 'setRecord') {
47
+ const node = namehash(name)
48
+ return nameWrapper.populateTransaction.setRecord(
49
+ node,
50
+ '0x0000000000000000000000000000000000000000',
51
+ '0x0000000000000000000000000000000000000000',
52
+ 0,
53
+ )
54
+ }
38
55
 
39
- return nameWrapper.populateTransaction.setSubnodeRecord(
56
+ const label = labels.shift() as string
57
+ const parentNodehash = namehash(labels.join('.'))
58
+ return nameWrapper.populateTransaction.setSubnodeOwner(
40
59
  parentNodehash,
41
60
  label,
42
61
  '0x0000000000000000000000000000000000000000',
43
- '0x0000000000000000000000000000000000000000',
44
- 0,
45
62
  0,
46
63
  0,
47
64
  )
@@ -1,6 +1,7 @@
1
1
  import { ENS } from '..'
2
2
  import setup from '../tests/setup'
3
3
  import { Name } from './getNames'
4
+ import { names as wrappedNames } from '../../deploy/00_register_wrapped'
4
5
 
5
6
  let ensInstance: ENS
6
7
 
@@ -172,10 +173,19 @@ describe('getNames', () => {
172
173
  type: 'wrappedOwner',
173
174
  page: 0,
174
175
  })
176
+
177
+ const nameCout = wrappedNames.reduce<number>((count, name) => {
178
+ if (name.namedOwner === 'owner2') count += 1
179
+ ;(name.subnames || []).forEach((subname: any) => {
180
+ if (subname.namedOwner === 'owner2') count += 1
181
+ })
182
+ return count
183
+ }, 0)
184
+
175
185
  // length of page one should be all the names on 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
176
186
  // minus 1 for the PCC expired name.
177
187
  // the result here implies that the PCC expired name is not returned
178
- expect(pageOne).toHaveLength(4)
188
+ expect(pageOne).toHaveLength(nameCout - 1)
179
189
  })
180
190
  describe('orderBy', () => {
181
191
  describe('registrations', () => {
@@ -144,6 +144,7 @@ const getNames = async (
144
144
  parent {
145
145
  name
146
146
  }
147
+ createdAt
147
148
  `
148
149
 
149
150
  let queryVars: object = {}
@@ -168,7 +169,6 @@ const getNames = async (
168
169
  }
169
170
  domains(first: 1000) {
170
171
  ${domainQueryData}
171
- createdAt
172
172
  registration {
173
173
  registrationDate
174
174
  expiryDate
@@ -203,7 +203,6 @@ const getNames = async (
203
203
  account(id: $id) {
204
204
  domains(orderBy: $orderBy, orderDirection: $orderDirection) {
205
205
  ${domainQueryData}
206
- createdAt
207
206
  registration {
208
207
  registrationDate
209
208
  expiryDate
@@ -234,7 +233,6 @@ const getNames = async (
234
233
  orderDirection: $orderDirection
235
234
  ) {
236
235
  ${domainQueryData}
237
- createdAt
238
236
  }
239
237
  }
240
238
  }
@@ -267,7 +265,6 @@ const getNames = async (
267
265
  fuses
268
266
  domain {
269
267
  ${domainQueryData}
270
- createdAt
271
268
  }
272
269
  }
273
270
  }
@@ -298,7 +295,6 @@ const getNames = async (
298
295
  fuses
299
296
  domain {
300
297
  ${domainQueryData}
301
- createdAt
302
298
  }
303
299
  }
304
300
  }