Skip to content

Commit

Permalink
initial_commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ans155 committed May 30, 2023
1 parent 0f8d742 commit 440744b
Show file tree
Hide file tree
Showing 8 changed files with 16,098 additions and 4,419 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts

39 changes: 9 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
# Sample Hardhat Project

## Getting Started
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract.

First, run the development server:
Try running some of the following tasks:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat run scripts/deploy.js
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
67 changes: 67 additions & 0 deletions contracts/chatApp.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX_License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

contract ChatApp{

//USER STRUCT
struct user {
string name;
friend[] friendList;

}
struct friend{
address pubkey;
string name;

}
struct message{
address sender;
uint256 timestamp;
string msg;
}

mapping(address => user) userList;
mapping(bytes32 => message[]) allMessages;

function checkUserExists(address pubkey ) public view returns(bool)
{
return bytes(userList[pubkey].name).length>0;
}

function createAccount(string calldata name) external {
require(checkUserExists(msg.sender) == false, "User already exists");
require(bytes(name).length>0, "Username cannot be empty");
userList[msg.sender].name =name;
}
function getUsername(address pubkey) external view returns(string memory)
{
require(checkUserExists(pubkey), "User is not registered");
return userList[pubkey].name;
}
function addFriend(address friend_key, string calldata name) external {
require(checkUserExists(msg.sender), "Create an account first");
require(checkUserExists(friend_key), "User is not registered");
require(msg.sender !=friend_key, "User cannot add themselves");
require(checkAlreadyFriends(msg.sender, friend_key)==false, "These users are already friend");
_addFriend(msg.sender, friend_key, name);
_addFriend(friend_key, msg.sender, userList[msg.sender]. name);
}

function checkAlreadyFriends(address pubkey1, address pubkey2) internal view returns(bool)
{
if(userList[pubkey1].friendList.length > userList[pubkey2].friendList.length)
{
address tmp=pubkey1;
pubkey1=pubkey2;
pubkey2=tmp;
}

for(uint256 i=0; i<userList[pubkey1].friendList.length;i++)
{
if(userList[pubkey1].friendList[i].pubkey = pubkey2)
return true;
}
return false;
}
}
6 changes: 6 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.18",
};
Loading

0 comments on commit 440744b

Please sign in to comment.