11import Listr from "listr" ;
22import { ethers } from "ethers" ;
3- import {
4- < << << << HEAD
5- < << << << HEAD
6-
7-
8- getEthereumUrl
9- } from "../utils/getEthereumUrl.js" ;
10- = === ===
11- //Apm,
12- === === =
13- isValidENSName ,
14- getEthereumProviderUrl ,
15- > >>> >>> refactor APM usage
16- encodeNewVersionCall ,
17- encodeNewRepoWithVersionCall
18- } from "../utils/Apm.js" ;
19- > >>> >>> integrate toolkit v1
203import { getPublishTxLink } from "../utils/getLinks.js" ;
214import { addReleaseTx } from "../utils/releaseRecord.js" ;
225import { defaultDir , YargsError } from "../params.js" ;
236import { CliGlobalOptions , ListrContextBuildAndPublish } from "../types.js" ;
247import { readManifest } from "../files/index.js" ;
25- import { ApmRepository } from "@dappnode/toolkit" ;
8+ import repoAbi from "../contracts/RepoAbi.json" assert { type : "json" } ;
269import registryAbi from "../contracts/ApmRegistryAbi.json" assert { type : "json" } ;
2710import { semverToArray } from "../utils/semverToArray.js" ;
28- import repoAbi from "../contracts/RepoAbi.json" assert { type : "json" } ;
11+ import { getEthereumUrl } from "../utils/getEthereumUrl.js" ;
2912
3013const isZeroAddress = ( address : string ) : boolean => parseInt ( address ) === 0 ;
3114
@@ -52,23 +35,9 @@ export function generatePublishTx({
5235 developerAddress ?: string ;
5336 ethProvider : string ;
5437} & CliGlobalOptions ) : Listr < ListrContextBuildAndPublish > {
55- < < < << << HEAD
56- // Init APM instance
57- < << << << HEAD
58- const ethereumUrl = getEthereumUrl ( ethProvider ) ;
59- const apm = new ApmRepository ( ethereumUrl ) ;
60- = === ===
61- //const apm = new Apm(ethProvider);
62-
63- const parsedProvider = new ethers . JsonRpcProvider ( getEthereumProviderUrl ( ethProvider ) )
64- // Init APM instance
65- const apm2 = new ApmRepository ( parsedProvider ) ;
66- > >>> >>> integrate toolkit v1
67- === = ===
6838
6939 //
70- const provider = new ethers . JsonRpcProvider ( getEthereumProviderUrl ( ethProvider ) )
71- >>> > >>> refactor APM usage
40+ const provider = new ethers . JsonRpcProvider ( getEthereumUrl ( ethProvider ) )
7241
7342 // Load manifest ##### Verify manifest object
7443 const { manifest } = readManifest ( { dir } ) ;
@@ -86,18 +55,9 @@ export function generatePublishTx({
8655 {
8756 title : "Generate transaction" ,
8857 task : async ctx => {
89- < < < << << HEAD
90- < << << << HEAD
91- try {
92- const repository = await apm . getRepoContract ( ensName ) ;
93- === === =
94- const repository = await parsedProvider . resolveName ( ensName ) ;
95- === === =
9658 isValidENSName ( ensName ) ;
9759 const repository = await provider . resolveName ( ensName ) ;
98- >>> >>> > refactor APM usage
9960 if ( repository ) {
100- >>> >>> > integrate toolkit v1
10161 ctx . txData = {
10262 to : repository ,
10363 value : 0 ,
@@ -111,29 +71,9 @@ export function generatePublishTx({
11171 currentVersion,
11272 releaseMultiHash
11373 } ;
114- << << << < HEAD
115- } catch ( e ) {
116- if ( e . message . includes ( "Could not resolve name" ) ) {
117- try {
118- const registryAddress = await new ethers . JsonRpcProvider (
119- ethereumUrl
120- ) . resolveName ( ensName . split ( "." ) . slice ( 1 ) . join ( "." ) ) ;
121- if ( ! registryAddress )
122- throw new Error ( "Registry not found for " + ensName ) ;
123-
124- // If repo does not exist, create a new repo and push version
125- // A developer address must be provided by the option -a or --developer_address.
126- if (
127- ! developerAddress ||
128- ! ethers . isAddress ( developerAddress ) ||
129- isZeroAddress ( developerAddress )
130- ) {
131- throw new YargsError (
132- `A new Aragon Package Manager Repo for ${ ensName } must be created.
133- =======
13474 } else {
135- const registry = await provider.resolveName(ensName.split(".").slice(1).join("."));
136- if (!registry )
75+ const registryAddress = await provider . resolveName ( ensName . split ( "." ) . slice ( 1 ) . join ( "." ) ) ;
76+ if ( ! registryAddress )
13777 throw Error (
13878 `There must exist a registry for DNP name ${ ensName } `
13979 ) ;
@@ -147,7 +87,6 @@ export function generatePublishTx({
14787 ) {
14888 throw new YargsError (
14989 `A new Aragon Package Manager Repo for ${ ensName } must be created.
150- > >>> > >> integrate toolkit v1
15190You must specify the developer address that will control it
15291
15392with ENV:
@@ -158,37 +97,10 @@ with command option:
15897
15998 dappnodesdk publish [type] --developer_address 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B
16099`
161- <<<<<<< HEAD
162- );
163- }
164-
165- ctx.txData = {
166- to: registryAddress,
167- value: 0,
168- data: encodeNewRepoWithVersionCall({
169- name: shortName,
170- developerAddress,
171- version: currentVersion,
172- contractAddress,
173- contentURI
174- }),
175- gasLimit: 1100000,
176- ensName,
177- currentVersion,
178- releaseMultiHash,
179- developerAddress
180- };
181- } catch (e) {
182- throw Error(
183- ` There must exist a registry for DNP name ${ensName } `
184- ) ;
185- }
186- } else throw e ;
187- === === =
188100 ) ;
189101 }
190102 ctx . txData = {
191- to : registry ,
103+ to : registryAddress ,
192104 value : 0 ,
193105 data : encodeNewRepoWithVersionCall ( {
194106 name : shortName ,
@@ -203,7 +115,6 @@ with command option:
203115 releaseMultiHash,
204116 developerAddress
205117 } ;
206- >>> > >>> integrate toolkit v1
207118 }
208119
209120 /**
@@ -221,17 +132,14 @@ with command option:
221132 ) ;
222133}
223134
224- // Utils
225-
226-
227135/**
228136 * newVersion(
229137 * uint16[3] _newSemanticVersion,
230138 * address _contractAddress,
231139 * bytes _contentURI
232140 * )
233141 */
234- export function encodeNewVersionCall ( {
142+ export function encodeNewVersionCall ( {
235143 version,
236144 contractAddress,
237145 contentURI
@@ -279,3 +187,41 @@ export function encodeNewRepoWithVersionCall({
279187 contentURI // bytes _contentURI
280188 ] ) ;
281189}
190+ /**
191+ *checks if the name is a valid ENS name. Returns all reasons why the name is not valid if it is not valid.
192+ * - ENS name must be between 1 and 63 characters.
193+ * - ENS name must contain only lowercase alphanumeric characters(a-z), hyphens(-) and dots(.).
194+ * - Labels must not start or end with a hyphen.
195+ * - Labels must not contain consecutive hyphens.
196+ * - Last label must be ".eth".
197+
198+ */
199+ export function isValidENSName ( name : string ) : void {
200+ const invalidMessages : string [ ] = [ ] ;
201+
202+ // Length Check
203+ if ( name . length < 3 || name . length > 63 ) {
204+ invalidMessages . push ( 'Length must be between 3 and 63 characters.' ) ;
205+ }
206+
207+ // Character Check
208+ if ( ! / ^ [ a - z 0 - 9 - .] + $ / . test ( name ) ) {
209+ invalidMessages . push ( 'Contains forbidden characters.' ) ;
210+ }
211+
212+ // Hyphen Placement Check
213+ if ( name . startsWith ( "-" ) || name . endsWith ( "-" ) || name . includes ( "--" ) ) {
214+ invalidMessages . push ( 'Hyphen placement is not allowed.' ) ;
215+ }
216+
217+ const labels = name . split ( "." ) ;
218+ // Last Label Check
219+ const tld = labels [ labels . length - 1 ] ;
220+ if ( tld . toLowerCase ( ) !== "eth" ) {
221+ invalidMessages . push ( 'Last label must be ".eth".' ) ;
222+ }
223+
224+ if ( invalidMessages . length > 0 ) {
225+ throw new Error ( `Invalid ENS name: ${ invalidMessages . join ( ' ' ) } ` ) ;
226+ }
227+ }
0 commit comments