-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
16,098 additions
and
4,419 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
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 |
---|---|---|
@@ -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. |
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,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; | ||
} | ||
} |
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,6 @@ | ||
require("@nomicfoundation/hardhat-toolbox"); | ||
|
||
/** @type import('hardhat/config').HardhatUserConfig */ | ||
module.exports = { | ||
solidity: "0.8.18", | ||
}; |
Oops, something went wrong.