You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unable to initialize empty mapping as described in solidity documentation. Using solana.
campaigns[campaignID] = Campaign(beneficiary, goal, 0, 0); gives error on line 25 - "struct 'Campaign' has 5 fields, not 4"
Also tried using curly brace syntax and still getting an error.
Will appreciate it if someone can let me know how to work around this.
Complete code below, it is just copied from solidity docs.
contract CrowdFunding {
// Defines a new type with two fields.
struct Funder {
address addr;
uint amount;
}
struct Campaign {
address beneficiary;
uint fundingGoal;
uint numFunders;
uint amount;
mapping (uint => Funder) funders;
}
uint numCampaigns;
mapping (uint => Campaign) campaigns;
function newCampaign(address beneficiary, uint goal) public returns (uint campaignID) {
campaignID = numCampaigns++; // campaignID is return variable
// Creates new struct and saves in storage. We leave out the mapping type.
// ========== ERROR BELOW ===========
// campaigns[campaignID] = Campaign(beneficiary, goal, 0, 0);
campaigns[campaignID] = Campaign({
beneficiary: beneficiary,
fundingGoal: goal,
numFunders: 0,
amount: 0
});
}
function contribute(uint campaignID) public payable {
Campaign storage c = campaigns[campaignID];
// Creates a new temporary memory struct, initialised with the given values
// and copies it over to storage.
// Note that you can also use Funder(msg.sender, msg.value) to initialise.
c.funders[c.numFunders++] = Funder({addr: msg.sender, amount: msg.value});
c.amount += msg.value;
}
function checkGoalReached(uint campaignID) public returns (bool reached) {
Campaign storage c = campaigns[campaignID];
if (c.amount < c.fundingGoal)
return false;
uint amount = c.amount;
c.amount = 0;
//c.beneficiary.transfer(amount);
return true;
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Unable to initialize empty mapping as described in solidity documentation. Using solana.
campaigns[campaignID] = Campaign(beneficiary, goal, 0, 0); gives error on line 25 - "struct 'Campaign' has 5 fields, not 4"
Also tried using curly brace syntax and still getting an error.
Will appreciate it if someone can let me know how to work around this.
Complete code below, it is just copied from solidity docs.
https://ethereum.stackexchange.com/questions/62784/how-to-initialize-a-new-struct-with-an-empty-mapping
Beta Was this translation helpful? Give feedback.
All reactions