4

I don't how initalize a variable with empty array ?

I have two structures :

    struct Concour {
    string theme;
    address admin;
    uint dateEndInscription;
    uint dateEndBet;
    uint dateResults;
    uint phase;
    Vin[] validatedVins;
    Vin[] proposedVins;
}

struct Vin {
    string url;
    uint nb_view_begin;
    uint nb_view_end;
}

And my function

function createConcour(string _theme, uint _dateEndInscription, uint _dateEndBet, uint _dateResults) {
        concours.push(Concour({
            theme: _theme,
            admin: msg.sender,
            dateEndInscription: _dateEndInscription,
            dateEndBet: _dateEndBet,
            dateResults: _dateResults,
            phase: 1,
            validatedVins: //empty list of vins hir,
            proposedVins: //maybe like this ? new Vin[](0)
        }));
    }
1

To initiate an array new string[](0) will works. But for a struct it won't. I guess the compiler tells you something like that.

Copying of type struct Test.Vin memory[] memory to storage not yet supported.

The solution here would be to instead of storing an array of Vin into Concour to store an array of bytes32 containing keys (or reference) to your Vin.

struct Concour {
    string theme;
    address admin;
    uint dateEndInscription;
    uint dateEndBet;
    uint dateResults;
    uint phase;
    bytes32[] validatedVins; // list of Vin keys
    bytes32[] proposedVins; // list of Vin keys
}

Then you'll have to write setters and getters to retrieve and write your data. I recommend you to check this article on Medium for more information about this pattern.

  • Yes i had exactely this message "Copying of type struct Test.Vin memory[] memory to storage not yet supported." Thanks i will try this solution – Charles Bourrée Jun 9 '17 at 7:29

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.