Skip to content

Commit

Permalink
DAPP sample project
Browse files Browse the repository at this point in the history
  • Loading branch information
halokid committed Nov 28, 2022
1 parent ebbf411 commit 64f6f58
Show file tree
Hide file tree
Showing 7 changed files with 1,186 additions and 0 deletions.
69 changes: 69 additions & 0 deletions web3/brownie_sample/brownie-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
project_structure:
build: build
contracts: contracts
interfaces: interfaces
reports: reports
scripts: scripts
tests: tests

networks:
default: goerli-alchemy
development:
gas_limit: max
gas_buffer: 1
gas_price: 0
max_fee: null
priority_fee: null
reverting_tx_gas_limit: max
default_contract_owner: true
cmd_settings: null
live:
gas_limit: auto
gas_buffer: 1.1
gas_price: auto
max_fee: null
priority_fee: null
reverting_tx_gas_limit: false
default_contract_owner: false

compiler:
evm_version: null
solc:
version: null
optimizer:
enabled: true
runs: 200
remappings: null
vyper:
version: null

console:
show_colors: true
color_style: monokai
auto_suggest: true
completions: true
editing_mode: emacs

reports:
exclude_paths: null
exclude_contracts: null
only_include_project: true

hypothesis:
deadline: null
max_examples: 50
report_multiple_bugs: False
stateful_step_count: 10
phases:
explicit: true
reuse: true
generate: true
target: true
shrink: true

autofetch_sources: false
dependencies: null
dev_deployment_artifacts: false



674 changes: 674 additions & 0 deletions web3/vote-dapp/LICENSE

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions web3/vote-dapp/Vote.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity =0.8.7;

contract Vote {

event Voted(address indexed voter, uint8 proposal);

mapping(address => bool) public voted;

uint256 public endTime;

uint256 public proposalA;
uint256 public proposalB;
uint256 public proposalC;

constructor(uint256 _endTime) {
endTime = _endTime;
}

function vote(uint8 _proposal) public {
require(block.timestamp < endTime, "Vote expired.");
require(_proposal >= 1 && _proposal <= 3, "Invalid proposal.");
require(!voted[msg.sender], "Cannot vote again.");
voted[msg.sender] = true;
if (_proposal == 1) {
proposalA ++;
}
else if (_proposal == 2) {
proposalB ++;
}
else if (_proposal == 3) {
proposalC ++;
}
emit Voted(msg.sender, _proposal);
}

function votes() public view returns (uint256) {
return proposalA + proposalB + proposalC;
}
}


44 changes: 44 additions & 0 deletions web3/vote-dapp/contracts/Vote.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity =0.8.7;

contract Vote {

event Voted(address indexed voter, uint8 proposal);

mapping(address => bool) public voted;

uint256 public endTime;

uint256 public proposalA;
uint256 public proposalB;
uint256 public proposalC;

constructor(uint256 _endTime) {
endTime = _endTime;
}

function vote(uint8 _proposal) public {
require(block.timestamp < endTime, "Vote expired.");
require(_proposal >= 1 && _proposal <= 3, "Invalid proposal.");
require(!voted[msg.sender], "Cannot vote again.");
voted[msg.sender] = true;
if (_proposal == 1) {
proposalA ++;
}
else if (_proposal == 2) {
proposalB ++;
}
else if (_proposal == 3) {
proposalC ++;
}
emit Voted(msg.sender, _proposal);
}

function votes() public view returns (uint256) {
return proposalA + proposalB + proposalC;
}
}



Binary file added web3/vote-dapp/favicon.ico
Binary file not shown.
Loading

0 comments on commit 64f6f58

Please sign in to comment.