0

I've recently finished a course in smart contract and am trying to expand on the current project. One thing I'm trying to do is give more info into each campaign - things like, description, category, etc. I've modified my smart contract, but am running into an error, if you can help me take a look and point me towards the right direction, that'd be really appreciated! Also, if you can just take a look overall how I've modified the contracts to see if I have any redundancy anywhere, that'd be awesome. Cheers.

the error i'm getting on line 50 is - TypeError: Member "manager" not found or not visible after argument-dependent lookup in struct Campaign.NewCampaignType storage ref[] storage ref require(msg.sender == campaigns.manager);

pragma solidity ^0.4.17;

contract CampaignFactory {

struct NewCampaignType {
string description;
uint minimumContribution;
string campaignCategory;
string endDate;
address manager;
}

address[] public deployedCampaigns;

function createCampaign(string description, uint minimumContribution, string campaignCategory, string endDate) public {
address newlyCreatedCampaign = new Campaign(description, minimumContribution, campaignCategory, endDate, msg.sender);
deployedCampaigns.push(newlyCreatedCampaign);
}

function getDeployedCampaigns() public view returns (address[]) {
return deployedCampaigns;
}
}

contract Campaign {

struct NewCampaignType {
string description;
uint minimumContribution;
string campaignCategory;
string endDate;
address manager;
}

struct Request {
string description;
uint value;
address recipient;
bool complete;
uint approvalCount;
mapping(address => bool) approvals;
}

NewCampaignType[] public campaigns;
Request[] public requests;
mapping(address => bool) public approvers;
uint public approversCount;

modifier restricted() {
require(msg.sender == campaigns.manager);
_;
}

function Campaign(string description, uint minimumContribution, string campaignCategory, string endDate, address manager) public {
NewCampaignType memory createCampaign = NewCampaignType({
description: description,
minimumContribution: minimumContribution,
campaignCategory: campaignCategory,
endDate: endDate,
manager: manager
});
campaigns.push(createCampaign);
}

function contribute() public payable {
require(msg.value > campaigns.minimumContribution);

approvers[msg.sender] = true;
approversCount++;
}

function createRequest(string description, uint value, address recipient) public restricted {
Request memory newRequest = Request({
description: description,
value: value,
recipient: recipient,
complete: false,
approvalCount: 0
});

requests.push(newRequest);
}

function approveRequest(uint index) public {
Request storage request = requests[index];

require(approvers[msg.sender]);
require(!request.approvals[msg.sender]);

request.approvals[msg.sender] = true;
request.approvalCount++;
}

function finalizeRequest(uint index) public restricted {
Request storage request = requests[index];

require(request.approvalCount > (approversCount / 2));
require(!request.complete);

request.recipient.transfer(request.value);
request.complete = true;
}

function getSummary() public view returns (
uint, uint, uint, uint, address
) {
return (
campaigns.minimumContribution,
this.balance,
requests.length,
approversCount,
campaigns.manager
);
}

function getRequestsCount() public view returns (uint) {
return requests.length;
}
}
  • thanks ivicaa for the edit, sorry i'm relatively new to the whole thing, appreciate your help! – PLO Mar 12 '18 at 6:00
0

campaigns is an array.

Like the error said, an array doesn't have a member called manager.

  • ah ok, so i would need access the array then the property of manager in the object? thanks – PLO Mar 12 '18 at 6:00
  • Yes. campaigns[0].manager would be valid, as long as you had inserted at least one element into the campaigns array. – smarx Mar 12 '18 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.