Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MTthoas committed Mar 21, 2024
2 parents 7b9c2c9 + d1d4199 commit 2848f9a
Show file tree
Hide file tree
Showing 34 changed files with 953 additions and 10,035 deletions.
4 changes: 0 additions & 4 deletions .prettierignore

This file was deleted.

1 change: 0 additions & 1 deletion .prettierrc

This file was deleted.

24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Annual project focused on creating a complete decentralized application (dApp) t
- npm
- Wallet ( metamask / trust .. )

<<<<<<< HEAD
## Technologies

To the global web architecture we're using foundry.Foundry manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the command-line and via Solidity scripts.
Expand Down Expand Up @@ -41,6 +42,8 @@ We're using React to create the frontend of the dApp. We're using TypeScript to

We're using Docker to run the API and the smart contracts on the same network.

=======
>>>>>>> develop
## Structure
```
├── contracts
Expand Down Expand Up @@ -68,6 +71,7 @@ We're using Docker to run the API and the smart contracts on the same network.
└── styles
```

<<<<<<< HEAD
## Installation

### 1. Clone the repository
Expand Down Expand Up @@ -101,4 +105,22 @@ npm run deploy
cd ./frontend
npm i
npm start
```
```
=======
















>>>>>>> develop
4 changes: 4 additions & 0 deletions api/.env.local
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
# Server settings:
SERVER_URL="0.0.0.0:5000"
SERVER_READ_TIMEOUT=60
Expand All @@ -14,3 +15,6 @@ DB_MAX_LIFETIME_CONNECTIONS=2

# CoinGecko settings:
API_URL=https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&category=ethereum-ecosystem&x_cg_demo_api_key=
=======
API_URL=https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&category=ethereum-ecosystem&x_cg_demo_api_key=
>>>>>>> develop
2 changes: 1 addition & 1 deletion api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.env
docs
build
*.out
*.out
19 changes: 8 additions & 11 deletions api/services/token.service.go → api/services/tokenService.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand All @@ -19,7 +19,7 @@ func goDotEnvVariable(key string) string {
err := godotenv.Load(".env")

if err != nil {
log.Fatalf("Error loading .env file")
log.Fatal("Error loading .env file")
}

return os.Getenv(key)
Expand All @@ -31,29 +31,26 @@ func ScrapeEthereumTokens() []models.Token {

resp, err := http.Get(apiUrl)
if err != nil {
fmt.Println("Erreur lors de la requête GET :", err)
log.Printf("Erreur lors de la requête GET : %v", err)
return nil
}
defer resp.Body.Close()

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal("Erreur lors de la lecture de la réponse :", err)
log.Fatalf("Erreur lors de la lecture de la réponse : %v", err)
}
bodyString := string(bodyBytes)
fmt.Println("Réponse brute de l'API :", bodyString)

// Réinitialiser le body pour le décodage JSON
resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
resp.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

// Décoder le JSON reçu
var tokens []models.Token
err = json.NewDecoder(resp.Body).Decode(&tokens)
if err != nil {
fmt.Println("Erreur lors du décodage JSON :", err)
log.Fatalf("Erreur lors de la lecture de la réponse : %v", err)
}

// Afficher les tokens récupérés pour le debug
fmt.Println("Tokens récupérés :", tokens)

return tokens
}
2 changes: 2 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
src = "src"
out = "out"
libs = ["lib"]
remappings = ["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/"]


# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
[remappings]
Expand Down
1 change: 1 addition & 0 deletions contracts/lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at dbb610
2 changes: 1 addition & 1 deletion contracts/script/Counter.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console2} from "forge-std/Script.sol";
import {Script, console} from "forge-std/Script.sol";

contract CounterScript is Script {
function setUp() public {}
Expand Down
124 changes: 124 additions & 0 deletions contracts/src/UserRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

/**
* @title UserRegistry
* @author ronfflex
* @notice This contract manages user registration, authentication, and administration for a decentralized exchange (DEX) platform.
*/
contract UserRegistry is Ownable {
using EnumerableSet for EnumerableSet.UintSet;

mapping(address => User) public users;

// Set to store registered user IDs
EnumerableSet.UintSet private registeredUserIds;

struct User {
uint256 id;
string name;
bool isBanned;
}

constructor() Ownable(msg.sender) {}

// Events to log
event UserRegistered(address indexed userAddress, uint256 userId);
event UserBanned(address indexed userAddress, uint256 userId);
event UserUnbanned(address indexed userAddress, uint256 userId);

/**
* @notice Gets the user IDs of all registered users.
* @return uint256[] An array of user IDs.
*/
function getRegisteredUserIds() public view returns (uint256[] memory) {
return registeredUserIds.values();
}

/**
* @notice Registers a new user with the provided name.
* @param _name The name of the user.
*/
function registerUser(string memory _name) public {
require(users[msg.sender].id == 0, "User already registered");

uint256 userId = registeredUserIds.length() + 1;
users[msg.sender] = User(userId, _name, false);
registeredUserIds.add(userId);

emit UserRegistered(msg.sender, userId);
}

/**
* @notice Checks if the given address is a registered user.
* @param _address The address to check.
* @return bool True if the address is a registered user, false otherwise.
*/
function isRegisteredUser(address _address) public view returns (bool) {
return users[_address].id != 0;
}

/**
* @notice Gets the user ID associated with the given address.
* @param _address The address of the user.
* @return uint256 The user ID.
*/
function getUserId(address _address) public view returns (uint256) {
return users[_address].id;
}

/**
* @notice Bans the user with the given address.
* @param _userAddress The address of the user to ban.
*/
function banUser(address _userAddress) public onlyOwner {
require(isRegisteredUser(_userAddress), "User not registered");

users[_userAddress].isBanned = true;

emit UserBanned(_userAddress, users[_userAddress].id);
}

/**
* @notice Unbans the user with the given address.
* @param _userAddress The address of the user to unban.
*/
function unbanUser(address _userAddress) public onlyOwner {
require(isRegisteredUser(_userAddress), "User not registered");
require(users[_userAddress].isBanned, "User not banned");

users[_userAddress].isBanned = false;

emit UserUnbanned(_userAddress, users[_userAddress].id);
}

/**
* @notice Checks if the given user is banned.
* @param _userAddress The address of the user.
* @return bool True if the user is banned, false otherwise.
*/
function isUserBanned(address _userAddress) public view returns (bool) {
return isRegisteredUser(_userAddress) && users[_userAddress].isBanned;
}

/**
* @notice Transfers the user ID from the old address to the new address.
* @param _oldAddress The old address of the user.
* @param _newAddress The new address of the user.
*/
function transferUserId(address _oldAddress, address _newAddress) public onlyOwner {
require(isRegisteredUser(_oldAddress), "Old address not registered");
require(!isRegisteredUser(_newAddress), "New address already registered");

uint256 userId = users[_oldAddress].id;
string memory name = users[_oldAddress].name;

delete users[_oldAddress];
users[_newAddress] = User(userId, name, false);

emit UserRegistered(_newAddress, userId);
}
}
2 changes: 1 addition & 1 deletion contracts/test/Counter.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console2} from "forge-std/Test.sol";
import {Test, console} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";

contract CounterTest is Test {
Expand Down
Loading

0 comments on commit 2848f9a

Please sign in to comment.