{"size": 1411, "ext": "js", "max_stars_repo_path": "src/config.js", "max_stars_repo_name": "billmlion/my-blockchain", "max_stars_repo_stars_event_min_datetime": "2020-08-11T10:32:03.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-11T10:32:03.000Z", "max_issues_repo_path": "src/config.js", "max_issues_repo_name": "billmlion/my-blockchain", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/config.js", "max_forks_repo_name": "billmlion/my-blockchain", "max_forks_repo_forks_event_min_datetime": "2020-10-26T05:29:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-17T04:50:24.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 31.3555555556, "max_line_length": 91, "alphanum_fraction": 0.6754075124}
import ipfsApi from 'ipfs-api'
import { expression } from '@babel/template'
import { notification, message } from 'antd'
import Web3 from 'web3'
import CourseList from '../src/compiled/CourseList.json'
import Course from '../src/compiled/Course.json'
import address from './address'



let ipfs = ipfsApi("ipfs.infura.io", "5001", { "protocol": "https" })
let ipfsPrefix = "https://ipfs.infura.io:5001/api/v0/cat?arg="


let web3
if (window.web3) {
    web3 = new Web3(window.web3.currentProvider)
} else {
    notification.error({
        message: '没有检测到以太坊',
        description: '请安装metaMask或者激活'
    })
}

let courseListContract = new web3.eth.Contract(JSON.parse(CourseList.interface), address)
// let courseContract = new web3.eth.Contract(JSON.parse(Course.interface),address)
let getCourseContract = (addr) => new web3.eth.Contract(JSON.parse(Course.interface), addr)


function saveImageToIpfs(file) {
    const hide = message.loading('上传中')
    return new Promise(function (resolve, reject) {
        let reader = new FileReader()
        reader.readAsArrayBuffer(file)
        reader.onloadend = async () => {
            const buffer = Buffer.from(reader.result)
            const res = await ipfs.add(buffer)
            console.log(res)
            hide()
            resolve(res[0].hash)
        }
    })
}

export { ipfs, ipfsPrefix, saveImageToIpfs, web3, courseListContract, getCourseContract}