@@ -10,15 +10,15 @@ import { contracts, executeTransaction, overrides, checkFuncInputs } from './hel
10
10
// Set up the script //
11
11
///////////////////////
12
12
13
- const { func, name, node } = minimist . default ( process . argv . slice ( 2 ) , {
14
- string : [ 'func' , 'name' , 'node' ] ,
13
+ const { func, name } = minimist . default ( process . argv . slice ( 2 ) , {
14
+ string : [ 'func' , 'name' ] ,
15
15
} )
16
16
17
- if ( ! func ) {
17
+ if ( ! func || ! name ) {
18
18
console . error (
19
19
`
20
20
Usage: ${ path . basename ( process . argv [ 1 ] ) }
21
- --func <string> - options: setRecord, setText, checkOwner
21
+ --func <string> - options: registerName, setRecord, setText, checkOwner, nameHash
22
22
23
23
Function arguments:
24
24
setRecord
@@ -58,28 +58,42 @@ Function arguments:
58
58
// )
59
59
// }
60
60
61
- const setTestRecord = async ( labelName : string ) => {
62
- checkFuncInputs ( [ labelName ] , [ 'labelName' ] , 'setTestRecord' )
63
- const node = utils . namehash ( 'test' )
64
- const labelNameFull = `${ labelName } .${ 'test' } `
65
- const label = utils . keccak256 ( utils . toUtf8Bytes ( labelName ) )
66
- console . log ( label )
61
+ // Must normalize name to lower case to get script to work with ethers namehash
62
+ // This is because in setTestRecord() - label uses the normal keccak
63
+ // TODO - follow UTS46 in scripts https://docs.ens.domains/contract-api-reference/name-processing
64
+ const normalizedName = name . toLowerCase ( )
65
+
66
+ const setTestRecord = async ( ) => {
67
+ // const node = utils.namehash('test')
68
+ // console.log('Namehash node for "test": ', node)
69
+ const labelNameFull = `${ normalizedName } .${ 'test' } `
67
70
const labelHashFull = utils . namehash ( labelNameFull )
68
- const signerAddress = await contracts . ens . signer . getAddress ( )
69
- const ensOverrides = overrides ( 'ens' , 'register' )
70
- console . log ( 'Namehash node for "test": ' , node )
71
- console . log ( `Hash of label ${ labelName } : ` , label )
72
71
console . log ( `Namehash for ${ labelNameFull } : ${ labelHashFull } ` )
73
72
73
+ const signerAddress = await contracts . ens . signer . getAddress ( )
74
+ const ensOverrides = overrides ( 'ens' , 'register' )
75
+ const label = utils . keccak256 ( utils . toUtf8Bytes ( normalizedName ) )
76
+ // console.log(`Hash of label being registered on ens ${name}: `, label)
74
77
await executeTransaction ( contracts . testRegistrar . register ( label , signerAddress , ensOverrides ) )
75
78
}
76
79
77
80
const setText = async ( ) => {
78
- checkFuncInputs ( [ node ] , [ 'node' ] , 'setText' )
81
+ const labelNameFull = `${ normalizedName } .${ 'test' } `
82
+ const labelHashFull = utils . namehash ( labelNameFull )
83
+ console . log ( `Setting text name: ${ labelNameFull } with node: ${ labelHashFull } ` )
84
+
79
85
const key = 'GRAPH NAME SERVICE'
80
86
const ensOverrides = overrides ( 'ens' , 'setText' )
81
87
const signerAddress = await contracts . publicResolver . signer . getAddress ( )
82
- await executeTransaction ( contracts . publicResolver . setText ( node , key , signerAddress , ensOverrides ) )
88
+ await executeTransaction (
89
+ contracts . publicResolver . setText ( labelHashFull , key , signerAddress , ensOverrides ) ,
90
+ )
91
+ }
92
+
93
+ // does everything in one func call
94
+ const registerName = async ( ) => {
95
+ await setTestRecord ( )
96
+ await setText ( )
83
97
}
84
98
85
99
const checkOwner = async ( ) => {
@@ -100,15 +114,15 @@ const checkOwner = async () => {
100
114
101
115
const main = async ( ) => {
102
116
try {
103
- if ( func == 'setTestRecord' ) {
117
+ if ( func == 'registerName' ) {
118
+ console . log ( `Registering ownership and text record for ${ name } ...` )
119
+ registerName ( )
120
+ } else if ( func == 'setTestRecord' ) {
104
121
console . log ( `Setting owner for ${ name } ...` )
105
- setTestRecord ( name )
122
+ setTestRecord ( )
106
123
} else if ( func == 'setText' ) {
107
124
console . log ( `Setting text record of 'GRAPH NAME SERVICE' for caller ...` )
108
125
setText ( )
109
- // } else if (func == 'setEthDomain') { NOT IN USE
110
- // console.log(`Setting '.eth' domain ...`)
111
- // setSubnodeRecord('', 'eth')
112
126
} else if ( func == 'checkOwner' ) {
113
127
console . log ( `Checking owner of ${ name } ...` )
114
128
checkOwner ( )
0 commit comments