-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0x9f7BF46F33D121a903fC5275Ff713e10Fa2085Ca |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const path = require('path'); | ||
const solc = require('solc'); | ||
const fs = require('fs-extra'); | ||
|
||
const buildPath = path.resolve(__dirname, 'build'); | ||
fs.removeSync(buildPath); | ||
|
||
const campaignPath = path.resolve(__dirname, 'contracts', 'HippoCampus.sol'); | ||
const source = fs.readFileSync(campaignPath, 'utf8'); | ||
const output = solc.compile(source, 1).contracts; | ||
|
||
fs.ensureDirSync(buildPath); | ||
|
||
console.log(output); | ||
for (let contract in output) { | ||
fs.outputJsonSync( | ||
path.resolve(buildPath, contract.replace(':', '') + '.json'), | ||
output[contract] | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
pragma solidity ^0.4.17; | ||
|
||
contract ContractFactory { | ||
|
||
address[] public deployedPatients; | ||
mapping(address => address) public patientContract; | ||
|
||
function createPatient( string bloodG) { | ||
|
||
address newPatient = new Patient( msg.sender, bloodG); | ||
deployedPatients.push(newPatient); | ||
patientContract[msg.sender] = newPatient; | ||
} | ||
|
||
function getDeployedPatients() public view returns ( address[] ) { | ||
|
||
return deployedPatients; | ||
} | ||
|
||
function getPatientContract() public view returns (address) { | ||
|
||
return patientContract[msg.sender]; | ||
} | ||
} | ||
|
||
contract Patient { | ||
|
||
struct Report { | ||
|
||
string description; | ||
string hashValue; | ||
} | ||
address public owner; | ||
string public bloodGroup; | ||
Report[] public reports; | ||
|
||
modifier restricted() { | ||
|
||
require( msg.sender == owner ); | ||
_; | ||
|
||
} | ||
|
||
function Patient( address creator, string bloodG ){ | ||
owner = creator; | ||
bloodGroup = bloodG; | ||
} | ||
|
||
/* function getReports() public view returns (Report[]) { | ||
return reports; | ||
}*/ | ||
|
||
function createReport(string description, string hashValue) { | ||
|
||
Report memory newReport = Report({ | ||
description: description, | ||
hashValue: hashValue | ||
}); | ||
reports.push( newReport ); | ||
} | ||
|
||
function getReportsCount() public view returns(uint) { | ||
|
||
return reports.length; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const HDWalletProvider = require('truffle-hdwallet-provider'); | ||
const Web3 = require('web3'); | ||
const compiledFactory = require('./build/ContractFactory.json'); | ||
|
||
const provider = new HDWalletProvider( | ||
'mule crouch dismiss unique aim any helmet cycle door language knock meat', | ||
'https://rinkeby.infura.io/v3/abd0dce74de548d6a376886446d25bbe' | ||
); | ||
|
||
const web3 = new Web3(provider); | ||
|
||
|
||
const INITIAL_MESSAGE = 'Hi there!'; | ||
const deploy = async () => { | ||
const accounts = await web3.eth.getAccounts(); | ||
|
||
console.log('Attemting to deploy from account', accounts[0]); | ||
|
||
const result = await new web3.eth.Contract(JSON.parse(compiledFactory.interface)) | ||
.deploy({ data: '0x'+compiledFactory.bytecode }) | ||
.send({ gas: '1000000', from: accounts[0]}); | ||
|
||
console.log('Contract deployed to', result.options.address); | ||
}; // we are using function just to use async await sytax and sice we have multiple accounts linked witha single mneumonic we will hae to select one. | ||
|
||
deploy(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import web3 from './web3'; | ||
import ContractFactory from './build/ContractFactory.json'; | ||
|
||
const instance = new web3.eth.Contract( | ||
JSON.parse(ContractFactory.interface), | ||
'0x9f7BF46F33D121a903fC5275Ff713e10Fa2085Ca' | ||
); | ||
|
||
export default instance; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Web3 from 'web3'; | ||
|
||
let web3; | ||
|
||
if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined') { //checking if its running on browser or server | ||
// We are in browser | ||
web3 = new Web3(window.web3.currentProvider); //scraping the older version of web3 injected by metamask and replacing it with a newer version | ||
} | ||
else { | ||
// We are on the server or the user is not running metamask | ||
const provider = new Web3.providers.HttpProvider( | ||
'https://rinkeby.infura.io/v3/abd0dce74de548d6a376886446d25bbe' | ||
); | ||
|
||
web3 = new Web3(provider); | ||
} | ||
|
||
export default web3; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.