Skip to content

Commit

Permalink
added contract and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh11515 committed Feb 8, 2023
1 parent 4db4695 commit 97be9a8
Show file tree
Hide file tree
Showing 11 changed files with 532 additions and 1,053 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions contracts/.keystore/dinesh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"e643cf465ede9ad11e152bab8d3cdc6cbc3712e1","id":"7b1c4539-2590-487b-a185-a80cd9ec6803","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"1604473865ba5ae684d58ce0dc53400e"},"ciphertext":"4c98240a7df683c3e5eba5194fcc91decaaa46318420dcb431cb47fb5f705054","kdf":"scrypt","kdfparams":{"salt":"c4925ac4115a60e3e7181a1ec7777aaedb404ffe8af9089372bc430436cfa111","n":131072,"dklen":32,"p":1,"r":8},"mac":"4ba3f626b20ec10e973ade9c3375b11243ec82d46ed5acee50d9aaed634fd4f7"},"x-ethers":{"client":"ethers.js","gethFilename":"UTC--2023-02-08T05-02-54.0Z--e643cf465ede9ad11e152bab8d3cdc6cbc3712e1","mnemonicCounter":"62f51230c6b456199c87b3c6183648e6","mnemonicCiphertext":"eb67bf6a3fb736177f455acf202a6a74","path":"m/44'/60'/0'/0/0","locale":"en","version":"0.1"}}
117 changes: 117 additions & 0 deletions contracts/contracts/LinkPay.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract LinkPay {
struct Payment {
address sender;
address receiver;
uint256 amount;
uint256 timestamp;
string tokenName;
}

struct tokenDetails {
address tokenAddress;
string tokenName;
}

struct User {
address userAddress;
string image;
string name;
string bio;
string twitter;
uint256 totalReceived;
uint256 totalSent;
}

mapping(string => User) public users;
mapping(address => string) public addressToUsername;
mapping(address => Payment[]) public paymentsByAddress;
mapping(string => tokenDetails[]) public acceptableTokens;

Payment[] public payments;

function generateLink(
string memory _username,
string memory _image,
string memory _name,
string memory _bio,
string memory _twitter,
tokenDetails[] memory _tokens
) public {
require(bytes(_username).length > 0, "Username cannot be empty");
require(bytes(_name).length > 0, "Name cannot be empty");
require(bytes(_bio).length > 0, "Bio cannot be empty");
require(bytes(_twitter).length > 0, "Twitter cannot be empty");
require(
bytes(addressToUsername[msg.sender]).length == 0,
"Address already exists"
);

users[_username] = User(
msg.sender,
_image,
_name,
_bio,
_twitter,
0,
0
);

for (uint256 i = 0; i < _tokens.length; i++) {
acceptableTokens[_username].push(_tokens[i]);
}

addressToUsername[msg.sender] = _username;
}

function getDetailsByName(string memory _username)
public
view
returns (User memory)
{
return users[_username];
}

function getDetailsByAddress(address _address)
public
view
returns (User memory)
{
return users[addressToUsername[_address]];
}

function payToUser(
string memory _username,
uint256 _amount,
address tokenAddress,
string memory _tokenName
) public {
require(_amount > 0, "Amount cannot be 0");
User storage user = users[_username];
require(user.userAddress != address(0), "User does not exist");
require(user.userAddress != msg.sender, "Cannot send to yourself");

Payment memory payment = Payment(
msg.sender,
user.userAddress,
_amount,
block.timestamp,
_tokenName
);
user.totalReceived += _amount;
users[addressToUsername[msg.sender]].totalSent += _amount;
paymentsByAddress[msg.sender].push(payment);
payments.push(payment);

ERC20 token = ERC20(tokenAddress);
token.transferFrom(
msg.sender,
user.userAddress,
_amount * (10**token.decimals())
);
}
}
34 changes: 0 additions & 34 deletions contracts/contracts/Lock.sol

This file was deleted.

10 changes: 10 additions & 0 deletions contracts/contracts/MyToken.test.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
constructor() ERC20("MyToken", "DIN") {
_mint(msg.sender, 1000 * 10**decimals());
}
}
2 changes: 1 addition & 1 deletion contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

import "hardhat-secure-accounts";
const config: HardhatUserConfig = {
solidity: "0.8.17",
};
Expand Down
Loading

1 comment on commit 97be9a8

@vercel
Copy link

@vercel vercel bot commented on 97be9a8 Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

linkpay – ./

linkpay.vercel.app
linkpay-dinesh11515.vercel.app
linkpay-git-main-dinesh11515.vercel.app

Please sign in to comment.