Skip to content

Commit

Permalink
price added to chat contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
tempe-techie committed Sep 24, 2024
1 parent faa03c6 commit 72f0658
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 85 deletions.
18 changes: 14 additions & 4 deletions contracts/chat/ChatContextV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract ChatContextV1 is Ownable {
address public modTokenAddress; // NFT, SBT, or ERC-20 token which is used to determine if an address is a mod
uint256 public modMinBalance; // minimum balance of mod token required to be considered a mod
bool public paused = false; // whether the contract is paused or not
uint256 public price = 0.0001 ether; // price to post a message (can serve as anti-spam measure; can be set to 0 to disable)

Message[] public mainMessages; // array of main messages
mapping(uint256 => Message[]) public replies; // mapping from main message index to array of replies
Expand Down Expand Up @@ -171,10 +172,11 @@ contract ChatContextV1 is Ownable {
* @notice Create a new main message
* @param url_ The URL of the main message
*/
function createMessage(string memory url_) external {
function createMessage(string memory url_) external payable {
require(!paused, "Contract is paused");
require(!suspended[msg.sender], "You are suspended from posting");
require(bytes(url_).length > 0, "URL cannot be empty");
require(msg.value >= price, "Payment is less than the price");

Message memory newMsg = Message({
author: msg.sender,
Expand All @@ -194,11 +196,11 @@ contract ChatContextV1 is Ownable {
* @param mainMsgIndex_ The index of the main message to reply to
* @param url_ The URL of the reply message
*/
function createReply(uint256 mainMsgIndex_, string memory url_) external {
function createReply(uint256 mainMsgIndex_, string memory url_) external payable {
require(!paused, "Contract is paused");
require(!suspended[msg.sender], "You are suspended from posting");
require(bytes(url_).length > 0, "URL cannot be empty");

require(msg.value >= price, "Payment is less than the price");
Message memory newReply = Message({
author: msg.sender,
url: url_,
Expand Down Expand Up @@ -322,12 +324,20 @@ contract ChatContextV1 is Ownable {
}

// OWNER
function withdrawRevenue(address to_) external onlyOwner {
(bool success, ) = to_.call{value: address(this).balance}("");
require(success, "Transfer failed");
}

function setModTokenAddress(address modTokenAddress_) external onlyOwner {
modTokenAddress = modTokenAddress_;
}

function setModMinBalance(uint256 modMinBalance_) external onlyOwner {
modMinBalance = modMinBalance_;
}


function setPrice(uint256 price_) external onlyOwner {
price = price_;
}
}
13 changes: 12 additions & 1 deletion contracts/chat/CommentsContextV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract CommentsContextV1 is Ownable {
address public modTokenAddress; // NFT, SBT, or ERC-20 token which is used to determine if an address is a mod
uint256 public modMinBalance; // minimum balance of mod token required to be considered a mod
bool public paused = false; // whether the contract is paused or not
uint256 public price = 0.0001 ether; // price of a comment

mapping(address => Comment[]) public comments; // mapping from subject address to array of comments
mapping(address => bool) public suspended; // whether an address is suspended from posting or not
Expand Down Expand Up @@ -122,10 +123,11 @@ contract CommentsContextV1 is Ownable {
* @param subjectAddress_ The address of the comments subject (NFT, playlist etc.) to comment to
* @param url_ The URL of the comment
*/
function createComment(address subjectAddress_, string memory url_) external {
function createComment(address subjectAddress_, string memory url_) external payable {
require(!paused, "Contract is paused");
require(!suspended[msg.sender], "You are suspended from posting");
require(bytes(url_).length > 0, "URL cannot be empty");
require(msg.value >= price, "Payment is less than the price");

Comment memory newComment = Comment({
author: msg.sender,
Expand Down Expand Up @@ -223,12 +225,21 @@ contract CommentsContextV1 is Ownable {
}

// OWNER
function withdrawRevenue(address to_) external onlyOwner {
(bool success, ) = to_.call{value: address(this).balance}("");
require(success, "Transfer failed");
}

function setModTokenAddress(address modTokenAddress_) external onlyOwner {
modTokenAddress = modTokenAddress_;
}

function setModMinBalance(uint256 modMinBalance_) external onlyOwner {
modMinBalance = modMinBalance_;
}

function setPrice(uint256 price_) external onlyOwner {
price = price_;
}

}
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ module.exports = {
chainId: 11155111,
accounts: [process.env.DEPLOYER_PRIVATE_KEY],
gas: "auto", // gas limit
gasPrice: 80000000000, // 80 gwei
gasPrice: 20000000000, // 20 gwei
},
sokol: { // Gnosis Chain testnet
url: 'https://sokol.poa.network',
Expand Down
Loading

0 comments on commit 72f0658

Please sign in to comment.