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
This means that we can't simply assign the segments function argument in a declarative way. If we do that, we would get the following error:
UnimplementedFeatureError: Copying of type struct Segment memory[] memory to storage not yet supported.
However, there is a solution, and that is to iterate over the in-memory array elements and use the push function to push each element, one-by-one, to the storage array:
ProStream storage stream = _streams[streamId];
// other assignments of struct propertiesuint256 segmentCount = args.segments.length;
for (uint256 i =0; i < segmentCount; ++i) {
stream.segments.push(args.segments[i]);
}
There are several benefits in switching to an array of structs:
It is true that it is not currently possible to copy an in-memory array to storage:
UnimplementedFeatureError
with no line indication when copying an array of structs to storage ethereum/solidity#12783This means that we can't simply assign the
segments
function argument in a declarative way. If we do that, we would get the following error:However, there is a solution, and that is to iterate over the in-memory array elements and use the
push
function to push each element, one-by-one, to the storage array:There are several benefits in switching to an array of structs:
segments
is more succinct thansegmentAmounts
,segmentExponents
, andsegmentMilestones
.checkCreateProArgs
function, because we no longer have to ensure that the segment arrays are equal.The text was updated successfully, but these errors were encountered: