@@ -10,15 +10,15 @@ import { contracts, executeTransaction, overrides, checkFuncInputs } from './hel
1010// Set up the script //
1111///////////////////////
1212
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' ] ,
1515} )
1616
17- if ( ! func ) {
17+ if ( ! func || ! name ) {
1818 console . error (
1919 `
2020Usage: ${ path . basename ( process . argv [ 1 ] ) }
21- --func <string> - options: setRecord, setText, checkOwner
21+ --func <string> - options: registerName, setRecord, setText, checkOwner, nameHash
2222
2323Function arguments:
2424 setRecord
@@ -58,28 +58,42 @@ Function arguments:
5858// )
5959// }
6060
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' } `
6770 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 )
7271 console . log ( `Namehash for ${ labelNameFull } : ${ labelHashFull } ` )
7372
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)
7477 await executeTransaction ( contracts . testRegistrar . register ( label , signerAddress , ensOverrides ) )
7578}
7679
7780const 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+
7985 const key = 'GRAPH NAME SERVICE'
8086 const ensOverrides = overrides ( 'ens' , 'setText' )
8187 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 ( )
8397}
8498
8599const checkOwner = async ( ) => {
@@ -100,15 +114,15 @@ const checkOwner = async () => {
100114
101115const main = async ( ) => {
102116 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' ) {
104121 console . log ( `Setting owner for ${ name } ...` )
105- setTestRecord ( name )
122+ setTestRecord ( )
106123 } else if ( func == 'setText' ) {
107124 console . log ( `Setting text record of 'GRAPH NAME SERVICE' for caller ...` )
108125 setText ( )
109- // } else if (func == 'setEthDomain') { NOT IN USE
110- // console.log(`Setting '.eth' domain ...`)
111- // setSubnodeRecord('', 'eth')
112126 } else if ( func == 'checkOwner' ) {
113127 console . log ( `Checking owner of ${ name } ...` )
114128 checkOwner ( )
0 commit comments