Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't use tx.origin, remove redundant functions #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions packages/form-XChange/contracts/FeedbackForm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,32 @@ contract FeedbackForm {
mapping(uint => Question) public questions;
mapping(address => bool) public feedbackProviders;

constructor(string memory _title, string memory _description) {
owner = tx.origin;
constructor(
address _owner,
string memory _title,
string memory _description
) {
owner = _owner;
title = _title;
description = _description;
}

modifier onlyOwner() {
require(tx.origin == owner, "Only owner can call this function.");
require(msg.sender == owner, "Only owner can call this function.");
_;
}

modifier hasProvidedFeedback() {
require(!feedbackProviders[tx.origin], "User has already prvoded feedback.");
require(
!feedbackProviders[msg.sender],
"User has already prvoded feedback."
);
_;
}

function getHasProvidedFeedback(address _address) public view returns (bool) {
function getHasProvidedFeedback(
address _address
) public view returns (bool) {
return feedbackProviders[_address];
}

Expand All @@ -52,11 +61,7 @@ contract FeedbackForm {
return (questions[_id].value, questions[_id].feedback);
}

function getAllQuestions()
public
view
returns (Question[] memory)
{
function getAllQuestions() public view returns (Question[] memory) {
Question[] memory allQuestions = new Question[](numberOfQuestions);
for (uint i; i < numberOfQuestions; i++) {
allQuestions[i] = questions[i];
Expand Down
16 changes: 5 additions & 11 deletions packages/form-XChange/contracts/FeedbackFormFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ contract FeedbackFormFactory {
string memory _title,
string memory _description
) public returns (FeedbackForm) {
FeedbackForm feedbackForm = new FeedbackForm(_title, _description);
FeedbackForm feedbackForm = new FeedbackForm(
msg.sender,
_title,
_description
);
feedbackForm.setQuestions(_questions);
feedbackForms.push(feedbackForm);
return feedbackForm;
Expand All @@ -24,14 +28,4 @@ contract FeedbackFormFactory {
function getFeedbackFormById(uint _id) public view returns (FeedbackForm) {
return feedbackForms[_id];
}

function getAllQuestions(
uint _id
) public view returns (FeedbackForm.Question[] memory) {
return feedbackForms[_id].getAllQuestions();
}

function submitFeedback(uint _id, uint[] memory _feedback) public {
feedbackForms[_id].submitFeedback(_feedback);
}
}