Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3247 from njgheorghita/ethpm-v3
Browse files Browse the repository at this point in the history
ethpmV3 support
  • Loading branch information
eggplantzzz authored Nov 3, 2020
2 parents f67b577 + 0a5de23 commit 3cc229d
Show file tree
Hide file tree
Showing 39 changed files with 2,401 additions and 261 deletions.
13 changes: 8 additions & 5 deletions packages/config/src/configDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ export const getInitialConfig = ({
resolver: null,
artifactor: null,
ethpm: {
ipfs_host: "ipfs.infura.io",
ipfs_protocol: "https",
registry: "0x8011df4830b4f696cd81393997e5371b93338878",
install_provider_uri:
"https://ropsten.infura.io/v3/26e88e46be924823983710becd929f36"
ipfsHost: "ipfs.infura.io",
ipfsProtocol: "https",
ipfsPort: "5001",
registry: {
address: "0x0bd0200357D26A0bB5d1D1c1Fd56C317B68d15d5",
network: "ropsten"
},
version: "3"
},
ens: {
enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module.exports = {
create: require("./lib/commands/create/helpers"),
// TODO: update this to non-legacy the next breaking change
contracts: require("@truffle/workflow-compile/legacy"),
package: require("./lib/package"),
test: require("./lib/testing/Test"),
package: require("@truffle/ethpm-v3"),
version: pkg.version,
ganache: require("ganache-core/public-exports")
};
3 changes: 2 additions & 1 deletion packages/core/lib/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ module.exports = {
networks: require("./networks"),
obtain: require("./obtain"),
opcode: require("./opcode"),
packages: require("./packages"),
publish: require("./publish"),
run: require("./run"),
test: require("./test"),
unbox: require("./unbox"),
version: require("./version"),
watch: require("./watch")
watch: require("./watch"),
};
51 changes: 35 additions & 16 deletions packages/core/lib/commands/install.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
const { callbackify } = require("util");

const command = {
command: "install",
description: "Install a package from the Ethereum Package Registry",
builder: {},
help: {
usage: "truffle install <package_name>[@<version>]",
usage: "truffle install <package_identifier> [--alias]",
options: [
{
option: "package_name",
description:
"Name of the package as listed in the Ethereum Package Registry. (required)"
option: "package_identifier",
description: `Name of the package as listed in the Ethereum Package Registry. Accepted formats: packageName, packageName@version, ethpm URI, ipfs URI. (required)`
},
{
option: "<@version>",
description:
"When specified, will install a specific version of the package, otherwise " +
"will install\n the latest version."
option: "--alias",
description: "An alternate name under which to install this package."
}
]
},
run: function(options, done) {
run: function (options, done) {
const Config = require("@truffle/config");
const Package = require("../package");
const PackageV1 = require("@truffle/ethpm-v1");
const PackageV3 = require("@truffle/ethpm-v3");

if (options._ && options._.length > 0) options.packages = options._;
if (options._ && options._.length == 0) {
done(
new Error(
`Please provide a package identifier. Run 'truffle help install' for more information on valid package identifiers.`
)
);
}
if (options._ && options._.length > 1) {
done(
new Error(
`Multiple package identifiers detected. Only one package can be installed at a time.`
)
);
}
options.package_identifier = options._[0];

const config = Config.detect(options);
Package.install(config)
.then(() => {
return done();
})
.catch(done);
let installPackage;

if (config.ethpm.version == "1") {
installPackage = callbackify(PackageV1.install);
} else if (config.ethpm.version == "3") {
installPackage = callbackify(PackageV3.install);
} else {
done(new Error(`Unsupported ethpm version: ${config.ethpm.version}.`));
}
installPackage(config, done);
}
};

Expand Down
30 changes: 30 additions & 0 deletions packages/core/lib/commands/packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { callbackify } = require("util");

const command = {
command: "packages",
description: "List available packages on connected EthPM Registry",
builder: {},
help: {
usage: "truffle packages",
options: []
},
run: function (options, done) {
const Config = require("@truffle/config");
const PackageV1 = require("@truffle/ethpm-v1");
const PackageV3 = require("@truffle/ethpm-v3");

const config = Config.detect(options);
let listPackages;

if (config.ethpm.version == "1") {
listPackages = callbackify(PackageV1.packages);
} else if (config.ethpm.version == "3") {
listPackages = callbackify(PackageV3.packages);
} else {
done(new Error(`Unsupported ethpm version: ${config.ethpm.version}.`));
}
listPackages(config, done);
}
};

module.exports = command;
28 changes: 18 additions & 10 deletions packages/core/lib/commands/publish.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
var command = {
const { callbackify } = require("util");

const command = {
command: "publish",
description: "Publish a package to the Ethereum Package Registry",
builder: {},
help: {
usage: "truffle publish",
options: []
},
run: function(options, done) {
var Config = require("@truffle/config");
var Package = require("../package");
run: function (options, done) {
const Config = require("@truffle/config");
const PackageV1 = require("@truffle/ethpm-v1");
const PackageV3 = require("@truffle/ethpm-v3");

const config = Config.detect(options);
let publishPackage;

var config = Config.detect(options);
Package.publish(config)
.then(() => {
return done();
})
.catch(done);
if (config.ethpm.version == "1") {
publishPackage = callbackify(PackageV1.publish);
} else if (config.ethpm.version == "3") {
publishPackage = callbackify(PackageV3.publish);
} else {
done(new Error(`Unsupported ethpm version: ${config.ethpm.version}.`));
}
publishPackage(config, done);
}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"@truffle/resolver": "^6.0.25",
"@truffle/source-fetcher": "^0.2.4",
"@truffle/workflow-compile": "^3.0.6",
"@truffle/ethpm-v1": "^1.0.0",
"@truffle/ethpm-v3": "^3.0.0",
"app-module-path": "^2.2.0",
"chai": "4.2.0",
"colors": "^1.1.2",
Expand All @@ -49,8 +51,6 @@
"del": "^2.2.0",
"ethereum-cryptography": "^0.1.3",
"ethereumjs-wallet": "^0.6.2",
"ethpm": "0.0.19",
"ethpm-registry": "0.1.0-next.3",
"fs-extra": "^8.1.0",
"ganache-core": "2.13.0",
"get-port": "^5.1.1",
Expand Down
9 changes: 9 additions & 0 deletions packages/ethpm-v1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# `ethpm-v1`

## Usage

```
const ethpmV1 = require('ethpm-v1');
```

This package contains support for the deprecated v1 version of the ethpm specification for backwards compatibility purposes.
78 changes: 71 additions & 7 deletions packages/core/lib/package.js → packages/ethpm-v1/lib/ethpm-v1.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,77 @@
const expect = require("@truffle/expect");
const TruffleError = require("@truffle/error");
const Networks = require("./networks");
const Networks = require("@truffle/core/lib/networks");
const EthPM = require("ethpm");
const EthPMRegistry = require("ethpm-registry");
const Web3 = require("web3");
const registryAbi = require("./registryAbi");
const { createInterfaceAdapter } = require("@truffle/interface-adapter");
const path = require("path");
const fs = require("fs");
const OS = require("os");
const contract = require("@truffle/contract");

const Package = {
install: async function(options, callback) {
const PackageV1 = {
packages: async options => {
options.logger.log(
`ethpmV1 is deprecated. Please consider updating your packages to ethpmV3.`
);
try {
expect.options(options, [
"ethpm",
"logger",
"working_directory",
"contracts_build_directory",
"networks"
]);
} catch (err) {
throw new TruffleError(
`Invalid ethpm configuration in truffle-config: ${err.message}`
);
}

const ethpmV1Network = "ropsten";
if (!options.networks[ethpmV1Network]) {
throw new TruffleError(
`Please include a provider in your networks config for the Ropsten testnet, the testnet where the ethpmV1 registry is deployed.`
);
}
const provider = options.networks["ropsten"].provider();
const ethpmV1RegistryAddress = "0x8011df4830b4f696cd81393997e5371b93338878";
const RegistryContract = contract({
abi: registryAbi.abi
});
RegistryContract.setProvider(provider);
const registryContract = await RegistryContract.at(ethpmV1RegistryAddress);
const owner = await registryContract.owner.call();

// Display info about connected registry
options.logger.log(
`Searching for packages published on registry located on the ethpm V1 registry: ${ethpmV1RegistryAddress}`
);
options.logger.log(`Registry controlled by : ${owner}`);

// Display info about all releases on registry
const numPackages = await registryContract.getNumPackages.call();
for (var x = 0; x < numPackages; x++) {
const packageName = await registryContract.getPackageName.call(x);
const releaseHashes = await registryContract.getAllPackageReleaseHashes.call(
packageName
);
options.logger.log(packageName);
for (const hash of releaseHashes) {
const releaseData = await registryContract.getReleaseData.call(hash);
const version = `${releaseData.major}.${releaseData.minor}.${releaseData.patch}`;
options.logger.log(`- ${version} @ ${releaseData.releaseLockfileURI}`);
}
}
return;
},

install: async function (options, callback) {
options.logger.log(
`ethpmV1 is deprecated. Please consider updating your packages to ethpmV3.`
);
const callbackPassed = typeof callback === "function";
expect.options(options, ["working_directory", "ethpm"]);

Expand Down Expand Up @@ -112,7 +173,10 @@ const Package = {
}
},

publish: async function(options, callback) {
publish: async function (options, callback) {
options.logger.log(
`ethpmV1 is deprecated. Please consider updating your packages to ethpmV3.`
);
const callbackPassed = typeof callback === "function";
var self = this;

Expand Down Expand Up @@ -208,12 +272,12 @@ const Package = {
}
},

digest: function(options, callback) {
digest: function (options, callback) {
callback(new Error("Not yet implemented"));
},

// Return a list of publishable artifacts
publishable_artifacts: async function(options, callback) {
publishable_artifacts: async function (options, callback) {
const callbackPassed = typeof callback === "function";
// Filter out "test" and "development" networks.
const ifReservedNetworks = new Set(["test", "development"]);
Expand Down Expand Up @@ -350,4 +414,4 @@ const Package = {
}
};

module.exports = Package;
module.exports = PackageV1;
Loading

0 comments on commit 3cc229d

Please sign in to comment.