watcher-ts/packages/lighthouse-watcher/tasks/lighthouse-store.ts
Ashwin Phatak a7ec3d8da8
Add APGL license and copyright notices (#212)
* Add license & copyright declarations for add-watcher.

* Add copyright declarations for cache.

* Add copyright declarations for erc20-watcher.

* Add copyright declarations for ipld-eth-client.

* Add copyright declarations for tracing-client.

* Add copyright declarations for uni-watcher.

* Add copyright declarations for solidity-mapper.

* Add copyright declarations for uni-info-watcher.

* Add copyright declarations for util.

* Add copyright declarations for lighthouse-watcher.

* Change license identifier in .sol files.

Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
2021-08-12 15:28:13 +05:30

46 lines
1.6 KiB
TypeScript

//
// Copyright 2021 Vulcanize, Inc.
//
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());
}
}
});