Skip to content

Commit

Permalink
Contracts and basic setup done
Browse files Browse the repository at this point in the history
  • Loading branch information
adish1997 committed Mar 13, 2019
0 parents commit bb7ba64
Show file tree
Hide file tree
Showing 20,216 changed files with 2,634,836 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions Address.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x9f7BF46F33D121a903fC5275Ff713e10Fa2085Ca
1 change: 1 addition & 0 deletions ethereum/build/ContractFactory.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ethereum/build/Patient.json

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions ethereum/compile.js
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]
);
}
68 changes: 68 additions & 0 deletions ethereum/contracts/HippoCampus.sol
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;
}

}
26 changes: 26 additions & 0 deletions ethereum/deploy.js
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();
9 changes: 9 additions & 0 deletions ethereum/factory.js
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;
18 changes: 18 additions & 0 deletions ethereum/web3.js
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;
15 changes: 15 additions & 0 deletions node_modules/.bin/JSONStream

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/JSONStream.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/_mocha

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/_mocha.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/acorn.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/ansi-html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/ansi-html.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/atob

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/atob.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/babylon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/babylon.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/browserslist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/browserslist.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/codeclimate-test-reporter

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/codeclimate-test-reporter.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/conventional-changelog-writer

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/conventional-changelog-writer.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/conventional-commits-parser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/conventional-commits-parser.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bb7ba64

Please sign in to comment.