TransWikia.com

How to add a field to a struct dynamically?

Ethereum Asked by Alireza Zojaji on December 24, 2020

Suppose we have a proxy contract that separates Data layer from Logic layer.
We have a struct in Data contract, like this:

struct person {
    uint id;
    string name;
}
mapping(address => person) persons;

We have deployed this contract and the Dapp users have entered data in it.

Now suppose we want to change the logic contract and add a birth_year field to the struct. how can we make this change to the struct dynamically? Its final form would be as follows:

struct person {
    uint id;
    string name;
    uint birth_year;
}
mapping(address => person) persons;

Even assembly language is acceptable, but sure Solidity is better.

One Answer

This is typically possible in interpreted languages like Python and Javascript.

And it is typically not possible in strongly-typed languages like C and Solidity.

Answered by goodvibration on December 24, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP