Skip to content

Commit

Permalink
Small improvements to the pinning feature
Browse files Browse the repository at this point in the history
  • Loading branch information
0xGabi committed Jul 7, 2021
1 parent 977e7cc commit 34a2ecd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Aragon Hardhat plugin",
"author": "1hive <info@1hive.org>",
"license": "MIT",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"main": "dist/src/internal/index.js",
"types": "dist/src/internal/index.d.ts",
"keywords": [
"ethereum",
"smart-contracts",
Expand Down
36 changes: 21 additions & 15 deletions src/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import path from 'path'
import { providers } from 'ethers'
import { extendConfig, extendEnvironment, task } from 'hardhat/config'
import { HardhatPluginError, lazyObject } from 'hardhat/plugins'
import { HardhatConfig, HardhatUserConfig } from 'hardhat/types'
import {
HardhatConfig,
HardhatUserConfig,
HttpNetworkConfig,
} from 'hardhat/types'
import * as types from 'hardhat/internal/core/params/argumentTypes'

import {
Expand Down Expand Up @@ -40,8 +44,10 @@ import {
assertUploadContetResolve,
} from './utils/ipfs'

import '@nomiclabs/hardhat-ethers'
import 'hardhat-deploy'
// We ommit these imports beacuse they are peer dependencies and will be added
// by the plugin user. Otherwise naming conflicts may araise
// import '@nomiclabs/hardhat-ethers'
// import 'hardhat-deploy'

// This import is needed to let the TypeScript compiler know that it should include your type
// extensions in your npm package's types file.
Expand Down Expand Up @@ -151,23 +157,20 @@ task(TASK_PUBLISH, 'Publish a new app version to Aragon Package Manager')
// for apps that were deployed to diferent repo names
const finalAppEnsName = hre.network.config.appEnsName ?? appEnsName

// Setup provider with the right ENS registy address
let provider
if (hre.network.name === 'localhost') {
if (hre.network.name === 'hardhat') {
hre.ethers.provider.network.ensAddress = hre.network.config.ensRegistry
provider = hre.ethers.provider
} else {
provider = new hre.ethers.providers.JsonRpcProvider(
hre.config.networks.localhost.url,
(hre.network.config as HttpNetworkConfig).url,
{
name: 'localhost',
name: hre.network.name,
ensAddress: hre.network.config.ensRegistry,
chainId: 31337,
chainId: parseInt(await hre.getChainId()),
}
)
} else {
// Mutate provider with new ENS address
if (hre.network.config.ensRegistry) {
hre.ethers.provider.network.ensAddress =
hre.network.config.ensRegistry
}
provider = hre.ethers.provider
}

const prevVersion = await _getLastestVersionIfExists(
Expand Down Expand Up @@ -197,7 +200,9 @@ task(TASK_PUBLISH, 'Publish a new app version to Aragon Package Manager')
contractAddress = existingContractAddress
log(`Using provided contract address: ${contractAddress}`)
} else if (!prevVersion || bump === 'major') {
log('Deploying new implementation contract')
log(
'Deploying new implementation contract. Or reusing last deployment if no changes.'
)
const deployment = await hre.deployments.deploy(appContractName, {
from: owner.address,
args: args.constructorArgs,
Expand Down Expand Up @@ -260,6 +265,7 @@ task(TASK_PUBLISH, 'Publish a new app version to Aragon Package Manager')
const response = await pinContent({
contentHash,
appEnsName: finalAppEnsName,
version: nextVersion,
network: hre.network.name,
pinata: hre.config.ipfs.pinata,
})
Expand Down
4 changes: 3 additions & 1 deletion src/internal/utils/ipfs/pinContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ const PIN_BY_HASH_API = 'pinByHash'
export async function pinContent({
contentHash,
appEnsName,
version,
network,
pinata,
}: {
contentHash: string
appEnsName: string
version: string
network: string
pinata: PinataConfig
}): Promise<any | undefined> {
const url = urlJoin(DEFAULT_PINATA_API_ENDPOINT, 'pinning', PIN_BY_HASH_API)
const body = {
hashToPin: contentHash,
pinataMetadata: {
name: `${network}:${appEnsName}`,
name: `${network}:${appEnsName}@${version}`,
},
}
try {
Expand Down
5 changes: 5 additions & 0 deletions test/fixture-project/hardhat-project/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const config: HardhatUserConfig = {
localhost: {
ensRegistry: '0xaafca6b0c89521752e559650206d7c925fd0e530',
},
frame: {
url: 'http://localhost:1248',
httpHeaders: { origin: 'hardhat' },
ensRegistry: '0x4E065c622d584Fbe5D9078C3081840155FA69581',
},
},
}

Expand Down

0 comments on commit 34a2ecd

Please sign in to comment.