@aragon/apm
Advanced tools
Comparing version
{ | ||
"name": "@aragon/apm", | ||
"version": "3.1.0-beta.1", | ||
"version": "3.1.0", | ||
"description": "JavaScript library for the Aragon Package Manager", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
110
src/index.js
@@ -126,2 +126,6 @@ const ens = require('./ens') | ||
function getKernel (app) { | ||
return app.methods.kernel().call() | ||
} | ||
return { | ||
@@ -234,7 +238,7 @@ validInitialVersions: ['0.0.1', '0.1.0', '1.0.0'], | ||
* If the destination repository does not exist, it falls back to creating a new | ||
* repository with an initial version. | ||
* repository with an initial version controlled by an initial manager. | ||
* | ||
* Returns the raw transaction to sign. | ||
* | ||
* @param {string} manager The address that has access to manage this repository. | ||
* @param {string} manager The address that will manage the new repo if it has to be created. | ||
* @param {string} appId The ENS name for the application repository. | ||
@@ -245,5 +249,44 @@ * @param {string} version A valid semantic version for this version. | ||
* @param {string} contract The new contract address for this version. | ||
* @param {string} from The account address we should estimate the gas with | ||
* @return {Promise} A promise that resolves to a raw transaction | ||
*/ | ||
async publishVersion (manager, appId, version, provider, directory, contract, from) { | ||
const { | ||
targetContract, | ||
name, | ||
params | ||
} = await this.publishVersionIntent(manager, appId, version, provider, directory, contract) | ||
try { | ||
const call = targetContract.methods[name](...params) | ||
// Return transaction to sign | ||
return { | ||
to: targetContract.options.address, | ||
data: call.encodeABI(), | ||
gas: Math.round(await call.estimateGas({ from }) * GAS_FUZZ_FACTOR), | ||
gasPrice: web3.utils.toWei('10', 'gwei') | ||
} | ||
} catch (err) { | ||
throw new Error(`Transaction would not succeed ("${err.message}")`) | ||
} | ||
}, | ||
/** | ||
* Create an intent to publish a new version (`version`) of `appId` using storage provider `provider`. | ||
* | ||
* If the destination repository does not exist, the intent will be for creating a new | ||
* repository with an initial version. | ||
* | ||
* Returns an object with the needed components to execute an aragon.js intent | ||
* | ||
* @param {string} manager The address that will manage the new repo if it has to be created. | ||
* @param {string} appId The ENS name for the application repository. | ||
* @param {string} version A valid semantic version for this version. | ||
* @param {string} provider The name of an APM storage provider. | ||
* @param {string} directory The directory that contains files to publish. | ||
* @param {string} contract The new contract address for this version. | ||
* @return {Promise} A promise that resolves to an aragon.js intent | ||
*/ | ||
async publishVersionIntent(manager, appId, version, provider, directory, contract) { | ||
if (!semver.valid(version)) { | ||
@@ -266,41 +309,38 @@ throw new Error(`${version} is not a valid semantic version`) | ||
// Default call creates a new repository and publishes the initial version | ||
const repoRegistry = await this.getRepoRegistry(appId) | ||
.catch(() => { | ||
throw new Error(`Repository ${appId} does not exist and it's registry does not exist`) | ||
}) | ||
let transactionDestination = repoRegistry.options.address | ||
let call = repoRegistry.methods.newRepoWithVersion( | ||
appId.split('.')[0], | ||
manager, | ||
formatVersion(version), | ||
contract, | ||
`0x${contentURI}` | ||
) | ||
// If the repository already exists, the call publishes a new version | ||
// If the repo exists, create a new version in the repo | ||
if (repo !== null) { | ||
transactionDestination = repo.options.address | ||
call = repo.methods.newVersion( | ||
formatVersion(version), | ||
contract, | ||
`0x${contentURI}` | ||
) | ||
} | ||
return { | ||
dao: await getKernel(repo), | ||
proxyAddress: repo.options.address, | ||
methodName: 'newVersion', | ||
params: [ | ||
formatVersion(version), | ||
contract, | ||
`0x${contentURI}` | ||
], | ||
targetContract: repo | ||
} | ||
} else { | ||
// If the repo does not exist yet, the intent will be for creating a repo with the first version | ||
const repoRegistry = await this.getRepoRegistry(appId) | ||
.catch(() => { | ||
throw new Error(`Repository ${appId} does not exist and its registry does not exist`) | ||
}) | ||
try { | ||
// Return transaction to sign | ||
return { | ||
to: transactionDestination, | ||
data: call.encodeABI(), | ||
gas: Math.round(await call.estimateGas({ from }) * GAS_FUZZ_FACTOR), | ||
gasPrice: web3.utils.toWei('10', 'gwei'), | ||
nonce: await web3.eth.getTransactionCount(manager) | ||
dao: await getKernel(repoRegistry), | ||
proxyAddress: repoRegistry.options.address, | ||
methodName: 'newRepoWithVersion', | ||
params: [ | ||
appId.split('.')[0], | ||
manager, | ||
formatVersion(version), | ||
contract, | ||
`0x${contentURI}` | ||
], | ||
targetContract: repoRegistry | ||
} | ||
} catch (err) { | ||
throw new Error(`Transaction would not succeed ("${err.message}")`) | ||
} | ||
} | ||
}, | ||
} | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
24866
7.25%447
9.29%1
-50%