This question was asked here but I thought I would make it a little more clear. Is it possible to access the funders
mapping (bolded) via Truffle console in the code below ? This is taken from the Solidity docs:
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) returns (uint campaignID) {
campaignID = numCampaigns++; // campaignID is return variable
// Creates new struct and saves in storage. We leave out the mapping type.
campaigns[campaignID] = Campaign(beneficiary, goal, 0, 0);
}
function contribute(uint campaignID) 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;
}
After you run newCampaign
and contribute
to add funds to the newly created campaign, the object returned back is below:
[ '0x740bd112e4d310a69aae3cee9ca8e72d1b1f8a21',
{ [String: '15000'] s: 1, e: 4, c: [ 15000 ] },
{ [String: '5'] s: 1, e: 0, c: [ 5 ] },
{ [String: '16000'] s: 1, e: 4, c: [ 16000 ] },
{ [String: '1504125631'] s: 1, e: 9, c: [ 1504125631 ] } ]
All the variables in the Campaign
struct are visible except for the funders
variable. Is this because funders
is not initialized in storage perhaps?