Skip to content

Commit

Permalink
feat(registry): add insert entry task
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone committed Oct 16, 2023
1 parent 03390b1 commit 8986ecc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '@nomiclabs/hardhat-ethers';
import '@typechain/hardhat';
import '@nomiclabs/hardhat-etherscan';
import './tasks/deploy';
import './tasks/registry';

task('accounts', 'Print a list of accounts', async (_, hre) => {
const accounts = await hre.ethers.getSigners();
Expand Down
46 changes: 46 additions & 0 deletions contracts/tasks/registry.ts
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}`);

});
22 changes: 22 additions & 0 deletions contracts/utils/artifacts.ts
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)
}

0 comments on commit 8986ecc

Please sign in to comment.