Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated the hackathon project issue #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ TEAM NAME-PROJECT NAME

The Three Amigo - modernhospital
HACKBIT - khana_bachao

The Wanderers- Stunation
12 changes: 12 additions & 0 deletions The Wanderers/Auction-master/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
]
}
21 changes: 21 additions & 0 deletions The Wanderers/Auction-master/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"parserOptions": {
"parser": "babel-eslint"
},
"extends": [
"airbnb-base",
"plugin:vue/recommended"
],
"rules": {
"no-console": "off",
},
"globals": {
"ethereum": true,
"web3": true,
},
};
12 changes: 12 additions & 0 deletions The Wanderers/Auction-master/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.DS_Store
node_modules/
dist/
npm-debug.log
yarn-error.log

# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
138 changes: 138 additions & 0 deletions The Wanderers/Auction-master/contracts/AuctionBox.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// We will be using Solidity version 0.5.3
pragma solidity 0.5.3;
// Importing OpenZeppelin's SafeMath Implementation
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";

contract AuctionBox{
Auction[] public auctions;

function createAuction (
string memory _title,
uint _startPrice,
string memory _description
) public{
require(_startPrice > 0);
// set the new instanc
Auction newAuction = new Auction(msg.sender, _title, _startPrice, _description);
// push the auction address to auctions array
auctions.push(newAuction);
}

function returnAllAuctions() public view returns(Auction[] memory){
return auctions;
}
}

contract Auction {

using SafeMath for uint256;

address payable private owner;
string title;
uint startPrice;
string description;

enum State{Default, Running, Finalized}
State public auctionState;

uint public highestPrice;
address payable public highestBidder;
mapping(address => uint) public bids;

/** @dev constructor to creat an auction
* @param _owner who call createAuction() in AuctionBox contract
* @param _title the title of the auction
* @param _startPrice the start price of the auction
* @param _description the description of the auction
*/

constructor(
address payable _owner,
string memory _title,
uint _startPrice,
string memory _description

) public {
// initialize auction
owner = _owner;
title = _title;
startPrice = _startPrice;
description = _description;
auctionState = State.Running;
}

modifier notOwner(){
require(msg.sender != owner);
_;
}

/** @dev Function to place a bid
* @return true
*/

function placeBid() public payable notOwner returns(bool) {
require(auctionState == State.Running);
require(msg.value > 0);
// update the current bid
// uint currentBid = bids[msg.sender] + msg.value;
uint currentBid = bids[msg.sender].add(msg.value);
require(currentBid > highestPrice);
// set the currentBid links with msg.sender
bids[msg.sender] = currentBid;
// update the highest price
highestPrice = currentBid;
highestBidder = msg.sender;

return true;
}

function finalizeAuction() public{
//the owner and bidders can finalize the auction.
require(msg.sender == owner || bids[msg.sender] > 0);

address payable recipiant;
uint value;

// owner can get highestPrice
if(msg.sender == owner){
recipiant = owner;
value = highestPrice;
}
// highestBidder can get no money
else if (msg.sender == highestBidder){
recipiant = highestBidder;
value = 0;
}
// Other bidders can get back the money
else {
recipiant = msg.sender;
value = bids[msg.sender];
}
// initialize the value
bids[msg.sender] = 0;
recipiant.transfer(value);
auctionState = State.Finalized;
}

/** @dev Function to return the contents od the auction
* @return the title of the auction
* @return the start price of the auction
* @return the description of the auction
* @return the state of the auction
*/

function returnContents() public view returns(
string memory,
uint,
string memory,
State
) {
return (
title,
startPrice,
description,
auctionState
);
}

}
64 changes: 64 additions & 0 deletions The Wanderers/Auction-master/contracts/auctionBoxInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import web3 from './web3';

const address = '0x2c65a8e0e59b72b0f4207d28daa986c719753ae9'; // THE CONTRACT ADDRESS
const abi = [
{
constant: false,
inputs: [
{
name: '_title',
type: 'string'
},
{
name: '_startPrice',
type: 'uint256'
},
{
name: '_description',
type: 'string'
}
],
name: 'createAuction',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
},
{
constant: true,
inputs: [
{
name: '',
type: 'uint256'
}
],
name: 'auctions',
outputs: [
{
name: '',
type: 'address'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'returnAllAuctions',
outputs: [
{
name: '',
type: 'address[]'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
}
]; // THE ABI

const instance = new web3.eth.Contract(abi, address);

export default instance;
Loading