I am trying to create the following objects:
Bounty[] public bounties;
struct Bounty {
address issuer;
uint256 fulfillmentAmount;
uint256 balance;
bool bountyOpen;
Fulfillment[] fulfillments;
mapping (bytes32 => bool) used;
}
struct Fulfillment {
uint256 fulfillmentAmount;
address fulfiller;
}
A brief explanation is that I want to have an array of "Bounties" which can be satisfied multiple times. Each bounty has a number of properties, one of which is an array of "Fulfillments". The fulfillments describe and store the different times the bounty was fulfilled.
When trying to create a new bounty, I use the following:
bounties.push(Bounty(msg.sender, _fulfillmentAmount, msg.value, true));
This gives me the error that I have one fewer parameters than needed to initialize the object, because I am missing the Fulfillment[]
array. (I do not need the mapping to be initialized.)
When I try to initialize with the array object like so:
bounties.push(Bounty(msg.sender, _fulfillmentAmount, msg.value, true, new Fullfillment[](0)));
I get the following error:
UnimplementedFeatureError: Copying of type struct ContractName.Fulfillment memory[] memory to storage not yet supported.
I have looked at a number of similar questions: [1] [2] [3]
They seem to imply that creating an object like this is not supported.
Instead, I could turn Fullfillment[] fulfillments
into:
uint fulfillmentLength;
mapping(uint => Fullfilment) fullfillments;
Keeping track of the length myself and doing some tricks to replace push()
.
Is this the best practice here? Or should I look at other alternatives like having the fulfillments
be an object outside of the Bounty
.
This is what Bounties-Network/StandardBounties
seems to do:
https://github.com/Bounties-Network/StandardBounties/blob/master/contracts/StandardBounties.sol
Looking for best practice advice here.