-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pranay Tulugu
committed
Aug 28, 2023
1 parent
e8d691e
commit 6c35728
Showing
1 changed file
with
62 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,62 @@ | ||
//SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity 0.8.21; // Force solidity compliance | ||
|
||
contract AltheaDB { | ||
struct Identity { | ||
string mesh_ip; | ||
string wg_key; | ||
address eth_addr; | ||
string nickname; | ||
} | ||
|
||
Identity[] private registered_users; | ||
mapping(string => Identity) private wg_key_to_reg_users_map; | ||
mapping(string => Identity) private mesh_ip_to_reg_users_map; | ||
mapping(address => Identity) private eth_addr_to_reg_users_map; | ||
|
||
// Add a new registered user | ||
function add_registered_user( | ||
string memory mesh_ip, | ||
string memory wg_key, | ||
address eth_addr, | ||
string memory nickname | ||
) public { | ||
Identity memory new_client = Identity( | ||
mesh_ip, | ||
wg_key, | ||
eth_addr, | ||
nickname | ||
); | ||
registered_users.push(new_client); | ||
wg_key_to_reg_users_map[wg_key] = new_client; | ||
mesh_ip_to_reg_users_map[mesh_ip] = new_client; | ||
eth_addr_to_reg_users_map[eth_addr] = new_client; | ||
} | ||
|
||
// Get all registered users | ||
function get_all_registered_users() | ||
public | ||
view | ||
returns (Identity[] memory) | ||
{ | ||
return registered_users; | ||
} | ||
|
||
function get_registered_client_with_wg_key( | ||
string memory wg_key | ||
) public view returns (Identity memory) { | ||
return wg_key_to_reg_users_map[wg_key]; | ||
} | ||
|
||
function get_registered_client_with_mesh_ip( | ||
string memory mesh_ip | ||
) public view returns (Identity memory) { | ||
return mesh_ip_to_reg_users_map[mesh_ip]; | ||
} | ||
|
||
function get_registered_client_with_eth_addr( | ||
address eth_addr | ||
) public view returns (Identity memory) { | ||
return eth_addr_to_reg_users_map[eth_addr]; | ||
} | ||
} |