watcher-ts/packages/lighthouse-watcher/tasks/lighthouse-store.ts
Ashwin Phatak 4fb0d95135
Lighthouse watcher (#205)
* Implement watcher for Lighthouse StorageRequest event.

* Add smoke test for lighthouse watcher.

* Add fileCost as value to Lighthouse store call.

Co-authored-by: nabarun <nabarun@deepstacksoft.com>
2021-08-11 17:27:49 +05:30

42 lines
1.5 KiB
TypeScript

import { task, types } from 'hardhat/config';
import '@nomiclabs/hardhat-ethers';
import { ContractTransaction, utils } from 'ethers';
task('lighthouse-store', 'Call Lighthouse store method')
.addParam('lighthouse', 'Address of Lighthouse contract', undefined, types.string)
.addParam('cid', 'store cid', undefined, types.string)
.addParam('storeConfig', 'store config', undefined, types.string)
.addParam('fileCost', 'store fileCost (wei)', undefined, types.float)
.setAction(async (args, hre) => {
const {
lighthouse: lighthouseAddress,
cid,
storeConfig: config,
fileCost
} = args;
await hre.run('compile');
const Ligthouse = await hre.ethers.getContractFactory('Lighthouse');
const lighthouse = Ligthouse.attach(lighthouseAddress);
const value = utils.parseUnits(String(fileCost), 'wei');
const transaction: ContractTransaction = await lighthouse.store(cid, config, { value });
const receipt = await transaction.wait();
if (receipt.events) {
console.log('receipt blockHash', receipt.blockHash);
const storageRequestEvent = receipt.events.find(el => el.event === 'StorageRequest');
if (storageRequestEvent && storageRequestEvent.args) {
console.log('StorageRequest Event');
console.log('uploader:', storageRequestEvent.args.uploader);
console.log('cid:', storageRequestEvent.args.cid);
console.log('config:', storageRequestEvent.args.config);
console.log('fileCost:', storageRequestEvent.args.fileCost.toString());
}
}
});