Skip to content

Commit

Permalink
Add basic solidity db contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranay Tulugu committed Aug 28, 2023
1 parent e8d691e commit 6c35728
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions solidity/contracts/AltheaDB.sol
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];
}
}

0 comments on commit 6c35728

Please sign in to comment.