Skip to content

Commit a9f6e59

Browse files
committed
rebase to main
1 parent 725b47a commit a9f6e59

6 files changed

Lines changed: 338 additions & 1138 deletions

File tree

src/tasks/generatePublishTx.ts

Lines changed: 45 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
import Listr from "listr";
22
import { 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
203
import { getPublishTxLink } from "../utils/getLinks.js";
214
import { addReleaseTx } from "../utils/releaseRecord.js";
225
import { defaultDir, YargsError } from "../params.js";
236
import { CliGlobalOptions, ListrContextBuildAndPublish } from "../types.js";
247
import { readManifest } from "../files/index.js";
25-
import { ApmRepository } from "@dappnode/toolkit";
8+
import repoAbi from "../contracts/RepoAbi.json" assert { type: "json" };
269
import registryAbi from "../contracts/ApmRegistryAbi.json" assert { type: "json" };
2710
import { semverToArray } from "../utils/semverToArray.js";
28-
import repoAbi from "../contracts/RepoAbi.json" assert { type: "json" };
11+
import { getEthereumUrl } from "../utils/getEthereumUrl.js";
2912

3013
const 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
15190
You must specify the developer address that will control it
15291
15392
with 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-z0-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+
}

src/utils/Apm.ts

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/utils/verifyEthConnection.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
1-
<<<<<<< HEAD
21
import { getEthereumUrl } from "./getEthereumUrl.js";
32
import { CliError } from "../params.js";
43
import { ethers } from "ethers";
54

6-
=======
7-
import { CliError } from "../params.js";
8-
import {getEthereumProviderUrl} from "./Apm.js";
9-
import { ethers } from "ethers";
10-
>>>>>>> refactor APM usage
115
/**
126
* Verify the eth connection outside of the eth library to ensure
137
* capturing HTTP errors
148
* @param ethProvider
159
*/
1610
export async function verifyEthConnection(ethProvider: string): Promise<void> {
1711
if (!ethProvider) throw Error("No ethProvider provided");
18-
const parsedProvider = new ethers.JsonRpcProvider(getEthereumProviderUrl(ethProvider))
1912

20-
<<<<<<< HEAD
2113
const provider = new ethers.JsonRpcProvider(getEthereumUrl(ethProvider));
2214

2315
try {
2416
const network = await provider.getNetwork();
2517
if (!network) {
2618
throw new CliError(`Could not reach ETH provider at ${ethProvider}`);
27-
=======
28-
try {
29-
const isListening = await parsedProvider.send("net_listening", []);
30-
if (isListening === false) {
31-
throw new CliError(`Eth provider ${ethProvider} is not listening`);
32-
>>>>>>> refactor APM usage
3319
}
3420
} catch (e) {
3521
if (ethProvider === "dappnode") {
@@ -42,4 +28,4 @@ export async function verifyEthConnection(ethProvider: string): Promise<void> {
4228
throw new CliError(`Could not reach ETH provider at ${ethProvider}`);
4329
}
4430
}
45-
}
31+
}

0 commit comments

Comments
 (0)