-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(registry): add insert entry task
Signed-off-by: Tomás Migone <[email protected]>
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {Wallet, ethers} from 'ethers'; | ||
import {task, types} from 'hardhat/config'; | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
import {loadArtifact} from '../utils/artifacts'; | ||
import {Registry} from '../types/contracts/Registry'; | ||
|
||
import addresses from '../addresses.json'; | ||
|
||
task('registry:insert', 'Insert an entry to the registry') | ||
.addParam('entryId', 'Entry ID to insert', undefined, types.int) | ||
.addParam('subscriptions', 'Comma separated list of subscription contract addresses to insert', undefined, types.string) | ||
.addParam('metadataHash', 'Metadata hash to insert', undefined, types.string) | ||
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => { | ||
const accounts = await hre.ethers.getSigners(); | ||
|
||
if (accounts.length === 0) { | ||
throw new Error( | ||
'No accounts available, set PRIVATE_KEY or MNEMONIC env variables' | ||
); | ||
} | ||
console.log( | ||
'Using the account:', | ||
accounts[0].address | ||
); | ||
|
||
const chainId = (hre.network.config.chainId as number).toString(); | ||
const registryAddress = (addresses as any)[chainId]['Registry']; | ||
|
||
const artifact = loadArtifact('Registry'); | ||
const registry = new ethers.Contract( | ||
registryAddress, | ||
artifact.abi, | ||
hre.ethers.provider | ||
) as Registry; | ||
|
||
console.log(`Registry contract address: ${registry.address}`); | ||
|
||
const tx = await registry.connect(accounts[0]).insertEntry(taskArgs.entryId, { | ||
subscriptions: taskArgs.subscriptions.split(','), | ||
metadataHash: taskArgs.metadataHash, | ||
}) | ||
|
||
const receipt = await tx.wait(); | ||
console.log(`Transaction successful: ${receipt.transactionHash}`); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import path from 'path' | ||
import { Artifacts } from 'hardhat/internal/artifacts' | ||
import { LinkReferences } from 'hardhat/types' | ||
import { utils } from 'ethers' | ||
|
||
type Abi = Array<string | utils.FunctionFragment | utils.EventFragment | utils.ParamType> | ||
|
||
type Artifact = { | ||
contractName: string | ||
abi: Abi | ||
bytecode: string | ||
deployedBytecode: string | ||
linkReferences?: LinkReferences | ||
deployedLinkReferences?: LinkReferences | ||
} | ||
|
||
const ARTIFACTS_PATH = path.resolve('artifacts') | ||
const artifacts = new Artifacts(ARTIFACTS_PATH) | ||
|
||
export const loadArtifact = (name: string): Artifact => { | ||
return artifacts.readArtifactSync(name) | ||
} |