-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from obscuronet/pedro/guessing_game_v2
Guessing Game v2
- Loading branch information
Showing
32 changed files
with
12,227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Deploy Number Guessing Game v2 | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
address: | ||
description: 'Contract Address' | ||
required: true | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
working-directory: ./guessing-game-v2 | ||
|
||
- name: Write Address to JSON | ||
run: | | ||
echo '{"address": "${{ github.event.inputs.address }}"}' > ./guessing-game-v2/src/assets/contract/address.json | ||
- name: Build application | ||
run: npm run build | ||
working-directory: ./guessing-game-v2 | ||
|
||
- name: Deploy | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./guessing-game-v2/dist | ||
destination_dir: ./guessing-game-v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
**/number-guessing-game/deployments | ||
**/number-guessing-game/typechain-types | ||
|
||
.idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-env node */ | ||
require('@rushstack/eslint-patch/modern-module-resolution') | ||
|
||
module.exports = { | ||
root: true, | ||
'extends': [ | ||
'plugin:vue/vue3-essential', | ||
'eslint:recommended', | ||
'@vue/eslint-config-prettier/skip-formatting' | ||
], | ||
parserOptions: { | ||
ecmaVersion: 'latest' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
coverage | ||
*.local | ||
|
||
/cypress/videos/ | ||
/cypress/screenshots/ | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/prettierrc", | ||
"semi": false, | ||
"tabWidth": 2, | ||
"singleQuote": true, | ||
"printWidth": 100, | ||
"trailingComma": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# guessing-game-v2 | ||
|
||
This template should help get you started developing with Vue 3 in Vite. | ||
|
||
## Recommended IDE Setup | ||
|
||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin). | ||
|
||
## Customize configuration | ||
|
||
See [Vite Configuration Reference](https://vitejs.dev/config/). | ||
|
||
## Project Setup | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
### Compile and Hot-Reload for Development | ||
|
||
```sh | ||
npm run dev | ||
``` | ||
|
||
### Compile and Minify for Production | ||
|
||
```sh | ||
npm run build | ||
``` | ||
|
||
### Lint with [ESLint](https://eslint.org/) | ||
|
||
```sh | ||
npm run lint | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract GuessingGame { | ||
|
||
uint256 private secretNumber; | ||
address private owner; | ||
uint256 public totalGuesses; | ||
uint256 public constant GUESS_FEE = 443e15; // 0.443 ETH | ||
|
||
event Guessed(address indexed user, uint256 guessedNumber, bool success); | ||
|
||
modifier onlyOwner() { | ||
require(msg.sender == owner, "Only the owner can call this function"); | ||
_; | ||
} | ||
|
||
constructor(uint256 _secretNumber) { | ||
require(_secretNumber > 0 && _secretNumber <= 1000, "Secret number should be between 1 and 1000"); | ||
secretNumber = _secretNumber; | ||
owner = msg.sender; | ||
} | ||
|
||
function guess(uint256 _number) external payable { | ||
require(_number > 0 && _number <= 1000, "Secret number should be between 1 and 1000"); | ||
require(msg.value == GUESS_FEE, "You need to send 0.443 ETH to make a guess"); | ||
totalGuesses += 1; | ||
|
||
if (_number == secretNumber) { | ||
// If the guess is correct, transfer all the contract balance to the user | ||
payable(msg.sender).transfer(address(this).balance); | ||
emit Guessed(msg.sender, _number, true); | ||
} else { | ||
emit Guessed(msg.sender, _number, false); | ||
} | ||
} | ||
|
||
function setSecretNumber(uint256 _newSecret) external onlyOwner { | ||
require(_newSecret > 0 && _newSecret <= 1000, "Secret number should be between 1 and 1000"); | ||
secretNumber = _newSecret; | ||
} | ||
|
||
function getContractBalance() external view returns (uint256) { | ||
return address(this).balance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @type import('hardhat/config').HardhatUserConfig */ | ||
module.exports = { | ||
solidity: "0.8.19", | ||
paths: { | ||
sources: "./contracts", | ||
artifacts: "./src/assets/contract/artifacts" | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<link rel="icon" href="/src/assets/icons/favicon.ico"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Obscuro's Guessing Game</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.js"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.